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

        protected void Page_Load(object sender, EventArgs e)
        {
            // Get document ID from query string
            var fileId = Request.QueryString["file"];

            // Locate document and read content from storage
            var fileContent = StorageMock.Read(fileId);

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

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

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

            // Return printer-friendly version as a downloadable file
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=printer-friendly.pdf");
            Response.BinaryWrite(pfvContent);
            Response.End();
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get verification code from query string
            var formattedVerificationCode = Request.QueryString["code"];

            // On PrinterFriendlyVersion.aspx, we stored the unformatted version of the verification code (without hyphens) but
            // used the formatted version (with hyphens) on the printer-friendly PDF. Now, we remove the hyphens before looking it up.
            var verificationCode = AlphaCode.Parse(formattedVerificationCode);

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

            if (fileId == null)
            {
                // Invalid code given!
                // 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
                Response.StatusCode = 404;
                Response.End();
                return;
            }

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

            // Open and validate signatures with Rest PKI
            var client      = Util.GetRestPkiClient();
            var sigExplorer = new PadesSignatureExplorer(client)
            {
                Validate = true,
                DefaultSignaturePolicyId = StandardPadesSignaturePolicies.Basic,
                SecurityContextId        = Util.GetSecurityContextId(),
            };

            sigExplorer.SetSignatureFile(fileContent);
            var signature = sigExplorer.Open();

            // Set properties for rendering on page (see aspx file)
            this.FileId = fileId;
            this.Model  = signature;
        }