private static void ValidateCertificate(AttestedDocument document) { try { // Build certificate from response X509Certificate2 cert = new X509Certificate2(System.Text.Encoding.UTF8.GetBytes(document.Signature)); // Build certificate chain X509Chain chain = new X509Chain(); chain.Build(cert); // Print certificate chain information foreach (X509ChainElement element in chain.ChainElements) { Console.WriteLine("Element issuer: {0}", element.Certificate.Issuer); Console.WriteLine("Element subject: {0}", element.Certificate.Subject); Console.WriteLine("Element certificate valid until: {0}", element.Certificate.NotAfter); Console.WriteLine("Element certificate is valid: {0}", element.Certificate.Verify()); Console.WriteLine("Element error status length: {0}", element.ChainElementStatus.Length); Console.WriteLine("Element information: {0}", element.Information); Console.WriteLine("Number of element extensions: {0}{1}", element.Certificate.Extensions.Count, Environment.NewLine); } } catch (CryptographicException ex) { Console.WriteLine("Exception: {0}", ex); } }
private static void ParseAttestedResponse(string response) { Console.WriteLine("Parsing Attested response"); AttestedDocument document = (AttestedDocument)SerializeObjectFromJsonString(typeof(AttestedDocument), response); ValidateCertificate(document); ValidateAttestedData(document); }
private static void ValidateAttestedData(AttestedDocument document) { try { byte[] blob = Convert.FromBase64String(document.Signature); SignedCms signedCms = new SignedCms(); signedCms.Decode(blob); string result = Encoding.UTF8.GetString(signedCms.ContentInfo.Content); Console.WriteLine("Attested data: {0}", result); AttestedData data = SerializeObjectFromJsonString(typeof(AttestedData), result) as AttestedData; if (data.Nonce.Equals(NonceValue)) { Console.WriteLine("Nonce values match"); } } catch (Exception ex) { Console.WriteLine("Error checking signature blob: '{0}'", ex); } }