Skip to content

Commit a44ae0e

Browse files
committed
fixup! crypto: add X.509 generation with CSR support
1 parent e1037ac commit a44ae0e

3 files changed

Lines changed: 16 additions & 36 deletions

File tree

‎deps/ncrypto/ncrypto.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,6 @@ class X509View final {
16911691
enum class CheckKeyResult {
16921692
MATCH, // The requested comparison passed.
16931693
NO_MATCH, // It completed and produced an ordinary mismatch.
1694-
INVALID_CERTIFICATE, // Reserved for certificate verification.
16951694
UNSUPPORTED_OPERATION, // The backend cannot compare these keys.
16961695
OPERATION_FAILED, // The backend failed for another reason.
16971696
};

‎lib/internal/crypto/x509_generation.js‎

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const {
1717
SafeSet,
1818
StringPrototypeCharCodeAt,
1919
StringPrototypeIncludes,
20+
StringPrototypeIsWellFormed,
2021
StringPrototypeSlice,
2122
Uint8Array,
2223
} = primordials;
@@ -145,12 +146,11 @@ function getRequired(object, property, name) {
145146
return value;
146147
}
147148

148-
function snapshotBinary(value, name) {
149+
function snapshotBinary(value, name, expectedTypes = [
150+
'ArrayBuffer', 'SharedArrayBuffer', 'Buffer', 'TypedArray', 'DataView',
151+
]) {
149152
if (!isAnyArrayBuffer(value) && !isArrayBufferView(value)) {
150-
throw new ERR_INVALID_ARG_TYPE(
151-
name,
152-
['ArrayBuffer', 'SharedArrayBuffer', 'Buffer', 'TypedArray', 'DataView'],
153-
value);
153+
throw new ERR_INVALID_ARG_TYPE(name, expectedTypes, value);
154154
}
155155
const view = isAnyArrayBuffer(value) ?
156156
new Uint8Array(value) :
@@ -160,39 +160,21 @@ function snapshotBinary(value, name) {
160160

161161
function snapshotCertificateRequest(value) {
162162
if (typeof value === 'string') return Buffer.from(value);
163-
if (!isAnyArrayBuffer(value) && !isArrayBufferView(value)) {
164-
throw new ERR_INVALID_ARG_TYPE(
165-
'options.csr',
166-
[
167-
'string',
168-
'ArrayBuffer',
169-
'SharedArrayBuffer',
170-
'Buffer',
171-
'TypedArray',
172-
'DataView',
173-
],
174-
value);
175-
}
176-
const view = isAnyArrayBuffer(value) ?
177-
new Uint8Array(value) :
178-
new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
179-
return Buffer.from(view);
163+
return snapshotBinary(value, 'options.csr', [
164+
'string',
165+
'ArrayBuffer',
166+
'SharedArrayBuffer',
167+
'Buffer',
168+
'TypedArray',
169+
'DataView',
170+
]);
180171
}
181172

182173
function validateUnicode(value, name) {
183174
validateString(value, name);
184-
for (let i = 0; i < value.length; i++) {
185-
const first = StringPrototypeCharCodeAt(value, i);
186-
if (first >= 0xd800 && first <= 0xdbff) {
187-
const second = StringPrototypeCharCodeAt(value, ++i);
188-
if (!(second >= 0xdc00 && second <= 0xdfff)) {
189-
throw new ERR_INVALID_ARG_VALUE(
190-
name, value, 'contains an unpaired surrogate');
191-
}
192-
} else if (first >= 0xdc00 && first <= 0xdfff) {
193-
throw new ERR_INVALID_ARG_VALUE(
194-
name, value, 'contains an unpaired surrogate');
195-
}
175+
if (!StringPrototypeIsWellFormed(value)) {
176+
throw new ERR_INVALID_ARG_VALUE(
177+
name, value, 'contains an unpaired surrogate');
196178
}
197179
}
198180

‎src/crypto/crypto_x509_gen.cc‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,6 @@ Maybe<void> X509GenerateTraits::AdditionalConfig(
10091009
return Nothing<void>();
10101010
case ncrypto::X509View::CheckKeyResult::UNSUPPORTED_OPERATION:
10111011
break;
1012-
case ncrypto::X509View::CheckKeyResult::INVALID_CERTIFICATE:
10131012
case ncrypto::X509View::CheckKeyResult::OPERATION_FAILED:
10141013
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Failed to compare public keys");
10151014
return Nothing<void>();

0 commit comments

Comments
 (0)