public void Equals_NotEqual()
        {
            var value1 = new FidoSignature(Encoding.Default.GetBytes("signature"));
            var value2 = new FidoSignature(Encoding.Default.GetBytes("Signature"));

            Assert.IsFalse(value1.Equals(value2));
        }
        private FidoRegistrationData(FidoPublicKey userPublicKey, FidoKeyHandle keyHandle,
						   FidoAttestationCertificate attestationCertificate,
						   FidoSignature signature)
        {
            UserPublicKey = userPublicKey;
            KeyHandle = keyHandle;
            AttestationCertificate = attestationCertificate;
            Signature = signature;
        }
        public void SerializeObject()
        {
            var randomBytes = new byte[256];
            RandomNumberGenerator.Create().GetBytes(randomBytes);

            var value = new FidoSignature(randomBytes);
            var serialized = JsonConvert.SerializeObject(value);

            var bytes = WebSafeBase64Converter.FromBase64String(serialized.Trim('"'));
            Assert.IsTrue(randomBytes.SequenceEqual(bytes));
        }
        public void DeserializeObject()
        {
            var publicKey = new byte[256];
            RandomNumberGenerator.Create().GetBytes(publicKey);

            var value = new FidoSignature(publicKey);
            var serialized = JsonConvert.SerializeObject(value);

            var deserialized = JsonConvert.DeserializeObject<FidoSignature>(serialized);

            Assert.AreEqual(value, deserialized);
        }
        public void SerializeObject()
        {
            var randomBytes = new byte[256];

            RandomNumberGenerator.Create().GetBytes(randomBytes);

            var value      = new FidoSignature(randomBytes);
            var serialized = JsonConvert.SerializeObject(value);

            var bytes = WebSafeBase64Converter.FromBase64String(serialized.Trim('"'));

            Assert.IsTrue(randomBytes.SequenceEqual(bytes));
        }
        public void DeserializeObject()
        {
            var publicKey = new byte[256];

            RandomNumberGenerator.Create().GetBytes(publicKey);

            var value      = new FidoSignature(publicKey);
            var serialized = JsonConvert.SerializeObject(value);

            var deserialized = JsonConvert.DeserializeObject <FidoSignature>(serialized);

            Assert.AreEqual(value, deserialized);
        }
Esempio n. 7
0
        private void VerifySignature(FidoAttestationCertificate certificate, FidoSignature signature,
                                     byte[] signedBytes)
        {
            try
            {
                var certPublicKey = certificate.Certificate.GetPublicKey();
                var signer        = SignerUtilities.GetSigner("SHA-256withECDSA");
                signer.Init(false, certPublicKey);
                signer.BlockUpdate(signedBytes, 0, signedBytes.Length);

                if (signer.VerifySignature(signature.ToByteArray()))
                {
                    throw new InvalidOperationException("Invalid signature");
                }
            }
            catch (Exception)
            {
                throw new InvalidOperationException("Invalid signature");
            }
        }
Esempio n. 8
0
        private void VerifySignature(FidoDeviceRegistration deviceRegistration, FidoSignature signature,
                                     byte[] signedBytes)
        {
            try
            {
                var certPublicKey = deviceRegistration.PublicKey.PublicKey;
                var signer        = SignerUtilities.GetSigner("SHA-256withECDSA");
                signer.Init(false, certPublicKey);
                signer.BlockUpdate(signedBytes, 0, signedBytes.Length);

                if (signer.VerifySignature(signature.ToByteArray()))
                {
                    throw new InvalidOperationException("Invalid signature");
                }
            }
            catch
            {
                throw new InvalidOperationException("Invalid signature");
            }
        }
 public void Equals_Null()
 {
     Assert.IsFalse(FidoSignature.FromWebSafeBase64("").Equals(null));
 }
        public void Constructor()
        {
            var value = new FidoSignature(Encoding.Default.GetBytes("signature"));

            Assert.AreEqual("signature", Encoding.Default.GetString(value.ToByteArray()));
        }
Esempio n. 11
0
 public void Validate_Good_NoException()
 {
     var value = new FidoSignature(WebSafeBase64Converter.FromBase64String(TestVectors.PublicKeyBase64));
     value.Validate();
 }
Esempio n. 12
0
 public void Validate_BytesEmpty_Throws()
 {
     var value = new FidoSignature(new byte[0]);
     Assert.Throws<InvalidOperationException>(() => value.Validate());
 }
Esempio n. 13
0
 public void Equals_NotEqual()
 {
     var value1 = new FidoSignature(Encoding.Default.GetBytes("signature"));
     var value2 = new FidoSignature(Encoding.Default.GetBytes("Signature"));
     Assert.IsFalse(value1.Equals(value2));
 }
Esempio n. 14
0
 public void Constructor()
 {
     var value = new FidoSignature(Encoding.Default.GetBytes("signature"));
     Assert.AreEqual("signature", Encoding.Default.GetString(value.ToByteArray()));
 }
        public void Validate_Good_NoException()
        {
            var value = new FidoSignature(WebSafeBase64Converter.FromBase64String(TestVectors.PublicKeyBase64));

            value.Validate();
        }
        private void VerifySignature(FidoAttestationCertificate certificate, FidoSignature signature, 
			byte[] signedBytes)
        {
            try
            {
                var certPublicKey = certificate.Certificate.GetPublicKey();
                var signer = SignerUtilities.GetSigner("SHA-256withECDSA");
                signer.Init(false, certPublicKey);
                signer.BlockUpdate(signedBytes, 0, signedBytes.Length);

                if (signer.VerifySignature(signature.ToByteArray()))
                    throw new InvalidOperationException("Invalid signature");
            }
            catch (Exception)
            {
                throw new InvalidOperationException("Invalid signature");
            }
        }
        public void Validate_BytesEmpty_Throws()
        {
            var value = new FidoSignature(new byte[0]);

            Assert.Throws <InvalidOperationException>(() => value.Validate());
        }
        private void VerifySignature(FidoDeviceRegistration deviceRegistration, FidoSignature signature, 
			byte[] signedBytes)
        {
            try
            {
                var certPublicKey = deviceRegistration.PublicKey.PublicKey;
                var signer = SignerUtilities.GetSigner("SHA-256withECDSA");
                signer.Init(false, certPublicKey);
                signer.BlockUpdate(signedBytes, 0, signedBytes.Length);

                if (signer.VerifySignature(signature.ToByteArray()))
                    throw new InvalidOperationException("Invalid signature");
            }
            catch
            {
                throw new InvalidOperationException("Invalid signature");
            }
        }
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     return(FidoSignature.FromWebSafeBase64(reader.Value.ToString()));
 }
Esempio n. 20
0
 public FidoSignatureData(byte userPresence, uint counter, FidoSignature signature)
 {
     UserPresence = userPresence;
     Counter = counter;
     Signature = signature;
 }