crypto: make X509 AKI & SKI generation consistently reject empty input

Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67781
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Tim Perry authored and Node.js GitHub Bot committed 2026-11-27 23:17:32 +00:00
1 parent f966e9f015
commit 4afd7d61ef
4 files changed
+21 -8

No files matched your search

+6 -5
View File
@@ -5418,13 +5418,14 @@ const extensions = [
ASCII strings without NUL and are not otherwise validated.
* Subject Key Identifier: `type: 'subjectKeyIdentifier'` and `value: 'auto'` or
`value` {ArrayBuffer|TypedArray|Buffer|DataView}. A binary value contains the
key identifier bytes, not DER. `'auto'` uses [RFC 7093][] method 1: the
leftmost 160 bits of the SHA-256 digest of the `subjectPublicKey` BIT STRING
contents. This typed form is always noncritical.
nonempty key identifier bytes, not DER. `'auto'` uses [RFC 7093][] method 1:
the leftmost 160 bits of the SHA-256 digest of the `subjectPublicKey` BIT
STRING contents. This typed form is always noncritical.
* Authority Key Identifier: `type: 'authorityKeyIdentifier'` and
`value: 'auto'` or `value`
{ArrayBuffer|TypedArray|Buffer|DataView}. A binary value contains the key
identifier bytes and populates only the extension's `keyIdentifier` field.
{ArrayBuffer|TypedArray|Buffer|DataView}. A binary value contains the
nonempty key identifier bytes and populates only the extension's
`keyIdentifier` field.
When `options.issuer` is supplied, `'auto'` asks the configured crypto backend
to decode and copy its Subject Key Identifier. If the extension is absent,
the identifier is instead derived from the issuer public key using
+7 -1
View File
@@ -434,12 +434,18 @@ function normalizeExtensions(extensions, arrayPath = 'options.extensions') {
case 'subjectKeyIdentifier':
case 'authorityKeyIdentifier': {
const value = getRequired(extension, 'value', `${path}.value`);
const identifier =
value === 'auto' ? undefined : snapshotBinary(value, `${path}.value`);
if (identifier?.length === 0) {
throw new ERR_INVALID_ARG_VALUE(
`${path}.value`, value, 'must not be empty');
}
normalized = [
type === 'subjectKeyIdentifier' ?
kExtensionSubjectKeyIdentifier :
kExtensionAuthorityKeyIdentifier,
false,
value === 'auto' ? undefined : snapshotBinary(value, `${path}.value`),
identifier,
];
break;
}
+2 -2
View File
@@ -440,11 +440,11 @@ bool ReadKeyIdentifierSpec(Environment* env,
if (!IsAnyBufferSource(identifier_value)) return false;
ArrayBufferOrViewContents<unsigned char> contents(identifier_value);
if (!contents.CheckSizeInt32()) return false;
if (!contents.CheckSizeInt32() || contents.size() == 0) return false;
identifier->reset(ASN1_OCTET_STRING_new());
return *identifier &&
ASN1_OCTET_STRING_set(identifier->get(),
contents.size() == 0 ? nullptr : contents.data(),
contents.data(),
static_cast<int>(contents.size())) == 1;
}
@@ -618,6 +618,12 @@ const invalidOptions = [
['ERR_INVALID_ARG_VALUE', baseOptions(leafKeys, {
subject: [{ name: 'CN', value: 'example.com\0.example' }],
})],
['ERR_INVALID_ARG_VALUE', baseOptions(leafKeys, {
extensions: [{ type: 'subjectKeyIdentifier', value: Buffer.alloc(0) }],
})],
['ERR_INVALID_ARG_VALUE', baseOptions(leafKeys, {
extensions: [{ type: 'authorityKeyIdentifier', value: Buffer.alloc(0) }],
})],
['ERR_INVALID_ARG_VALUE', baseOptions(leafKeys, {
subject: [
{ name: 'CN', value: 'example.com' },