Skip to content

The Open Source DocuSign Alternative.

feat: support leading cert from custom path

Mythie32f904ad686d
diff --git a/.env.example b/.env.example
index 7da56a2e3..6be73a6f8 100644
--- a/.env.example
+++ b/.env.example
@@ -16,6 +16,9 @@ NEXT_PUBLIC_WEBAPP_URL='http://localhost:3000'
NEXTAUTH_SECRET='lorem ipsum sit dolor random string for encryption this could literally be anything'
NEXTAUTH_URL='http://localhost:3000'
+# SIGNING
+CERT_FILE_PATH=
+
# MAIL (NODEMAILER)
# SENDGRID
# Get a Sendgrid Api key here: https://signup.sendgrid.com
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 17ceca23e..2b4738c00 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -13,7 +13,13 @@
"editor.codeActionsOnSave": {
"source.removeUnusedImports": false
},
- "typescript.tsdk": "node_modules\\typescript\\lib",
- "spellright.language": ["de"],
- "spellright.documentTypes": ["markdown", "latex", "plaintext"]
-}
+ "typescript.tsdk": "node_modules/typescript/lib",
+ "spellright.language": [
+ "de"
+ ],
+ "spellright.documentTypes": [
+ "markdown",
+ "latex",
+ "plaintext"
+ ]
+}
\ No newline at end of file
diff --git a/apps/web/pages/documents/[id]/sign.tsx b/apps/web/pages/documents/[id]/sign.tsx
index 252d0f429..3ad4bac1a 100644
--- a/apps/web/pages/documents/[id]/sign.tsx
+++ b/apps/web/pages/documents/[id]/sign.tsx
@@ -59,7 +59,7 @@ export async function getServerSideProps(context: any) {
},
});
- const recipient = await prisma.recipient.findFirstOrThrow({
+ const recipient = await prisma.recipient.findFirst({
where: {
token: recipientToken,
},
@@ -68,6 +68,15 @@ export async function getServerSideProps(context: any) {
},
});
+ if (!recipient) {
+ return {
+ redirect: {
+ permanent: false,
+ destination: "/404",
+ },
+ };
+ }
+
// Document is already signed
if (recipient.Document.status === DocumentStatus.COMPLETED) {
return {
diff --git a/packages/signing/addDigitalSignature.ts b/packages/signing/addDigitalSignature.ts
index b77c60138..dd7569f50 100644
--- a/packages/signing/addDigitalSignature.ts
+++ b/packages/signing/addDigitalSignature.ts
@@ -1,4 +1,5 @@
-import { PDFDocument, PDFHexString, PDFName, PDFNumber, PDFString } from "pdf-lib";
+import { PDFAcroSignature, PDFDocument, PDFHexString, PDFName, PDFNumber, PDFSignature, 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.
@@ -8,8 +9,8 @@ export const addDigitalSignature = async (documentAsBase64: string): Promise<str
// Custom code to add Byterange to PDF
const PDFArrayCustom = require("./PDFArrayCustom");
const pdfBuffer = Buffer.from(documentAsBase64, "base64");
- const p12Buffer = fs.readFileSync("ressources/certificate.p12");
- const SIGNATURE_LENGTH = 4540;
+ const p12Buffer = fs.readFileSync(process.env.CERT_FILE_PATH || "ressources/cert.p12");
+ const SIGNATURE_LENGTH = 12000;
const pdfDoc = await PDFDocument.load(pdfBuffer);
const pages = pdfDoc.getPages();
@@ -64,4 +65,4 @@ export const addDigitalSignature = async (documentAsBase64: string): Promise<str
});
return signedPdfBuffer.toString("base64");
-};
+};
\ No newline at end of file