@certd/plugin-cert 1.24.2 → 1.24.4
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/CHANGELOG.md +10 -0
- package/dist/access/eab-access.d.ts +4 -4
- package/dist/access/eab-access.js +48 -48
- package/dist/access/index.d.ts +1 -1
- package/dist/access/index.js +1 -1
- package/dist/bundle.js +1 -1
- package/dist/d/plugin/cert-plugin/acme.d.ts +2 -0
- package/dist/d/plugin/cert-plugin/index.d.ts +1 -0
- package/dist/dns-provider/api.d.ts +27 -27
- package/dist/dns-provider/api.js +1 -1
- package/dist/dns-provider/base.d.ts +8 -8
- package/dist/dns-provider/base.js +6 -6
- package/dist/dns-provider/decorator.d.ts +3 -3
- package/dist/dns-provider/decorator.js +25 -25
- package/dist/dns-provider/index.d.ts +4 -4
- package/dist/dns-provider/index.js +4 -4
- package/dist/dns-provider/registry.d.ts +2 -2
- package/dist/dns-provider/registry.js +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/plugin/cert-plugin/acme.d.ts +65 -65
- package/dist/plugin/cert-plugin/acme.js +2 -2
- package/dist/plugin/cert-plugin/base.d.ts +46 -46
- package/dist/plugin/cert-plugin/base.js +7 -11
- package/dist/plugin/cert-plugin/cert-reader.d.ts +31 -31
- package/dist/plugin/cert-plugin/cert-reader.js +92 -89
- package/dist/plugin/cert-plugin/convert.d.ts +21 -21
- package/dist/plugin/cert-plugin/convert.js +70 -70
- package/dist/plugin/cert-plugin/index.d.ts +18 -18
- package/dist/plugin/cert-plugin/index.js +206 -206
- package/dist/plugin/cert-plugin/lego/dns.d.ts +1 -1
- package/dist/plugin/cert-plugin/lego/dns.js +1 -1
- package/dist/plugin/cert-plugin/lego/index.d.ts +17 -17
- package/dist/plugin/cert-plugin/lego/index.js +171 -171
- package/dist/plugin/cert-plugin/lego.d.ts +16 -16
- package/dist/plugin/cert-plugin/lego.js +145 -153
- package/dist/plugin/index.d.ts +2 -2
- package/dist/plugin/index.js +2 -2
- package/package.json +4 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/plugin-cert.mjs +0 -11786
- package/dist/plugin-cert.umd.js +0 -28
- package/stats.html +0 -6177
- package/test/user.secret.js +0 -7
- package/test/user.secret.ts +0 -4
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { CertInfo } from "./acme.js";
|
|
2
|
-
import { ILogger } from "@certd/pipeline";
|
|
3
|
-
export type CertReaderHandleContext = {
|
|
4
|
-
reader: CertReader;
|
|
5
|
-
tmpCrtPath: string;
|
|
6
|
-
tmpKeyPath: string;
|
|
7
|
-
tmpPfxPath?: string;
|
|
8
|
-
tmpDerPath?: string;
|
|
9
|
-
};
|
|
10
|
-
export type CertReaderHandle = (ctx: CertReaderHandleContext) => Promise<void>;
|
|
11
|
-
export type HandleOpts = {
|
|
12
|
-
logger: ILogger;
|
|
13
|
-
handle: CertReaderHandle;
|
|
14
|
-
};
|
|
15
|
-
export declare class CertReader {
|
|
16
|
-
cert: CertInfo;
|
|
17
|
-
crt: string;
|
|
18
|
-
key: string;
|
|
19
|
-
csr: string;
|
|
20
|
-
detail: any;
|
|
21
|
-
expires: number;
|
|
22
|
-
constructor(certInfo: CertInfo);
|
|
23
|
-
toCertInfo(): CertInfo;
|
|
24
|
-
getCrtDetail(crt?: string): {
|
|
25
|
-
detail: import("@certd/acme-client").CertificateInfo;
|
|
26
|
-
expires: Date;
|
|
27
|
-
};
|
|
28
|
-
saveToFile(type: "crt" | "key" | "pfx" | "der", filepath?: string): string;
|
|
29
|
-
readCertFile(opts: HandleOpts): Promise<void>;
|
|
30
|
-
buildCertFileName(suffix: string, applyTime: number, prefix?: string): string;
|
|
31
|
-
}
|
|
1
|
+
import { CertInfo } from "./acme.js";
|
|
2
|
+
import { ILogger } from "@certd/pipeline";
|
|
3
|
+
export type CertReaderHandleContext = {
|
|
4
|
+
reader: CertReader;
|
|
5
|
+
tmpCrtPath: string;
|
|
6
|
+
tmpKeyPath: string;
|
|
7
|
+
tmpPfxPath?: string;
|
|
8
|
+
tmpDerPath?: string;
|
|
9
|
+
};
|
|
10
|
+
export type CertReaderHandle = (ctx: CertReaderHandleContext) => Promise<void>;
|
|
11
|
+
export type HandleOpts = {
|
|
12
|
+
logger: ILogger;
|
|
13
|
+
handle: CertReaderHandle;
|
|
14
|
+
};
|
|
15
|
+
export declare class CertReader {
|
|
16
|
+
cert: CertInfo;
|
|
17
|
+
crt: string;
|
|
18
|
+
key: string;
|
|
19
|
+
csr: string;
|
|
20
|
+
detail: any;
|
|
21
|
+
expires: number;
|
|
22
|
+
constructor(certInfo: CertInfo);
|
|
23
|
+
toCertInfo(): CertInfo;
|
|
24
|
+
getCrtDetail(crt?: string): {
|
|
25
|
+
detail: import("@certd/acme-client").CertificateInfo;
|
|
26
|
+
expires: Date;
|
|
27
|
+
};
|
|
28
|
+
saveToFile(type: "crt" | "key" | "pfx" | "der", filepath?: string): string;
|
|
29
|
+
readCertFile(opts: HandleOpts): Promise<void>;
|
|
30
|
+
buildCertFileName(suffix: string, applyTime: number, prefix?: string): string;
|
|
31
|
+
}
|
|
@@ -1,89 +1,92 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import os from "os";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { crypto } from "@certd/acme-client";
|
|
5
|
-
import dayjs from "dayjs";
|
|
6
|
-
export class CertReader {
|
|
7
|
-
cert;
|
|
8
|
-
crt;
|
|
9
|
-
key;
|
|
10
|
-
csr;
|
|
11
|
-
detail;
|
|
12
|
-
expires;
|
|
13
|
-
constructor(certInfo) {
|
|
14
|
-
this.cert = certInfo;
|
|
15
|
-
this.crt = certInfo.crt;
|
|
16
|
-
this.key = certInfo.key;
|
|
17
|
-
this.csr = certInfo.csr;
|
|
18
|
-
const { detail, expires } = this.getCrtDetail(this.cert.crt);
|
|
19
|
-
this.detail = detail;
|
|
20
|
-
this.expires = expires.getTime();
|
|
21
|
-
}
|
|
22
|
-
toCertInfo() {
|
|
23
|
-
return this.cert;
|
|
24
|
-
}
|
|
25
|
-
getCrtDetail(crt = this.cert.crt) {
|
|
26
|
-
const detail = crypto.readCertificateInfo(crt.toString());
|
|
27
|
-
const expires = detail.notAfter;
|
|
28
|
-
return { detail, expires };
|
|
29
|
-
}
|
|
30
|
-
saveToFile(type, filepath) {
|
|
31
|
-
if (!this.cert[type]) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (filepath == null) {
|
|
35
|
-
//写入临时目录
|
|
36
|
-
filepath = path.join(os.tmpdir(), "/certd/tmp/", Math.floor(Math.random() * 1000000) + "", `cert.${type}`);
|
|
37
|
-
}
|
|
38
|
-
const dir = path.dirname(filepath);
|
|
39
|
-
if (!fs.existsSync(dir)) {
|
|
40
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
41
|
-
}
|
|
42
|
-
if (type === "crt" || type === "key") {
|
|
43
|
-
fs.writeFileSync(filepath, this.cert[type]);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
fs.writeFileSync(filepath, Buffer.from(this.cert[type], "base64"));
|
|
47
|
-
}
|
|
48
|
-
return filepath;
|
|
49
|
-
}
|
|
50
|
-
async readCertFile(opts) {
|
|
51
|
-
const logger = opts.logger;
|
|
52
|
-
logger.info("将证书写入本地缓存文件");
|
|
53
|
-
const tmpCrtPath = this.saveToFile("crt");
|
|
54
|
-
const tmpKeyPath = this.saveToFile("key");
|
|
55
|
-
const tmpPfxPath = this.saveToFile("pfx");
|
|
56
|
-
const tmpDerPath = this.saveToFile("der");
|
|
57
|
-
logger.info("本地文件写入成功");
|
|
58
|
-
try {
|
|
59
|
-
await opts.handle({
|
|
60
|
-
reader: this,
|
|
61
|
-
tmpCrtPath: tmpCrtPath,
|
|
62
|
-
tmpKeyPath: tmpKeyPath,
|
|
63
|
-
tmpPfxPath: tmpPfxPath,
|
|
64
|
-
tmpDerPath: tmpDerPath,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
removeFile(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { crypto } from "@certd/acme-client";
|
|
5
|
+
import dayjs from "dayjs";
|
|
6
|
+
export class CertReader {
|
|
7
|
+
cert;
|
|
8
|
+
crt;
|
|
9
|
+
key;
|
|
10
|
+
csr;
|
|
11
|
+
detail;
|
|
12
|
+
expires;
|
|
13
|
+
constructor(certInfo) {
|
|
14
|
+
this.cert = certInfo;
|
|
15
|
+
this.crt = certInfo.crt;
|
|
16
|
+
this.key = certInfo.key;
|
|
17
|
+
this.csr = certInfo.csr;
|
|
18
|
+
const { detail, expires } = this.getCrtDetail(this.cert.crt);
|
|
19
|
+
this.detail = detail;
|
|
20
|
+
this.expires = expires.getTime();
|
|
21
|
+
}
|
|
22
|
+
toCertInfo() {
|
|
23
|
+
return this.cert;
|
|
24
|
+
}
|
|
25
|
+
getCrtDetail(crt = this.cert.crt) {
|
|
26
|
+
const detail = crypto.readCertificateInfo(crt.toString());
|
|
27
|
+
const expires = detail.notAfter;
|
|
28
|
+
return { detail, expires };
|
|
29
|
+
}
|
|
30
|
+
saveToFile(type, filepath) {
|
|
31
|
+
if (!this.cert[type]) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (filepath == null) {
|
|
35
|
+
//写入临时目录
|
|
36
|
+
filepath = path.join(os.tmpdir(), "/certd/tmp/", Math.floor(Math.random() * 1000000) + "", `cert.${type}`);
|
|
37
|
+
}
|
|
38
|
+
const dir = path.dirname(filepath);
|
|
39
|
+
if (!fs.existsSync(dir)) {
|
|
40
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
if (type === "crt" || type === "key") {
|
|
43
|
+
fs.writeFileSync(filepath, this.cert[type]);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
fs.writeFileSync(filepath, Buffer.from(this.cert[type], "base64"));
|
|
47
|
+
}
|
|
48
|
+
return filepath;
|
|
49
|
+
}
|
|
50
|
+
async readCertFile(opts) {
|
|
51
|
+
const logger = opts.logger;
|
|
52
|
+
logger.info("将证书写入本地缓存文件");
|
|
53
|
+
const tmpCrtPath = this.saveToFile("crt");
|
|
54
|
+
const tmpKeyPath = this.saveToFile("key");
|
|
55
|
+
const tmpPfxPath = this.saveToFile("pfx");
|
|
56
|
+
const tmpDerPath = this.saveToFile("der");
|
|
57
|
+
logger.info("本地文件写入成功");
|
|
58
|
+
try {
|
|
59
|
+
return await opts.handle({
|
|
60
|
+
reader: this,
|
|
61
|
+
tmpCrtPath: tmpCrtPath,
|
|
62
|
+
tmpKeyPath: tmpKeyPath,
|
|
63
|
+
tmpPfxPath: tmpPfxPath,
|
|
64
|
+
tmpDerPath: tmpDerPath,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
//删除临时文件
|
|
72
|
+
logger.info("删除临时文件");
|
|
73
|
+
function removeFile(filepath) {
|
|
74
|
+
if (filepath) {
|
|
75
|
+
fs.unlinkSync(filepath);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
removeFile(tmpCrtPath);
|
|
79
|
+
removeFile(tmpKeyPath);
|
|
80
|
+
removeFile(tmpPfxPath);
|
|
81
|
+
removeFile(tmpDerPath);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
buildCertFileName(suffix, applyTime, prefix = "cert") {
|
|
85
|
+
const detail = this.getCrtDetail();
|
|
86
|
+
let domain = detail.detail.domains.commonName;
|
|
87
|
+
domain = domain.replace(".", "_").replace("*", "_");
|
|
88
|
+
const timeStr = dayjs(applyTime).format("YYYYMMDDHHmmss");
|
|
89
|
+
return `${prefix}_${domain}_${timeStr}.${suffix}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC1yZWFkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcGx1Z2luL2NlcnQtcGx1Z2luL2NlcnQtcmVhZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxNQUFNLElBQUksQ0FBQztBQUNwQixPQUFPLEVBQUUsTUFBTSxJQUFJLENBQUM7QUFDcEIsT0FBTyxJQUFJLE1BQU0sTUFBTSxDQUFDO0FBQ3hCLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUU1QyxPQUFPLEtBQUssTUFBTSxPQUFPLENBQUM7QUFLMUIsTUFBTSxPQUFPLFVBQVU7SUFDckIsSUFBSSxDQUFXO0lBQ2YsR0FBRyxDQUFTO0lBQ1osR0FBRyxDQUFTO0lBQ1osR0FBRyxDQUFTO0lBRVosTUFBTSxDQUFNO0lBQ1osT0FBTyxDQUFTO0lBQ2hCLFlBQVksUUFBa0I7UUFDNUIsSUFBSSxDQUFDLElBQUksR0FBRyxRQUFRLENBQUM7UUFDckIsSUFBSSxDQUFDLEdBQUcsR0FBRyxRQUFRLENBQUMsR0FBRyxDQUFDO1FBQ3hCLElBQUksQ0FBQyxHQUFHLEdBQUcsUUFBUSxDQUFDLEdBQUcsQ0FBQztRQUN4QixJQUFJLENBQUMsR0FBRyxHQUFHLFFBQVEsQ0FBQyxHQUFHLENBQUM7UUFFeEIsTUFBTSxFQUFFLE1BQU0sRUFBRSxPQUFPLEVBQUUsR0FBRyxJQ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xDQUFDLENBQUM7UUFDcEQsTUFBTSxPQUFPLEdBQUcsS0FBSyxDQUFDLFNBQVMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO1FBQzFELE9BQU8sR0FBRyxNQUFNLElBQUksTUFBTSxJQUFJLE9BQU8sSUFBSSxNQUFNLEVBQUUsQ0FBQztJQUNwRCxDQUFDO0NBQ0YifQ==
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { ILogger } from "@certd/pipeline";
|
|
2
|
-
import type { CertInfo } from "../cert-plugin/acme.js";
|
|
3
|
-
import { CertReader } from "../cert-plugin/cert-reader.js";
|
|
4
|
-
export { CertReader };
|
|
5
|
-
export type { CertInfo };
|
|
6
|
-
export declare class CertConverter {
|
|
7
|
-
logger: ILogger;
|
|
8
|
-
constructor(opts: {
|
|
9
|
-
logger: ILogger;
|
|
10
|
-
});
|
|
11
|
-
convert(opts: {
|
|
12
|
-
cert: CertInfo;
|
|
13
|
-
pfxPassword: string;
|
|
14
|
-
}): Promise<{
|
|
15
|
-
pfxPath: string;
|
|
16
|
-
derPath: string;
|
|
17
|
-
}>;
|
|
18
|
-
exec(cmd: string): Promise<void>;
|
|
19
|
-
private convertPfx;
|
|
20
|
-
private convertDer;
|
|
21
|
-
}
|
|
1
|
+
import { ILogger } from "@certd/pipeline";
|
|
2
|
+
import type { CertInfo } from "../cert-plugin/acme.js";
|
|
3
|
+
import { CertReader } from "../cert-plugin/cert-reader.js";
|
|
4
|
+
export { CertReader };
|
|
5
|
+
export type { CertInfo };
|
|
6
|
+
export declare class CertConverter {
|
|
7
|
+
logger: ILogger;
|
|
8
|
+
constructor(opts: {
|
|
9
|
+
logger: ILogger;
|
|
10
|
+
});
|
|
11
|
+
convert(opts: {
|
|
12
|
+
cert: CertInfo;
|
|
13
|
+
pfxPassword: string;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
pfxPath: string;
|
|
16
|
+
derPath: string;
|
|
17
|
+
}>;
|
|
18
|
+
exec(cmd: string): Promise<void>;
|
|
19
|
+
private convertPfx;
|
|
20
|
+
private convertDer;
|
|
21
|
+
}
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { sp } from "@certd/pipeline";
|
|
2
|
-
import { CertReader } from "../cert-plugin/cert-reader.js";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import os from "os";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
export { CertReader };
|
|
7
|
-
export class CertConverter {
|
|
8
|
-
logger;
|
|
9
|
-
constructor(opts) {
|
|
10
|
-
this.logger = opts.logger;
|
|
11
|
-
}
|
|
12
|
-
async convert(opts) {
|
|
13
|
-
const certReader = new CertReader(opts.cert);
|
|
14
|
-
let pfxPath;
|
|
15
|
-
let derPath;
|
|
16
|
-
const handle = async (opts) => {
|
|
17
|
-
// 调用openssl 转pfx
|
|
18
|
-
pfxPath = await this.convertPfx(opts);
|
|
19
|
-
// 转der
|
|
20
|
-
derPath = await this.convertDer(opts);
|
|
21
|
-
};
|
|
22
|
-
await certReader.readCertFile({ logger: this.logger, handle });
|
|
23
|
-
return {
|
|
24
|
-
pfxPath,
|
|
25
|
-
derPath,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async exec(cmd) {
|
|
29
|
-
await sp.spawn({
|
|
30
|
-
cmd: cmd,
|
|
31
|
-
logger: this.logger,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async convertPfx(opts, pfxPassword) {
|
|
35
|
-
const { tmpCrtPath, tmpKeyPath } = opts;
|
|
36
|
-
const pfxPath = path.join(os.tmpdir(), "/certd/tmp/", Math.floor(Math.random() * 1000000) + "", "cert.pfx");
|
|
37
|
-
const dir = path.dirname(pfxPath);
|
|
38
|
-
if (!fs.existsSync(dir)) {
|
|
39
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
40
|
-
}
|
|
41
|
-
let passwordArg = "-passout pass:";
|
|
42
|
-
if (pfxPassword) {
|
|
43
|
-
passwordArg = `-password pass:${pfxPassword}`;
|
|
44
|
-
}
|
|
45
|
-
await this.exec(`openssl pkcs12 -export -out ${pfxPath} -inkey ${tmpKeyPath} -in ${tmpCrtPath} ${passwordArg}`);
|
|
46
|
-
return pfxPath;
|
|
47
|
-
// const fileBuffer = fs.readFileSync(pfxPath);
|
|
48
|
-
// this.pfxCert = fileBuffer.toString("base64");
|
|
49
|
-
//
|
|
50
|
-
// const applyTime = new Date().getTime();
|
|
51
|
-
// const filename = reader.buildCertFileName("pfx", applyTime);
|
|
52
|
-
// this.saveFile(filename, fileBuffer);
|
|
53
|
-
}
|
|
54
|
-
async convertDer(opts) {
|
|
55
|
-
const { tmpCrtPath } = opts;
|
|
56
|
-
const derPath = path.join(os.tmpdir(), "/certd/tmp/", Math.floor(Math.random() * 1000000) + "", `cert.der`);
|
|
57
|
-
const dir = path.dirname(derPath);
|
|
58
|
-
if (!fs.existsSync(dir)) {
|
|
59
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
60
|
-
}
|
|
61
|
-
await this.exec(`openssl x509 -outform der -in ${tmpCrtPath} -out ${derPath}`);
|
|
62
|
-
return derPath;
|
|
63
|
-
// const fileBuffer = fs.readFileSync(derPath);
|
|
64
|
-
// this.derCert = fileBuffer.toString("base64");
|
|
65
|
-
//
|
|
66
|
-
// const applyTime = new Date().getTime();
|
|
67
|
-
// const filename = reader.buildCertFileName("der", applyTime);
|
|
68
|
-
// this.saveFile(filename, fileBuffer);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
import { sp } from "@certd/pipeline";
|
|
2
|
+
import { CertReader } from "../cert-plugin/cert-reader.js";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import os from "os";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
export { CertReader };
|
|
7
|
+
export class CertConverter {
|
|
8
|
+
logger;
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.logger = opts.logger;
|
|
11
|
+
}
|
|
12
|
+
async convert(opts) {
|
|
13
|
+
const certReader = new CertReader(opts.cert);
|
|
14
|
+
let pfxPath;
|
|
15
|
+
let derPath;
|
|
16
|
+
const handle = async (opts) => {
|
|
17
|
+
// 调用openssl 转pfx
|
|
18
|
+
pfxPath = await this.convertPfx(opts);
|
|
19
|
+
// 转der
|
|
20
|
+
derPath = await this.convertDer(opts);
|
|
21
|
+
};
|
|
22
|
+
await certReader.readCertFile({ logger: this.logger, handle });
|
|
23
|
+
return {
|
|
24
|
+
pfxPath,
|
|
25
|
+
derPath,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async exec(cmd) {
|
|
29
|
+
await sp.spawn({
|
|
30
|
+
cmd: cmd,
|
|
31
|
+
logger: this.logger,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async convertPfx(opts, pfxPassword) {
|
|
35
|
+
const { tmpCrtPath, tmpKeyPath } = opts;
|
|
36
|
+
const pfxPath = path.join(os.tmpdir(), "/certd/tmp/", Math.floor(Math.random() * 1000000) + "", "cert.pfx");
|
|
37
|
+
const dir = path.dirname(pfxPath);
|
|
38
|
+
if (!fs.existsSync(dir)) {
|
|
39
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
40
|
+
}
|
|
41
|
+
let passwordArg = "-passout pass:";
|
|
42
|
+
if (pfxPassword) {
|
|
43
|
+
passwordArg = `-password pass:${pfxPassword}`;
|
|
44
|
+
}
|
|
45
|
+
await this.exec(`openssl pkcs12 -export -out ${pfxPath} -inkey ${tmpKeyPath} -in ${tmpCrtPath} ${passwordArg}`);
|
|
46
|
+
return pfxPath;
|
|
47
|
+
// const fileBuffer = fs.readFileSync(pfxPath);
|
|
48
|
+
// this.pfxCert = fileBuffer.toString("base64");
|
|
49
|
+
//
|
|
50
|
+
// const applyTime = new Date().getTime();
|
|
51
|
+
// const filename = reader.buildCertFileName("pfx", applyTime);
|
|
52
|
+
// this.saveFile(filename, fileBuffer);
|
|
53
|
+
}
|
|
54
|
+
async convertDer(opts) {
|
|
55
|
+
const { tmpCrtPath } = opts;
|
|
56
|
+
const derPath = path.join(os.tmpdir(), "/certd/tmp/", Math.floor(Math.random() * 1000000) + "", `cert.der`);
|
|
57
|
+
const dir = path.dirname(derPath);
|
|
58
|
+
if (!fs.existsSync(dir)) {
|
|
59
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
await this.exec(`openssl x509 -outform der -in ${tmpCrtPath} -out ${derPath}`);
|
|
62
|
+
return derPath;
|
|
63
|
+
// const fileBuffer = fs.readFileSync(derPath);
|
|
64
|
+
// this.derCert = fileBuffer.toString("base64");
|
|
65
|
+
//
|
|
66
|
+
// const applyTime = new Date().getTime();
|
|
67
|
+
// const filename = reader.buildCertFileName("der", applyTime);
|
|
68
|
+
// this.saveFile(filename, fileBuffer);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
71
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udmVydC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wbHVnaW4vY2VydC1wbHVnaW4vY29udmVydC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQVcsRUFBRSxFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFFOUMsT0FBTyxFQUFFLFVBQVUsRUFBMkIsTUFBTSwrQkFBK0IsQ0FBQztBQUNwRixPQUFPLElBQUksTUFBTSxNQUFNLENBQUM7QUFDeEIsT0FBTyxFQUFFLE1BQU0sSUFBSSxDQUFDO0FBQ3BCLE9BQU8sRUFBRSxNQUFNLElBQUksQ0FBQztBQUVwQixPQUFPLEVBQUUsVUFBVSxFQUFFLENBQUM7QUFHdEIsTUFBTSxPQUFPLGFBQWE7SUFDeEIsTUFBTSxDQUFVO0lBRWhCLFlBQVksSUFBeUI7UUFDbkMsSUFBSSxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUMsTUFBTSxDQUFDO0lBQzVCLENBQUM7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FNLEdBQUcsR0FBRyxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBQ2xDLElBQUksQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLEdBQUcsQ0FBQyxFQUFFO1lBQ3ZCLEVBQUUsQ0FBQyxTQUFTLENBQUMsR0FBRyxFQUFFLEVBQUUsU0FBUyxFQUFFLElBQUksRUFBRSxDQUFDLENBQUM7U0FDeEM7UUFFRCxNQUFNLElBQUksQ0FBQyxJQUFJLENBQUMsaUNBQWlDLFVBQVUsU0FBUyxPQUFPLEVBQUUsQ0FBQyxDQUFDO1FBRS9FLE9BQU8sT0FBTyxDQUFDO1FBRWYsK0NBQStDO1FBQy9DLGdEQUFnRDtRQUNoRCxFQUFFO1FBQ0YsMENBQTBDO1FBQzFDLCtEQUErRDtRQUMvRCx1Q0FBdUM7SUFDekMsQ0FBQztDQUNGIn0=
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { CertInfo, PrivateKeyType, SSLProvider } from "./acme.js";
|
|
2
|
-
import { AcmeService } from "./acme.js";
|
|
3
|
-
import { CertReader } from "./cert-reader.js";
|
|
4
|
-
import { CertApplyBasePlugin } from "./base.js";
|
|
5
|
-
export type { CertInfo };
|
|
6
|
-
export * from "./cert-reader.js";
|
|
7
|
-
export declare class CertApplyPlugin extends CertApplyBasePlugin {
|
|
8
|
-
sslProvider: SSLProvider;
|
|
9
|
-
eabAccessId: number;
|
|
10
|
-
privateKeyType: PrivateKeyType;
|
|
11
|
-
dnsProviderType: string;
|
|
12
|
-
dnsProviderAccess: string;
|
|
13
|
-
useProxy: boolean;
|
|
14
|
-
skipLocalVerify: boolean;
|
|
15
|
-
acme: AcmeService;
|
|
16
|
-
onInit(): Promise<void>;
|
|
17
|
-
doCertApply(): Promise<CertReader>;
|
|
18
|
-
}
|
|
1
|
+
import type { CertInfo, PrivateKeyType, SSLProvider } from "./acme.js";
|
|
2
|
+
import { AcmeService } from "./acme.js";
|
|
3
|
+
import { CertReader } from "./cert-reader.js";
|
|
4
|
+
import { CertApplyBasePlugin } from "./base.js";
|
|
5
|
+
export type { CertInfo };
|
|
6
|
+
export * from "./cert-reader.js";
|
|
7
|
+
export declare class CertApplyPlugin extends CertApplyBasePlugin {
|
|
8
|
+
sslProvider: SSLProvider;
|
|
9
|
+
eabAccessId: number;
|
|
10
|
+
privateKeyType: PrivateKeyType;
|
|
11
|
+
dnsProviderType: string;
|
|
12
|
+
dnsProviderAccess: string;
|
|
13
|
+
useProxy: boolean;
|
|
14
|
+
skipLocalVerify: boolean;
|
|
15
|
+
acme: AcmeService;
|
|
16
|
+
onInit(): Promise<void>;
|
|
17
|
+
doCertApply(): Promise<CertReader>;
|
|
18
|
+
}
|