Ejemplo n.º 1
0
        public void ComputeJwkThumbprintSpec()
        {
            // https://tools.ietf.org/html/rfc7638#section-3.1
            var context = TestUtilities.WriteHeader($"{this}.ComputeJwkThumbprintSpec", "", true);

            var jwk = new JsonWebKey()
            {
                Kty = JsonWebAlgorithmsKeyTypes.RSA,
                E   = "AQAB",
                N   = "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw"
            };

            var jwkThumbprint = jwk.ComputeJwkThumbprint();
            var base64UrlEncodedJwkThumbprint = Base64UrlEncoder.Encode(jwkThumbprint);

            var expectedJwkThumbprint = new byte[]
            {
                55, 54, 203, 177, 120, 124, 184, 48, 156, 119, 238, 140, 55, 5, 197,
                225, 111, 251, 158, 133, 151, 21, 144, 31, 30, 76, 89, 177, 17, 130,
                245, 123
            };
            var expectedBase64UrlEncodedThumbprint = "NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs";

            IdentityComparer.AreBytesEqual(jwkThumbprint, expectedJwkThumbprint, context);
            IdentityComparer.AreStringsEqual(base64UrlEncodedJwkThumbprint, expectedBase64UrlEncodedThumbprint, context);
            TestUtilities.AssertFailIfErrors(context);
        }
Ejemplo n.º 2
0
        public void RSASignVerifyData(RSACryptoServiceProviderProxyTheoryData theoryData)
        {
            var context = TestUtilities.WriteHeader($"{this}.RSASignVerifyData", theoryData);

            try
            {
                var proxy          = new RSACryptoServiceProviderProxy(theoryData.RsaCryptoServiceProvider);
                var signatureProxy = proxy.SignData(theoryData.Input, theoryData.HashAlgorithm);
                var signatureRsa   = theoryData.RsaCryptoServiceProvider.SignData(theoryData.Input, theoryData.HashAlgorithm);
                IdentityComparer.AreBytesEqual(signatureProxy, signatureRsa, context);
                if (!proxy.VerifyData(theoryData.Input, theoryData.HashAlgorithm, signatureRsa))
                {
                    context.AddDiff("!proxy.VerifyData(theoryData.Input, theoryData.HashAlgorithm, signatureRsa)");
                }

                if (!theoryData.RsaCryptoServiceProvider.VerifyData(theoryData.Input, theoryData.HashAlgorithm, signatureProxy))
                {
                    context.AddDiff("!theoryData.RsaCryptoServiceProvider.VerifyData(theoryData.Input, theoryData.HashAlgorithm, signatureProxy)");
                }
            }
            catch (Exception ex)
            {
                theoryData.ExpectedException.ProcessException(ex, context);
            }

            TestUtilities.AssertFailIfErrors(context);
        }
        public void CompareJwkThumbprints(JsonWebKeyConverterTheoryData theoryData)
        {
            var context = TestUtilities.WriteHeader($"{this}.CompareJwkThumbprints", theoryData);

            try
            {
                JsonWebKey convertedKey;
                if (theoryData.SecurityKey is X509SecurityKey x509SecurityKey)
                {
                    convertedKey = JsonWebKeyConverter.ConvertFromX509SecurityKey(x509SecurityKey, true);
                }
                else
                {
                    convertedKey = JsonWebKeyConverter.ConvertFromSecurityKey(theoryData.SecurityKey);
                }

                theoryData.ExpectedException.ProcessNoException(context);
                IdentityComparer.AreBytesEqual(convertedKey.ComputeJwkThumbprint(), theoryData.SecurityKey.ComputeJwkThumbprint(), context);
            }
            catch (Exception ex)
            {
                theoryData.ExpectedException.ProcessException(ex, context);
            }

            TestUtilities.AssertFailIfErrors(context);
        }
Ejemplo n.º 4
0
        public void RSAEncryptDecryptValue(RSACryptoServiceProviderProxyTheoryData theoryData)
        {
            var context = TestUtilities.WriteHeader($"{this}.RSAEncryptDecryptValue", theoryData);

            try
            {
                var proxy           = new RSACryptoServiceProviderProxy(theoryData.RsaCryptoServiceProvider);
                var cipherTextProxy = proxy.EncryptValue(theoryData.Input);
                var cipherTextRsa   = theoryData.RsaCryptoServiceProvider.EncryptValue(theoryData.Input);
                IdentityComparer.AreBytesEqual(
                    proxy.DecryptValue(cipherTextProxy),
                    theoryData.RsaCryptoServiceProvider.DecryptValue(cipherTextRsa),
                    context);
            }
            catch (Exception ex)
            {
                theoryData.ExpectedException.ProcessException(ex, context);
            }

            TestUtilities.AssertFailIfErrors(context);
        }