node-pki-signer 0.1.0 → 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/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/shadow.d.ts +12 -1
- package/dist/shadow.js +15 -3
- package/dist/shadow.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { createKmsClient, kmsKey, type KmsClient } from './kms-key.ts';
|
|
|
5
5
|
export { opensslKey, type OpenSSLKeySource } from './openssl-key.ts';
|
|
6
6
|
export type { Pkcs11KeyRef, SignOptions, SignParams, SignResult } from './options.ts';
|
|
7
7
|
export { Pkcs11Sessions } from './pkcs11-key.ts';
|
|
8
|
-
export { shadowCASignCSR, type ShadowResult } from './shadow.ts';
|
|
8
|
+
export { shadowCASignCSR, type IssuedSignature, type ShadowResult } from './shadow.ts';
|
|
9
9
|
export { createSigner, type CASignCSRResult, type Fallback, type SignedBy, type Signer, type SignerSettings, } from './signer.ts';
|
|
10
10
|
export type { SigningKey } from './signing-key.ts';
|
|
11
11
|
export { softwareKey } from './software-key.ts';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAuB,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,EAAkB,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,UAAU,EAAyB,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAuB,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,EAAkB,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,UAAU,EAAyB,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,eAAe,EAA2C,MAAM,aAAa,CAAC;AACvF,OAAO,EACL,YAAY,GAMb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/shadow.d.ts
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
import type { SignParams } from './options.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Whether the issued certificate's signature verifies with the CA certificate's public key;
|
|
4
|
+
* `unchecked` when either certificate can't be parsed or the key type can't verify.
|
|
5
|
+
*/
|
|
6
|
+
export type IssuedSignature = 'valid' | 'invalid' | 'unchecked';
|
|
2
7
|
/**
|
|
3
8
|
* What the native signer would have done: `match` built the same TBS byte for byte, `differ` lists
|
|
4
9
|
* the TBS fields that differ (names only, never values), `unsupported` would have gone to OpenSSL and
|
|
5
10
|
* `refused` would have refused the request. `algorithm` is the CA's signature algorithm, when known.
|
|
11
|
+
* `tbs` is the TBS the native signer built (DER), to keep for reproducing a difference. `signature`
|
|
12
|
+
* checks the issued certificate itself, whatever the outcome.
|
|
6
13
|
*/
|
|
7
14
|
export type ShadowResult = {
|
|
15
|
+
signature: IssuedSignature;
|
|
16
|
+
} & ({
|
|
8
17
|
outcome: 'match';
|
|
9
18
|
algorithm: string;
|
|
19
|
+
tbs: Uint8Array;
|
|
10
20
|
} | {
|
|
11
21
|
outcome: 'differ';
|
|
12
22
|
algorithm: string;
|
|
13
23
|
fields: string[];
|
|
24
|
+
tbs: Uint8Array;
|
|
14
25
|
} | {
|
|
15
26
|
outcome: 'unsupported' | 'refused';
|
|
16
27
|
algorithm?: string;
|
|
17
28
|
step: string;
|
|
18
29
|
reason: string;
|
|
19
|
-
};
|
|
30
|
+
});
|
|
20
31
|
/**
|
|
21
32
|
* Compares `certificate` (PEM), issued for `params`, with the TBS the native signer builds for
|
|
22
33
|
* `params` using the certificate's serial number, and its validity when the options give no
|
package/dist/shadow.js
CHANGED
|
@@ -8,12 +8,21 @@ import { buildTBS, parseRequest, validity } from "./ca-sign-csr.js";
|
|
|
8
8
|
import { SignerError, UnsupportedError } from "./errors.js";
|
|
9
9
|
import { children, decode, tbsFields } from "./tbs-fields.js";
|
|
10
10
|
const message = (err) => (err instanceof Error ? err.message : String(err));
|
|
11
|
+
function issuedSignature(certificate, ca) {
|
|
12
|
+
try {
|
|
13
|
+
return new X509Certificate(certificate).verify(new X509Certificate(ca).publicKey) ? 'valid' : 'invalid';
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return 'unchecked';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
11
19
|
/**
|
|
12
20
|
* Compares `certificate` (PEM), issued for `params`, with the TBS the native signer builds for
|
|
13
21
|
* `params` using the certificate's serial number, and its validity when the options give no
|
|
14
22
|
* startdate. Needs no private key: `params.key`, `pkcs11` and `kms` are ignored.
|
|
15
23
|
*/
|
|
16
24
|
export async function shadowCASignCSR(params, certificate) {
|
|
25
|
+
const signature = issuedSignature(certificate, params.ca);
|
|
17
26
|
let algorithm;
|
|
18
27
|
try {
|
|
19
28
|
let issued;
|
|
@@ -31,15 +40,18 @@ export async function shadowCASignCSR(params, certificate) {
|
|
|
31
40
|
algorithm = signatureAlgorithm(request.issuer.publicKey, params.options.hash ?? 'sha256');
|
|
32
41
|
const dates = params.options.startdate ? validity(params.options) : issued.certificate.tbsCertificate.validity;
|
|
33
42
|
const tbs = buildTBS({ ...params, key: '' }, request, algorithm, new Uint8Array(issued.tbs.serial).buffer, dates);
|
|
34
|
-
const
|
|
43
|
+
const der = new Uint8Array(AsnConvert.serialize(tbs));
|
|
44
|
+
const native = tbsFields(decode(der)).fields;
|
|
35
45
|
const fields = [...new Set([...native.keys(), ...issued.tbs.fields.keys()])].filter((field) => native.get(field) !== issued.tbs.fields.get(field));
|
|
36
|
-
return fields.length
|
|
46
|
+
return fields.length
|
|
47
|
+
? { signature, outcome: 'differ', algorithm, fields, tbs: der }
|
|
48
|
+
: { signature, outcome: 'match', algorithm, tbs: der };
|
|
37
49
|
}
|
|
38
50
|
catch (err) {
|
|
39
51
|
const step = err instanceof SignerError ? err.step : 'native signer';
|
|
40
52
|
const reason = err instanceof SignerError ? err.message : `native signer: unexpected error: ${message(err)}`;
|
|
41
53
|
const outcome = err instanceof UnsupportedError || !(err instanceof SignerError) ? 'unsupported' : 'refused';
|
|
42
|
-
return { outcome, ...(algorithm ? { algorithm } : {}), step, reason };
|
|
54
|
+
return { signature, outcome, ...(algorithm ? { algorithm } : {}), step, reason };
|
|
43
55
|
}
|
|
44
56
|
}
|
|
45
57
|
//# sourceMappingURL=shadow.js.map
|
package/dist/shadow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadow.js","sourceRoot":"","sources":["../src/shadow.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,gGAAgG;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5D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