node-pki-signer 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +46 -2
- package/dist/algorithms.d.ts +10 -0
- package/dist/algorithms.js +73 -0
- package/dist/algorithms.js.map +1 -0
- package/dist/allowlist.d.ts +2 -0
- package/dist/allowlist.js +45 -0
- package/dist/allowlist.js.map +1 -0
- package/dist/ca-sign-csr.d.ts +31 -0
- package/dist/ca-sign-csr.js +197 -0
- package/dist/ca-sign-csr.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensions.d.ts +3 -0
- package/dist/extensions.js +298 -0
- package/dist/extensions.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +24 -0
- package/dist/keys.js +76 -0
- package/dist/keys.js.map +1 -0
- package/dist/kms-key.d.ts +19 -0
- package/dist/kms-key.js +49 -0
- package/dist/kms-key.js.map +1 -0
- package/dist/openssl-key.d.ts +14 -0
- package/dist/openssl-key.js +60 -0
- package/dist/openssl-key.js.map +1 -0
- package/dist/options.d.ts +48 -0
- package/dist/options.js +2 -0
- package/dist/options.js.map +1 -0
- package/dist/pkcs11-key.d.ts +12 -0
- package/dist/pkcs11-key.js +266 -0
- package/dist/pkcs11-key.js.map +1 -0
- package/dist/shadow.d.ts +36 -0
- package/dist/shadow.js +57 -0
- package/dist/shadow.js.map +1 -0
- package/dist/signer.d.ts +49 -0
- package/dist/signer.js +96 -0
- package/dist/signer.js.map +1 -0
- package/dist/signing-key.d.ts +15 -0
- package/dist/signing-key.js +2 -0
- package/dist/signing-key.js.map +1 -0
- package/dist/software-key.d.ts +3 -0
- package/dist/software-key.js +34 -0
- package/dist/software-key.js.map +1 -0
- package/dist/subject.d.ts +3 -0
- package/dist/subject.js +90 -0
- package/dist/subject.js.map +1 -0
- package/dist/tbs-fields.d.ts +14 -0
- package/dist/tbs-fields.js +57 -0
- package/dist/tbs-fields.js.map +1 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lyas Spiehler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# node-pki-signer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Fast, in-process X.509 signing for [PKIaaS.io](https://pkiaas.io) and the [IoT HSM](https://github.com/lspiehler/iot-hsm) agent.
|
|
4
|
+
|
|
5
|
+
It signs certificates with software keys, PKCS#11 tokens (YubiKey, SoftHSM) and Google Cloud KMS, including post-quantum keys (ML-DSA, SLH-DSA). Anything it can't do natively falls back to OpenSSL, so new algorithms work as soon as OpenSSL supports them.
|
|
6
|
+
|
|
7
|
+
Status: early development (0.x): the API may still change. PKIaaS.io runs it in shadow mode (ADR 0004) before it signs there.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
`createSigner` is a drop-in for node-openssl-cert2's `x509.CASignCSR`: same parameters, same callback. It signs natively when the CA's signature algorithm is on the allowlist for a backend that can reach the key (`src/allowlist.ts`, ADR 0003) and hands the whole request to node-openssl-cert2 otherwise:
|
|
12
|
+
|
|
13
|
+
| Key | Backends, preferred first | Allowlisted |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `key` (PEM) | node:crypto, then `openssl dgst` | every CA key type and hash |
|
|
16
|
+
| `pkcs11: { uri, pin, modulePath }` | pkcs11js, then `openssl dgst` with pkcs11-provider | RSA and ECDSA |
|
|
17
|
+
| `kms: { keyVersion }` | the Google Cloud KMS API | RSA with SHA-256 (tested against a real KMS key) |
|
|
18
|
+
|
|
19
|
+
Non-software signatures are verified against the CA certificate before the certificate is returned. pkcs11js and @google-cloud/kms are optional dependencies, loaded only when needed.
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const { createSigner } = require('node-pki-signer');
|
|
23
|
+
|
|
24
|
+
const signer = createSigner({
|
|
25
|
+
// optional: the openssl binary for the fallback
|
|
26
|
+
binpath: '/usr/bin/openssl',
|
|
27
|
+
// optional: algorithms that always go to OpenSSL, or true for all of them
|
|
28
|
+
forceOpenSSL: ['ML-DSA-65'],
|
|
29
|
+
// optional: the backends that may sign natively; all by default
|
|
30
|
+
backends: ['software', 'openssl', 'pkcs11', 'openssl-pkcs11', 'kms'],
|
|
31
|
+
// every fallback with its reason; a console.warn by default
|
|
32
|
+
onFallback: (fallback) => log.logEvent(`${fallback.operation} fell back to OpenSSL: ${fallback.reason}`),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
signer.x509.CASignCSR({ csr, options, ca, key, password }, (err, crt) => {
|
|
36
|
+
// crt.data is the certificate; crt.signedBy is 'native' or 'openssl'
|
|
37
|
+
});
|
|
38
|
+
// or: const { data, serial, signedBy } = await signer.caSignCSR({ csr, options, ca, key, password });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
What falls back:
|
|
42
|
+
|
|
43
|
+
- **Not supported natively** (`UnsupportedError`): hashes and key types outside the allowlist, libkmsp11 keys without `kms.keyVersion`, a missing pkcs11js or @google-cloud/kms, a CA certificate the library can't re-encode exactly.
|
|
44
|
+
- **Forced** by `forceOpenSSL`.
|
|
45
|
+
- **Unexpected errors** in the native path, so a bug there doesn't stop issuance.
|
|
46
|
+
|
|
47
|
+
A refusal of the request itself (`SignerError`: wrong passphrase or PIN, a token or KMS key that isn't the CA's, a CSR whose signature doesn't verify, a subject OpenSSL would refuse) doesn't fall back, because OpenSSL refuses it too. Fallback reasons never contain keys, passphrases, PINs or CSRs. Requests that fall back get node-openssl-cert2's old subject and date behaviour (ADR 0002).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AlgorithmIdentifier } from '@peculiar/asn1-x509';
|
|
2
|
+
import type { KeyObject } from 'node:crypto';
|
|
3
|
+
/** The algorithm a key of this type signs with as `openssl ca -md <hash>` does, from its private or public key. */
|
|
4
|
+
export declare function signatureAlgorithm(key: KeyObject, hash: string): string;
|
|
5
|
+
/** The hash a signature algorithm signs a digest of, or null when it signs the message itself. */
|
|
6
|
+
export declare function signatureHash(name: string): string | null;
|
|
7
|
+
/** The AlgorithmIdentifier for a signature algorithm name, e.g. 'sha256WithRSAEncryption'. */
|
|
8
|
+
export declare function algorithmIdentifier(name: string): AlgorithmIdentifier;
|
|
9
|
+
/** The hash node:crypto needs to verify a signature with this algorithm OID (null: none). */
|
|
10
|
+
export declare function verifyHash(oid: string): string | null;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Signature algorithms: how a SigningKey's algorithm appears in a certificate, and how to verify
|
|
2
|
+
// a CSR's self-signature.
|
|
3
|
+
import { AlgorithmIdentifier } from '@peculiar/asn1-x509';
|
|
4
|
+
import { UnsupportedError } from "./errors.js";
|
|
5
|
+
const rsa = '1.2.840.113549.1.1';
|
|
6
|
+
const ecdsa = '1.2.840.10045.4';
|
|
7
|
+
const nistSigAlgs = '2.16.840.1.101.3.4.3';
|
|
8
|
+
// the hash, or null for algorithms that sign the message itself
|
|
9
|
+
const algorithms = {
|
|
10
|
+
sha1WithRSAEncryption: { oid: `${rsa}.5`, hash: 'sha1', nullParameters: true },
|
|
11
|
+
sha224WithRSAEncryption: { oid: `${rsa}.14`, hash: 'sha224', nullParameters: true },
|
|
12
|
+
sha256WithRSAEncryption: { oid: `${rsa}.11`, hash: 'sha256', nullParameters: true },
|
|
13
|
+
sha384WithRSAEncryption: { oid: `${rsa}.12`, hash: 'sha384', nullParameters: true },
|
|
14
|
+
sha512WithRSAEncryption: { oid: `${rsa}.13`, hash: 'sha512', nullParameters: true },
|
|
15
|
+
'ecdsa-with-SHA1': { oid: `${ecdsa}.1`, hash: 'sha1' },
|
|
16
|
+
'ecdsa-with-SHA224': { oid: `${ecdsa}.3.1`, hash: 'sha224' },
|
|
17
|
+
'ecdsa-with-SHA256': { oid: `${ecdsa}.3.2`, hash: 'sha256' },
|
|
18
|
+
'ecdsa-with-SHA384': { oid: `${ecdsa}.3.3`, hash: 'sha384' },
|
|
19
|
+
'ecdsa-with-SHA512': { oid: `${ecdsa}.3.4`, hash: 'sha512' },
|
|
20
|
+
Ed25519: { oid: '1.3.101.112', hash: null },
|
|
21
|
+
Ed448: { oid: '1.3.101.113', hash: null },
|
|
22
|
+
// FIPS 204 and 205, in the order of their OIDs
|
|
23
|
+
...Object.fromEntries([
|
|
24
|
+
'ML-DSA-44',
|
|
25
|
+
'ML-DSA-65',
|
|
26
|
+
'ML-DSA-87',
|
|
27
|
+
...['SHA2', 'SHAKE'].flatMap((hash) => ['128', '192', '256'].flatMap((bits) => ['s', 'f'].map((speed) => `SLH-DSA-${hash}-${bits}${speed}`))),
|
|
28
|
+
].map((name, i) => [name, { oid: `${nistSigAlgs}.${17 + i}`, hash: null }])),
|
|
29
|
+
};
|
|
30
|
+
// the hashes PKIaaS.io offers; 'default' is OpenSSL's default for the key type
|
|
31
|
+
const hashes = new Set(['sha1', 'sha256', 'sha384', 'sha512', 'default']);
|
|
32
|
+
/** The algorithm a key of this type signs with as `openssl ca -md <hash>` does, from its private or public key. */
|
|
33
|
+
export function signatureAlgorithm(key, hash) {
|
|
34
|
+
if (!hashes.has(hash))
|
|
35
|
+
throw new UnsupportedError('load CA key', `hash ${hash}`);
|
|
36
|
+
const digest = hash === 'default' ? 'sha256' : hash;
|
|
37
|
+
const type = key.asymmetricKeyType ?? '';
|
|
38
|
+
if (type === 'rsa')
|
|
39
|
+
return `${digest}WithRSAEncryption`;
|
|
40
|
+
if (type === 'ec')
|
|
41
|
+
return `ecdsa-with-${digest.toUpperCase()}`;
|
|
42
|
+
// ML-DSA and SLH-DSA sign the message itself, and OpenSSL ignores the hash
|
|
43
|
+
// e.g. slh-dsa-sha2-128s is SLH-DSA-SHA2-128s
|
|
44
|
+
if (/^(ml-dsa|slh-dsa)-/.test(type))
|
|
45
|
+
return type.toUpperCase().replace(/[SF]$/, (s) => s.toLowerCase());
|
|
46
|
+
throw new UnsupportedError('load CA key', `key type ${type || 'unknown'}`);
|
|
47
|
+
}
|
|
48
|
+
/** The hash a signature algorithm signs a digest of, or null when it signs the message itself. */
|
|
49
|
+
export function signatureHash(name) {
|
|
50
|
+
const algorithm = algorithms[name];
|
|
51
|
+
if (!algorithm)
|
|
52
|
+
throw new UnsupportedError('load CA key', `no signature algorithm ${name}`);
|
|
53
|
+
return algorithm.hash;
|
|
54
|
+
}
|
|
55
|
+
/** The AlgorithmIdentifier for a signature algorithm name, e.g. 'sha256WithRSAEncryption'. */
|
|
56
|
+
export function algorithmIdentifier(name) {
|
|
57
|
+
const algorithm = algorithms[name];
|
|
58
|
+
if (!algorithm)
|
|
59
|
+
throw new UnsupportedError('build TBS', `no signature algorithm ${name}`);
|
|
60
|
+
return new AlgorithmIdentifier({
|
|
61
|
+
algorithm: algorithm.oid,
|
|
62
|
+
...(algorithm.nullParameters ? { parameters: null } : {}),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** The hash node:crypto needs to verify a signature with this algorithm OID (null: none). */
|
|
66
|
+
export function verifyHash(oid) {
|
|
67
|
+
for (const algorithm of Object.values(algorithms)) {
|
|
68
|
+
if (algorithm.oid === oid)
|
|
69
|
+
return algorithm.hash;
|
|
70
|
+
}
|
|
71
|
+
throw new UnsupportedError('verify CSR signature', `no signature algorithm ${oid}`);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=algorithms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algorithms.js","sourceRoot":"","sources":["../src/algorithms.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,0BAA0B;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,GAAG,GAAG,oBAAoB,CAAC;AACjC,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAChC,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAE3C,gEAAgE;AAChE,MAAM,UAAU,GAAmF;IACjG,qBAAqB,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE;IAC9E,uBAAuB,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE;IACnF,uBAAuB,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc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AAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,gBAAgB,CAAC,aAAa,EAAE,0BAA0B,IAAI,EAAE,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,IAAI,CAAC;AACxB,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,EAAE,0BAA0B,IAAI,EAAE,CAAC,CAAC;IAC1F,OAAO,IAAI,mBAAmB,CAAC;QAC7B,SAAS,EAAE,SAAS,CAAC,GAAG;QACxB,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAClD,IAAI,SAAS,CAAC,GAAG,KAAK,GAAG;YAAE,OAAO,SAAS,CAAC,IAAI,CAAC;IACnD,CAAC;IACD,MAAM,IAAI,gBAAgB,CAAC,sBAAsB,EAAE,0BAA0B,GAAG,EAAE,CAAC,CAAC;AACtF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The algorithm × backend pairs the native path may sign with (ADR 0001): only those the
|
|
2
|
+
// differential harness has passed against OpenSSL. Everything else falls back to OpenSSL.
|
|
3
|
+
// every CA key type PKIaaS.io offers, with every hash (test/differential/differential.test.ts)
|
|
4
|
+
const everyCAKey = new Set([
|
|
5
|
+
'sha1WithRSAEncryption',
|
|
6
|
+
'sha256WithRSAEncryption',
|
|
7
|
+
'sha384WithRSAEncryption',
|
|
8
|
+
'sha512WithRSAEncryption',
|
|
9
|
+
'ecdsa-with-SHA1',
|
|
10
|
+
'ecdsa-with-SHA256',
|
|
11
|
+
'ecdsa-with-SHA384',
|
|
12
|
+
'ecdsa-with-SHA512',
|
|
13
|
+
'ML-DSA-44',
|
|
14
|
+
'ML-DSA-65',
|
|
15
|
+
'ML-DSA-87',
|
|
16
|
+
'SLH-DSA-SHA2-128s',
|
|
17
|
+
'SLH-DSA-SHA2-128f',
|
|
18
|
+
'SLH-DSA-SHA2-192s',
|
|
19
|
+
'SLH-DSA-SHA2-192f',
|
|
20
|
+
'SLH-DSA-SHA2-256s',
|
|
21
|
+
'SLH-DSA-SHA2-256f',
|
|
22
|
+
'SLH-DSA-SHAKE-128s',
|
|
23
|
+
'SLH-DSA-SHAKE-128f',
|
|
24
|
+
'SLH-DSA-SHAKE-192s',
|
|
25
|
+
'SLH-DSA-SHAKE-192f',
|
|
26
|
+
'SLH-DSA-SHAKE-256s',
|
|
27
|
+
'SLH-DSA-SHAKE-256f',
|
|
28
|
+
]);
|
|
29
|
+
// RSA and ECDSA, which SoftHSM signs (test/differential/backends.test.ts)
|
|
30
|
+
const classical = new Set([...everyCAKey].filter((a) => /RSA|ecdsa/.test(a)));
|
|
31
|
+
const allowlist = {
|
|
32
|
+
software: everyCAKey,
|
|
33
|
+
// the CA's PEM key, signed by `openssl dgst` (ADR 0003)
|
|
34
|
+
openssl: everyCAKey,
|
|
35
|
+
// keys on a token, through pkcs11js and through openssl with pkcs11-provider
|
|
36
|
+
pkcs11: classical,
|
|
37
|
+
'openssl-pkcs11': classical,
|
|
38
|
+
// Google Cloud KMS: what a test against the real service passed (test/live/kms.test.ts, ADR 0003)
|
|
39
|
+
kms: new Set(['sha256WithRSAEncryption']),
|
|
40
|
+
};
|
|
41
|
+
/** The signature algorithms allowlisted for a backend. */
|
|
42
|
+
export function allowlisted(backend) {
|
|
43
|
+
return allowlist[backend] ?? new Set();
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=allowlist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist.js","sourceRoot":"","sources":["../src/allowlist.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,0FAA0F;AAE1F,+FAA+F;AAC/F,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IAC9C,uBAAuB;IACvB,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,iBAAiB;IACjB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,WAAW;IACX,WAAW;IACX,WAAW;IACX,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;CACrB,CAAC,CAAC;AAEH,0EAA0E;AAC1E,MAAM,SAAS,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnG,MAAM,SAAS,GAAwC;IACrD,QAAQ,EAAE,UAAU;IACpB,wDAAwD;IACxD,OAAO,EAAE,UAAU;IACnB,6EAA6E;IAC7E,MAAM,EAAE,SAAS;IACjB,gBAAgB,EAAE,SAAS;IAC3B,kGAAkG;IAClG,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,yBAAyB,CAAC,CAAC;CAC1C,CAAC;AAEF,0DAA0D;AAC1D,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,SAAS,CAAC,OAAO,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SubjectKeyIdentifier, TBSCertificate, Validity } from '@peculiar/asn1-x509';
|
|
2
|
+
import { type KeyObject } from 'node:crypto';
|
|
3
|
+
import { type KeySettings } from './keys.ts';
|
|
4
|
+
import type { SignParams, SignResult } from './options.ts';
|
|
5
|
+
declare function parseCSR(pem: string): Promise<import("@peculiar/asn1-csr").CertificationRequestInfo>;
|
|
6
|
+
declare function parseIssuer(pem: string): {
|
|
7
|
+
subject: import("@peculiar/asn1-x509").Name;
|
|
8
|
+
keyIdentifier: SubjectKeyIdentifier;
|
|
9
|
+
publicKey: KeyObject;
|
|
10
|
+
};
|
|
11
|
+
export type NativeSettings = KeySettings;
|
|
12
|
+
type CSRInfo = Awaited<ReturnType<typeof parseCSR>>;
|
|
13
|
+
type Issuer = ReturnType<typeof parseIssuer>;
|
|
14
|
+
/** Parses and checks the CSR and the CA certificate. */
|
|
15
|
+
export declare function parseRequest(params: SignParams): Promise<{
|
|
16
|
+
info: CSRInfo;
|
|
17
|
+
issuer: Issuer;
|
|
18
|
+
}>;
|
|
19
|
+
/** The validity from the options: startdate to enddate, or `days` from now without a startdate. */
|
|
20
|
+
export declare function validity(options: SignParams['options']): Validity;
|
|
21
|
+
/** The TBS certificate `openssl ca` would build for this request, with the given serial and validity. */
|
|
22
|
+
export declare function buildTBS(params: SignParams, { info, issuer }: {
|
|
23
|
+
info: CSRInfo;
|
|
24
|
+
issuer: Issuer;
|
|
25
|
+
}, algorithm: string, serial: ArrayBuffer, dates: Validity): TBSCertificate;
|
|
26
|
+
/**
|
|
27
|
+
* Signs a CSR with a CA, taking the same parameters as node-openssl-cert2's x509.CASignCSR and
|
|
28
|
+
* returning its `data` and `serial`. Throws UnsupportedError for what must go to OpenSSL instead.
|
|
29
|
+
*/
|
|
30
|
+
export declare function caSignCSR(params: SignParams, settings?: NativeSettings): Promise<SignResult>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Signs a CSR natively: the same certificate `openssl ca` issues through node-openssl-cert2's
|
|
2
|
+
// x509.CASignCSR (ADR 0001), apart from the intended differences in ADR 0002.
|
|
3
|
+
import { CertificationRequest } from '@peculiar/asn1-csr';
|
|
4
|
+
import { AsnConvert, OctetString } from '@peculiar/asn1-schema';
|
|
5
|
+
import { AuthorityKeyIdentifier, Certificate, Extension, Extensions, KeyIdentifier, SubjectKeyIdentifier, TBSCertificate, Validity, Version, id_ce_authorityKeyIdentifier, id_ce_subjectKeyIdentifier, } from '@peculiar/asn1-x509';
|
|
6
|
+
import * as asn1js from 'asn1js';
|
|
7
|
+
import { X509Certificate, createHash, createPublicKey, randomBytes, verify } from 'node:crypto';
|
|
8
|
+
import { promisify } from 'node:util';
|
|
9
|
+
import { algorithmIdentifier, verifyHash } from "./algorithms.js";
|
|
10
|
+
import { SignerError, UnsupportedError } from "./errors.js";
|
|
11
|
+
import { buildExtensions } from "./extensions.js";
|
|
12
|
+
import { selectKey } from "./keys.js";
|
|
13
|
+
import { buildSubject } from "./subject.js";
|
|
14
|
+
const verifyAsync = promisify(verify);
|
|
15
|
+
const day = 24 * 60 * 60 * 1000;
|
|
16
|
+
function pemToDER(pem, label, step) {
|
|
17
|
+
const match = new RegExp(`-----BEGIN ${label}-----([^-]+)-----END ${label}-----`).exec(pem);
|
|
18
|
+
if (!match?.[1])
|
|
19
|
+
throw new SignerError(step, `no ${label} PEM`);
|
|
20
|
+
return new Uint8Array(Buffer.from(match[1], 'base64'));
|
|
21
|
+
}
|
|
22
|
+
function derToPEM(der, label) {
|
|
23
|
+
const lines = Buffer.from(der)
|
|
24
|
+
.toString('base64')
|
|
25
|
+
.match(/.{1,64}/g) ?? [];
|
|
26
|
+
return `-----BEGIN ${label}-----\n${lines.join('\n')}\n-----END ${label}-----\n`;
|
|
27
|
+
}
|
|
28
|
+
const asBytes = (a) => (a instanceof Uint8Array ? a : new Uint8Array(a));
|
|
29
|
+
const equal = (a, b) => Buffer.from(asBytes(a)).equals(asBytes(b));
|
|
30
|
+
async function parseCSR(pem) {
|
|
31
|
+
let csr;
|
|
32
|
+
try {
|
|
33
|
+
csr = AsnConvert.parse(pemToDER(pem, '(?:NEW )?CERTIFICATE REQUEST', 'parse CSR'), CertificationRequest);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err instanceof SignerError)
|
|
37
|
+
throw err;
|
|
38
|
+
throw new SignerError('parse CSR', 'not a certificate request');
|
|
39
|
+
}
|
|
40
|
+
const info = csr.certificationRequestInfo;
|
|
41
|
+
const raw = csr.certificationRequestInfoRaw;
|
|
42
|
+
if (!raw)
|
|
43
|
+
throw new SignerError('parse CSR', 'no certification request info');
|
|
44
|
+
// `openssl ca` refuses a request whose self-signature doesn't verify
|
|
45
|
+
const hash = verifyHash(csr.signatureAlgorithm.algorithm);
|
|
46
|
+
let verified;
|
|
47
|
+
try {
|
|
48
|
+
const publicKey = createPublicKey({
|
|
49
|
+
key: Buffer.from(AsnConvert.serialize(info.subjectPKInfo)),
|
|
50
|
+
format: 'der',
|
|
51
|
+
type: 'spki',
|
|
52
|
+
});
|
|
53
|
+
verified = await verifyAsync(hash, new Uint8Array(raw), publicKey, new Uint8Array(csr.signature));
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
throw new UnsupportedError('verify CSR signature', err instanceof Error ? err.message : String(err));
|
|
57
|
+
}
|
|
58
|
+
if (!verified)
|
|
59
|
+
throw new SignerError('verify CSR signature', 'the signature does not match the request');
|
|
60
|
+
return info;
|
|
61
|
+
}
|
|
62
|
+
// the issuer's subject, which must re-encode to its exact bytes, and its key identifier
|
|
63
|
+
function parseIssuer(pem) {
|
|
64
|
+
let x509;
|
|
65
|
+
let certificate;
|
|
66
|
+
try {
|
|
67
|
+
x509 = new X509Certificate(pem);
|
|
68
|
+
certificate = AsnConvert.parse(x509.raw, Certificate);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
throw new SignerError('parse CA certificate', 'not a certificate');
|
|
72
|
+
}
|
|
73
|
+
const tbs = certificate.tbsCertificate;
|
|
74
|
+
const children = (block) => (block?.valueBlock).value;
|
|
75
|
+
const tbsFields = children(children(asn1js.fromBER(new Uint8Array(x509.raw)).result)?.[0]);
|
|
76
|
+
// version [0], serialNumber, signature, issuer, validity, subject
|
|
77
|
+
const subjectRaw = tbsFields?.[tbsFields[0]?.idBlock.tagClass === 3 ? 5 : 4]?.valueBeforeDecodeView;
|
|
78
|
+
if (!subjectRaw || !equal(AsnConvert.serialize(tbs.subject), subjectRaw)) {
|
|
79
|
+
throw new UnsupportedError('parse CA certificate', "the CA's subject doesn't re-encode exactly");
|
|
80
|
+
}
|
|
81
|
+
const ski = tbs.extensions?.find((e) => e.extnID === id_ce_subjectKeyIdentifier);
|
|
82
|
+
// `authorityKeyIdentifier = keyid:always` needs the CA's own key identifier
|
|
83
|
+
if (!ski)
|
|
84
|
+
throw new UnsupportedError('parse CA certificate', 'the CA has no subject key identifier');
|
|
85
|
+
const keyIdentifier = AsnConvert.parse(ski.extnValue, SubjectKeyIdentifier);
|
|
86
|
+
return { subject: tbs.subject, keyIdentifier, publicKey: x509.publicKey };
|
|
87
|
+
}
|
|
88
|
+
function date(value, name) {
|
|
89
|
+
const parsed = value === undefined ? new Date() : new Date(value);
|
|
90
|
+
if (Number.isNaN(parsed.getTime()))
|
|
91
|
+
throw new SignerError('build TBS', `invalid ${name}`);
|
|
92
|
+
// OpenSSL takes whole seconds, always as UTC (ADR 0002)
|
|
93
|
+
return new Date(Math.floor(parsed.getTime() / 1000) * 1000);
|
|
94
|
+
}
|
|
95
|
+
/** A random positive serial of up to 159 bits, as `openssl ca -create_serial` draws it: DER content and hex. */
|
|
96
|
+
function randomSerial() {
|
|
97
|
+
for (;;) {
|
|
98
|
+
const bytes = randomBytes(20);
|
|
99
|
+
bytes[0] = (bytes[0] ?? 0) & 0x7f;
|
|
100
|
+
const start = bytes.findIndex((b) => b !== 0);
|
|
101
|
+
if (start < 0)
|
|
102
|
+
continue;
|
|
103
|
+
const magnitude = bytes.subarray(start);
|
|
104
|
+
const content = (magnitude[0] ?? 0) & 0x80 ? Buffer.concat([Buffer.from([0]), magnitude]) : magnitude;
|
|
105
|
+
return { content: new Uint8Array(content).buffer, hex: magnitude.toString('hex').toUpperCase() };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Signs a TBS certificate with `key` and returns the certificate DER. */
|
|
109
|
+
async function signTBS(tbs, key, issuerKey) {
|
|
110
|
+
const tbsDER = AsnConvert.serialize(tbs);
|
|
111
|
+
const signature = await key.sign(new Uint8Array(tbsDER));
|
|
112
|
+
// a token, KMS or openssl signs with a key we never see, so check it's the CA's (ADR 0003)
|
|
113
|
+
if (key.backend !== 'software') {
|
|
114
|
+
let verified;
|
|
115
|
+
try {
|
|
116
|
+
verified = await verifyAsync(verifyHash(tbs.signature.algorithm), new Uint8Array(tbsDER), issuerKey, signature);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
throw new SignerError('verify signature', err instanceof Error ? err.message : String(err));
|
|
120
|
+
}
|
|
121
|
+
if (!verified) {
|
|
122
|
+
throw new SignerError('verify signature', `the ${key.backend} key doesn't match the CA certificate`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return AsnConvert.serialize(new Certificate({
|
|
126
|
+
tbsCertificate: tbs,
|
|
127
|
+
signatureAlgorithm: tbs.signature,
|
|
128
|
+
signatureValue: new Uint8Array(signature).buffer,
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
/** Parses and checks the CSR and the CA certificate. */
|
|
132
|
+
export async function parseRequest(params) {
|
|
133
|
+
return { info: await parseCSR(params.csr), issuer: parseIssuer(params.ca) };
|
|
134
|
+
}
|
|
135
|
+
/** The validity from the options: startdate to enddate, or `days` from now without a startdate. */
|
|
136
|
+
export function validity(options) {
|
|
137
|
+
const startdate = options.startdate ? date(options.startdate, 'startdate') : date(undefined, 'startdate');
|
|
138
|
+
const enddate = options.startdate
|
|
139
|
+
? date(options.enddate, 'enddate')
|
|
140
|
+
: new Date(startdate.getTime() + (options.days ?? 365) * day);
|
|
141
|
+
return new Validity({ notBefore: startdate, notAfter: enddate });
|
|
142
|
+
}
|
|
143
|
+
/** The TBS certificate `openssl ca` would build for this request, with the given serial and validity. */
|
|
144
|
+
export function buildTBS(params, { info, issuer }, algorithm, serial, dates) {
|
|
145
|
+
const options = params.options;
|
|
146
|
+
const spki = info.subjectPKInfo;
|
|
147
|
+
const subjectKeyIdentifier = createHash('sha1').update(new Uint8Array(spki.subjectPublicKey)).digest();
|
|
148
|
+
const extensions = [
|
|
149
|
+
new Extension({
|
|
150
|
+
extnID: id_ce_subjectKeyIdentifier,
|
|
151
|
+
critical: false,
|
|
152
|
+
extnValue: new OctetString(AsnConvert.serialize(new SubjectKeyIdentifier(subjectKeyIdentifier))),
|
|
153
|
+
}),
|
|
154
|
+
new Extension({
|
|
155
|
+
extnID: id_ce_authorityKeyIdentifier,
|
|
156
|
+
critical: false,
|
|
157
|
+
extnValue: new OctetString(AsnConvert.serialize(new AuthorityKeyIdentifier({ keyIdentifier: new KeyIdentifier(issuer.keyIdentifier) }))),
|
|
158
|
+
}),
|
|
159
|
+
...buildExtensions(options.extensions),
|
|
160
|
+
];
|
|
161
|
+
try {
|
|
162
|
+
return new TBSCertificate({
|
|
163
|
+
version: Version.v3,
|
|
164
|
+
serialNumber: serial,
|
|
165
|
+
signature: algorithmIdentifier(algorithm),
|
|
166
|
+
issuer: issuer.subject,
|
|
167
|
+
validity: dates,
|
|
168
|
+
// the subject is forced from the options when they have one (`-subj`); the CSR's extensions are never copied
|
|
169
|
+
subject: Object.hasOwn(options, 'subject') ? buildSubject(options.subject) : info.subject,
|
|
170
|
+
subjectPublicKeyInfo: spki,
|
|
171
|
+
extensions: new Extensions(extensions),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
if (err instanceof SignerError)
|
|
176
|
+
throw err;
|
|
177
|
+
throw new SignerError('build TBS', err instanceof Error ? err.message : String(err));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Signs a CSR with a CA, taking the same parameters as node-openssl-cert2's x509.CASignCSR and
|
|
182
|
+
* returning its `data` and `serial`. Throws UnsupportedError for what must go to OpenSSL instead.
|
|
183
|
+
*/
|
|
184
|
+
export async function caSignCSR(params, settings = {}) {
|
|
185
|
+
const request = await parseRequest(params);
|
|
186
|
+
const { issuer } = request;
|
|
187
|
+
const key = await selectKey(params, issuer.publicKey, settings);
|
|
188
|
+
const caPublicKey = issuer.publicKey.export({ type: 'spki', format: 'der' });
|
|
189
|
+
if (!equal(await key.publicKey(), caPublicKey)) {
|
|
190
|
+
throw new SignerError('load CA key', "the CA certificate and private key don't match");
|
|
191
|
+
}
|
|
192
|
+
const dates = validity(params.options);
|
|
193
|
+
const serial = randomSerial();
|
|
194
|
+
const tbs = buildTBS(params, request, key.algorithm, serial.content, dates);
|
|
195
|
+
return { data: derToPEM(await signTBS(tbs, key, issuer.publicKey), 'CERTIFICATE'), serial: serial.hex };
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=ca-sign-csr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ca-sign-csr.js","sourceRoot":"","sources":["../src/ca-sign-csr.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,8EAA8E;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,QAAQ,EACR,OAAO,EACP,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAkB,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CA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AG,YAAY,EAAE,CAAC;IAC9B,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5E,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;AAC1G,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** A signing failure, naming the step that failed so callers can log it to the CA's log. */
|
|
2
|
+
export declare class SignerError extends Error {
|
|
3
|
+
readonly step: string;
|
|
4
|
+
constructor(step: string, message: string, options?: ErrorOptions);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The native path can't build or sign this request yet (ADR 0001), so it must go to OpenSSL.
|
|
8
|
+
* Not a refusal of the request itself: the OpenSSL fallback may well sign it.
|
|
9
|
+
*/
|
|
10
|
+
export declare class UnsupportedError extends SignerError {
|
|
11
|
+
constructor(step: string, message: string);
|
|
12
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A signing failure, naming the step that failed so callers can log it to the CA's log. */
|
|
2
|
+
export class SignerError extends Error {
|
|
3
|
+
step;
|
|
4
|
+
constructor(step, message, options) {
|
|
5
|
+
super(`${step}: ${message}`, options);
|
|
6
|
+
this.name = 'SignerError';
|
|
7
|
+
this.step = step;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The native path can't build or sign this request yet (ADR 0001), so it must go to OpenSSL.
|
|
12
|
+
* Not a refusal of the request itself: the OpenSSL fallback may well sign it.
|
|
13
|
+
*/
|
|
14
|
+
export class UnsupportedError extends SignerError {
|
|
15
|
+
constructor(step, message) {
|
|
16
|
+
super(step, message);
|
|
17
|
+
this.name = 'UnsupportedError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,OAAe,EAAE,OAAsB;QAC/D,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAC/C,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|