@certd/acme-client 0.1.10 → 0.2.0
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 -3
- package/src/crypto/forge.js +23 -14
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@certd/acme-client",
|
|
3
3
|
"description": "Simple and unopinionated ACME client,base version 4.1.2",
|
|
4
4
|
"author": "greper",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.2.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"types": "types",
|
|
8
8
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"build-docs": "jsdoc2md src/client.js > docs/client.md && jsdoc2md src/crypto/forge.js > docs/forge.md",
|
|
42
42
|
"lint": "eslint .",
|
|
43
43
|
"lint-types": "dtslint types",
|
|
44
|
-
"
|
|
44
|
+
"1prepublishOnly": "npm run build-docs",
|
|
45
45
|
"test": "mocha -b -t 60000 \"test/setup.js\" \"test/**/*.spec.js\"",
|
|
46
46
|
"test-local": "/bin/bash scripts/run-tests.sh",
|
|
47
47
|
"build": "webpack ./src/index.js ./dist/bundle.js"
|
|
@@ -60,5 +60,6 @@
|
|
|
60
60
|
],
|
|
61
61
|
"bugs": {
|
|
62
62
|
"url": "https://github.com/publishlab/node-acme-client/issues"
|
|
63
|
-
}
|
|
63
|
+
},
|
|
64
|
+
"gitHead": "5fbd7742665c0a949333d805153e9b6af91c0a71"
|
|
64
65
|
}
|
package/src/crypto/forge.js
CHANGED
|
@@ -71,8 +71,7 @@ function parseDomains(obj) {
|
|
|
71
71
|
|
|
72
72
|
if (rootAltNames && rootAltNames.altNames && rootAltNames.altNames.length) {
|
|
73
73
|
altNamesDict = rootAltNames.altNames;
|
|
74
|
-
}
|
|
75
|
-
else if (rootExtensions && rootExtensions.extensions && rootExtensions.extensions.length) {
|
|
74
|
+
} else if (rootExtensions && rootExtensions.extensions && rootExtensions.extensions.length) {
|
|
76
75
|
const extAltNames = rootExtensions.extensions.find((e) => 'altNames' in e);
|
|
77
76
|
|
|
78
77
|
if (extAltNames && extAltNames.altNames && extAltNames.altNames.length) {
|
|
@@ -113,11 +112,22 @@ function parseDomains(obj) {
|
|
|
113
112
|
*/
|
|
114
113
|
|
|
115
114
|
async function createPrivateKey(size = 2048) {
|
|
116
|
-
const keyPair = await generateKeyPair({
|
|
117
|
-
const
|
|
115
|
+
const keyPair = await generateKeyPair({bits: size});
|
|
116
|
+
// const privateKey = forge.pki.privateKeyToPem(keyPair.privateKey);
|
|
117
|
+
|
|
118
|
+
// convert a Forge private key to an ASN.1 RSAPrivateKey
|
|
119
|
+
var rsaPrivateKey = forge.pki.privateKeyToAsn1(keyPair.privateKey);
|
|
120
|
+
|
|
121
|
+
// wrap an RSAPrivateKey ASN.1 object in a PKCS#8 ASN.1 PrivateKeyInfo
|
|
122
|
+
var privateKeyInfo = forge.pki.wrapRsaPrivateKey(rsaPrivateKey);
|
|
123
|
+
|
|
124
|
+
// convert a PKCS#8 ASN.1 PrivateKeyInfo to PEM
|
|
125
|
+
var pemKey = forge.pki.privateKeyInfoToPem(privateKeyInfo);
|
|
126
|
+
console.log('privatekey ', pemKey)
|
|
118
127
|
return Buffer.from(pemKey);
|
|
119
128
|
}
|
|
120
129
|
|
|
130
|
+
|
|
121
131
|
exports.createPrivateKey = createPrivateKey;
|
|
122
132
|
|
|
123
133
|
|
|
@@ -133,7 +143,7 @@ exports.createPrivateKey = createPrivateKey;
|
|
|
133
143
|
* ```
|
|
134
144
|
*/
|
|
135
145
|
|
|
136
|
-
exports.createPublicKey = async function(key) {
|
|
146
|
+
exports.createPublicKey = async function (key) {
|
|
137
147
|
const privateKey = forge.pki.privateKeyFromPem(key);
|
|
138
148
|
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
|
139
149
|
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
|
@@ -179,7 +189,7 @@ exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
|
|
179
189
|
* ```
|
|
180
190
|
*/
|
|
181
191
|
|
|
182
|
-
exports.getModulus = async function(input) {
|
|
192
|
+
exports.getModulus = async function (input) {
|
|
183
193
|
if (!Buffer.isBuffer(input)) {
|
|
184
194
|
input = Buffer.from(input);
|
|
185
195
|
}
|
|
@@ -203,7 +213,7 @@ exports.getModulus = async function(input) {
|
|
|
203
213
|
* ```
|
|
204
214
|
*/
|
|
205
215
|
|
|
206
|
-
exports.getPublicExponent = async function(input) {
|
|
216
|
+
exports.getPublicExponent = async function (input) {
|
|
207
217
|
if (!Buffer.isBuffer(input)) {
|
|
208
218
|
input = Buffer.from(input);
|
|
209
219
|
}
|
|
@@ -228,7 +238,7 @@ exports.getPublicExponent = async function(input) {
|
|
|
228
238
|
* ```
|
|
229
239
|
*/
|
|
230
240
|
|
|
231
|
-
exports.readCsrDomains = async function(csr) {
|
|
241
|
+
exports.readCsrDomains = async function (csr) {
|
|
232
242
|
if (!Buffer.isBuffer(csr)) {
|
|
233
243
|
csr = Buffer.from(csr);
|
|
234
244
|
}
|
|
@@ -257,7 +267,7 @@ exports.readCsrDomains = async function(csr) {
|
|
|
257
267
|
* ```
|
|
258
268
|
*/
|
|
259
269
|
|
|
260
|
-
exports.readCertificateInfo = async function(cert) {
|
|
270
|
+
exports.readCertificateInfo = async function (cert) {
|
|
261
271
|
if (!Buffer.isBuffer(cert)) {
|
|
262
272
|
cert = Buffer.from(cert);
|
|
263
273
|
}
|
|
@@ -309,7 +319,7 @@ function createCsrSubject(subjectObj) {
|
|
|
309
319
|
return Object.entries(subjectObj).reduce((result, [shortName, value]) => {
|
|
310
320
|
if (value) {
|
|
311
321
|
const valueTagClass = getCsrValueTagClass(shortName);
|
|
312
|
-
result.push({
|
|
322
|
+
result.push({shortName, value, valueTagClass});
|
|
313
323
|
}
|
|
314
324
|
|
|
315
325
|
return result;
|
|
@@ -329,7 +339,7 @@ function createCsrSubject(subjectObj) {
|
|
|
329
339
|
function formatCsrAltNames(altNames) {
|
|
330
340
|
return altNames.map((value) => {
|
|
331
341
|
const type = net.isIP(value) ? 7 : 2;
|
|
332
|
-
return {
|
|
342
|
+
return {type, value};
|
|
333
343
|
});
|
|
334
344
|
}
|
|
335
345
|
|
|
@@ -388,11 +398,10 @@ function formatCsrAltNames(altNames) {
|
|
|
388
398
|
* }, certificateKey);
|
|
389
399
|
*/
|
|
390
400
|
|
|
391
|
-
exports.createCsr = async function(data, key = null) {
|
|
401
|
+
exports.createCsr = async function (data, key = null) {
|
|
392
402
|
if (!key) {
|
|
393
403
|
key = await createPrivateKey(data.keySize);
|
|
394
|
-
}
|
|
395
|
-
else if (!Buffer.isBuffer(key)) {
|
|
404
|
+
} else if (!Buffer.isBuffer(key)) {
|
|
396
405
|
key = Buffer.from(key);
|
|
397
406
|
}
|
|
398
407
|
|