Skip to content

Commit 0cb66d0

Browse files
committed
src,crypto: relax RSA/EC keygen arg checks
Loosens two `AdditionalConfig` precondition checks so the new Web Crypto keygen jobs added earlier (RsaKeyPairGenJob, EcKeyPairGenJob) can reuse the shared traits without threading unused encoding args through the job constructor. - `RsaKeyGenTraits::AdditionalConfig` now CHECKs RSA key type-dependant argument count accounting for being able to skip unused parameters. - `EcKeyGenTraits::AdditionalConfig` now defaults `param_encoding` to `OPENSSL_EC_NAMED_CURVE`, this is not observable in existing crypto.generateKeyPair(Sync) as its dispatch already applies the same default. This is just so that a stray OPENSSL_EC_NAMED_CURVE isn't needed in ec.js Pure precondition relaxation — no new code paths. Existing `generateKeyPair` callers still pass the same args and hit the same branches. Signed-off-by: Filip Skokan <[email protected]>
1 parent 02c2456 commit 0cb66d0

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/crypto/crypto_ec.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ Maybe<void> EcKeyGenTraits::AdditionalConfig(
436436
EcKeyPairGenConfig* params) {
437437
Environment* env = Environment::GetCurrent(args);
438438
CHECK(args[*offset]->IsString()); // curve name
439-
CHECK(args[*offset + 1]->IsInt32()); // param encoding
440439

441440
Utf8Value curve_name(env->isolate(), args[*offset]);
442441
params->params.curve_nid = Ec::GetCurveIdFromName(*curve_name);
@@ -445,11 +444,17 @@ Maybe<void> EcKeyGenTraits::AdditionalConfig(
445444
return Nothing<void>();
446445
}
447446

448-
params->params.param_encoding = args[*offset + 1].As<Int32>()->Value();
449-
if (params->params.param_encoding != OPENSSL_EC_NAMED_CURVE &&
450-
params->params.param_encoding != OPENSSL_EC_EXPLICIT_CURVE) {
451-
THROW_ERR_OUT_OF_RANGE(env, "Invalid param_encoding specified");
452-
return Nothing<void>();
447+
// param encoding
448+
if (args[*offset + 1]->IsNullOrUndefined()) {
449+
params->params.param_encoding = OPENSSL_EC_NAMED_CURVE;
450+
} else {
451+
CHECK(args[*offset + 1]->IsInt32());
452+
params->params.param_encoding = args[*offset + 1].As<Int32>()->Value();
453+
if (params->params.param_encoding != OPENSSL_EC_NAMED_CURVE &&
454+
params->params.param_encoding != OPENSSL_EC_EXPLICIT_CURVE) {
455+
THROW_ERR_OUT_OF_RANGE(env, "Invalid param_encoding specified");
456+
return Nothing<void>();
457+
}
453458
}
454459

455460
*offset += 2;

src/crypto/crypto_rsa.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ Maybe<void> RsaKeyGenTraits::AdditionalConfig(
128128
static_cast<RSAKeyVariant>(args[*offset].As<Uint32>()->Value());
129129

130130
CHECK_IMPLIES(params->params.variant != kKeyVariantRSA_PSS,
131-
args.Length() == 10);
131+
static_cast<unsigned int>(args.Length()) >= *offset + 3);
132132
CHECK_IMPLIES(params->params.variant == kKeyVariantRSA_PSS,
133-
args.Length() == 13);
133+
static_cast<unsigned int>(args.Length()) >= *offset + 6);
134134

135135
params->params.modulus_bits = args[*offset + 1].As<Uint32>()->Value();
136136
params->params.exponent = args[*offset + 2].As<Uint32>()->Value();

0 commit comments

Comments
 (0)