| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,10 +96,13 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> { | |||
| 96 | 96 | Environment* env = AsyncWrap::env(); | |
| 97 | 97 | CryptoErrorStore* errors = CryptoJob<KeyGenTraits>::errors(); | |
| 98 | 98 | AdditionalParams* params = CryptoJob<KeyGenTraits>::params(); | |
| 99 | - if (status_ == KeyGenJobStatus::OK && | ||
| 100 | - LIKELY(!KeyGenTraits::EncodeKey(env, params, result).IsNothing())) { | ||
| 101 | - *err = Undefined(env->isolate()); | ||
| 102 | - return v8::Just(true); | ||
| 99 | + | ||
| 100 | + if (status_ == KeyGenJobStatus::OK) { | ||
| 101 | + v8::Maybe<bool> ret = KeyGenTraits::EncodeKey(env, params, result); | ||
| 102 | + if (ret.IsJust() && ret.FromJust()) { | ||
| 103 | + *err = Undefined(env->isolate()); | ||
| 104 | + } | ||
| 105 | + return ret; | ||
| 103 | 106 | } | |
| 104 | 107 | ||
| 105 | 108 | if (errors->Empty()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -602,6 +602,11 @@ size_t ManagedEVPPKey::size_of_public_key() const { | |||
| 602 | 602 | pkey_.get(), nullptr, &len) == 1) ? len : 0; | |
| 603 | 603 | } | |
| 604 | 604 | ||
| 605 | + // This maps true to Just<bool>(true) and false to Nothing<bool>(). | ||
| 606 | + static inline Maybe<bool> Tristate(bool b) { | ||
| 607 | + return b ? Just(true) : Nothing<bool>(); | ||
| 608 | + } | ||
| 609 | + | ||
| 605 | 610 | Maybe<bool> ManagedEVPPKey::ToEncodedPublicKey( | |
| 606 | 611 | Environment* env, | |
| 607 | 612 | ManagedEVPPKey key, | |
@@ -613,9 +618,10 @@ Maybe<bool> ManagedEVPPKey::ToEncodedPublicKey( | |||
| 613 | 618 | // private key. | |
| 614 | 619 | std::shared_ptr<KeyObjectData> data = | |
| 615 | 620 | KeyObjectData::CreateAsymmetric(kKeyTypePublic, std::move(key)); | |
| 616 | - return Just(KeyObjectHandle::Create(env, data).ToLocal(out)); | ||
| 621 | + return Tristate(KeyObjectHandle::Create(env, data).ToLocal(out)); | ||
| 617 | 622 | } | |
| 618 | - return Just(WritePublicKey(env, key.get(), config).ToLocal(out)); | ||
| 623 | + | ||
| 624 | + return Tristate(WritePublicKey(env, key.get(), config).ToLocal(out)); | ||
| 619 | 625 | } | |
| 620 | 626 | ||
| 621 | 627 | Maybe<bool> ManagedEVPPKey::ToEncodedPrivateKey( | |
@@ -627,10 +633,10 @@ Maybe<bool> ManagedEVPPKey::ToEncodedPrivateKey( | |||
| 627 | 633 | if (config.output_key_object_) { | |
| 628 | 634 | std::shared_ptr<KeyObjectData> data = | |
| 629 | 635 | KeyObjectData::CreateAsymmetric(kKeyTypePrivate, std::move(key)); | |
| 630 | - return Just(KeyObjectHandle::Create(env, data).ToLocal(out)); | ||
| 636 | + return Tristate(KeyObjectHandle::Create(env, data).ToLocal(out)); | ||
| 631 | 637 | } | |
| 632 | 638 | ||
| 633 | - return Just(WritePrivateKey(env, key.get(), config).ToLocal(out)); | ||
| 639 | + return Tristate(WritePrivateKey(env, key.get(), config).ToLocal(out)); | ||
| 634 | 640 | } | |
| 635 | 641 | ||
| 636 | 642 | NonCopyableMaybe<PrivateKeyEncodingConfig> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -349,9 +349,27 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork { | |||
| 349 | 349 | if (status == UV_ECANCELED) return; | |
| 350 | 350 | v8::HandleScope handle_scope(env->isolate()); | |
| 351 | 351 | v8::Context::Scope context_scope(env->context()); | |
| 352 | + | ||
| 353 | + // TODO(tniessen): Remove the exception handling logic here as soon as we | ||
| 354 | + // can verify that no code path in ToResult will ever throw an exception. | ||
| 355 | + v8::Local<v8::Value> exception; | ||
| 352 | 356 | v8::Local<v8::Value> args[2]; | |
| 353 | - if (ptr->ToResult(&args[0], &args[1]).FromJust()) | ||
| 357 | + { | ||
| 358 | + node::errors::TryCatchScope try_catch(env); | ||
| 359 | + v8::Maybe<bool> ret = ptr->ToResult(&args[0], &args[1]); | ||
| 360 | + if (!ret.IsJust()) { | ||
| 361 | + CHECK(try_catch.HasCaught()); | ||
| 362 | + exception = try_catch.Exception(); | ||
| 363 | + } else if (!ret.FromJust()) { | ||
| 364 | + return; | ||
| 365 | + } | ||
| 366 | + } | ||
| 367 | + | ||
| 368 | + if (exception.IsEmpty()) { | ||
| 354 | 369 | ptr->MakeCallback(env->ondone_string(), arraysize(args), args); | |
| 370 | + } else { | ||
| 371 | + ptr->MakeCallback(env->ondone_string(), 1, &exception); | ||
| 372 | + } | ||
| 355 | 373 | } | |
| 356 | 374 | ||
| 357 | 375 | virtual v8::Maybe<bool> ToResult( | |
@@ -384,7 +402,8 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork { | |||
| 384 | 402 | v8::Local<v8::Value> ret[2]; | |
| 385 | 403 | env->PrintSyncTrace(); | |
| 386 | 404 | job->DoThreadPoolWork(); | |
| 387 | - if (job->ToResult(&ret[0], &ret[1]).FromJust()) { | ||
| 405 | + v8::Maybe<bool> result = job->ToResult(&ret[0], &ret[1]); | ||
| 406 | + if (result.IsJust() && result.FromJust()) { | ||
| 388 | 407 | args.GetReturnValue().Set( | |
| 389 | 408 | v8::Array::New(env->isolate(), ret, arraysize(ret))); | |
| 390 | 409 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ const { | |||
| 12 | 12 | createVerify, | |
| 13 | 13 | generateKeyPair, | |
| 14 | 14 | generateKeyPairSync, | |
| 15 | + getCurves, | ||
| 15 | 16 | publicEncrypt, | |
| 16 | 17 | privateDecrypt, | |
| 17 | 18 | sign, | |
@@ -1314,3 +1315,33 @@ if (!common.hasOpenSSL3) { | |||
| 1314 | 1315 | ); | |
| 1315 | 1316 | } | |
| 1316 | 1317 | } | |
| 1318 | + | ||
| 1319 | + { | ||
| 1320 | + // This test creates EC key pairs on curves without associated OIDs. | ||
| 1321 | + // Specifying a key encoding should not crash. | ||
| 1322 | + | ||
| 1323 | + if (process.versions.openssl >= '1.1.1i') { | ||
| 1324 | + for (const namedCurve of ['Oakley-EC2N-3', 'Oakley-EC2N-4']) { | ||
| 1325 | + if (!getCurves().includes(namedCurve)) | ||
| 1326 | + continue; | ||
| 1327 | + | ||
| 1328 | + const params = { | ||
| 1329 | + namedCurve, | ||
| 1330 | + publicKeyEncoding: { | ||
| 1331 | + format: 'der', | ||
| 1332 | + type: 'spki' | ||
| 1333 | + } | ||
| 1334 | + }; | ||
| 1335 | + | ||
| 1336 | + assert.throws(() => { | ||
| 1337 | + generateKeyPairSync('ec', params); | ||
| 1338 | + }, { | ||
| 1339 | + code: 'ERR_OSSL_EC_MISSING_OID' | ||
| 1340 | + }); | ||
| 1341 | + | ||
| 1342 | + generateKeyPair('ec', params, common.mustCall((err) => { | ||
| 1343 | + assert.strictEqual(err.code, 'ERR_OSSL_EC_MISSING_OID'); | ||
| 1344 | + })); | ||
| 1345 | + } | ||
| 1346 | + } | ||
| 1347 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments