public void Equals_NotEqual()
        {
            var value1 = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
            var value2 = new FidoPublicKey(Encoding.Default.GetBytes("Publickey"));

            Assert.IsFalse(value1.Equals(value2));
        }
        private static FidoDeviceRegistration CreateTestDeviceRegistration()
        {
            var cert      = FidoAttestationCertificate.FromWebSafeBase64(TestVectors.AttestationCertificate);
            var keyHandle = FidoKeyHandle.FromWebSafeBase64(TestVectors.KeyHandle);
            var publicKey = FidoPublicKey.FromWebSafeBase64(TestVectors.PublicKeyBase64);

            return(new FidoDeviceRegistration(keyHandle, publicKey, cert, 0));
        }
Ejemplo n.º 3
0
        private FidoRegistrationData(FidoPublicKey userPublicKey, FidoKeyHandle keyHandle,
						   FidoAttestationCertificate attestationCertificate,
						   FidoSignature signature)
        {
            UserPublicKey = userPublicKey;
            KeyHandle = keyHandle;
            AttestationCertificate = attestationCertificate;
            Signature = signature;
        }
Ejemplo n.º 4
0
        private static FidoDeviceRegistration CreateTestDeviceRegistration()
        {
            var keyHandle   = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle"));
            var publicKey   = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
            var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate"));

            var deviceRegistration = new FidoDeviceRegistration(keyHandle, publicKey, certificate, 12345);

            return(deviceRegistration);
        }
        public void SerializeObject()
        {
            var randomBytes = new byte[256];
            RandomNumberGenerator.Create().GetBytes(randomBytes);

            var value = new FidoPublicKey(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 FidoPublicKey(publicKey);
            var serialized = JsonConvert.SerializeObject(value);

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

            Assert.AreEqual(value, deserialized);
        }
Ejemplo n.º 7
0
        public void FromJson()
        {
            var deviceRegistration = FidoDeviceRegistration.FromJson("{\"Certificate\":\"Y2VydGlmaWNhdGU\",\"Counter\":12345,\"KeyHandle\":\"a2V5aGFuZGxl\",\"PublicKey\":\"cHVibGlja2V5\"}");

            var keyHandle   = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle"));
            var publicKey   = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
            var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate"));

            Assert.AreEqual(12345, deviceRegistration.Counter);
            Assert.IsTrue(certificate.Equals(deviceRegistration.Certificate));
            Assert.IsTrue(publicKey.Equals(deviceRegistration.PublicKey));
            Assert.IsTrue(keyHandle.Equals(deviceRegistration.KeyHandle));
        }
Ejemplo n.º 8
0
        public void SerializeObject()
        {
            var randomBytes = new byte[256];

            RandomNumberGenerator.Create().GetBytes(randomBytes);

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

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

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

            RandomNumberGenerator.Create().GetBytes(publicKey);

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

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

            Assert.AreEqual(value, deserialized);
        }
Ejemplo n.º 10
0
        public void ToJson()
        {
            var keyHandle   = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle"));
            var publicKey   = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
            var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate"));

            var deviceRegistration = new FidoDeviceRegistration(keyHandle, publicKey, certificate, 12345);

            var serialized = deviceRegistration.ToJson();

            var jsonObject = JObject.Parse(serialized);
            var properties = jsonObject.Properties().ToLookup(x => x.Name.ToLowerInvariant(), x => x.Value.ToString());

            Assert.AreEqual("Y2VydGlmaWNhdGU", properties["certificate"].Single());
            Assert.AreEqual("12345", properties["counter"].Single());
            Assert.AreEqual("a2V5aGFuZGxl", properties["keyhandle"].Single());
            Assert.AreEqual("cHVibGlja2V5", properties["publickey"].Single());
        }
Ejemplo n.º 11
0
        public void Validate_Good_NoException()
        {
            var value = new FidoPublicKey(WebSafeBase64Converter.FromBase64String(TestVectors.PublicKeyBase64));

            value.Validate();
        }
Ejemplo n.º 12
0
 public void Validate_InvalidBytes_Throws()
 {
     var value = new FidoPublicKey(new byte[65]);
     Assert.Throws<ArgumentException>(() => value.Validate());
 }
Ejemplo n.º 13
0
 public void Validate_Good_NoException()
 {
     var value = new FidoPublicKey(WebSafeBase64Converter.FromBase64String(TestVectors.PublicKeyBase64));
     value.Validate();
 }
Ejemplo n.º 14
0
 public void Validate_BytesEmpty_Throws()
 {
     var value = new FidoPublicKey(new byte[0]);
     Assert.Throws<InvalidOperationException>(() => value.Validate());
 }
Ejemplo n.º 15
0
 public void Equals_NotEqual()
 {
     var value1 = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
     var value2 = new FidoPublicKey(Encoding.Default.GetBytes("Publickey"));
     Assert.IsFalse(value1.Equals(value2));
 }
Ejemplo n.º 16
0
 public void Constructor()
 {
     var value = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
     Assert.AreEqual("publickey", Encoding.Default.GetString(value.ToByteArray()));
 }
Ejemplo n.º 17
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     return(FidoPublicKey.FromWebSafeBase64(reader.Value.ToString()));
 }
        public void FromJson()
        {
            var deviceRegistration = FidoDeviceRegistration.FromJson("{\"Certificate\":\"Y2VydGlmaWNhdGU\",\"Counter\":12345,\"KeyHandle\":\"a2V5aGFuZGxl\",\"PublicKey\":\"cHVibGlja2V5\"}");

            var keyHandle = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle"));
            var publicKey = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
            var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate"));

            Assert.AreEqual(12345, deviceRegistration.Counter);
            Assert.IsTrue(certificate.Equals(deviceRegistration.Certificate));
            Assert.IsTrue(publicKey.Equals(deviceRegistration.PublicKey));
            Assert.IsTrue(keyHandle.Equals(deviceRegistration.KeyHandle));
        }
