Beispiel #1
0
        public void AnchorGettersShouldRetrieveCorrectValues()
        {
            ProtoBuf.Attribute.Attribute attribute = TestTools.Anchors.BuildAnchoredAttribute(
                Constants.UserProfile.GivenNamesAttribute,
                StringValue,
                Yoti.Auth.ProtoBuf.Attribute.ContentType.String,
                TestAnchors.DrivingLicenseAnchor);

            ProtoBuf.Attribute.Anchor protobufAnchor = attribute.Anchors.Single();

            var yotiAnchor = new Anchor(protobufAnchor);

            Assert.AreEqual(AnchorType.SOURCE, yotiAnchor.GetAnchorType());
            Assert.IsFalse(yotiAnchor.GetSignature().IsDefault());
            Assert.AreEqual(636590455839235370, yotiAnchor.GetSignedTimeStamp().GetTimestamp().Ticks);
            Assert.AreEqual(1, yotiAnchor.GetSignedTimeStamp().GetVersion());
            Assert.IsFalse(yotiAnchor.GetSignedTimeStamp().GetMessageDigest().IsDefault());
            Assert.IsFalse(yotiAnchor.GetSignedTimeStamp().GetChainDigest().IsDefault());
            Assert.IsFalse(yotiAnchor.GetSignedTimeStamp().GetChainDigestSkip1().IsDefault());
            Assert.IsFalse(yotiAnchor.GetSignedTimeStamp().GetChainDigestSkip2().IsDefault());
            Assert.AreEqual("", yotiAnchor.GetSubType());
            Assert.AreEqual("DRIVING_LICENCE", yotiAnchor.GetValue());

            X509Certificate2 firstOriginServerCert = yotiAnchor.GetOriginServerCerts().First();

            Assert.AreEqual("CN=driving-licence-registration-server", firstOriginServerCert.Subject);
            Assert.AreEqual("CN=driving-licence-registration-server", firstOriginServerCert.Issuer);
            Assert.AreEqual("22B4AA0414D35D6C6019FE8EBD59B95C", firstOriginServerCert.SerialNumber);
            Assert.AreEqual(new DateTime(2018, 4, 5, 14, 27, 36, DateTimeKind.Utc), firstOriginServerCert.NotBefore.ToUniversalTime());
            Assert.AreEqual(new DateTime(2018, 4, 12, 14, 27, 36, DateTimeKind.Utc), firstOriginServerCert.NotAfter.ToUniversalTime());
            Assert.AreEqual("3C753FFD1D8A359EC89AD2BD679563F2E4F9B767", firstOriginServerCert.Thumbprint);
        }
        public static AnchorVerifierSourceData GetTypesFromAnchor(ProtoBuf.Attribute.Anchor anchor)
        {
            Validation.NotNull(anchor, nameof(anchor));

            var        types      = new HashSet <string>();
            AnchorType anchorType = AnchorType.UNKNOWN;

            foreach (ByteString byteString in anchor.OriginServerCerts)
            {
                var extensions = new List <string>();
                X509Certificate2 certificate = new X509Certificate2(byteString.ToByteArray());

                // certificate is only disposable in .NET 4.6+
#if !NET452
                using (certificate)
                {
#endif
                foreach (X509Extension x509Extension in certificate.Extensions.OfType <X509Extension>())
                {
                    var extensionOid = x509Extension.Oid.Value;

                    if (extensionOid == AnchorType.SOURCE.ExtensionOid())
                    {
                        anchorType = AnchorType.SOURCE;
                    }
                    else if (extensionOid == AnchorType.VERIFIER.ExtensionOid())
                    {
                        anchorType = AnchorType.VERIFIER;
                    }
                    else
                    {
                        continue;
                    }

                    extensions = GetListOfStringsFromExtension(certificate, extensionOid);
                }
#if !NET452
            }
#endif
                if (extensions.Count == 0)
                {
                    return(new AnchorVerifierSourceData(new HashSet <string> {
                        ""
                    }, AnchorType.UNKNOWN));
                }

                types.UnionWith(extensions);
            }

            return(new AnchorVerifierSourceData(types, anchorType));
        }
Beispiel #3
0
        public Anchor(ProtoBuf.Attribute.Anchor protobufAnchor)
        {
            Validation.NotNull(protobufAnchor, nameof(protobufAnchor));

            AnchorVerifierSourceData anchorSourceData = AnchorCertificateParser.GetTypesFromAnchor(protobufAnchor);

            _anchorType = anchorSourceData.GetAnchorType();
            _value      = anchorSourceData.GetEntries().FirstOrDefault();

            _signature         = protobufAnchor.Signature.ToByteArray();
            _subType           = protobufAnchor.SubType;
            _originServerCerts = ConvertRawCertToX509List(protobufAnchor.OriginServerCerts);

            var protobufSignedTimestamp = ProtoBuf.Common.SignedTimestamp.Parser.ParseFrom(protobufAnchor.SignedTimeStamp.ToByteArray());

            _signedTimeStamp = new SignedTimestamp(protobufSignedTimestamp);
        }
Beispiel #4
0
        public void UnknownAnchorShouldHaveCorrectValues()
        {
            ProtoBuf.Attribute.Attribute attribute = TestTools.Anchors.BuildAnchoredAttribute(
                Constants.UserProfile.NationalityAttribute,
                "LND",
                ProtoBuf.Attribute.ContentType.String,
                TestAnchors.UnknownAnchor);

            ProtoBuf.Attribute.Anchor protobufAnchor = attribute.Anchors.Single();

            var yotiAnchor = new Anchor(protobufAnchor);

            Assert.AreEqual(AnchorType.UNKNOWN, yotiAnchor.GetAnchorType());
            Assert.AreEqual("", yotiAnchor.GetValue());
            Assert.AreEqual("TEST UNKNOWN SUB TYPE", yotiAnchor.GetSubType());
            Assert.AreEqual(636873795118400370, yotiAnchor.GetSignedTimeStamp().GetTimestamp().Ticks);
            Assert.AreEqual("00ABA6DD34D84D2696171C6E856E952C81", yotiAnchor.GetOriginServerCerts().First().SerialNumber);
        }