mirror of https://github.com/certd/certd
Merge branch 'acme_sync' into v2
# Conflicts: # packages/core/acme-client/.gitignore # packages/core/acme-client/package.json # packages/core/acme-client/src/auto.js # packages/core/acme-client/src/crypto/forge.js # packages/core/acme-client/types/index.d.tspull/9/head^2
commit
f08f765529
|
@ -169,9 +169,6 @@ module.exports = async function(client, userOpts) {
|
||||||
await challengeFunc(authz);
|
await challengeFunc(authz);
|
||||||
});
|
});
|
||||||
|
|
||||||
log('[auto] Waiting for challenge valid status');
|
|
||||||
// await Promise.all(challengePromises);
|
|
||||||
|
|
||||||
log('开始challenge');
|
log('开始challenge');
|
||||||
let promise = Promise.resolve();
|
let promise = Promise.resolve();
|
||||||
function runPromisesSerially(tasks) {
|
function runPromisesSerially(tasks) {
|
||||||
|
@ -183,6 +180,11 @@ module.exports = async function(client, userOpts) {
|
||||||
|
|
||||||
await runPromisesSerially(challengePromises);
|
await runPromisesSerially(challengePromises);
|
||||||
log('challenge结束');
|
log('challenge结束');
|
||||||
|
|
||||||
|
// log('[auto] Waiting for challenge valid status');
|
||||||
|
// await Promise.all(challengePromises);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalize order and download certificate
|
* Finalize order and download certificate
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -74,7 +74,8 @@ function parseDomains(obj) {
|
||||||
|
|
||||||
if (rootAltNames && rootAltNames.altNames && rootAltNames.altNames.length) {
|
if (rootAltNames && rootAltNames.altNames && rootAltNames.altNames.length) {
|
||||||
altNamesDict = rootAltNames.altNames;
|
altNamesDict = rootAltNames.altNames;
|
||||||
} else if (rootExtensions && rootExtensions.extensions && rootExtensions.extensions.length) {
|
}
|
||||||
|
else if (rootExtensions && rootExtensions.extensions && rootExtensions.extensions.length) {
|
||||||
const extAltNames = rootExtensions.extensions.find((e) => 'altNames' in e);
|
const extAltNames = rootExtensions.extensions.find((e) => 'altNames' in e);
|
||||||
|
|
||||||
if (extAltNames && extAltNames.altNames && extAltNames.altNames.length) {
|
if (extAltNames && extAltNames.altNames && extAltNames.altNames.length) {
|
||||||
|
@ -115,21 +116,11 @@ function parseDomains(obj) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function createPrivateKey(size = 2048) {
|
async function createPrivateKey(size = 2048) {
|
||||||
const keyPair = await generateKeyPair({bits: size});
|
const keyPair = await generateKeyPair({ bits: size });
|
||||||
// const privateKey = forge.pki.privateKeyToPem(keyPair.privateKey);
|
const pemKey = forge.pki.privateKeyToPem(keyPair.privateKey);
|
||||||
|
|
||||||
// convert a Forge private key to an ASN.1 RSAPrivateKey
|
|
||||||
var rsaPrivateKey = forge.pki.privateKeyToAsn1(keyPair.privateKey);
|
|
||||||
|
|
||||||
// wrap an RSAPrivateKey ASN.1 object in a PKCS#8 ASN.1 PrivateKeyInfo
|
|
||||||
var privateKeyInfo = forge.pki.wrapRsaPrivateKey(rsaPrivateKey);
|
|
||||||
|
|
||||||
// convert a PKCS#8 ASN.1 PrivateKeyInfo to PEM
|
|
||||||
var pemKey = forge.pki.privateKeyInfoToPem(privateKeyInfo);
|
|
||||||
return Buffer.from(pemKey);
|
return Buffer.from(pemKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.createPrivateKey = createPrivateKey;
|
exports.createPrivateKey = createPrivateKey;
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,7 +136,7 @@ exports.createPrivateKey = createPrivateKey;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createPublicKey = async function (key) {
|
exports.createPublicKey = async function(key) {
|
||||||
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);
|
||||||
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
||||||
|
@ -191,7 +182,7 @@ exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getModulus = async function (input) {
|
exports.getModulus = async function(input) {
|
||||||
if (!Buffer.isBuffer(input)) {
|
if (!Buffer.isBuffer(input)) {
|
||||||
input = Buffer.from(input);
|
input = Buffer.from(input);
|
||||||
}
|
}
|
||||||
|
@ -215,7 +206,7 @@ exports.getModulus = async function (input) {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getPublicExponent = async function (input) {
|
exports.getPublicExponent = async function(input) {
|
||||||
if (!Buffer.isBuffer(input)) {
|
if (!Buffer.isBuffer(input)) {
|
||||||
input = Buffer.from(input);
|
input = Buffer.from(input);
|
||||||
}
|
}
|
||||||
|
@ -240,7 +231,7 @@ exports.getPublicExponent = async function (input) {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.readCsrDomains = async function (csr) {
|
exports.readCsrDomains = async function(csr) {
|
||||||
if (!Buffer.isBuffer(csr)) {
|
if (!Buffer.isBuffer(csr)) {
|
||||||
csr = Buffer.from(csr);
|
csr = Buffer.from(csr);
|
||||||
}
|
}
|
||||||
|
@ -269,7 +260,7 @@ exports.readCsrDomains = async function (csr) {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.readCertificateInfo = async function (cert) {
|
exports.readCertificateInfo = async function(cert) {
|
||||||
if (!Buffer.isBuffer(cert)) {
|
if (!Buffer.isBuffer(cert)) {
|
||||||
cert = Buffer.from(cert);
|
cert = Buffer.from(cert);
|
||||||
}
|
}
|
||||||
|
@ -321,7 +312,7 @@ function createCsrSubject(subjectObj) {
|
||||||
return Object.entries(subjectObj).reduce((result, [shortName, value]) => {
|
return Object.entries(subjectObj).reduce((result, [shortName, value]) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
const valueTagClass = getCsrValueTagClass(shortName);
|
const valueTagClass = getCsrValueTagClass(shortName);
|
||||||
result.push({shortName, value, valueTagClass});
|
result.push({ shortName, value, valueTagClass });
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -341,7 +332,7 @@ function createCsrSubject(subjectObj) {
|
||||||
function formatCsrAltNames(altNames) {
|
function formatCsrAltNames(altNames) {
|
||||||
return altNames.map((value) => {
|
return altNames.map((value) => {
|
||||||
const type = net.isIP(value) ? 7 : 2;
|
const type = net.isIP(value) ? 7 : 2;
|
||||||
return {type, value};
|
return { type, value };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,10 +391,11 @@ function formatCsrAltNames(altNames) {
|
||||||
* }, certificateKey);
|
* }, certificateKey);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createCsr = async function (data, key = null) {
|
exports.createCsr = async function(data, key = null) {
|
||||||
if (!key) {
|
if (!key) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue