// You may also change texts, positions and more by editing directly the method
        // generatePrinterFriendlyVersion() below.
        // ####################################################################################################

        // GET: PrinterFriendlyPadesRestPki?userfile={id}
        public ActionResult Index(string userfile)
        {
            // Locate document and read content from storage. Our action only works if the a valid fileId is
            // given.
            byte[] fileContent;
            try {
                fileContent = StorageMock.Read(userfile);
            } catch (FileNotFoundException) {
                return(HttpNotFound());
            }

            // Check if doc already has a verification code registered on storage.
            var verificationCode = StorageMock.GetVerificationCode(userfile);

            if (verificationCode == null)
            {
                // If not, generate a code an register it.
                verificationCode = Util.GenerateVerificationCode();
                StorageMock.SetVerificationCode(userfile, verificationCode);
            }

            // Generate the printer-friendly version.
            var pfvContent = generatePrinterFriendlyVersion(fileContent, verificationCode);

            // Return printer-friendly version as a downloadable file.
            return(File(pfvContent, "application/pdf", "printer-friendly.pdf"));
        }
Beispiel #2
0
        // GET: CheckPadesRest?c={id}
        public ActionResult Index(string c)
        {
            // On PrinterFriendlyVersionController, we stored the unformatted version of the verification
            // code (without hyphens) but used the formatted version (with hiphens) on the printer-friendly
            // PDF. Now, we remove the hyphens before looking it up.
            var verificationCode = AlphaCode.Parse(c);

            // Get document associated with verification code.
            var fileId = StorageMock.LookupVerificationCode(verificationCode);

            if (fileId == null)
            {
                // Invalid code give!
                // Small delay to slow down brute-force attacks (if you want to be extra careful you might
                // want to add a CAPTCHA to the process).
                Thread.Sleep(TimeSpan.FromSeconds(2));
                // Return Not Found
                return(HttpNotFound());
            }

            // Read document from storage.
            var fileContent = StorageMock.Read(fileId);

            // Get an instance of the PadesSignatureExplorer class, used to open/validate PDF signatures.
            var sigExplorer = new PadesSignatureExplorer(Util.GetRestPkiClient())
            {
                // Specify that we want to validate the signatures in the file, not only inspect them.
                Validate = true,
                // Specify the parameters for the signature validation:
                // Accept any PAdES signature as long as the signer has an ICP-Brasil certificate.
                DefaultSignaturePolicyId = StandardPadesSignaturePolicies.Basic,
                // Specify the security context to be used to determine trust in the certificate chain. We
                // have encapsulated the security context choice on Util.cs.
                SecurityContextId = Util.GetSecurityContextId()
            };

            // Set the PDF file.
            sigExplorer.SetSignatureFile(fileContent);

            // Call the Open() method, which returns the signature file's information.
            var signature = sigExplorer.Open();

            // Render the information (see file Check/Index.html for more information on
            // the information returned).
            return(View(new OpenPadesSignatureModel()
            {
                Signature = signature,
                File = fileId
            }));
        }
Beispiel #3
0
        public ActionResult File(string id)
        {
            byte[] content;

            if (id == null)
            {
                return(HttpNotFound());
            }

            string filename;

            try {
                content = StorageMock.Read(id, out filename);
            } catch (FileNotFoundException) {
                return(HttpNotFound());
            }

            return(File(content, MimeMapping.GetMimeMapping(filename), filename));
        }
Beispiel #4
0
        public ActionResult File(string id)
        {
            byte[] content;

            if (id == null)
            {
                return(NotFound());
            }

            string filename;

            try
            {
                content = StorageMock.Read(id, _env, out filename);
            }
            catch (FileNotFoundException)
            {
                return(NotFound());
            }

            return(File(content, "application/pdf", filename));
        }
        // GET: CheckCadesSdk?c={id}
        public ActionResult Index(string c)
        {
            // On PrinterFriendlyVersionController, we stored the unformatted version of the verification
            // code (without hyphens) but used the formatted version (with hiphens) on the printer-friendly
            // PDF. Now, we remove the hyphens before looking it up.
            var verificationCode = AlphaCode.Parse(c);

            // Get document associated with verification code.
            var fileId = StorageMock.LookupVerificationCode(verificationCode);

            if (fileId == null)
            {
                // Invalid code give!
                // Small delay to slow down brute-force attacks (if you want to be extra careful you might
                // want to add a CAPTCHA to the process).
                Thread.Sleep(TimeSpan.FromSeconds(2));
                // Return Not Found
                return(HttpNotFound());
            }

            // Read document from storage.
            var fileContent = StorageMock.Read(fileId);

            var signature = CadesSignature.Open(fileContent);

            // Specify the parameters for the signature validation:
            // Define the trust arbitrator used to validate the certificate.
            var trustArbitrator = Util.GetTrustArbitrator();
            var policyMapper    = CadesPoliciesForValidation.GetCadesBasic(trustArbitrator);

            // Render the information (see file Check/Index.html for more information on
            // the information returned).
            return(View(new OpenCadesSignatureModel()
            {
                Signature = new CadesSignatureModel(signature, policyMapper),
                File = fileId
            }));
        }
        public ActionResult Manifesto()
        {
            var fileContent = StorageMock.Read(StorageMock.GetSampleManifestPath());

            return(File(fileContent, "text/xml", "EventoManifesto.xml"));
        }
        public ActionResult SampleInvoice()
        {
            var fileContent = StorageMock.Read(StorageMock.GetXmlInvoiceWithSigsPath());

            return(File(fileContent, "text/xml", "InvoiceWithSigs.xml"));
        }
        public ActionResult SampleNFe()
        {
            var fileContent = StorageMock.Read(StorageMock.GetSampleNFePath());

            return(File(fileContent, "text/xml", "SampleNFe.xml"));
        }
        public ActionResult Doc(int id)
        {
            var fileContent = StorageMock.Read(StorageMock.GetBatchDocPath(id));

            return(File(fileContent, "application/pdf", string.Format("Doc{0:D2}.pdf", id)));
        }
Beispiel #10
0
        public ActionResult SamplePeer()
        {
            var fileContent = StorageMock.Read(Util.GetSamplePeerDocumentPath());

            return(File(fileContent, "text/xml", "SamplePeerDocument.xml"));
        }
Beispiel #11
0
        public ActionResult Sample()
        {
            var fileContent = StorageMock.Read(Util.GetSampleDocPath());

            return(File(fileContent, "application/pdf", "Sample.pdf"));
        }