Exemple #1
0
            public void GivenUnsupportedAlgorithmType_ThrowsNotSupportedException()
            {
                var    unsupported = new CustomSignatureAlgorithm("CUSTOM");
                Action act         = () => SignatureAlgorithmDataRecord.FromSignatureAlgorithm(unsupported);

                act.Should().Throw <NotSupportedException>();
            }
Exemple #2
0
 public ToSignatureAlgorithm()
 {
     _sut = new SignatureAlgorithmDataRecord {
         Type          = "HMAC",
         Parameter     = "s3cr3t",
         HashAlgorithm = HashAlgorithmName.MD5.Name
     };
 }
Exemple #3
0
 public void GivenHMACAlgorithm_ReturnsExpectedDataRecord()
 {
     using (var hmac = SignatureAlgorithm.CreateForVerification("s3cr3t", HashAlgorithmName.SHA384)) {
         var actual   = SignatureAlgorithmDataRecord.FromSignatureAlgorithm(hmac);
         var expected = new SignatureAlgorithmDataRecord {
             Type          = "HMAC",
             Parameter     = "s3cr3t",
             HashAlgorithm = HashAlgorithmName.SHA384.Name
         };
         actual.Should().BeEquivalentTo(expected);
     }
 }
Exemple #4
0
 public void GivenECDsaAlgorithm_ReturnsExpectedDataRecord()
 {
     using (var ecdsa = ECDsa.Create()) {
         using (var ecdsaAlg = SignatureAlgorithm.CreateForVerification(ecdsa, HashAlgorithmName.SHA384)) {
             var actual   = SignatureAlgorithmDataRecord.FromSignatureAlgorithm(ecdsaAlg);
             var expected = new SignatureAlgorithmDataRecord {
                 Type          = "ECDsa",
                 Parameter     = ecdsa.ExportParameters(false).ToXml(),
                 HashAlgorithm = HashAlgorithmName.SHA384.Name
             };
             actual.Should().BeEquivalentTo(expected);
         }
     }
 }
Exemple #5
0
 public void GivenRSAAlgorithm_ReturnsExpectedDataRecord()
 {
     using (var rsa = new RSACryptoServiceProvider()) {
         using (var rsaAlg = SignatureAlgorithm.CreateForVerification(rsa, HashAlgorithmName.SHA384)) {
             var actual   = SignatureAlgorithmDataRecord.FromSignatureAlgorithm(rsaAlg);
             var expected = new SignatureAlgorithmDataRecord {
                 Type          = "RSA",
                 Parameter     = rsa.ExportParameters(false).ToXml(),
                 HashAlgorithm = HashAlgorithmName.SHA384.Name
             };
             actual.Should().BeEquivalentTo(expected);
         }
     }
 }
Exemple #6
0
            public void GivenHMACDataRecord_ReturnsHMACDataRecord()
            {
                var sut = new SignatureAlgorithmDataRecord {
                    Type          = "HMAC",
                    Parameter     = "s3cr3t",
                    HashAlgorithm = HashAlgorithmName.MD5.Name
                };

                using (var actual = sut.ToSignatureAlgorithm()) {
                    var expected = new HMACSignatureAlgorithm("s3cr3t", HashAlgorithmName.MD5);
                    actual.Should().BeAssignableTo <HMACSignatureAlgorithm>();
                    actual.As <HMACSignatureAlgorithm>().Should().BeEquivalentTo(expected);
                }
            }
Exemple #7
0
            public void GivenECDsaDataRecord_ReturnsECDsaAlgorithm()
            {
                using (var ecdsa = ECDsa.Create()) {
                    var publicParameters = ecdsa.ExportParameters(false);
                    var sut = new SignatureAlgorithmDataRecord {
                        Type          = "ECDsa",
                        Parameter     = publicParameters.ToXml(),
                        HashAlgorithm = HashAlgorithmName.MD5.Name
                    };

                    using (var actual = sut.ToSignatureAlgorithm()) {
                        var expected = ECDsaSignatureAlgorithm.CreateForVerification(HashAlgorithmName.MD5, publicParameters);
                        actual.Should().BeAssignableTo <ECDsaSignatureAlgorithm>();
                        actual.As <ECDsaSignatureAlgorithm>().Should().BeEquivalentTo(expected);
                        actual.As <ECDsaSignatureAlgorithm>().GetPublicKey().ToXml().Should().Be(publicParameters.ToXml());
                    }
                }
            }
Exemple #8
0
            public void GivenRSADataRecord_ReturnsRSAAlgorithm()
            {
                using (var rsa = new RSACryptoServiceProvider()) {
                    var publicParameters = rsa.ExportParameters(false);
                    var sut = new SignatureAlgorithmDataRecord {
                        Type          = "RSA",
                        Parameter     = publicParameters.ToXml(),
                        HashAlgorithm = HashAlgorithmName.MD5.Name
                    };

                    using (var actual = sut.ToSignatureAlgorithm()) {
                        var expected = RSASignatureAlgorithm.CreateForVerification(HashAlgorithmName.MD5, publicParameters);
                        actual.Should().BeAssignableTo <RSASignatureAlgorithm>();
                        actual.As <RSASignatureAlgorithm>().Should().BeEquivalentTo(expected);
                        actual.As <RSASignatureAlgorithm>().GetPublicKey().ToXml().Should().Be(publicParameters.ToXml());
                    }
                }
            }
        public Task Register(Client client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var record = new ClientDataRecord {
                Id                 = client.Id,
                Name               = client.Name,
                NonceExpiration    = client.NonceLifetime.TotalSeconds,
                Claims             = client.Claims?.Select(c => ClaimDataRecord.FromClaim(c))?.ToArray(),
                SignatureAlgorithm = SignatureAlgorithmDataRecord.FromSignatureAlgorithm(client.SignatureAlgorithm)
            };

            var collection = _lazyCollection.Value;

            return(collection.ReplaceOneAsync(r => r.Id == record.Id, record, new ReplaceOptions {
                IsUpsert = true
            }));
        }
Exemple #10
0
            public void GivenNullSignatureAlgorithm_ThrowsArgumentNullException()
            {
                Action act = () => SignatureAlgorithmDataRecord.FromSignatureAlgorithm(null);

                act.Should().Throw <ArgumentNullException>();
            }