Beispiel #1
0
        public void AsymmetricSignatureProvider_Publics()
        {
            AsymmetricSignatureProvider provider = new AsymmetricSignatureProvider(KeyingMaterial.DefaultX509SigningCreds_2048_RsaSha2_Sha2.SigningKey as AsymmetricSecurityKey, KeyingMaterial.DefaultX509SigningCreds_2048_RsaSha2_Sha2.SignatureAlgorithm);

            SignatureProvider_SignVariation(provider, null, null, ExpectedException.ArgumentNullException());
            SignatureProvider_SignVariation(provider, new byte[0], null, ExpectedException.ArgumentException("IDX10624:"));
            SignatureProvider_SignVariation(provider, new byte[1], null, ExpectedException.InvalidOperationException("IDX10620:"));

            SignatureProvider_VerifyVariation(provider, null, null, ExpectedException.ArgumentNullException());
            SignatureProvider_VerifyVariation(provider, new byte[1], null, ExpectedException.ArgumentNullException());
            SignatureProvider_VerifyVariation(provider, new byte[0], new byte[1], ExpectedException.ArgumentException("IDX10625:"));
            SignatureProvider_VerifyVariation(provider, new byte[1], new byte[0], ExpectedException.ArgumentException("IDX10626:"));
        }
Beispiel #2
0
        public void NamedKeySecurityKeyIdentifierClause_Constructor()
        {
            NamedKeySecurityKeyIdentifierClause namedKeySecurityKeyIdentifierClause;
            ExpectedException expectedException = new ExpectedException(typeExpected: typeof(ArgumentNullException), substringExpected: "name");

            try
            {
                namedKeySecurityKeyIdentifierClause = new NamedKeySecurityKeyIdentifierClause(null, null);
                expectedException.ProcessNoException();
            }
            catch (Exception exception)
            {
                expectedException.ProcessException(exception);
            }

            expectedException = new ExpectedException(typeExpected: typeof(ArgumentNullException), substringExpected: "id");
            try
            {
                namedKeySecurityKeyIdentifierClause = new NamedKeySecurityKeyIdentifierClause("name", null);
                expectedException.ProcessNoException();
            }
            catch (Exception exception)
            {
                expectedException.ProcessException(exception);
            }

            expectedException = ExpectedException.ArgumentNullException(substringExpected: "name");
            try
            {
                namedKeySecurityKeyIdentifierClause = new NamedKeySecurityKeyIdentifierClause(name: "     ", id: "id");
                expectedException.ProcessNoException();
            }
            catch (Exception exception)
            {
                expectedException.ProcessException(exception);
            }

            expectedException = ExpectedException.ArgumentNullException(substringExpected: "id");
            try
            {
                namedKeySecurityKeyIdentifierClause = new NamedKeySecurityKeyIdentifierClause("name", "     ");
                expectedException.ProcessNoException();
            }
            catch (Exception exception)
            {
                expectedException.ProcessException(exception);
            }
        }
