Пример #1
0
        private void bulkTestWithKeyInfoID(CertificateX509 certificate, PrivateKeyManager key, string pathSigned)
        {
            XmlDSigSigner signer       = new XmlDSigSigner();
            string        pathSignedID = pathSigned + "_id";

            for (int c = 0; c < arrayCanonicalization.Length; c++)
            {
                /**** TEST FILES ****/
                optionsID.DSigSignatureType = dSigType;
                optionsID.Canonicalization  = arrayCanonicalization[c];

                optionsID.XmlSchemaPath = xmlIDSchemaPath;
                bool signedFile = signer.DoSignFileElement(xmlUnsignedIDPathFile, id, key, certificate,
                                                           Path.Combine(xmlSignedPathRoot, pathSignedID + ".xml"), optionsID);
                Assert.IsTrue(signedFile);
                True(signedFile, signer);

                bool verifyFile = false;
                optionsID.XmlSchemaPath = "";
                KeyInfoType keyInfo = KeyInfoTypeUtils.getKeyInfoType(optionsID.KeyInfoType, error);
                if (keyInfo != KeyInfoType.NONE)
                {
                    verifyFile = signer.DoVerifyFile(Path.Combine(xmlSignedPathRoot, pathSignedID + ".xml"), optionsID);
                }
                else
                {
                    verifyFile = signer.DoVerifyFileWithCert(Path.Combine(xmlSignedPathRoot, pathSignedID + ".xml"), certificate,
                                                             optionsID);
                }
                True(verifyFile, signer);

                /**** TEST STRINGS ****/
                optionsID.XmlSchemaPath = xmlIDSchemaPath;
                string signedString     = signer.DoSignElement(xmlUnsignedID, id, key, certificate, optionsID);
                bool   resultSignString = false;

                optionsID.XmlSchemaPath = "";
                if (keyInfo != KeyInfoType.NONE)
                {
                    resultSignString = signer.DoVerify(signedString, optionsID);
                }
                else
                {
                    resultSignString = signer.DoVerifyWithCert(signedString, certificate, optionsID);
                }
                Assert.IsTrue(resultSignString);
                True(resultSignString, signer);
            }
        }
        public virtual void SetUp()
        {
            signer             = new XmlDSigSigner();
            path_RSA_sha1_1024 = Path.Combine(BASE_PATH, "dummycerts", "RSA_sha1_1024");
            //xmlUnsigned = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Envelope xmlns=\"http://example.org/envelope\">"
            //		+ "  <Body>" + "    Ola mundo" + "  </Body>" + "</Envelope>";
            //dSigType = "ENVELOPED ";
            options = new DSigOptions();

            pathKey  = Path.Combine(path_RSA_sha1_1024, "sha1d_key.pem");
            pathCert = Path.Combine(path_RSA_sha1_1024, "sha1_cert.crt");

            key  = new PrivateKeyManager();
            cert = new CertificateX509();
        }
Пример #3
0
        public virtual void SetUp()
        {
            cert = new CertificateX509();
            cert.Load(BASE_PATH + "dummycerts\\RSA_sha256_1024\\sha256_cert.crt");
            key = new PrivateKeyManager();
            key.Load(BASE_PATH + "dummycerts\\RSA_sha256_1024\\sha256d_key.pem");

            signer  = new XmlDSigSigner();
            options = new DSigOptions();

            options.IdentifierAttribute = "Id";

            xmlInput = "<envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"1.00\"><idLote>1</idLote><evento versao=\"1.00\"><infEvento Id=\"ID2102103521011431017000298855005000016601157405784801\"><cOrgao>91</cOrgao><tpAmb>1</tpAmb><CNPJ>31102046000145</CNPJ><chNFe>35210114310170002988550050000166011574057848</chNFe><dhEvento>2021-01-26T11:12:34-03:00</dhEvento><tpEvento>210210</tpEvento><nSeqEvento>1</nSeqEvento><verEvento>1.00</verEvento><detEvento versao=\"1.00\"><descEvento>Ciencia da Operacao</descEvento></detEvento></infEvento></evento></envEvento>";
            xPath    = "#ID2102103521011431017000298855005000016601157405784801";
        }
Пример #4
0
        private void bulkTestWithKeyInfoXPath(CertificateX509 certificate, PrivateKeyManager key, string pathSigned)
        {
#if NETCORE
            //******Net Core no tiene habilitado usar la transform xpath******//
            Assert.IsTrue(true);
#else
            XmlDSigSigner signer = new XmlDSigSigner();

            string pathSignedXPath = pathSigned + "_xPAth";
            for (int c = 0; c < arrayCanonicalization.Length; c++)
            {
                /**** TEST FILES ****/
                optionsXPath.DSigSignatureType = dSigType;
                optionsXPath.Canonicalization  = arrayCanonicalization[c];
                bool signedFile = signer.DoSignFileElement(xmlUnsignedXPathFile, xPath, key, certificate,
                                                           Path.Combine(xmlSignedPathRoot, pathSignedXPath + ".xml"), optionsXPath);
                Assert.IsTrue(signedFile);
                True(signedFile, signer);

                bool        verifyFile = false;
                KeyInfoType keyInfo    = KeyInfoTypeUtils.getKeyInfoType(optionsXPath.KeyInfoType, error);
                if (keyInfo != KeyInfoType.NONE)
                {
                    verifyFile = signer.DoVerifyFile(Path.Combine(xmlSignedPathRoot, pathSignedXPath + ".xml"), optionsXPath);
                }
                else
                {
                    verifyFile = signer.DoVerifyFileWithCert(Path.Combine(xmlSignedPathRoot, pathSignedXPath + ".xml"), certificate,
                                                             optionsXPath);
                }
                //True(verifyFile, signer);

                /**** TEST STRINGS ****/

                string signedString     = signer.DoSignElement(xmlUnsignedXPath, xPath, key, certificate, optionsXPath);
                bool   resultSignString = false;
                if (keyInfo != KeyInfoType.NONE)
                {
                    resultSignString = signer.DoVerify(signedString, optionsXPath);
                }
                else
                {
                    resultSignString = signer.DoVerifyWithCert(signedString, certificate, optionsXPath);
                }
                //True(resultSignString, signer);
            }
#endif
        }
        public void TestSignBase64()
        {
            CertificateX509 newCert = new CertificateX509();
            bool            loaded  = newCert.FromBase64(base64);

            Assert.IsTrue(loaded);
            True(loaded, newCert);
            PrivateKeyManager key = new PrivateKeyManager();
            bool privateLoaded    = key.Load(pathKey);

            Assert.IsTrue(privateLoaded);
            True(privateLoaded, key);
            XmlDSigSigner signer = new XmlDSigSigner();
            bool          result = signer.DoSignFile(xmlUnsignedPath, key, newCert, xmlSignedPathRoot + pathSigned, options);

            Assert.IsTrue(result);
            True(result, signer);
            bool verify = signer.DoVerifyFile(xmlSignedPathRoot + pathSigned, options);

            Assert.IsTrue(verify);
            True(verify, signer);
        }