Ejemplo n.º 1
0
        public void GetXml()
        {
            DsaKeyValue dsa    = new DsaKeyValue();
            XmlElement  xmlkey = dsa.GetXml();

            XmlNamespaceManager ns = new XmlNamespaceManager(xmlkey.OwnerDocument.NameTable);

            ns.AddNamespace("schema", XmlNameSpace.Url[NS.XmlDsigNamespaceUrl]);

            IEnumerable <XmlNode> elements =
                new[] { "P", "Q", "G", "Y", "J", "Seed", "PgenCounter" }
            .Select(elementName => xmlkey.SelectSingleNode($"/schema:DSAKeyValue/schema:{elementName}", ns))
            .Where(element => element != null);


            Assert.NotEmpty(elements);


            Assert.True(elements.SingleOrDefault(element => element.Name == "Y") != null);


            Assert.True(elements.All(element => !string.IsNullOrEmpty(element.InnerText)));


            elements.Select(element => Convert.FromBase64String(element.InnerText));
        }
Ejemplo n.º 2
0
        public void LoadXml()
        {
            const string pValue           = "oDZlcdJA1Kf6UeNEIZqm4KDqA6zpX7CmEtAGWi9pgnBhWOUDVEfhswfsvTLR5BCbKfE6KoHvt5Hh8D1RcAko//iZkLZ+gds9y/5Oxape8tu3TUi1BnNPWu8ieXjMtdnpyudKFsCymssJked1rBeRePG23HTVwOV1DpopjRkjBEU=";
            const string qValue           = "0JxsZhjbIteTbrtfWmt5Uif6il8=";
            const string gValue           = "EOVCfv1saTWIc6Dgim24a07dqqyCJXmIT+5PrgrfV3M8/hfmaMfZtpvM0BUkXVv0dFScnN7txnSpnLWchBz0RfehL6c7Mofu/d2H1cp8zvwTasfiJhypQHDuC4p1aSXuQ1hnzzyYeHKzBH9r0PA78haL7/HnwrrscttXGhmU/L0=";
            const string yValue           = "HBHSdiOJDoZhRpK+B4Ft5hisHvRjz6rELay+aPrya2yKRUUN7ZysNi12PltAvljexay0gEpPncg6TrRtH1+7usTxbgkuIwcQ3RPPIzM7y+XldbcyVUfyze5+zXy9ALiugT+zP8DOMRj9Yj6kR6ZsgbnSdlH2hGIn9NctXgRQ6Kg=";
            const string seedValue        = "NKemrvYwT/4u8DNiXoPj9jO6LAg=";
            const string pgenCounterValue = "uA==";
            string       dsaKey           = $"<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><DSAKeyValue><P>{pValue}</P><Q>{qValue}</Q><G>{gValue}</G><Y>{yValue}</Y><Seed>{seedValue}</Seed><PgenCounter>{pgenCounterValue}</PgenCounter></DSAKeyValue></KeyValue>";

            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(dsaKey);

            var dsaKeyValue = new DsaKeyValue();

            dsaKeyValue.LoadXml(xmlDoc.DocumentElement);

            var parameters = dsaKeyValue.GetKey().Parameters;

            Assert.Equal(Convert.ToBase64String(parameters.P.ToByteArray()), pValue);
            Assert.Equal(Convert.ToBase64String(parameters.Q.ToByteArray()), qValue);
            Assert.Equal(Convert.ToBase64String(parameters.G.ToByteArray()), gValue);
            Assert.Equal(Convert.ToBase64String(dsaKeyValue.GetKey().Y.ToByteArray()), yValue);
            var seed = parameters.ValidationParameters.GetSeed();

            Assert.NotNull(seed);
            Assert.Equal(Convert.ToBase64String(seed), seedValue);
            Assert.Equal(BitConverter.GetBytes(parameters.ValidationParameters.Counter)[0], Convert.FromBase64String(pgenCounterValue)[0]);
        }
Ejemplo n.º 3
0
        public void Ctor_Dsa()
        {
            var         pair        = TestHelpers.DSAGenerateKeyPair();
            DsaKeyValue dsaKeyValue = new DsaKeyValue((DsaPublicKeyParameters)pair.Public);

            Assert.Equal(pair.Public, dsaKeyValue.GetKey());
        }
Ejemplo n.º 4
0
        public void GetXml_SameDsa()
        {
            var         pair         = TestHelpers.DSAGenerateKeyPair();
            DsaKeyValue dsaKeyValue1 = new DsaKeyValue((DsaPublicKeyParameters)pair.Public);
            DsaKeyValue dsaKeyValue2 = new DsaKeyValue((DsaPublicKeyParameters)pair.Public);

            Assert.Equal(dsaKeyValue1.GetXml(), dsaKeyValue2.GetXml());
        }
Ejemplo n.º 5
0
        public void Ctor_Dsa_Null()
        {
            DsaKeyValue dsaKeyValue = new DsaKeyValue(null);



            Assert.Null(dsaKeyValue.GetKey());
        }
Ejemplo n.º 6
0
        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.SetUri("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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        public void Ctor_Empty()
        {
            DsaKeyValue dsaKeyValue = new DsaKeyValue();

            Assert.NotNull(dsaKeyValue.GetKey());
        }
Ejemplo n.º 9
0
        public void LoadXml_Null()
        {
            DsaKeyValue dsa1 = new DsaKeyValue();

            Assert.Throws <ArgumentNullException>(() => dsa1.LoadXml(null));
        }