@cenk1cenk2/md-printer 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/{_@oxc-project_runtime@0.153.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/decorate.mjs +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.153.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/decorateMetadata.mjs +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.153.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/decorateParam.mjs +1 -1
- package/dist/commands/index.mjs +1 -1
- package/dist/modules/md-printer/md-printer.handler.mjs +2 -2
- package/dist/modules/md-printer/md-printer.module.mjs +1 -1
- package/dist/services/i18n.service.mjs +2 -2
- package/dist/services/markdown.service.mjs +1 -1
- package/dist/services/printer.module.mjs +1 -1
- package/dist/services/printer.service.mjs +2 -2
- package/dist/services/renderer/app-window.mjs +44 -0
- package/dist/services/renderer/browser.service.mjs +3 -3
- package/dist/services/renderer/renderer.service.mjs +2 -2
- package/dist/services/session/preview.service.mjs +9 -25
- package/dist/services/session/session.service.mjs +2 -2
- package/dist/services/signature/adapters/a-trust.adapter.mjs +37 -12
- package/dist/services/signature/signature.service.mjs +33 -4
- package/dist/services/template/template.service.mjs +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +5 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.
|
|
1
|
+
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/decorate.js
|
|
2
2
|
function __decorate(decorators, target, key, desc) {
|
|
3
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.
|
|
1
|
+
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/decorateMetadata.js
|
|
2
2
|
function __decorateMetadata(k, v) {
|
|
3
3
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
4
4
|
}
|
package/dist/commands/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import __decorate from "../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import __decorate from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
2
2
|
import { MdPrinterHandler } from "../modules/md-printer/md-printer.handler.mjs";
|
|
3
3
|
import { MdPrinterModule } from "../modules/md-printer/md-printer.module.mjs";
|
|
4
4
|
import { MdPrinterSchema } from "../modules/md-printer/md-printer.schema.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
2
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
3
3
|
import { BrowserService } from "../../services/renderer/browser.service.mjs";
|
|
4
4
|
import { PrinterService } from "../../services/printer.service.mjs";
|
|
5
5
|
import { PreviewService } from "../../services/session/preview.service.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
2
2
|
import { PrinterModule } from "../../services/printer.module.mjs";
|
|
3
3
|
import "../../services/index.mjs";
|
|
4
4
|
import { MdPrinterHandler } from "./md-printer.handler.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { I18N_ACCEPTED_TYPES } from "../constants/template.constants.mjs";
|
|
2
|
-
import __decorateMetadata from "../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
3
|
+
import __decorate from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
4
4
|
import { Injectable } from "@nestjs/common";
|
|
5
5
|
import { readdir } from "fs/promises";
|
|
6
6
|
import { basename, extname, join } from "path";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DIRECTIVE_TAG, PAGE_BREAK_CLASS } from "../constants/template.constants.mjs";
|
|
2
|
-
import __decorate from "../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorate from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
3
3
|
import { Injectable } from "@nestjs/common";
|
|
4
4
|
import { toHtml } from "hast-util-to-html";
|
|
5
5
|
import { all } from "lowlight";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PRINTER_MODULE_OPTIONS } from "../constants/template.constants.mjs";
|
|
2
|
-
import __decorate from "../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorate from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
3
3
|
import { I18nService } from "./i18n.service.mjs";
|
|
4
4
|
import { MarkdownService } from "./markdown.service.mjs";
|
|
5
5
|
import { BrowserService } from "./renderer/browser.service.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_PDF_OPTIONS } from "../constants/template.constants.mjs";
|
|
2
2
|
import { OutputFileType } from "../constants/file.constants.mjs";
|
|
3
|
-
import __decorateMetadata from "../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import __decorate from "../_virtual/_@oxc-project_runtime@0.
|
|
3
|
+
import __decorateMetadata from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
4
|
+
import __decorate from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
5
5
|
import { I18nService } from "./i18n.service.mjs";
|
|
6
6
|
import { MarkdownService } from "./markdown.service.mjs";
|
|
7
7
|
import { inlineHtml } from "./template/assets.mjs";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "fs/promises";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { tmpdir } from "os";
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import { once } from "events";
|
|
6
|
+
//#region src/services/renderer/app-window.ts
|
|
7
|
+
/**
|
|
8
|
+
* A browser window in app mode with a throwaway profile, so it shares no tabs, cookies or history with the browser of the user.
|
|
9
|
+
*/
|
|
10
|
+
var AppWindow = class AppWindow {
|
|
11
|
+
process;
|
|
12
|
+
profile;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves when the window exits, rejects when the browser can not be started.
|
|
15
|
+
*/
|
|
16
|
+
closed;
|
|
17
|
+
constructor(process, profile) {
|
|
18
|
+
this.process = process;
|
|
19
|
+
this.profile = profile;
|
|
20
|
+
this.closed = new Promise((resolve, reject) => {
|
|
21
|
+
process.once("exit", () => resolve());
|
|
22
|
+
process.once("error", reject);
|
|
23
|
+
});
|
|
24
|
+
this.closed.catch(() => void 0);
|
|
25
|
+
}
|
|
26
|
+
static async open(executable, url) {
|
|
27
|
+
const profile = await mkdtemp(join(tmpdir(), "md-printer-window-"));
|
|
28
|
+
return new AppWindow(spawn(executable, [
|
|
29
|
+
`--app=${url}`,
|
|
30
|
+
`--user-data-dir=${profile}`,
|
|
31
|
+
"--no-first-run",
|
|
32
|
+
"--no-default-browser-check"
|
|
33
|
+
], { stdio: "ignore" }), profile);
|
|
34
|
+
}
|
|
35
|
+
async close() {
|
|
36
|
+
if (this.process.exitCode === null && this.process.signalCode === null && this.process.kill()) await once(this.process, "exit");
|
|
37
|
+
await rm(this.profile, {
|
|
38
|
+
recursive: true,
|
|
39
|
+
force: true
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { AppWindow };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PRINTER_MODULE_OPTIONS } from "../../constants/template.constants.mjs";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
4
4
|
import { discoverBrowser } from "./browser.mjs";
|
|
5
|
-
import __decorateParam from "../../_virtual/_@oxc-project_runtime@0.
|
|
5
|
+
import __decorateParam from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateParam.mjs";
|
|
6
6
|
import { Inject, Injectable } from "@nestjs/common";
|
|
7
7
|
import { LoggerService } from "@cenk1cenk2/oclif-common";
|
|
8
8
|
import puppeteer from "puppeteer-core";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PAGE_BREAK_CLASS } from "../../constants/template.constants.mjs";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
4
4
|
import { BrowserService } from "./browser.service.mjs";
|
|
5
5
|
import { mimeType, resolveConfined } from "../template/assets.mjs";
|
|
6
6
|
import { Injectable } from "@nestjs/common";
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import "../../constants/file.constants.mjs";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
4
4
|
import { resolveConfined } from "../template/assets.mjs";
|
|
5
5
|
import { isLoopbackRequest } from "../loopback.mjs";
|
|
6
|
+
import { AppWindow } from "../renderer/app-window.mjs";
|
|
6
7
|
import { TemplateService } from "../template/template.service.mjs";
|
|
7
8
|
import { Injectable } from "@nestjs/common";
|
|
8
|
-
import { mkdtemp, rm } from "fs/promises";
|
|
9
9
|
import { join } from "path";
|
|
10
10
|
import { LoggerService } from "@cenk1cenk2/oclif-common";
|
|
11
11
|
import { fileURLToPath } from "url";
|
|
12
|
-
import { tmpdir } from "os";
|
|
13
|
-
import { spawn } from "child_process";
|
|
14
12
|
import { once } from "events";
|
|
15
13
|
import { createServer } from "http";
|
|
16
14
|
import serveStatic from "serve-static";
|
|
@@ -22,7 +20,6 @@ let PreviewService = class PreviewService {
|
|
|
22
20
|
clients = /* @__PURE__ */ new Set();
|
|
23
21
|
build;
|
|
24
22
|
error;
|
|
25
|
-
profile;
|
|
26
23
|
window;
|
|
27
24
|
constructor(logger, template) {
|
|
28
25
|
this.logger = logger;
|
|
@@ -60,39 +57,26 @@ let PreviewService = class PreviewService {
|
|
|
60
57
|
this.send("failed", this.error);
|
|
61
58
|
}
|
|
62
59
|
async open(executable, url) {
|
|
63
|
-
this.
|
|
64
|
-
this.window
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"--no-first-run",
|
|
68
|
-
"--no-default-browser-check"
|
|
69
|
-
], { stdio: "ignore" });
|
|
70
|
-
await new Promise((done) => {
|
|
71
|
-
this.window.on("exit", () => done());
|
|
72
|
-
this.window.on("error", (err) => {
|
|
73
|
-
this.logger.warn("Can not open the preview window, open it manually: %s (%s)", url, err.message);
|
|
74
|
-
});
|
|
60
|
+
this.window = await AppWindow.open(executable, url);
|
|
61
|
+
await this.window.closed.catch((err) => {
|
|
62
|
+
this.logger.warn("Can not open the preview window, open it manually: %s (%s)", url, err.message);
|
|
63
|
+
return new Promise(() => void 0);
|
|
75
64
|
});
|
|
76
65
|
}
|
|
77
66
|
async onModuleDestroy() {
|
|
78
67
|
await this.close();
|
|
79
68
|
}
|
|
80
69
|
async close() {
|
|
81
|
-
const { server, window
|
|
70
|
+
const { server, window } = this;
|
|
82
71
|
this.server = void 0;
|
|
83
72
|
this.window = void 0;
|
|
84
|
-
this.profile = void 0;
|
|
85
73
|
for (const client of this.clients) client.end();
|
|
86
74
|
this.clients.clear();
|
|
87
|
-
|
|
75
|
+
await window?.close();
|
|
88
76
|
if (server?.listening) {
|
|
89
77
|
server.close();
|
|
90
78
|
await once(server, "close");
|
|
91
79
|
}
|
|
92
|
-
if (profile) await rm(profile, {
|
|
93
|
-
recursive: true,
|
|
94
|
-
force: true
|
|
95
|
-
});
|
|
96
80
|
}
|
|
97
81
|
async handle(req, res, shell) {
|
|
98
82
|
if (!isLoopbackRequest(req)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../../constants/template.constants.mjs";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
4
4
|
import { PrinterService } from "../printer.service.mjs";
|
|
5
5
|
import { Injectable } from "@nestjs/common";
|
|
6
6
|
import { dirname, join, resolve } from "path";
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import "../../../constants/signature.constants.mjs";
|
|
2
|
-
import __decorateMetadata from "../../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
3
|
+
import __decorate from "../../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
4
|
+
import { BrowserNotFoundError } from "../../renderer/browser.mjs";
|
|
5
|
+
import { BrowserService } from "../../renderer/browser.service.mjs";
|
|
4
6
|
import { isLoopbackRequest } from "../../loopback.mjs";
|
|
7
|
+
import { AppWindow } from "../../renderer/app-window.mjs";
|
|
5
8
|
import { SignatureAdapter } from "../signature.adapter.mjs";
|
|
6
9
|
import { Injectable } from "@nestjs/common";
|
|
7
10
|
import { readFile } from "fs/promises";
|
|
@@ -14,11 +17,13 @@ import getRawBody from "raw-body";
|
|
|
14
17
|
let ATrustAdapter = class ATrustAdapter extends SignatureAdapter {
|
|
15
18
|
logger;
|
|
16
19
|
context;
|
|
20
|
+
browser;
|
|
17
21
|
name = "a-trust";
|
|
18
|
-
constructor(logger, context) {
|
|
22
|
+
constructor(logger, context, browser) {
|
|
19
23
|
super();
|
|
20
24
|
this.logger = logger;
|
|
21
25
|
this.context = context;
|
|
26
|
+
this.browser = browser;
|
|
22
27
|
this.logger.setup(this.constructor.name);
|
|
23
28
|
}
|
|
24
29
|
async sign(request) {
|
|
@@ -89,24 +94,44 @@ let ATrustAdapter = class ATrustAdapter extends SignatureAdapter {
|
|
|
89
94
|
return res.end("This does not look like a signature, it should start with MII.");
|
|
90
95
|
}
|
|
91
96
|
res.writeHead(200);
|
|
92
|
-
res.end("Signature received
|
|
97
|
+
res.end("Signature received.");
|
|
93
98
|
resolve(Buffer.from(cms, "base64"));
|
|
94
99
|
});
|
|
95
100
|
server.listen(0, "127.0.0.1");
|
|
96
101
|
await once(server, "listening");
|
|
97
102
|
const url = `http://127.0.0.1:${server.address().port}/`;
|
|
98
103
|
this.logger.info("Sign the document in the browser, then paste the signature back: %s", url);
|
|
99
|
-
this.open(url)
|
|
104
|
+
const window = await this.open(url).catch((err) => {
|
|
105
|
+
server.close();
|
|
106
|
+
throw err;
|
|
107
|
+
});
|
|
100
108
|
this.context.signal.addEventListener("abort", () => reject(/* @__PURE__ */ new Error("Signing is aborted.")), { once: true });
|
|
101
|
-
|
|
109
|
+
window?.closed.then(() => reject(/* @__PURE__ */ new Error("The signing window is closed before the signature arrived.")), (err) => this.logger.warn("Can not open the signing window, open the link manually: %s (%s)", url, err.message));
|
|
110
|
+
return result.finally(async () => {
|
|
111
|
+
server.close();
|
|
112
|
+
await window?.close();
|
|
113
|
+
});
|
|
102
114
|
}
|
|
103
|
-
open(url) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
115
|
+
async open(url) {
|
|
116
|
+
let executable;
|
|
117
|
+
try {
|
|
118
|
+
executable = this.browser.executable();
|
|
119
|
+
} catch (err) {
|
|
120
|
+
if (!(err instanceof BrowserNotFoundError)) throw err;
|
|
121
|
+
this.logger.warn("Can not find a browser to sign in a window of its own, close the tabs of any earlier signing before you continue. %s", err.message);
|
|
122
|
+
spawn("xdg-open", [url], {
|
|
123
|
+
stdio: "ignore",
|
|
124
|
+
detached: true
|
|
125
|
+
}).on("error", (err) => this.logger.warn("Can not open the browser, open the link manually: %s", err.message)).unref();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
return AppWindow.open(executable, url);
|
|
108
129
|
}
|
|
109
130
|
};
|
|
110
|
-
ATrustAdapter = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [
|
|
131
|
+
ATrustAdapter = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [
|
|
132
|
+
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
133
|
+
typeof CommandContext === "undefined" ? Object : CommandContext,
|
|
134
|
+
typeof BrowserService === "undefined" ? Object : BrowserService
|
|
135
|
+
])], ATrustAdapter);
|
|
111
136
|
//#endregion
|
|
112
137
|
export { ATrustAdapter };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
2
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
3
3
|
import { ATrustAdapter } from "./adapters/a-trust.adapter.mjs";
|
|
4
4
|
import { Injectable } from "@nestjs/common";
|
|
5
5
|
import { readFile } from "fs/promises";
|
|
6
6
|
import { isAbsolute, join } from "path";
|
|
7
7
|
import { plainAddPlaceholder } from "@signpdf/placeholder-plain";
|
|
8
8
|
import { SUBFILTER_ETSI_CADES_DETACHED, findByteRange, removeTrailingNewLine } from "@signpdf/utils";
|
|
9
|
-
import { X509Certificate } from "crypto";
|
|
9
|
+
import { X509Certificate, webcrypto } from "crypto";
|
|
10
10
|
import { homedir } from "os";
|
|
11
|
+
import { ContentInfo, SignedData, getAlgorithmByOID } from "pkijs";
|
|
11
12
|
//#region src/services/signature/signature.service.ts
|
|
12
13
|
var _SignatureService;
|
|
13
14
|
let SignatureService = class SignatureService {
|
|
@@ -15,6 +16,7 @@ let SignatureService = class SignatureService {
|
|
|
15
16
|
_SignatureService = this;
|
|
16
17
|
}
|
|
17
18
|
static LENGTH = 16384;
|
|
19
|
+
static MESSAGE_DIGEST = "1.2.840.113549.1.9.4";
|
|
18
20
|
adapters;
|
|
19
21
|
constructor(aTrust) {
|
|
20
22
|
this.adapters = [aTrust];
|
|
@@ -39,7 +41,7 @@ let SignatureService = class SignatureService {
|
|
|
39
41
|
async sign(pdf, options) {
|
|
40
42
|
const request = this.prepare(pdf, options);
|
|
41
43
|
const cms = await this.adapter(options.provider).sign(request);
|
|
42
|
-
|
|
44
|
+
await this.verify(request, cms, options.certificate);
|
|
43
45
|
return this.embed(request, cms);
|
|
44
46
|
}
|
|
45
47
|
adapter(provider) {
|
|
@@ -74,6 +76,30 @@ let SignatureService = class SignatureService {
|
|
|
74
76
|
excluded: [from, to]
|
|
75
77
|
};
|
|
76
78
|
}
|
|
79
|
+
async verify({ pdf, excluded: [from, to] }, cms, certificate) {
|
|
80
|
+
const content = new Uint8Array(Buffer.concat([pdf.subarray(0, from), pdf.subarray(to + 1)])).buffer;
|
|
81
|
+
let signed;
|
|
82
|
+
try {
|
|
83
|
+
signed = new SignedData({ schema: ContentInfo.fromBER(new Uint8Array(cms)).content });
|
|
84
|
+
} catch (err) {
|
|
85
|
+
throw new Error(`The returned signature is not a CMS signature: ${err.message}`, { cause: err });
|
|
86
|
+
}
|
|
87
|
+
const [info] = signed.signerInfos;
|
|
88
|
+
const digest = info?.signedAttrs?.attributes.find((attribute) => attribute.type === _SignatureService.MESSAGE_DIGEST);
|
|
89
|
+
if (!digest) throw new Error("The returned signature does not carry the digest of the document it signs.");
|
|
90
|
+
const algorithm = getAlgorithmByOID(info.digestAlgorithm.algorithmId, true, "digestAlgorithm");
|
|
91
|
+
if (!Buffer.from(digest.values[0].valueBlock.valueHexView).equals(Buffer.from(await webcrypto.subtle.digest(algorithm.name, content)))) throw new Error("The returned signature belongs to a different document, it is likely left over from an earlier signing.");
|
|
92
|
+
const { signatureVerified, signerCertificate } = await signed.verify({
|
|
93
|
+
signer: 0,
|
|
94
|
+
data: content,
|
|
95
|
+
extendedMode: true
|
|
96
|
+
}).catch((err) => {
|
|
97
|
+
throw new Error(`Can not verify the returned signature: ${err.message}`, { cause: err });
|
|
98
|
+
});
|
|
99
|
+
const signer = new X509Certificate(Buffer.from(signerCertificate.toSchema().toBER()));
|
|
100
|
+
if (certificate && !signer.raw.equals(certificate.raw)) throw new Error([`The returned signature is signed by ${this.identify(signer)}, but the configured certificate is ${this.identify(certificate)}.`, "The signature block would show the wrong signer."].join(" "));
|
|
101
|
+
if (!signatureVerified) throw new Error(`The returned signature does not verify against the certificate of ${this.identify(signer)}.`);
|
|
102
|
+
}
|
|
77
103
|
embed({ pdf, excluded: [from, to] }, cms) {
|
|
78
104
|
const signature = cms.toString("hex");
|
|
79
105
|
const length = to - from - 1;
|
|
@@ -84,6 +110,9 @@ let SignatureService = class SignatureService {
|
|
|
84
110
|
pdf.subarray(to)
|
|
85
111
|
]);
|
|
86
112
|
}
|
|
113
|
+
identify(certificate) {
|
|
114
|
+
return `${this.commonName(certificate.subject)} (serial ${certificate.serialNumber})`;
|
|
115
|
+
}
|
|
87
116
|
commonName(name) {
|
|
88
117
|
return name.split("\n").find((part) => part.startsWith("CN="))?.slice(3);
|
|
89
118
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../../constants/template.constants.mjs";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.mjs";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.mjs";
|
|
4
4
|
import { inlineCss, inlineHtml } from "./assets.mjs";
|
|
5
5
|
import { sveltePlugin } from "./svelte.plugin.mjs";
|
|
6
6
|
import { Injectable } from "@nestjs/common";
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cenk1cenk2/md-printer",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Render markdown or yaml through Svelte templates into PDF or HTML with Puppeteer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@fontsource/montserrat": "^5.3.0",
|
|
54
54
|
"@listr2/manager": "^4.3.1",
|
|
55
55
|
"@nestjs/common": "^12.1.2",
|
|
56
|
-
"@oclif/core": "^5.1.
|
|
56
|
+
"@oclif/core": "^5.1.3",
|
|
57
57
|
"@oclif/plugin-help": "^7.0.2",
|
|
58
58
|
"@signpdf/placeholder-plain": "^3.3.0",
|
|
59
59
|
"@signpdf/utils": "^3.3.0",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"lowlight": "^3.3.0",
|
|
76
76
|
"mime": "^4.1.1",
|
|
77
77
|
"perfect-debounce": "^2.1.0",
|
|
78
|
+
"pkijs": "^3.4.1",
|
|
78
79
|
"property-information": "^7.2.0",
|
|
79
80
|
"puppeteer-core": "^25.13.0",
|
|
80
81
|
"raw-body": "^4.0.0",
|
|
@@ -112,10 +113,11 @@
|
|
|
112
113
|
"@types/serve-static": "^2.2.0",
|
|
113
114
|
"@types/which": "^3.0.4",
|
|
114
115
|
"@types/write-file-atomic": "^4.0.3",
|
|
116
|
+
"asn1js": "^3.0.10",
|
|
115
117
|
"eslint": "^10.12.0",
|
|
116
118
|
"eslint-plugin-svelte": "^3.23.1",
|
|
117
119
|
"execa": "^10.1.0",
|
|
118
|
-
"oclif": "^6.0.
|
|
120
|
+
"oclif": "^6.0.3",
|
|
119
121
|
"prettier": "^3.9.9",
|
|
120
122
|
"prettier-plugin-svelte": "^4.1.1",
|
|
121
123
|
"svelte-eslint-parser": "^1.9.0",
|