Beispiel #3
0
        public void SymmetricSignatureProvider_Publics()
        {
            SymmetricSignatureProvider provider = new SymmetricSignatureProvider(KeyingMaterial.DefaultSymmetricSigningCreds_256_Sha2.SigningKey as SymmetricSecurityKey, KeyingMaterial.DefaultSymmetricSigningCreds_256_Sha2.SignatureAlgorithm);

            SignatureProvider_SignVariation(provider, null, null, ExpectedException.ArgumentNullException());
            SignatureProvider_SignVariation(provider, new byte[0], null, ExpectedException.ArgumentException("IDX10624:"));
            SignatureProvider_SignVariation(provider, new byte[1], null, ExpectedException.NoExceptionExpected);

            SignatureProvider_VerifyVariation(provider, null, null, ExpectedException.ArgumentNullException());
            SignatureProvider_VerifyVariation(provider, new byte[0], null, ExpectedException.ArgumentNullException());
            SignatureProvider_VerifyVariation(provider, new byte[0], new byte[0], ExpectedException.ArgumentException("IDX10625:"));
            SignatureProvider_VerifyVariation(provider, new byte[1], new byte[0], ExpectedException.ArgumentException("IDX10626:"));
            SignatureProvider_VerifyVariation(provider, new byte[1], new byte[1], ExpectedException.NoExceptionExpected);

            provider.Dispose();
            SignatureProvider_SignVariation(provider, new byte[1], new byte[1], ExpectedException.ObjectDisposedException);
            SignatureProvider_VerifyVariation(provider, new byte[1], new byte[1], ExpectedException.ObjectDisposedException);
        }
        public void Validators_Issuer()
        {
            List <string> issuers = new List <string> {
                "", IdentityUtilities.DefaultIssuer
            };
            List <string> invalidIssuers = new List <string> {
                "", IdentityUtilities.NotDefaultIssuer
            };

            RunIssuerTest(issuer: null, securityToken: null, validationParameters: null, ee: ExpectedException.ArgumentNullException());
            RunIssuerTest(issuer: null, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidateIssuer = false
            }, ee: ExpectedException.NoExceptionExpected);
            RunIssuerTest(issuer: null, securityToken: null, validationParameters: new TokenValidationParameters(), ee: ExpectedException.SecurityTokenInvalidIssuerException(substringExpected: "IDX10211:"));
            RunIssuerTest(issuer: IdentityUtilities.DefaultIssuer, securityToken: null, validationParameters: new TokenValidationParameters(), ee: ExpectedException.SecurityTokenInvalidIssuerException(substringExpected: "IDX10204:"));
            RunIssuerTest(issuer: IdentityUtilities.DefaultIssuer, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidIssuer = IdentityUtilities.NotDefaultIssuer
            }, ee: ExpectedException.SecurityTokenInvalidIssuerException(substringExpected: "IDX10205:"));
            RunIssuerTest(issuer: IdentityUtilities.DefaultIssuer, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidIssuers = invalidIssuers
            }, ee: ExpectedException.SecurityTokenInvalidIssuerException(substringExpected: "IDX10205:"));
            RunIssuerTest(issuer: IdentityUtilities.DefaultIssuer, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidIssuer = IdentityUtilities.DefaultIssuer
            }, ee: ExpectedException.NoExceptionExpected);
            RunIssuerTest(issuer: IdentityUtilities.DefaultIssuer, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidIssuers = issuers
            }, ee: ExpectedException.NoExceptionExpected);
        }
        public void Validators_Audience()
        {
            List <string> audiences = new List <string> {
                "", IdentityUtilities.DefaultAudience
            };
            List <string> invalidAudiences = new List <string> {
                "", IdentityUtilities.NotDefaultAudience
            };

            RunAudienceTest(audiences: null, securityToken: null, validationParameters: null, ee: ExpectedException.ArgumentNullException());
            RunAudienceTest(audiences: null, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidateAudience = false
            }, ee: ExpectedException.NoExceptionExpected);
            RunAudienceTest(audiences: null, securityToken: null, validationParameters: new TokenValidationParameters(), ee: ExpectedException.SecurityTokenInvalidAudienceException(substringExpected: "IDX10214:"));
            RunAudienceTest(audiences: audiences, securityToken: null, validationParameters: new TokenValidationParameters(), ee: ExpectedException.SecurityTokenInvalidAudienceException(substringExpected: "IDX10208:"));
            RunAudienceTest(audiences: audiences, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidAudience = IdentityUtilities.NotDefaultAudience
            }, ee: ExpectedException.SecurityTokenInvalidAudienceException(substringExpected: "IDX10214:"));
            RunAudienceTest(audiences: audiences, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidAudiences = invalidAudiences
            }, ee: ExpectedException.SecurityTokenInvalidAudienceException(substringExpected: "IDX10214:"));
            RunAudienceTest(audiences: audiences, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidAudience = IdentityUtilities.DefaultAudience
            }, ee: ExpectedException.NoExceptionExpected);
            RunAudienceTest(audiences: audiences, securityToken: null, validationParameters: new TokenValidationParameters {
                ValidAudiences = audiences
            }, ee: ExpectedException.NoExceptionExpected);
        }
 public void Validators_Lifetime()
 {
     RunLifetimeTest(expires: null, notBefore: null, securityToken: null, validationParameters: null, ee: ExpectedException.ArgumentNullException());
     RunLifetimeTest(expires: null, notBefore: null, securityToken: null, validationParameters: new TokenValidationParameters {
         ValidateLifetime = false
     }, ee: ExpectedException.NoExceptionExpected);
     RunLifetimeTest(expires: null, notBefore: null, securityToken: null, validationParameters: new TokenValidationParameters {
     }, ee: ExpectedException.SecurityTokenNoExpirationException(substringExpected: "IDX10225:"));
     RunLifetimeTest(expires: DateTime.UtcNow, notBefore: DateTime.UtcNow + TimeSpan.FromHours(1), securityToken: null, validationParameters: new TokenValidationParameters {
     }, ee: ExpectedException.SecurityTokenInvalidLifetimeException(substringExpected: "IDX10224:"));
     RunLifetimeTest(expires: DateTime.UtcNow + TimeSpan.FromHours(2), notBefore: DateTime.UtcNow + TimeSpan.FromHours(1), securityToken: null, validationParameters: new TokenValidationParameters {
     }, ee: ExpectedException.SecurityTokenNotYetValidException(substringExpected: "IDX10222:"));
     RunLifetimeTest(expires: DateTime.UtcNow - TimeSpan.FromHours(1), notBefore: DateTime.UtcNow - TimeSpan.FromHours(2), securityToken: null, validationParameters: new TokenValidationParameters {
     }, ee: ExpectedException.SecurityTokenExpiredException(substringExpected: "IDX10223:"));
     RunLifetimeTest(expires: DateTime.UtcNow, notBefore: DateTime.UtcNow - TimeSpan.FromHours(2), securityToken: null, validationParameters: new TokenValidationParameters {
     }, ee: ExpectedException.NoExceptionExpected);
 }
        public void JwtSecurityToken_EncodedStringConstruction()
        {
            Console.WriteLine("Entering: " + MethodBase.GetCurrentMethod());
            string[] tokenParts = EncodedJwts.Asymmetric_LocalSts.Split('.');

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: OverClaims",
                EncodedString     = EncodedJwts.OverClaims,
                ExpectedException = ExpectedException.NoExceptionExpected,
            });


            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: InvalidPayloadFormat",
                EncodedString     = EncodedJwts.InvalidPayload,
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(FormatException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: null",
                EncodedString     = null,
                ExpectedException = ExpectedException.ArgumentNullException(),
            });
            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: string.Empty",
                EncodedString     = string.Empty,
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10002:"),
            });
            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: single character: '1'",
                EncodedString     = "1",
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709:"),
            });
            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: two parts each a single character: '1.2'",
                EncodedString     = "1.2",
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709:"),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: header is not encoded properly: '123'",
                EncodedString     = string.Format("{0}.{1}.{2}", "123", tokenParts[1], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(ArgumentException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: header is not encoded properly: '123=='",
                EncodedString     = string.Format("{0}.{1}.{2}", "123==", tokenParts[1], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709"),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: payload is not encoded correctly: '123'",
                EncodedString     = string.Format("{1}.{0}.{2}", "123", tokenParts[0], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(ArgumentException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: payload is not encoded properly: '123=='",
                EncodedString     = string.Format("{1}.{0}.{2}", "123==", tokenParts[0], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709:"),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: valid encoding, NO signature (JWT_AsymmetricSigned_AcsV2)",
                EncodedString     = string.Format("{0}.{1}.", tokenParts[0], tokenParts[1]),
                ExpectedException = ExpectedException.NoExceptionExpected,
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: valid encoding, NO signature (JWT_AsymmetricSigned_AcsV2)",
                EncodedString     = string.Format("{0}.{1}.{2}.{3}", tokenParts[0], tokenParts[1], tokenParts[2], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709:"),
            });
        }
        public void JwtSecurityToken_EncodedStringConstruction()
        {
            Console.WriteLine("Entering: " + MethodBase.GetCurrentMethod());
            string[] tokenParts = EncodedJwts.Asymmetric_LocalSts.Split('.');

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: OverClaims",
                EncodedString     = EncodedJwts.OverClaims,
                ExpectedException = ExpectedException.NoExceptionExpected,
            });


            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: InvalidPayloadFormat",
                EncodedString     = EncodedJwts.InvalidPayload,
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(FormatException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: null",
                EncodedString     = null,
                ExpectedException = ExpectedException.ArgumentNullException(),
            });
            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: string.Empty",
                EncodedString     = string.Empty,
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10002:"),
            });
            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: single character: '1'",
                EncodedString     = "1",
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709:"),
            });
            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: two parts each a single character: '1.2'",
                EncodedString     = "1.2",
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709:"),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: header is not encoded properly: '123'",
                EncodedString     = string.Format("{0}.{1}.{2}", "123", tokenParts[1], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(ArgumentException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: header is not encoded properly: '123=='",
                EncodedString     = string.Format("{0}.{1}.{2}", "123==", tokenParts[1], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709"),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: payload is not encoded correctly: '123'",
                EncodedString     = string.Format("{1}.{0}.{2}", "123", tokenParts[0], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(ArgumentException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: payload is not encoded properly: '123=='",
                EncodedString     = string.Format("{1}.{0}.{2}", "123==", tokenParts[0], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709:"),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: valid encoding, NO signature (JWT_AsymmetricSigned_AcsV2)",
                EncodedString     = string.Format("{0}.{1}.", tokenParts[0], tokenParts[1]),
                ExpectedException = ExpectedException.NoExceptionExpected,
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: invalid for header, NO signature (JWT_AsymmetricSigned_AcsV2)",
                EncodedString     = "iJsL8.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuY29yZS53aW5kb3dzLm5ldC8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8yZWU5NDA1Mi1iZjM0LTRlODMtYWE2Zi1mODIxMjVjNjVkNzQvIiwiaWF0IjoxNDI2Nzk2MDA1LCJuYmYiOjE0MjY3OTYwMDUsImV4cCI6MTQyNjc5OTkwNSwidmVyIjoiMS4wIiwidGlkIjoiMmVlOTQwNTItYmYzNC00ZTgzLWFhNmYtZjgyMTI1YzY1ZDc0IiwiYW1yIjpbInB3ZCJdLCJvaWQiOiJlMWUxZTY0Ny01ZTJhLTQyMGYtYjY3Ny1lYWU3MWMxNjQ4ZWIiLCJ1cG4iOiJkYXZpZEBzb29jaGkub25taWNyb3NvZnQuY29tIiwicHVpZCI6IjEwMDMzRkZGOENEQzE0OUEiLCJzdWIiOiJWUjgzRllKTDhXR0o1MmVRMk8yMG81N0ZwNGR0OW5uUFVRT0ZtM3FWenpzIiwiZ2l2ZW5fbmFtZSI6IkRhdmlkIiwiZmFtaWx5X25hbWUiOiJNdXJyYXkiLCJuYW1lIjoiZGF2aWRtdSIsImdyb3VwcyI6WyI0NjVmYjhhNS03Njk5LTQyMDQtYjNlNy0zNzBlYjFkNDhjYjkiXSwidW5pcXVlX25hbWUiOiJkYXZpZEBzb29jaGkub25taWNyb3NvZnQuY29tIiwiYXBwaWQiOiIxOTUwYTI1OC0yMjdiLTRlMzEtYTljZi03MTc0OTU5NDVmYzIiLCJhcHBpZGFjciI6IjAiLCJzY3AiOiJ1c2VyX2ltcGVyc29uYXRpb24iLCJhY3IiOiIxIn0.iJsL8",
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(System.FormatException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: invalid for payload, NO signature (JWT_AsymmetricSigned_AcsV2)",
                EncodedString     = tokenParts[0] + ".eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuY29yZS53aW5kb3dzLm5ldC8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8yZWU5NDA1Mi1iZjM0LTRlODMtYWE2Zi1mODIxMjVjNjVkNzQvIiwiaWF0IjoxNDI2Nzk2MDA1LCJuYmYiOjE0MjY3OTYwMDUsImV4cCI6MTQyNjc5OTkwNSwidmVyIjoiMS4wIiwidGlkIjoiMmVlOTQwNTItYmYzNC00ZTgzLWFhNmYtZjgyMTI1YzY1ZDc0IiwiYW1yIjpbInB3ZCJdLCJvaWQiOiJlMWUxZTY0Ny01ZTJhLTQyMGYtYjY3Ny1lYWU3MWMxNjQ4ZWIiLCJ1cG4iOiJkYXZpZEBzb29jaGkub25taWNyb3NvZnQuY29tIiwicHVpZCI6IjEwMDMzRkZGOENEQzE0OUEiLCJzdWIiOiJWUjgzRllKTDhXR0o1MmVRMk8yMG81N0ZwNGR0OW5uUFVRT0ZtM3FWenpzIiwiZ2l2ZW5fbmFtZSI6IkRhdmlkIiwiZmFtaWx5X25hbWUiOiJNdXJyYXkiLCJuYW1lIjoiZGF2aWRtdSIsImdyb3VwcyI6WyI0NjVmYjhhNS03Njk5LTQyMDQtYjNlNy0zNzBlYjFkNDhjYjkiXSwidW5pcXVlX25hbWUiOiJkYXZpZEBzb29jaGkub25taWNyb3NvZnQuY29tIiwiYXBwaWQiOiIxOTUwYTI1OC0yMjdiLTRlMzEtYTljZi03MTc0OTU5NDVmYzIiLCJhcHBpZGFjciI6IjAiLCJzY3AiOiJ1c2VyX2ltcGVyc29uYXRpb24iLCJhY3IiOiIxIn0.iJsL8",
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(System.FormatException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: valid encoding, NO signature (JWT_AsymmetricSigned_AcsV2)",
                EncodedString     = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuY29yZS53aW5kb3dzLm5ldC8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8yZWU5NDA1Mi1iZjM0LTRlODMtYWE2Zi1mODIxMjVjNjVkNzQvIiwiaWF0IjoxNDI2Nzk2MDA1LCJuYmYiOjE0MjY3OTYwMDUsImV4cCI6MTQyNjc5OTkwNSwidmVyIjoiMS4wIiwidGlkIjoiMmVlOTQwNTItYmYzNC00ZTgzLWFhNmYtZjgyMTI1YzY1ZDc0IiwiYW1yIjpbInB3ZCJdLCJvaWQiOiJlMWUxZTY0Ny01ZTJhLTQyMGYtYjY3Ny1lYWU3MWMxNjQ4ZWIiLCJ1cG4iOiJkYXZpZEBzb29jaGkub25taWNyb3NvZnQuY29tIiwicHVpZCI6IjEwMDMzRkZGOENEQzE0OUEiLCJzdWIiOiJWUjgzRllKTDhXR0o1MmVRMk8yMG81N0ZwNGR0OW5uUFVRT0ZtM3FWenpzIiwiZ2l2ZW5fbmFtZSI6IkRhdmlkIiwiZmFtaWx5X25hbWUiOiJNdXJyYXkiLCJuYW1lIjoiZGF2aWRtdSIsImdyb3VwcyI6WyI0NjVmYjhhNS03Njk5LTQyMDQtYjNlNy0zNzBlYjFkNDhjYjkiXSwidW5pcXVlX25hbWUiOiJkYXZpZEBzb29jaGkub25taWNyb3NvZnQuY29tIiwiYXBwaWQiOiIxOTUwYTI1OC0yMjdiLTRlMzEtYTljZi03MTc0OTU5NDVmYzIiLCJhcHBpZGFjciI6IjAiLCJzY3AiOiJ1c2VyX2ltcGVyc29uYXRpb24iLCJhY3IiOiIxIn0.iJsL8",
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10703:", inner: typeof(System.FormatException)),
            });

            RunEncodedTest(new JwtSecurityTokenTestVariation
            {
                Name              = "EncodedString: valid encoding, invalid encoding on signature",
                EncodedString     = string.Format("{0}.{1}.{2}.{3}", tokenParts[0], tokenParts[1], tokenParts[2], tokenParts[2]),
                ExpectedException = ExpectedException.ArgumentException(substringExpected: "IDX10709:"),
            });
        }
Beispiel #9
0
        public void SymmetricSignatureProvider_ConstructorTests()
        {
            // no errors
            SymmetricSignatureProvider_ConstructorVariation("Creates with no errors", KeyingMaterial.DefaultSymmetricSecurityKey_256, SecurityAlgorithms.HmacSha256Signature, ExpectedException.NoExceptionExpected);

            // null, empty algorithm digest
            SymmetricSignatureProvider_ConstructorVariation("Constructor:   - NUll key", null, SecurityAlgorithms.HmacSha256Signature, ExpectedException.ArgumentNullException());
            SymmetricSignatureProvider_ConstructorVariation("Constructor:   - algorithm == string.Empty", KeyingMaterial.DefaultSymmetricSecurityKey_256, string.Empty, ExpectedException.ArgumentException());

            // GetKeyedHashAlgorithm throws
            SymmetricSecurityKey key = new FaultingSymmetricSecurityKey(KeyingMaterial.DefaultSymmetricSecurityKey_256, new CryptographicException("hi from inner"));

            SymmetricSignatureProvider_ConstructorVariation("Constructor:   - SecurityKey.GetKeyedHashAlgorithm throws", key, SecurityAlgorithms.HmacSha256Signature, ExpectedException.InvalidOperationException("IDX10632:", typeof(CryptographicException)));

            // Key returns null KeyedHash
            key = new FaultingSymmetricSecurityKey(KeyingMaterial.DefaultSymmetricSecurityKey_256, null);
            SymmetricSignatureProvider_ConstructorVariation("Constructor:   - SecurityKey returns null KeyedHashAlgorithm", key, SecurityAlgorithms.HmacSha256Signature, ExpectedException.InvalidOperationException("IDX10633:"));

            //_keyedHash.Key = _key.GetSymmetricKey() is null;
            KeyedHashAlgorithm keyedHashAlgorithm = KeyingMaterial.DefaultSymmetricSecurityKey_256.GetKeyedHashAlgorithm(SecurityAlgorithms.HmacSha256Signature);

            key = new FaultingSymmetricSecurityKey(KeyingMaterial.DefaultSymmetricSecurityKey_256, null, null, keyedHashAlgorithm, null);
            SymmetricSignatureProvider_ConstructorVariation("Constructor:   - key returns null bytes to pass to _keyedHashKey", key, SecurityAlgorithms.HmacSha256Signature, ExpectedException.InvalidOperationException("IDX10634:", typeof(NullReferenceException)));
        }
Beispiel #10
0
        public void AsymmetricSignatureProvider_Constructor()
        {
            AsymmetricSecurityKey privateKey = KeyingMaterial.DefaultX509SigningCreds_2048_RsaSha2_Sha2.SigningKey as AsymmetricSecurityKey;
            AsymmetricSecurityKey publicKey  = KeyingMaterial.DefaultX509SigningCreds_Public_2048_RsaSha2_Sha2.SigningKey as AsymmetricSecurityKey;
            string sha2SignatureAlgorithm    = KeyingMaterial.DefaultX509SigningCreds_2048_RsaSha2_Sha2.SignatureAlgorithm;

            // no errors
            AsymmetricConstructorVariation("Signing:  - Creates with no errors", privateKey, sha2SignatureAlgorithm, expectedException: ExpectedException.NoExceptionExpected);
            AsymmetricConstructorVariation("Verifying: - Creates with no errors (Private Key)", privateKey, sha2SignatureAlgorithm, expectedException: ExpectedException.NoExceptionExpected);
            AsymmetricConstructorVariation("Verifying: - Creates with no errors (Public Key)", publicKey, sha2SignatureAlgorithm, expectedException: ExpectedException.NoExceptionExpected);

            // null, empty algorithm digest
            AsymmetricConstructorVariation("Signing:   - NUll key", null, sha2SignatureAlgorithm, expectedException: ExpectedException.ArgumentNullException());
            AsymmetricConstructorVariation("Signing:   - SignatureAlorithm == null", privateKey, null, expectedException: ExpectedException.ArgumentNullException());
            AsymmetricConstructorVariation("Signing:   - SignatureAlorithm == whitespace", privateKey, "    ", expectedException: ExpectedException.ArgumentException("IDX10002"));

            // Private keys missing
            AsymmetricConstructorVariation("Signing:   - SecurityKey without private key", publicKey, sha2SignatureAlgorithm, expectedException: ExpectedException.InvalidOperationException(inner: typeof(NotSupportedException)));
            AsymmetricConstructorVariation("Verifying: - SecurityKey without private key", publicKey, sha2SignatureAlgorithm, expectedException: ExpectedException.NoExceptionExpected);

            // _formatter not created
            AsymmetricConstructorVariation("Signing:   - key cannot create _formatter", KeyingMaterial.DefaultAsymmetricKey_2048, "SecurityAlgorithms.RsaSha256Signature", expectedException: ExpectedException.InvalidOperationException(substringExpected: "IDX10618", inner: typeof(NotSupportedException)));

            // _deformatter not created
            AsymmetricConstructorVariation("Verifying: - key cannot create _deformatter", KeyingMaterial.DefaultAsymmetricKey_Public_2048, "SecurityAlgorithms.RsaSha256Signature", expectedException: ExpectedException.InvalidOperationException(substringExpected: "IDX10618", inner: typeof(NotSupportedException)));

            Console.WriteLine("Test missing: key.GetHashAlgorithmForSignature( signingCredentials.SignatureAlgorithm );"); //TODO: Should this be fixed?
        }