public virtual void SetUp()
        {
            path_RSA_sha1_1024 = Path.Combine(BASE_PATH, "dummycerts", "RSA_sha1_1024");

            options = new DSigOptions();

            xmlUnsignedPath   = Path.Combine(BASE_PATH, "Temp", "toSign.xml");
            pathSigned        = "base64.xml";
            pathKey           = Path.Combine(path_RSA_sha1_1024, "sha1d_key.pem");
            xmlSignedPathRoot = Path.Combine(BASE_PATH, "Temp", "outputTestFilesJ");
        }
Exemple #2
0
        public bool DoVerify(string xmlSigned, DSigOptions options)
        {
            this.error.cleanError();
            XmlDocument xmlDoc = SignatureUtils.documentFromString(xmlSigned, options.XmlSchemaPath, this.error);

            if (this.HasError())
            {
                return(false);
            }
            return(verify(xmlDoc, options.IdentifierAttribute));
        }
        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();
        }
Exemple #4
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";
        }
Exemple #5
0
        public bool DoVerifyFile(string xmlFilePath, DSigOptions options)
        {
            this.error.cleanError();
            if (!SignatureUtils.validateExtensionXML(xmlFilePath))
            {
                this.error.setError("DS001", "The file is not an xml file");
                return(false);
            }
            XmlDocument xmlDoc = SignatureUtils.documentFromFile(xmlFilePath, options.XmlSchemaPath, this.error);

            if (this.HasError())
            {
                return(false);
            }
            return(verify(xmlDoc, options.IdentifierAttribute));
        }
Exemple #6
0
        public bool DoVerifyWithCert(string xmlSigned, CertificateX509 certificate, DSigOptions options)
        {
            this.error.cleanError();
            if (!certificate.Inicialized)
            {
                this.error.setError("DS003", "Certificate not loaded");
                return(false);
            }
            if (SecurityUtils.compareStrings(certificate.getPublicKeyAlgorithm(), "ECDSA"))
            {
                this.error.setError("DS004", "XML signature with ECDSA keys is not implemented on Net Framework");
                return(false);
            }
            XmlDocument xmlDoc = SignatureUtils.documentFromString(xmlSigned, options.XmlSchemaPath, this.error);

            if (this.HasError())
            {
                return(false);
            }
            return(verify(xmlDoc, certificate, options.IdentifierAttribute));
        }
