public static AnchorVerifierSourceData GetTypesFromAnchor(AttrpubapiV1.Anchor 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()); var anchorEnum = typeof(AnchorType); foreach (AnchorType type in Enum.GetValues(anchorEnum)) { var name = Enum.GetName(anchorEnum, type); string extensionOid = anchorEnum.GetRuntimeField(name) .GetCustomAttributes(inherit: false) .OfType <ExtensionOidAttribute>() .Single().ExtensionOid; extensions = GetListOfStringsFromExtension(certificate, extensionOid); if (extensions.Count() > 0) { anchorType = type; break; } } types.UnionWith(extensions); } return(new AnchorVerifierSourceData(types, anchorType)); }
public void Anchor_Getters() { AttrpubapiV1.Attribute attribute = TestTools.Anchors.BuildAnchoredAttribute( "given_names", "givenNameValue", AttrpubapiV1.ContentType.String, TestAnchors.DrivingLicenseAnchor); AttrpubapiV1.Anchor protobufAnchor = attribute.Anchors.Single(); var yotiAnchor = new Yoti.Auth.Anchors.Anchor(protobufAnchor); Assert.IsFalse(yotiAnchor.GetAnchorType().IsDefault()); Assert.IsFalse(yotiAnchor.GetArtifactSignature().IsDefault()); Assert.IsFalse(yotiAnchor.GetSignature().IsDefault()); Assert.IsFalse(yotiAnchor.GetSignedTimeStamp().GetTimestamp().IsDefault()); Assert.IsFalse(yotiAnchor.GetSignedTimeStamp().GetVersion().IsDefault()); 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.IsFalse(yotiAnchor.GetSubType().IsDefault()); Assert.IsFalse(yotiAnchor.GetOriginServerCerts().IsDefault()); Assert.IsFalse(yotiAnchor.GetValue().IsDefault()); }
public Anchor(AttrpubapiV1.Anchor protobufAnchor) { AnchorVerifierSourceData anchorSourceData = AnchorCertificateParser.GetTypesFromAnchor(protobufAnchor); _anchorType = anchorSourceData.GetAnchorType(); _value = anchorSourceData.GetEntries().ToList(); _artifactSignature = protobufAnchor.ArtifactSignature.ToByteArray(); _signature = protobufAnchor.Signature.ToByteArray(); _subType = protobufAnchor.SubType; _originServerCerts = ConvertRawCertToX509List(protobufAnchor.OriginServerCerts); var protobufSignedTimestamp = CompubapiV1.SignedTimestamp.Parser.ParseFrom(protobufAnchor.SignedTimeStamp.ToByteArray()); _signedTimeStamp = new SignedTimestamp(protobufSignedTimestamp); }