mirror of https://github.com/certd/certd
parent
e358a88696
commit
17ead547aa
|
@ -10,6 +10,7 @@
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const { promisify } = require('util');
|
const { promisify } = require('util');
|
||||||
const forge = require('node-forge');
|
const forge = require('node-forge');
|
||||||
|
const { createPrivateEcdsaKey, getPublicKey } = require('./index');
|
||||||
|
|
||||||
const generateKeyPair = promisify(forge.pki.rsa.generateKeyPair);
|
const generateKeyPair = promisify(forge.pki.rsa.generateKeyPair);
|
||||||
|
|
||||||
|
@ -378,13 +379,17 @@ function formatCsrAltNames(altNames) {
|
||||||
* }, certificateKey);
|
* }, certificateKey);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createCsr = async (data, key = null) => {
|
exports.createCsr = async (data, keyType = null) => {
|
||||||
if (!key) {
|
let key = null;
|
||||||
|
if (keyType === 'ec') {
|
||||||
|
key = await createPrivateEcdsaKey();
|
||||||
|
}
|
||||||
|
else {
|
||||||
key = await createPrivateKey(data.keySize);
|
key = await createPrivateKey(data.keySize);
|
||||||
}
|
}
|
||||||
else if (!Buffer.isBuffer(key)) {
|
// else if (!Buffer.isBuffer(key)) {
|
||||||
key = Buffer.from(key);
|
// key = Buffer.from(key);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (typeof data.altNames === 'undefined') {
|
if (typeof data.altNames === 'undefined') {
|
||||||
data.altNames = [];
|
data.altNames = [];
|
||||||
|
@ -396,6 +401,8 @@ exports.createCsr = async (data, key = null) => {
|
||||||
const privateKey = forge.pki.privateKeyFromPem(key);
|
const privateKey = forge.pki.privateKeyFromPem(key);
|
||||||
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
||||||
csr.publicKey = publicKey;
|
csr.publicKey = publicKey;
|
||||||
|
// const privateKey = key;
|
||||||
|
// csr.publicKey = getPublicKey(key);
|
||||||
|
|
||||||
/* Ensure subject common name is present in SAN - https://cabforum.org/wp-content/uploads/BRv1.2.3.pdf */
|
/* Ensure subject common name is present in SAN - https://cabforum.org/wp-content/uploads/BRv1.2.3.pdf */
|
||||||
if (data.commonName && !data.altNames.includes(data.commonName)) {
|
if (data.commonName && !data.altNames.includes(data.commonName)) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ export type CertInfo = {
|
||||||
csr: string;
|
csr: string;
|
||||||
};
|
};
|
||||||
export type SSLProvider = "letsencrypt" | "google" | "zerossl";
|
export type SSLProvider = "letsencrypt" | "google" | "zerossl";
|
||||||
|
export type PrivateKeyType = "rsa" | "ec";
|
||||||
type AcmeServiceOptions = {
|
type AcmeServiceOptions = {
|
||||||
userContext: IContext;
|
userContext: IContext;
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
|
@ -21,6 +22,7 @@ type AcmeServiceOptions = {
|
||||||
eab?: ClientExternalAccountBindingOptions;
|
eab?: ClientExternalAccountBindingOptions;
|
||||||
skipLocalVerify?: boolean;
|
skipLocalVerify?: boolean;
|
||||||
useMappingProxy?: boolean;
|
useMappingProxy?: boolean;
|
||||||
|
privateKeyType?: PrivateKeyType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class AcmeService {
|
export class AcmeService {
|
||||||
|
@ -208,18 +210,33 @@ export class AcmeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async order(options: { email: string; domains: string | string[]; dnsProvider: any; csrInfo: any; isTest?: boolean }) {
|
async order(options: {
|
||||||
|
email: string;
|
||||||
|
domains: string | string[];
|
||||||
|
dnsProvider: any;
|
||||||
|
csrInfo: any;
|
||||||
|
isTest?: boolean;
|
||||||
|
privateKeyType?: string;
|
||||||
|
}): Promise<CertInfo> {
|
||||||
const { email, isTest, domains, csrInfo, dnsProvider } = options;
|
const { email, isTest, domains, csrInfo, dnsProvider } = options;
|
||||||
const client: acme.Client = await this.getAcmeClient(email, isTest);
|
const client: acme.Client = await this.getAcmeClient(email, isTest);
|
||||||
|
|
||||||
/* Create CSR */
|
/* Create CSR */
|
||||||
const { commonName, altNames } = this.buildCommonNameByDomains(domains);
|
const { commonName, altNames } = this.buildCommonNameByDomains(domains);
|
||||||
|
let privateKey = null;
|
||||||
const [key, csr] = await acme.forge.createCsr({
|
if (options.privateKeyType == "ec") {
|
||||||
commonName,
|
privateKey = await acme.crypto.createPrivateEcdsaKey();
|
||||||
...csrInfo,
|
} else {
|
||||||
altNames,
|
privateKey = await acme.crypto.createPrivateRsaKey();
|
||||||
});
|
}
|
||||||
|
const [key, csr] = await acme.forge.createCsr(
|
||||||
|
{
|
||||||
|
commonName,
|
||||||
|
...csrInfo,
|
||||||
|
altNames,
|
||||||
|
},
|
||||||
|
privateKey
|
||||||
|
);
|
||||||
if (dnsProvider == null) {
|
if (dnsProvider == null) {
|
||||||
throw new Error("dnsProvider 不能为空");
|
throw new Error("dnsProvider 不能为空");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Decorator, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
|
import { Decorator, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
|
||||||
import type { CertInfo, SSLProvider } from "./acme.js";
|
import type { CertInfo, PrivateKeyType, SSLProvider } from "./acme.js";
|
||||||
import { AcmeService } from "./acme.js";
|
import { AcmeService } from "./acme.js";
|
||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
import { DnsProviderContext, DnsProviderDefine, dnsProviderRegistry } from "../../dns-provider/index.js";
|
import { DnsProviderContext, DnsProviderDefine, dnsProviderRegistry } from "../../dns-provider/index.js";
|
||||||
|
@ -42,6 +42,21 @@ export class CertApplyPlugin extends CertApplyBasePlugin {
|
||||||
})
|
})
|
||||||
sslProvider!: SSLProvider;
|
sslProvider!: SSLProvider;
|
||||||
|
|
||||||
|
@TaskInput({
|
||||||
|
title: "证书私钥类型",
|
||||||
|
value: "rsa",
|
||||||
|
component: {
|
||||||
|
name: "a-select",
|
||||||
|
vModel: "value",
|
||||||
|
options: [
|
||||||
|
{ value: "rsa", label: "RSA" },
|
||||||
|
{ value: "ec", label: "EC" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
privateKeyType!: PrivateKeyType;
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: "EAB授权",
|
title: "EAB授权",
|
||||||
component: {
|
component: {
|
||||||
|
@ -116,6 +131,7 @@ export class CertApplyPlugin extends CertApplyBasePlugin {
|
||||||
eab,
|
eab,
|
||||||
skipLocalVerify: this.skipLocalVerify,
|
skipLocalVerify: this.skipLocalVerify,
|
||||||
useMappingProxy: this.useProxy,
|
useMappingProxy: this.useProxy,
|
||||||
|
privateKeyType: this.privateKeyType,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +172,7 @@ export class CertApplyPlugin extends CertApplyBasePlugin {
|
||||||
dnsProvider,
|
dnsProvider,
|
||||||
csrInfo,
|
csrInfo,
|
||||||
isTest: false,
|
isTest: false,
|
||||||
|
privateKeyType: this.privateKeyType,
|
||||||
});
|
});
|
||||||
|
|
||||||
const certInfo = this.formatCerts(cert);
|
const certInfo = this.formatCerts(cert);
|
||||||
|
|
|
@ -283,6 +283,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
const entity: PipelineEntity = await this.info(id);
|
const entity: PipelineEntity = await this.info(id);
|
||||||
|
|
||||||
const pipeline = JSON.parse(entity.content);
|
const pipeline = JSON.parse(entity.content);
|
||||||
|
if (!pipeline.id) {
|
||||||
|
pipeline.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
if (!pipeline.stages || pipeline.stages.length === 0) {
|
if (!pipeline.stages || pipeline.stages.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -306,7 +309,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
await this.saveHistory(history);
|
await this.saveHistory(history);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const pipelineEntity = new PipelineEntity();
|
const pipelineEntity = new PipelineEntity();
|
||||||
pipelineEntity.id = parseInt(history.pipeline.id);
|
pipelineEntity.id = id;
|
||||||
pipelineEntity.status = 'error';
|
pipelineEntity.status = 'error';
|
||||||
pipelineEntity.lastHistoryTime = history.pipeline.status.startTime;
|
pipelineEntity.lastHistoryTime = history.pipeline.status.startTime;
|
||||||
await this.update(pipelineEntity);
|
await this.update(pipelineEntity);
|
||||||
|
@ -339,7 +342,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async cancel(historyId) {
|
async cancel(historyId:number) {
|
||||||
const executor = runningTasks.get(historyId);
|
const executor = runningTasks.get(historyId);
|
||||||
if (executor) {
|
if (executor) {
|
||||||
await executor.cancel();
|
await executor.cancel();
|
||||||
|
|
Loading…
Reference in New Issue