Exemple #7
0
        public virtual void SetUp()
        {
            eu = new EncodingUtil();
            eu.setEncoding("UTF_8");
            path_RSA_sha1_1024   = Path.Combine(BASE_PATH, "dummycerts", "RSA_sha1_1024");
            path_RSA_sha256_1024 = Path.Combine(BASE_PATH, "dummycerts", "RSA_sha256_1024");
            path_RSA_sha256_2048 = Path.Combine(BASE_PATH, "dummycerts", "RSA_sha256_2048");
            path_RSA_sha512_2048 = Path.Combine(BASE_PATH, "dummycerts", "RSA_sha512_2048");

            alias    = "1";
            password = "******";

            xmlUnsigned = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Envelope xmlns=\"http://example.org/envelope\">"
                          + "  <Body>" + "    Ola mundo" + "  </Body>" + "</Envelope>";

            xmlUnsignedPath   = Path.Combine(BASE_PATH, "Temp", "toSign.xml");
            xmlSignedPathRoot = Path.Combine(BASE_PATH, "Temp", "outputTestFilesC");

            dSigType = "ENVELOPED";
            arrayCanonicalization = new string[] { "C14n_WITH_COMMENTS", "C14n_OMIT_COMMENTS", "exc_C14n_OMIT_COMMENTS",
                                                   "exc_C14N_WITH_COMMENTS" };
            arrayKeyInfoType = new string[] { "KeyValue", "X509Certificate", "NONE" };

            options = new DSigOptions();

            optionsXPath = new DSigOptions();

            error = new Error();
#if !NETCORE
            xmlUnsignedXPathFile = Path.Combine(BASE_PATH, "Temp", "bookSample.xml");
            xPath = "/bookstore/book[1]";
#endif

            xmlUnsignedIDPathFile = Path.Combine(BASE_PATH, "Temp", "xmlID.xml");
            identifierAttribute   = "id";
            id = "#tag1";
            xmlIDSchemaPath = Path.Combine(BASE_PATH, "Temp", "xmlIDSchema.xsd");

            optionsID = new DSigOptions();
            optionsID.IdentifierAttribute = identifierAttribute;

            xmlUnsignedID = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<messages>\r\n" + "  <note id='tag1'>\r\n"
                            + "    <to>Tove</to>\r\n" + "    <from>Jani</from>\r\n" + "    <heading>Reminder</heading>\r\n"
                            + "    <body>Don't forget me this weekend!</body>\r\n" + "  </note>\r\n" + "  <note id='tag2'>\r\n"
                            + "    <to>Jani</to>\r\n" + "    <from>Tove</from>\r\n" + "    <heading>Re: Reminder</heading>\r\n"
                            + "    <body>I will not</body>\r\n" + "  </note>\r\n" + "</messages>";
#if !NETCORE
            xmlUnsignedXPath = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<bookstore>\r\n"
                               + "<book category=\"cooking\">\r\n" + "  <title lang=\"en\">Everyday Italian</title>\r\n"
                               + "  <author>Giada De Laurentiis</author>\r\n" + "  <year>2005</year>\r\n"
                               + "  <price>30.00</price>\r\n" + "</book>\r\n" + "<book category=\"children\">\r\n"
                               + "  <title lang=\"en\">Harry Potter</title>\r\n" + "  <author>J K. Rowling</author>\r\n"
                               + "  <year>2005</year>\r\n" + "  <price>29.99</price>\r\n" + "</book>\r\n"
                               + "<book category=\"web\">\r\n" + "  <title lang=\"en\">XQuery Kick Start</title>\r\n"
                               + "  <author>James McGovern</author>\r\n" + "  <author>Per Bothner</author>\r\n"
                               + "  <author>Kurt Cagle</author>\r\n" + "  <author>James Linn</author>\r\n"
                               + "  <author>Vaidyanathan Nagarajan</author>\r\n" + "  <year>2003</year>\r\n"
                               + "  <price>49.99</price>\r\n" + "</book>\r\n" + "<book category=\"web\">\r\n"
                               + "  <title lang=\"en\">Learning XML</title>\r\n" + "  <author>Erik T. Ray</author>\r\n"
                               + "  <year>2003</year>\r\n" + "  <price>39.95</price>\r\n" + "</book>\r\n" + "</bookstore>";
#endif
        }
Exemple #8
0
 public string DoSignElement(string xmlInput, string xPath, PrivateKeyManager key, CertificateX509 certificate, DSigOptions options)
 {
     this.error.cleanError();
     return(doSignElementPKCS12(xmlInput, xPath, key, certificate, options.DSigSignatureType, options.Canonicalization, options.KeyInfoType, options.XmlSchemaPath, options.IdentifierAttribute));
 }
Exemple #9
0
 public string DoSign(string xmlInput, PrivateKeyManager key, CertificateX509 certificate, DSigOptions options)
 {
     this.error.cleanError();
     return(doSignPKCS12(xmlInput, key, certificate, options.DSigSignatureType, options.Canonicalization, options.KeyInfoType, options.XmlSchemaPath));
 }
Exemple #10
0
        /******** EXTERNAL OBJECT PUBLIC METHODS - BEGIN ********/

        public bool DoSignFile(string xmlFilePath, PrivateKeyManager key, CertificateX509 certificate, string outputPath, DSigOptions options)
        {
            this.error.cleanError();
            return(doSignFilePKCS12(xmlFilePath, key, certificate, options.DSigSignatureType, options.Canonicalization, outputPath, options.KeyInfoType, options.XmlSchemaPath));
        }
Exemple #11
0
        public bool DoVerifyFileWithCert(string xmlFilePath, CertificateX509 certificate, DSigOptions options)
        {
            this.error.cleanError();
            if (!certificate.Inicialized)
            {
                this.error.setError("DS005", "Certificate not loaded");
            }
            if (SecurityUtils.compareStrings(certificate.getPublicKeyAlgorithm(), "ECDSA"))
            {
                this.error.setError("DS006", "XML signature with ECDSA keys is not implemented on Net Framework");
                return(false);
            }
            if (!SignatureUtils.validateExtensionXML(xmlFilePath))
            {
                this.error.setError("DS007", "The file is not an xml file");
                return(false);
            }
            XmlDocument xmlDoc = SignatureUtils.documentFromFile(xmlFilePath, options.XmlSchemaPath, this.error);

            return(verify(xmlDoc, certificate, options.IdentifierAttribute));
        }