@certd/acme-client 0.3.1 → 1.0.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/package.json +4 -2
- package/src/auto.js +12 -6
- package/src/crypto/forge.js +14 -22
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certd/acme-client",
|
|
3
3
|
"description": "Simple and unopinionated ACME client",
|
|
4
|
+
"private": false,
|
|
4
5
|
"author": "nmorsman",
|
|
5
|
-
"version": "0.
|
|
6
|
+
"version": "1.0.2",
|
|
6
7
|
"main": "src/index.js",
|
|
7
8
|
"types": "types",
|
|
8
9
|
"license": "MIT",
|
|
@@ -56,5 +57,6 @@
|
|
|
56
57
|
],
|
|
57
58
|
"bugs": {
|
|
58
59
|
"url": "https://github.com/publishlab/node-acme-client/issues"
|
|
59
|
-
}
|
|
60
|
+
},
|
|
61
|
+
"gitHead": "1a738403fcb2732c0797b51cba15ad2b18b66523"
|
|
60
62
|
}
|
package/src/auto.js
CHANGED
|
@@ -114,9 +114,9 @@ module.exports = async function(client, userOpts) {
|
|
|
114
114
|
/* Trigger challengeCreateFn() */
|
|
115
115
|
log(`[auto] [${d}] Trigger challengeCreateFn()`);
|
|
116
116
|
const keyAuthorization = await client.getChallengeKeyAuthorization(challenge);
|
|
117
|
-
|
|
117
|
+
let recordItem = null;
|
|
118
118
|
try {
|
|
119
|
-
await opts.challengeCreateFn(authz, challenge, keyAuthorization);
|
|
119
|
+
recordItem = await opts.challengeCreateFn(authz, challenge, keyAuthorization);
|
|
120
120
|
|
|
121
121
|
/* Challenge verification */
|
|
122
122
|
if (opts.skipChallengeVerification === true) {
|
|
@@ -134,12 +134,16 @@ module.exports = async function(client, userOpts) {
|
|
|
134
134
|
|
|
135
135
|
await client.waitForValidStatus(challenge);
|
|
136
136
|
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message}`);
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
137
141
|
finally {
|
|
138
142
|
/* Trigger challengeRemoveFn(), suppress errors */
|
|
139
143
|
log(`[auto] [${d}] Trigger challengeRemoveFn()`);
|
|
140
144
|
|
|
141
145
|
try {
|
|
142
|
-
await opts.challengeRemoveFn(authz, challenge, keyAuthorization);
|
|
146
|
+
await opts.challengeRemoveFn(authz, challenge, keyAuthorization, recordItem);
|
|
143
147
|
}
|
|
144
148
|
catch (e) {
|
|
145
149
|
log(`[auto] [${d}] challengeRemoveFn threw error: ${e.message}`);
|
|
@@ -169,9 +173,6 @@ module.exports = async function(client, userOpts) {
|
|
|
169
173
|
await challengeFunc(authz);
|
|
170
174
|
});
|
|
171
175
|
|
|
172
|
-
log('[auto] Waiting for challenge valid status');
|
|
173
|
-
// await Promise.all(challengePromises);
|
|
174
|
-
|
|
175
176
|
log('开始challenge');
|
|
176
177
|
let promise = Promise.resolve();
|
|
177
178
|
function runPromisesSerially(tasks) {
|
|
@@ -183,6 +184,11 @@ module.exports = async function(client, userOpts) {
|
|
|
183
184
|
|
|
184
185
|
await runPromisesSerially(challengePromises);
|
|
185
186
|
log('challenge结束');
|
|
187
|
+
|
|
188
|
+
// log('[auto] Waiting for challenge valid status');
|
|
189
|
+
// await Promise.all(challengePromises);
|
|
190
|
+
|
|
191
|
+
|
|
186
192
|
/**
|
|
187
193
|
* Finalize order and download certificate
|
|
188
194
|
*/
|
package/src/crypto/forge.js
CHANGED
|
@@ -74,7 +74,8 @@ function parseDomains(obj) {
|
|
|
74
74
|
|
|
75
75
|
if (rootAltNames && rootAltNames.altNames && rootAltNames.altNames.length) {
|
|
76
76
|
altNamesDict = rootAltNames.altNames;
|
|
77
|
-
}
|
|
77
|
+
}
|
|
78
|
+
else if (rootExtensions && rootExtensions.extensions && rootExtensions.extensions.length) {
|
|
78
79
|
const extAltNames = rootExtensions.extensions.find((e) => 'altNames' in e);
|
|
79
80
|
|
|
80
81
|
if (extAltNames && extAltNames.altNames && extAltNames.altNames.length) {
|
|
@@ -115,21 +116,11 @@ function parseDomains(obj) {
|
|
|
115
116
|
*/
|
|
116
117
|
|
|
117
118
|
async function createPrivateKey(size = 2048) {
|
|
118
|
-
const keyPair = await generateKeyPair({bits: size});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// convert a Forge private key to an ASN.1 RSAPrivateKey
|
|
122
|
-
var rsaPrivateKey = forge.pki.privateKeyToAsn1(keyPair.privateKey);
|
|
123
|
-
|
|
124
|
-
// wrap an RSAPrivateKey ASN.1 object in a PKCS#8 ASN.1 PrivateKeyInfo
|
|
125
|
-
var privateKeyInfo = forge.pki.wrapRsaPrivateKey(rsaPrivateKey);
|
|
126
|
-
|
|
127
|
-
// convert a PKCS#8 ASN.1 PrivateKeyInfo to PEM
|
|
128
|
-
var pemKey = forge.pki.privateKeyInfoToPem(privateKeyInfo);
|
|
119
|
+
const keyPair = await generateKeyPair({ bits: size });
|
|
120
|
+
const pemKey = forge.pki.privateKeyToPem(keyPair.privateKey);
|
|
129
121
|
return Buffer.from(pemKey);
|
|
130
122
|
}
|
|
131
123
|
|
|
132
|
-
|
|
133
124
|
exports.createPrivateKey = createPrivateKey;
|
|
134
125
|
|
|
135
126
|
|
|
@@ -145,7 +136,7 @@ exports.createPrivateKey = createPrivateKey;
|
|
|
145
136
|
* ```
|
|
146
137
|
*/
|
|
147
138
|
|
|
148
|
-
exports.createPublicKey = async function
|
|
139
|
+
exports.createPublicKey = async function(key) {
|
|
149
140
|
const privateKey = forge.pki.privateKeyFromPem(key);
|
|
150
141
|
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
|
151
142
|
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
|
@@ -191,7 +182,7 @@ exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
|
|
191
182
|
* ```
|
|
192
183
|
*/
|
|
193
184
|
|
|
194
|
-
exports.getModulus = async function
|
|
185
|
+
exports.getModulus = async function(input) {
|
|
195
186
|
if (!Buffer.isBuffer(input)) {
|
|
196
187
|
input = Buffer.from(input);
|
|
197
188
|
}
|
|
@@ -215,7 +206,7 @@ exports.getModulus = async function (input) {
|
|
|
215
206
|
* ```
|
|
216
207
|
*/
|
|
217
208
|
|
|
218
|
-
exports.getPublicExponent = async function
|
|
209
|
+
exports.getPublicExponent = async function(input) {
|
|
219
210
|
if (!Buffer.isBuffer(input)) {
|
|
220
211
|
input = Buffer.from(input);
|
|
221
212
|
}
|
|
@@ -240,7 +231,7 @@ exports.getPublicExponent = async function (input) {
|
|
|
240
231
|
* ```
|
|
241
232
|
*/
|
|
242
233
|
|
|
243
|
-
exports.readCsrDomains = async function
|
|
234
|
+
exports.readCsrDomains = async function(csr) {
|
|
244
235
|
if (!Buffer.isBuffer(csr)) {
|
|
245
236
|
csr = Buffer.from(csr);
|
|
246
237
|
}
|
|
@@ -269,7 +260,7 @@ exports.readCsrDomains = async function (csr) {
|
|
|
269
260
|
* ```
|
|
270
261
|
*/
|
|
271
262
|
|
|
272
|
-
exports.readCertificateInfo = async function
|
|
263
|
+
exports.readCertificateInfo = async function(cert) {
|
|
273
264
|
if (!Buffer.isBuffer(cert)) {
|
|
274
265
|
cert = Buffer.from(cert);
|
|
275
266
|
}
|
|
@@ -321,7 +312,7 @@ function createCsrSubject(subjectObj) {
|
|
|
321
312
|
return Object.entries(subjectObj).reduce((result, [shortName, value]) => {
|
|
322
313
|
if (value) {
|
|
323
314
|
const valueTagClass = getCsrValueTagClass(shortName);
|
|
324
|
-
result.push({shortName, value, valueTagClass});
|
|
315
|
+
result.push({ shortName, value, valueTagClass });
|
|
325
316
|
}
|
|
326
317
|
|
|
327
318
|
return result;
|
|
@@ -341,7 +332,7 @@ function createCsrSubject(subjectObj) {
|
|
|
341
332
|
function formatCsrAltNames(altNames) {
|
|
342
333
|
return altNames.map((value) => {
|
|
343
334
|
const type = net.isIP(value) ? 7 : 2;
|
|
344
|
-
return {type, value};
|
|
335
|
+
return { type, value };
|
|
345
336
|
});
|
|
346
337
|
}
|
|
347
338
|
|
|
@@ -400,10 +391,11 @@ function formatCsrAltNames(altNames) {
|
|
|
400
391
|
* }, certificateKey);
|
|
401
392
|
*/
|
|
402
393
|
|
|
403
|
-
exports.createCsr = async function
|
|
394
|
+
exports.createCsr = async function(data, key = null) {
|
|
404
395
|
if (!key) {
|
|
405
396
|
key = await createPrivateKey(data.keySize);
|
|
406
|
-
}
|
|
397
|
+
}
|
|
398
|
+
else if (!Buffer.isBuffer(key)) {
|
|
407
399
|
key = Buffer.from(key);
|
|
408
400
|
}
|
|
409
401
|
|