static void Test7() //negative LoadXml test { try { data = new KeyInfoX509Data(); data.LoadXml(data.GetXml()); rv = false; } catch (CryptographicException ce) { Console.WriteLine(ce.ToString()); rv = true; } catch (Exception e) { Console.WriteLine(e.ToString()); rv = false; } try { data = new KeyInfoX509Data(); data.LoadXml(null); rv = false; } catch { rv = true; } }
public void Complex() { KeyInfoX509Data data1 = new KeyInfoX509Data(cert); KeyInfoX509Data data2 = new KeyInfoX509Data(); XmlElement xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); byte[] c = (data1.Certificates[0] as X509Certificate).GetRawCertData(); AssertCrypto.AssertEquals("Certificate[0]", cert, c); // add a second X.509 certificate X509Certificate x509 = new X509Certificate(cert2); data1.AddCertificate(x509); xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); c = (data1.Certificates[1] as X509Certificate).GetRawCertData(); Assert.Equal(cert2, c); // add properties from a third X.509 certificate x509 = new X509Certificate(cert3); data1.AddIssuerSerial(x509.Issuer, x509.GetSerialNumberString()); xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); // TODO: The type of IssuerSerial isn't documented // X509Certificate doesn't export SubjectKeyId so we must improvise byte[] skid = { 0xDE, 0xAD, 0xC0, 0xDE }; data1.AddSubjectKeyId(skid); xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); Assert.Equal(skid, (byte[])data1.SubjectKeyIds[0]); data1.AddSubjectName(x509.Subject); xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); string s = (string)data1.SubjectNames[0]; Assert.Equal(x509.Subject, s); }
public void ReadXml(XmlReader r) { r.MoveToContent(); XmlDocument doc = new XmlDocument(); data = new KeyInfoX509Data(); data.LoadXml(doc.ReadNode(r) as XmlElement); }
public void Complex() { KeyInfoX509Data data1 = new KeyInfoX509Data(cert); KeyInfoX509Data data2 = new KeyInfoX509Data(); XmlElement xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); byte[] c = (data1.Certificates[0] as X509Certificate).GetEncoded(); AssertCrypto.AssertEquals("Certificate[0]", cert, c); X509Certificate x509 = new X509CertificateParser().ReadCertificate(cert2); data1.AddCertificate(x509); xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); c = (data1.Certificates[1] as X509Certificate).GetEncoded(); Assert.Equal(cert2, c); x509 = new X509CertificateParser().ReadCertificate(cert3); data1.AddIssuerSerial(x509.IssuerDN.ToString(), x509.SerialNumber.ToString()); xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); byte[] skid = { 0xDE, 0xAD, 0xC0, 0xDE }; data1.AddSubjectKeyId(skid); xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); Assert.Equal(skid, (byte[])data1.SubjectKeyIds[0]); data1.AddSubjectName(x509.SubjectDN.ToString()); xel = data1.GetXml(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); string s = (string)data1.SubjectNames[0]; Assert.Equal(x509.SubjectDN.ToString(), s); }
public void InvalidKeyNode3() { string bad = "<Test></Test>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(bad); KeyInfoX509Data data1 = new KeyInfoX509Data(); Assert.Throws <CryptographicException>(() => data1.LoadXml(doc.DocumentElement)); }
public void InvalidKeyNode3() { string bad = "<Test></Test>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(bad); KeyInfoX509Data data1 = new KeyInfoX509Data(); data1.LoadXml(doc.DocumentElement); }
public void CRL() { KeyInfoX509Data data1 = new KeyInfoX509Data(); data1.CRL = x509crl; XmlElement xel = data1.GetXml(); KeyInfoX509Data data2 = new KeyInfoX509Data(); data2.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); Assert.Equal(data1.CRL, data2.CRL); }
static void Test6() //Xml roundtrip { int i = 0; data = new KeyInfoX509Data(); //add certs data.AddCertificate(TestCert); data.AddCertificate(EndCert); //add subject name data.AddSubjectName(TestCert.SubjectName.Name); data.AddSubjectName(EndCert.SubjectName.Name); //add subject keys data.AddSubjectKeyId(new byte[] { 1, 2, 3, 4, 5, 6 }); data.AddSubjectKeyId(new byte[] { 7, 8, 9, 10, 11, 12 }); //add issuer serials data.AddIssuerSerial(TestCert.IssuerName.Name, TestCert.SerialNumber); data.AddIssuerSerial(EndCert.IssuerName.Name, EndCert.SerialNumber); //add the crl byte[] b = { 100, 101, 102, 104 }; data.CRL = b; KeyInfoX509Data rt = new KeyInfoX509Data(); rt.LoadXml(data.GetXml()); for (i = 0; i < rt.CRL.Length; i++) { rv = rt.CRL[i] == data.CRL[i]; } for (i = 0; i < rt.Certificates.Count; i++) { rv = rt.Certificates[i].ToString() == data.Certificates[i].ToString(); } for (i = 0; i < rt.SubjectKeyIds.Count; i++) { rv = rt.SubjectKeyIds[i].ToString() == data.SubjectKeyIds[i].ToString(); } for (i = 0; i < rt.SubjectNames.Count; i++) { rv = rt.SubjectNames[i].ToString() == data.SubjectNames[i].ToString(); } }
public void Constructor_X509Certificate() { KeyInfoX509Data data1 = new KeyInfoX509Data(); KeyInfoX509Data data2 = new KeyInfoX509Data(cert); XmlElement xel = data2.GetXml(); string s = "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Certificate>MIIJuTCCCSKgAwIBAgIQIAs1Xs7EsGO33sY0uXA0RDANBgkqhkiG9w0BAQQFADBiMREwDwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWduIENsYXNzIDEgQ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ml)); data1.LoadXml(xel); Assert.Equal((data1.GetXml().OuterXml), (data2.GetXml().OuterXml)); X509Certificate x509 = new X509Certificate(cert); KeyInfoX509Data data3 = new KeyInfoX509Data(x509); Assert.Equal((data2.GetXml().OuterXml), (data3.GetXml().OuterXml)); }
public void ImportX509Data() { string simple = "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Certificate>MIIJuTCCCSKgAwIBAgIQIAs1Xs7EsGO33sY0uXA0RDANBgkqhkiG9w0BAQQFADBiMREwDwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwHhcNOTYwODIxMDAwMDAwWhcNOTcwODIwMjM1OTU5WjCCAQoxETAPBgNVBAcTCEludGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjFGMEQGA1UECxM9d3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUyBJbmNvcnAuIGJ5IFJlZi4sTElBQi5MVEQoYyk5NjEmMCQGA1UECxMdRGlnaXRhbCBJRCBDbGFzcyAxIC0gTmV0c2NhcGUxFjAUBgNVBAMTDURhdmlkIFQuIEdyYXkxHjAcBgkqhkiG9w0BCQEWD2RhdmlkQGZvcm1hbC5pZTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDFgQei6w+4//j4HO4y/78SNWr5a8i+L/s+rwRRSqzdECmozUBbZh6Y7/JMd/qPhtEhZ5JESsSJyYPPiJ9v4jI1AgMBAAGjggcIMIIHBDAJBgNVHRMEAjAAMIICHwYDVR0DBIICFjCCAhIwggIOMIICCgYLYIZIAYb4RQEHAQEwggH5FoIBp1RoaXMgY2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVzI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BdHRyaWJ1dGVzIGV4dGVuc2lvbiB2YWx1ZSBzaGFsbCAKbm90IGJlIGNvbnNpZGVyZWQgYXMgYWNjdXJhdGUgaW5mb3JtYXRpb24gdmFsaWRhdGVkIApieSB0aGUgSUEuMA0GCSqGSIb3DQEBBAUAA4GBACs9RMcyWa7xX48/h+M+64Ew+KmW2wFCCwTvNwI/1CBhWMRKOjmz+9n4pcReM1oO+pNWL2/WYaKvpQwd4kFl80B1ZoPSWrS3VguODaEzE31Jw7EAaIN/tWbUMjL+i5pa1gFyMV2FkbyTm2VgJcYfvN1pRGLCsm9Gqy8gpW/aSGyc</X509Certificate></X509Data>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(simple); KeyInfoX509Data data1 = new KeyInfoX509Data(); data1.LoadXml(doc.DocumentElement); // verify that proper XML is generated (equals to original) string s = (data1.GetXml().OuterXml); Assert.Equal(simple, s); // verify that property is parsed correctly byte[] c = (data1.Certificates[0] as X509Certificate).GetRawCertData(); Assert.Equal(cert, c); string complex = "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509IssuerSerial><X509IssuerName>C=US, O=U.S. Government, OU=DoD, CN=Armed Forces Root</X509IssuerName><X509SerialNumber>03</X509SerialNumber></X509IssuerSerial><X509SKI>3q3A3g==</X509SKI><X509SubjectName>C=US, O=U.S. Government, OU=DoD, CN=Armed Forces Root</X509SubjectName><X509Certificate>MIIJuTCCCSKgAwIBAgIQIAs1Xs7EsGO33sY0uXA0RDANBgkqhkiG9w0BAQQFADBiMREwDwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwHhcNOTYwODIxMDAwMDAwWhcNOTcwODIwMjM1OTU5WjCCAQoxETAPBgNVBAcTCEludGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrV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AwWhcNOTkwNTA3MDAwMDAwWjBYMQswCQYDVQQGEwJDQTEfMB0GA1UEAxMWS2V5d2l0bmVzcyBDYW5hZGEgSW5jLjEoMCYGCisGAQQBKgILAgETGGtleXdpdG5lc3NAa2V5d2l0bmVzcy5jYTCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAzSP6KuHtmPTp0JM+13qAAkzMwQKvXLYff/pXQm8w0SDFtSEHQCyphsLzZISuPYUu7YW9VLAYKO9q+BvnCxYfkyVPx/iOw7nKmIQOVdAv73h3xXIoX2C/GSvRcqK32D/glzRaAb0EnMh4Rc2TjRXydhARq7hbLp5S3YE+nGTIKZMCAQMwDQYJKoZIhvcNAQEEBQADgYEAMho1ur9DJ9a01Lh25eObTWzAhsl3NbprFi0TRkqwMlOhW1rpmeIMhogXTg3+gqxOR+/7/zms7jXI+lI3CkmtWa3iiqkcxl8f+G9zfs2gMegMvvVN2bKrihK2MHhoEXwN8UlNo/2y6f8d8JH6VIX/M5Dowb+km6RiRr1hElmYQYk=</X509Certificate></X509Data>"; doc.LoadXml(complex); KeyInfoX509Data data2 = new KeyInfoX509Data(); data2.LoadXml(doc.DocumentElement); s = (data2.GetXml().OuterXml); Assert.Equal(complex, s); string crl = "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509CRL>HoIBBTByAgEBMAsGCSqGSIb3DQEBBTBRMQswCQYDVQQGEwJVUzEYMBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxGjAYBgNVBAMTEUFybWVkIEZvcmNlcyBSb290Fw0wMjEwMTExMzEyNTBaMAsGCSqGSIb3DQEBBQOBgQB9otEZbQ8Py+SjvuA2CvNMm6/mT/bjr89V88bbq0wWMqpzrczcMjNg34vMk7VPauxwU6/PBw+gzWasAFfGXF0hsb0wiY53jdRpfsA2ftLYIHEIgNLLdIvYQhcEmYCkUnAuwOOMC/95t0V33MXPQ5iRffEB91PXxlE18InMwf/iiQ==</X509CRL></X509Data>"; doc.LoadXml(crl); KeyInfoX509Data data3 = new KeyInfoX509Data(); data3.LoadXml(doc.DocumentElement); s = (data3.GetXml().OuterXml); Assert.Equal(crl, s); }
public void InvalidKeyNode1() { KeyInfoX509Data data1 = new KeyInfoX509Data(); Assert.Throws <ArgumentNullException>(() => data1.LoadXml(null)); }
SecurityKeyIdentifierClause ReadSecurityTokenReference(XmlReader reader) { reader.ReadStartElement(); reader.MoveToContent(); if (reader.NamespaceURI == SignedXml.XmlDsigNamespaceUrl) { KeyInfoX509Data x509 = new KeyInfoX509Data(); x509.LoadXml(new XmlDocument().ReadNode(reader) as XmlElement); if (x509.IssuerSerials.Count == 0) { throw new XmlException("'X509IssuerSerial' element is expected inside 'X509Data' element"); } X509IssuerSerial s = (X509IssuerSerial)x509.IssuerSerials [0]; reader.MoveToContent(); reader.ReadEndElement(); return(new X509IssuerSerialKeyIdentifierClause(s.IssuerName, s.SerialNumber)); } if (reader.NamespaceURI != Constants.WssNamespace) { throw new XmlException(String.Format("Unexpected SecurityTokenReference content: expected local name 'Reference' and namespace URI '{0}' but found local name '{1}' and namespace '{2}'.", Constants.WssNamespace, reader.LocalName, reader.NamespaceURI)); } switch (reader.LocalName) { case "Reference": Type ownerType = null; // FIXME: there could be more token types. if (reader.MoveToAttribute("ValueType")) { switch (reader.Value) { case Constants.WSSEncryptedKeyToken: ownerType = typeof(WrappedKeySecurityToken); break; case Constants.WSSX509Token: ownerType = typeof(X509SecurityToken); break; case Constants.WsscContextToken: ownerType = typeof(SecurityContextSecurityToken); break; default: throw new XmlException(String.Format("Unexpected ValueType in 'Reference' element: '{0}'", reader.Value)); } } reader.MoveToElement(); string uri = reader.GetAttribute("URI"); if (String.IsNullOrEmpty(uri)) { uri = "#"; } SecurityKeyIdentifierClause ic = null; if (ownerType == typeof(SecurityContextSecurityToken) && uri [0] != '#') { // FIXME: Generation? ic = new SecurityContextKeyIdentifierClause(new UniqueId(uri)); } else { ic = new LocalIdKeyIdentifierClause(uri.Substring(1), ownerType); } reader.Skip(); reader.MoveToContent(); reader.ReadEndElement(); return(ic); case "KeyIdentifier": string valueType = reader.GetAttribute("ValueType"); string value = reader.ReadElementContentAsString(); reader.MoveToContent(); reader.ReadEndElement(); // consume </Reference> switch (valueType) { case Constants.WssKeyIdentifierX509Thumbptint: return(new X509ThumbprintKeyIdentifierClause(Convert.FromBase64String(value))); case Constants.WssKeyIdentifierEncryptedKey: return(new InternalEncryptedKeyIdentifierClause(Convert.FromBase64String(value))); case Constants.WssKeyIdentifierSamlAssertion: return(new SamlAssertionKeyIdentifierClause(value)); default: // It is kinda weird but it throws XmlException here ... throw new XmlException(String.Format("KeyIdentifier type '{0}' is not supported in WSSecurityTokenSerializer.", valueType)); } default: throw new XmlException(String.Format("Unexpected SecurityTokenReference content: expected local name 'Reference' and namespace URI '{0}' but found local name '{1}' and namespace '{2}'.", Constants.WssNamespace, reader.LocalName, reader.NamespaceURI)); } }
static void Test7() //negative LoadXml test { try { data = new KeyInfoX509Data() ; data.LoadXml( data.GetXml() ) ; rv = false ; } catch( CryptographicException ce ) { Console.WriteLine( ce.ToString() ) ; rv = true ; } catch( Exception e ) { Console.WriteLine( e.ToString() ) ; rv = false ; } try { data = new KeyInfoX509Data() ; data.LoadXml( null ) ; rv = false ; } catch { rv = true ; } }
static void Test6() //Xml roundtrip { int i = 0 ; data = new KeyInfoX509Data() ; //add certs data.AddCertificate( TestCert ) ; data.AddCertificate( EndCert ) ; //add subject name data.AddSubjectName( TestCert.SubjectName.Name ) ; data.AddSubjectName( EndCert.SubjectName.Name ) ; //add subject keys data.AddSubjectKeyId( new byte[]{1,2,3,4,5,6} ) ; data.AddSubjectKeyId( new byte[]{7,8,9,10,11,12} ) ; //add issuer serials data.AddIssuerSerial( TestCert.IssuerName.Name , TestCert.SerialNumber ) ; data.AddIssuerSerial( EndCert.IssuerName.Name , EndCert.SerialNumber ) ; //add the crl byte[] b = { 100, 101 , 102 , 104 } ; data.CRL = b ; KeyInfoX509Data rt = new KeyInfoX509Data() ; rt.LoadXml( data.GetXml() ) ; for( i = 0 ; i < rt.CRL.Length ; i++ ) { rv = rt.CRL[i] == data.CRL[i] ; } for( i = 0 ; i < rt.Certificates.Count ; i++ ) { rv = rt.Certificates[i].ToString() == data.Certificates[i].ToString() ; } for( i = 0 ; i < rt.SubjectKeyIds.Count ; i++ ) { rv = rt.SubjectKeyIds[i].ToString() == data.SubjectKeyIds[i].ToString() ; } for( i = 0 ; i < rt.SubjectNames.Count ; i++ ) { rv = rt.SubjectNames[i].ToString() == data.SubjectNames[i].ToString() ; } }
public void InvalidKeyNode1() { KeyInfoX509Data data1 = new KeyInfoX509Data(); data1.LoadXml(null); }