Ejemplo n.º 19
0
        public void Validate_InvalidBytes_Throws()
        {
            var value = new FidoPublicKey(new byte[65]);

            Assert.Throws <ArgumentException>(() => value.Validate());
        }
Ejemplo n.º 20
0
        public void Validate_BytesEmpty_Throws()
        {
            var value = new FidoPublicKey(new byte[0]);

            Assert.Throws <InvalidOperationException>(() => value.Validate());
        }
        public void ToJson()
        {
            var keyHandle = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle"));
            var publicKey = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
            var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate"));

            var deviceRegistration = new FidoDeviceRegistration(keyHandle, publicKey, certificate, 12345);

            var serialized = deviceRegistration.ToJson();

            var jsonObject = JObject.Parse(serialized);
            var properties = jsonObject.Properties().ToLookup(x => x.Name.ToLowerInvariant(), x => x.Value.ToString());

            Assert.AreEqual("Y2VydGlmaWNhdGU", properties["certificate"].Single());
            Assert.AreEqual("12345", properties["counter"].Single());
            Assert.AreEqual("a2V5aGFuZGxl", properties["keyhandle"].Single());
            Assert.AreEqual("cHVibGlja2V5", properties["publickey"].Single());
        }
Ejemplo n.º 22
0
 public void Equals_Null()
 {
     Assert.IsFalse(FidoPublicKey.FromWebSafeBase64("").Equals(null));
 }
Ejemplo n.º 23
0
        public void Constructor()
        {
            var value = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));

            Assert.AreEqual("publickey", Encoding.Default.GetString(value.ToByteArray()));
        }
        private static FidoDeviceRegistration CreateTestDeviceRegistration()
        {
            var keyHandle = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle"));
            var publicKey = new FidoPublicKey(Encoding.Default.GetBytes("publickey"));
            var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate"));

            var deviceRegistration = new FidoDeviceRegistration(keyHandle, publicKey, certificate, 12345);
            return deviceRegistration;
        }