public void Load() { string expected = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>/Vvq6sXEVbtZC8GwNtLQnGOy/VI=</DigestValue></Reference></SignedInfo><SignatureValue>A6XuE8Cy9iOffRXaW9b0+dUcMUJQnlmwLsiqtQnADbCtZXnXAaeJ6nGnQ4Mm0IGi0AJc7/2CoJReXl7iW4hltmFguG1e3nl0VxCyCTHKGOCo1u8R3K+B1rTaenFbSxs42EM7/D9KETsPlzfYfis36yM3PqatiCUOsoMsAiMGzlc=</SignatureValue><KeyInfo><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>tI8QYIpbG/m6JLyvP+S3X8mzcaAIayxomyTimSh9UCpEucRnGvLw0P73uStNpiF7wltTZA1HEsv+Ha39dY/0j/Wiy3RAodGDRNuKQao1wu34aNybZ673brbsbHFUfw/o7nlKD2xO84fbajBZmKtBBDy63NHt+QL+grSrREPfCTM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo><Object Id=\"MyObjectId\"><MyElement xmlns=\"samples\">This is some text</MyElement></Object></Signature>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(expected); signature.LoadXml(doc.DocumentElement); string result = signature.GetXml().OuterXml; AssertCrypto.AssertXmlEquals("Load", expected, result); }
public void X509Data() { X509Certificate x509 = new X509CertificateParser().ReadCertificate(cert); KeyInfoX509Data x509data = new KeyInfoX509Data(x509); info.AddClause(x509data); AssertCrypto.AssertXmlEquals("X509Data", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Certificate>MIICHTCCAYYCARQwDQYJKoZIhvcNAQEEBQAwWDELMAkGA1UEBhMCQ0ExHzAdBgNVBAMTFktleXdpdG5lc3MgQ2FuYWRhIEluYy4xKDAmBgorBgEEASoCCwIBExhrZXl3aXRuZXNzQGtleXdpdG5lc3MuY2EwHhcNOTYwNTA3MDAwMDAwWhcNOTkwNTA3MDAwMDAwWjBYMQswCQYDVQQGEwJDQTEfMB0GA1UEAxMWS2V5d2l0bmVzcyBDYW5hZGEgSW5jLjEoMCYGCisGAQQBKgILAgETGGtleXdpdG5lc3NAa2V5d2l0bmVzcy5jYTCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAzSP6KuHtmPTp0JM+13qAAkzMwQKvXLYff/pXQm8w0SDFtSEHQCyphsLzZISuPYUu7YW9VLAYKO9q+BvnCxYfkyVPx/iOw7nKmIQOVdAv73h3xXIoX2C/GSvRcqK32D/glzRaAb0EnMh4Rc2TjRXydhARq7hbLp5S3YE+nGTIKZMCAQMwDQYJKoZIhvcNAQEEBQADgYEAMho1ur9DJ9a01Lh25eObTWzAhsl3NbprFi0TRkqwMlOhW1rpmeIMhogXTg3+gqxOR+/7/zms7jXI+lI3CkmtWa3iiqkcxl8f+G9zfs2gMegMvvVN2bKrihK2MHhoEXwN8UlNo/2y6f8d8JH6VIX/M5Dowb+km6RiRr1hElmYQYk=</X509Certificate></X509Data></KeyInfo>", (info.GetXml().OuterXml)); Assert.Equal(1, info.Count); }
public void InvalidKeyNode2() { string bad = "<Test></Test>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(bad); KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod(); uri1.LoadXml(doc.DocumentElement); AssertCrypto.AssertXmlEquals("invalid", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml().OuterXml)); }
public void RSAKeyValue() { var key = new RsaKeyParameters( isPrivate: false, modulus: new BigInteger(1, Convert.FromBase64String(rsaModulus)), exponent: new BigInteger(1, Convert.FromBase64String(rsaExponent)) ); RSAKeyValue rsa = new RSAKeyValue(key); info.AddClause(rsa); AssertCrypto.AssertXmlEquals("rsa", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + xmlRSA + "</KeyValue></KeyInfo>", (info.GetXml().OuterXml)); Assert.Equal(1, info.Count); }
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); // add a second X.509 certificate 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); // add properties from a third X.509 certificate 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)); // 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.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 Complex() { KeyInfoName name = new KeyInfoName(); name.Value = "CoreFx::"; info.AddClause(name); var keyDSA = new DsaPublicKeyParameters(y: new BigInteger(Convert.FromBase64String(dsaY)), parameters: new DsaParameters( p: new BigInteger(1, Convert.FromBase64String(dsaP)), q: new BigInteger(1, Convert.FromBase64String(dsaQ)), g: new BigInteger(1, Convert.FromBase64String(dsaG)) ) ); DSAKeyValue dsa = new DSAKeyValue(keyDSA); info.AddClause(dsa); var keyRSA = new RsaKeyParameters( isPrivate: false, modulus: new BigInteger(1, Convert.FromBase64String(rsaModulus)), exponent: new BigInteger(1, Convert.FromBase64String(rsaExponent)) ); RSAKeyValue rsa = new RSAKeyValue(keyRSA); info.AddClause(rsa); KeyInfoRetrievalMethod retrieval = new KeyInfoRetrievalMethod(); retrieval.Uri = "https://github.com/dotnet/corefx"; info.AddClause(retrieval); X509Certificate x509 = new X509CertificateParser().ReadCertificate(cert); KeyInfoX509Data x509data = new KeyInfoX509Data(x509); info.AddClause(x509data); string s = "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyName>CoreFx::</KeyName><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><DSAKeyValue><P>rjxsMU368YOCTQejWkiuO9e/vUVwkLtq1jKiU3TtJ53hBJqjFRuTa228vZe+BH2su9RPn/vYFWfQDv6zgBYe3eNdu4Afw+Ny0FatX6dl3E77Ra6Tsd3MmLXBiGSQ1mMNd5G2XQGpbt9zsGlUaexXekeMLxIufgfZLwYp67M+2WM=</P><Q>tf0K9rMyvUrU4cIkwbCrDRhQAJk=</Q><G>S8Z+1pGCed00w6DtVcqZLKjfqlCJ7JsugEFIgSy/Vxtu9YGCMclV4ijGEbPo/jU8YOSMuD7E9M7UaopMRcmKQjoKZzoJjkgVFP48Ohxl1f08lERnButsxanx3+OstFwUGQ8XNaGg3KrIoZt1FUnfxN3RHHTvVhjzNSHxMGULGaU=</G><Y>LnrxxRGLYeV2XLtK3SYz8RQHlHFZYrtznDZyMotuRfO5uC5YODhSFyLXvb1qB3WeGtF4h3Eo4KzHgMgfN2ZMlffxFRhJgTtH3ctbL8lfQoDkjeiPPnYGhspdJxr0tyZmiy0gkjJG3vwHYrLnvZWx9Wm/unqiOlGBPNuxJ+hOeP8=</Y></DSAKeyValue></KeyValue>"; s += "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>9DC4XNdQJwMRnz5pP2a6U51MHCODRilaIoVXqUPhCUb0lJdGroeqVYT84ZyIVrcarzD7Tqs3aEOIa3rKox0N1bxQpZPqayVQeLAkjLLtzJW/ScRJx3uEDJdgT1JnM1FH0GZTinmEdCUXdLc7+Y/c/qqIkTfbwHbRZjW0bBJyExM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue>"; s += "<RetrievalMethod URI=\"https://github.com/dotnet/corefx\" />"; s += "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">"; s += "<X509Certificate>MIICHTCCAYYCARQwDQYJKoZIhvcNAQEEBQAwWDELMAkGA1UEBhMCQ0ExHzAdBgNVBAMTFktleXdpdG5lc3MgQ2FuYWRhIEluYy4xKDAmBgorBgEEASoCCwIBExhrZXl3aXRuZXNzQGtleXdpdG5lc3MuY2EwHhcNOTYwNTA3MDAwMDAwWhcNOTkwNTA3MDAwMDAwWjBYMQswCQYDVQQGEwJDQTEfMB0GA1UEAxMWS2V5d2l0bmVzcyBDYW5hZGEgSW5jLjEoMCYGCisGAQQBKgILAgETGGtleXdpdG5lc3NAa2V5d2l0bmVzcy5jYTCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAzSP6KuHtmPTp0JM+13qAAkzMwQKvXLYff/pXQm8w0SDFtSEHQCyphsLzZISuPYUu7YW9VLAYKO9q+BvnCxYfkyVPx/iOw7nKmIQOVdAv73h3xXIoX2C/GSvRcqK32D/glzRaAb0EnMh4Rc2TjRXydhARq7hbLp5S3YE+nGTIKZMCAQMwDQYJKoZIhvcNAQEEBQADgYEAMho1ur9DJ9a01Lh25eObTWzAhsl3NbprFi0TRkqwMlOhW1rpmeIMhogXTg3+gqxOR+/7/zms7jXI+lI3CkmtWa3iiqkcxl8f+G9zfs2gMegMvvVN2bKrihK2MHhoEXwN8UlNo/2y6f8d8JH6VIX/M5Dowb+km6RiRr1hElmYQYk=</X509Certificate></X509Data></KeyInfo>"; AssertCrypto.AssertXmlEquals("Complex", s, (info.GetXml().OuterXml)); Assert.Equal(5, info.Count); }
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 DSAKeyValue() { var key = new DsaPublicKeyParameters(y: new BigInteger(1, Convert.FromBase64String(dsaY)), parameters: new DsaParameters( p: new BigInteger(1, Convert.FromBase64String(dsaP)), q: new BigInteger(1, Convert.FromBase64String(dsaQ)), g: new BigInteger(1, Convert.FromBase64String(dsaG)) )); DsaKeyValue dsa = new DsaKeyValue(key); info.AddClause(dsa); AssertCrypto.AssertXmlEquals("dsa", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + xmlDSA + "</KeyValue></KeyInfo>", (info.GetXml().OuterXml)); Assert.Equal(1, info.Count); }