Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public void X509Data()
 {
     using (X509Certificate x509 = new X509Certificate(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();

            // no exception is thrown
            uri1.LoadXml(doc.DocumentElement);
            AssertCrypto.AssertXmlEquals("invalid", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml().OuterXml));
        }
Exemplo n.º 4
0
        public void ImportKeyNode()
        {
            string value = "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyName>Mono::</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><J>9RhE5TycDtdEIXxS3HfxFyXYgpy81zY5lVjwD6E9JP37MWEi80BlX6ab1YPm6xYSEoqReMPP9RgGiW6DuACpgI7+8vgCr4i/7VhzModJAA56PwvTu6UMt9xxKU/fT672v8ucREkMWoc7lEey</J><Seed>HxW3N4RHWVgqDQKuGg7iJTUTiCs=</Seed><PgenCounter>Asw=</PgenCounter></DSAKeyValue></KeyValue>";

            value += "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>9DC4XNdQJwMRnz5pP2a6U51MHCODRilaIoVXqUPhCUb0lJdGroeqVYT84ZyIVrcarzD7Tqs3aEOIa3rKox0N1bxQpZPqayVQeLAkjLLtzJW/ScRJx3uEDJdgT1JnM1FH0GZTinmEdCUXdLc7+Y/c/qqIkTfbwHbRZjW0bBJyExM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue><RetrievalElement URI=\"http://www.go-mono.org/\" /><X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">";
            value += "<X509Certificate>MIICHTCCAYYCARQwDQYJKoZIhvcNAQEEBQAwWDELMAkGA1UEBhMCQ0ExHzAdBgNVBAMTFktleXdpdG5lc3MgQ2FuYWRhIEluYy4xKDAmBgorBgEEASoCCwIBExhrZXl3aXRuZXNzQGtleXdpdG5lc3MuY2EwHhcNOTYwNTA3MDAwMDAwWhcNOTkwNTA3MDAwMDAwWjBYMQswCQYDVQQGEwJDQTEfMB0GA1UEAxMWS2V5d2l0bmVzcyBDYW5hZGEgSW5jLjEoMCYGCisGAQQBKgILAgETGGtleXdpdG5lc3NAa2V5d2l0bmVzcy5jYTCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAzSP6KuHtmPTp0JM+13qAAkzMwQKvXLYff/pXQm8w0SDFtSEHQCyphsLzZISuPYUu7YW9VLAYKO9q+BvnCxYfkyVPx/iOw7nKmIQOVdAv73h3xXIoX2C/GSvRcqK32D/glzRaAb0EnMh4Rc2TjRXydhARq7hbLp5S3YE+nGTIKZMCAQMwDQYJKoZIhvcNAQEEBQADgYEAMho1ur9DJ9a01Lh25eObTWzAhsl3NbprFi0TRkqwMlOhW1rpmeIMhogXTg3+gqxOR+/7/zms7jXI+lI3CkmtWa3iiqkcxl8f+G9zfs2gMegMvvVN2bKrihK2MHhoEXwN8UlNo/2y6f8d8JH6VIX/M5Dowb+km6RiRr1hElmYQYk=</X509Certificate></X509Data></KeyInfo>";
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(value);
            info.LoadXml(doc.DocumentElement);

            AssertCrypto.AssertXmlEquals("Import", value, (info.GetXml().OuterXml));
            Assert.Equal(5, info.Count);
        }
Exemplo n.º 5
0
        public void Complex()
        {
            KeyInfoName name = new KeyInfoName();

            name.Value = "CoreFx::";
            info.AddClause(name);

            using (DSA keyDSA = DSA.Create())
            {
                keyDSA.ImportParameters(new DSAParameters
                {
                    P = Convert.FromBase64String(dsaP),
                    Q = Convert.FromBase64String(dsaQ),
                    G = Convert.FromBase64String(dsaG),
                    Y = Convert.FromBase64String(dsaY),
                });
                DSAKeyValue dsa = new DSAKeyValue(keyDSA);
                info.AddClause(dsa);

                using (RSA keyRSA = RSA.Create())
                {
                    keyRSA.ImportParameters(new RSAParameters()
                    {
                        Modulus  = Convert.FromBase64String(rsaModulus),
                        Exponent = 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);

                    using (X509Certificate x509 = new X509Certificate(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);
                    }
                }
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 public void RSAKeyValue()
 {
     using (RSA key = RSA.Create())
     {
         key.ImportParameters(new RSAParameters()
         {
             Modulus  = Convert.FromBase64String(rsaModulus),
             Exponent = 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);
     }
 }
Exemplo n.º 8
0
 public void DSAKeyValue()
 {
     using (DSA key = DSA.Create())
     {
         key.ImportParameters(new DSAParameters {
             P = Convert.FromBase64String(dsaP),
             Q = Convert.FromBase64String(dsaQ),
             G = Convert.FromBase64String(dsaG),
             Y = Convert.FromBase64String(dsaY),
             //J = Convert.FromBase64String(dsaJ),
             //Seed = Convert.FromBase64String(dsaSeed),
             //Counter = BitConverter.ToUInt16(Convert.FromBase64String(dsaPgenCounter), 0)
         });
         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);
     }
 }