Merge branch 'main' into feature/update-branding

This commit is contained in:
Timur Ercan
2023-05-27 18:22:13 +02:00
committed by GitHub
5 changed files with 32 additions and 8 deletions

View File

@ -16,6 +16,11 @@ NEXT_PUBLIC_WEBAPP_URL='http://localhost:3000'
NEXTAUTH_SECRET='lorem ipsum sit dolor random string for encryption this could literally be anything' NEXTAUTH_SECRET='lorem ipsum sit dolor random string for encryption this could literally be anything'
NEXTAUTH_URL='http://localhost:3000' NEXTAUTH_URL='http://localhost:3000'
# SIGNING
CERT_FILE_PATH=
CERT_PASSPHRASE=
CERT_FILE_ENCODING=
# MAIL (NODEMAILER) # MAIL (NODEMAILER)
# SENDGRID # SENDGRID
# Get a Sendgrid Api key here: https://signup.sendgrid.com # Get a Sendgrid Api key here: https://signup.sendgrid.com

10
.vscode/settings.json vendored
View File

@ -14,6 +14,12 @@
"source.removeUnusedImports": false "source.removeUnusedImports": false
}, },
"typescript.tsdk": "node_modules/typescript/lib", "typescript.tsdk": "node_modules/typescript/lib",
"spellright.language": ["de"], "spellright.language": [
"spellright.documentTypes": ["markdown", "latex", "plaintext"] "de"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext"
]
} }

View File

@ -1,4 +1,4 @@
> We are launching on Product Hunt soon! Sign up to support the launch: > <strong>We are launching TOMORROW on Product Hunt soon! Sign up to support the launch: </strong>
> <center><a href="https://dub.sh/documenso-launch"><img src="https://img.shields.io/badge/Documenso%20on%20Product%20Hunt-Notify%20Me-orange" alt="Product Hunt"></a></center> > <center><a href="https://dub.sh/documenso-launch"><img src="https://img.shields.io/badge/Documenso%20on%20Product%20Hunt-Notify%20Me-orange" alt="Product Hunt"></a></center>
<p align="center" style="margin-top: 12px"> <p align="center" style="margin-top: 12px">

View File

@ -59,7 +59,7 @@ export async function getServerSideProps(context: any) {
}, },
}); });
const recipient = await prisma.recipient.findFirstOrThrow({ const recipient = await prisma.recipient.findFirst({
where: { where: {
token: recipientToken, token: recipientToken,
}, },
@ -68,6 +68,15 @@ export async function getServerSideProps(context: any) {
}, },
}); });
if (!recipient) {
return {
redirect: {
permanent: false,
destination: "/404",
},
};
}
// Document is already signed // Document is already signed
if (recipient.Document.status === DocumentStatus.COMPLETED) { if (recipient.Document.status === DocumentStatus.COMPLETED) {
return { return {

View File

@ -1,6 +1,6 @@
import fs from "fs";
import { PDFDocument, PDFHexString, PDFName, PDFNumber, PDFString } from "pdf-lib"; import { PDFDocument, PDFHexString, PDFName, PDFNumber, PDFString } from "pdf-lib";
const fs = require("fs");
// Local copy of Node SignPDF because https://github.com/vbuch/node-signpdf/pull/187 was not published in NPM yet. Can be switched to npm packge. // Local copy of Node SignPDF because https://github.com/vbuch/node-signpdf/pull/187 was not published in NPM yet. Can be switched to npm packge.
const signer = require("./node-signpdf/dist/signpdf"); const signer = require("./node-signpdf/dist/signpdf");
@ -8,8 +8,12 @@ export const addDigitalSignature = async (documentAsBase64: string): Promise<str
// Custom code to add Byterange to PDF // Custom code to add Byterange to PDF
const PDFArrayCustom = require("./PDFArrayCustom"); const PDFArrayCustom = require("./PDFArrayCustom");
const pdfBuffer = Buffer.from(documentAsBase64, "base64"); const pdfBuffer = Buffer.from(documentAsBase64, "base64");
const p12Buffer = fs.readFileSync("ressources/certificate.p12"); const p12Buffer = Buffer.from(
const SIGNATURE_LENGTH = 4540; fs.readFileSync(process.env.CERT_FILE_PATH || "ressources/certificate.p12", {
encoding: (process.env.CERT_FILE_ENCODING as BufferEncoding) || null,
})
);
const SIGNATURE_LENGTH = 12000;
const pdfDoc = await PDFDocument.load(pdfBuffer); const pdfDoc = await PDFDocument.load(pdfBuffer);
const pages = pdfDoc.getPages(); const pages = pdfDoc.getPages();
@ -60,7 +64,7 @@ export const addDigitalSignature = async (documentAsBase64: string): Promise<str
const signObj = new signer.SignPdf(); const signObj = new signer.SignPdf();
const signedPdfBuffer: Buffer = signObj.sign(modifiedPdfBuffer, p12Buffer, { const signedPdfBuffer: Buffer = signObj.sign(modifiedPdfBuffer, p12Buffer, {
passphrase: "", passphrase: process.env.CERT_PASSPHRASE || "",
}); });
return signedPdfBuffer.toString("base64"); return signedPdfBuffer.toString("base64");