| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bd62771 commit 30c62de
47 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -361,7 +361,11 @@ | |||
| 361 | 361 | ], | |
| 362 | 362 | }], | |
| 363 | 363 | ], | |
| 364 | - }]] | ||
| 364 | + }, { | ||
| 365 | + # Set 1.0.0 as the API compability level to avoid the | ||
| 366 | + # deprecation warnings when using OpenSSL 3.0. | ||
| 367 | + 'defines': ['OPENSSL_API_COMPAT=0x10000000L'], | ||
| 368 | + }]] | ||
| 365 | 369 | ||
| 366 | 370 | }, { | |
| 367 | 371 | 'defines': [ 'HAVE_OPENSSL=0' ] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -342,8 +342,11 @@ void CipherBase::Init(const char* cipher_type, | |||
| 342 | 342 | unsigned int auth_tag_len) { | |
| 343 | 343 | HandleScope scope(env()->isolate()); | |
| 344 | 344 | MarkPopErrorOnReturn mark_pop_error_on_return; | |
| 345 | - | ||
| 345 | + #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 346 | + if (EVP_default_properties_is_fips_enabled(nullptr)) { | ||
| 347 | + #else | ||
| 346 | 348 | if (FIPS_mode()) { | |
| 349 | + #endif | ||
| 347 | 350 | return THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env(), | |
| 348 | 351 | "crypto.createCipher() is not supported in FIPS mode."); | |
| 349 | 352 | } | |
@@ -527,7 +530,13 @@ bool CipherBase::InitAuthenticated( | |||
| 527 | 530 | } | |
| 528 | 531 | ||
| 529 | 532 | // TODO(tniessen) Support CCM decryption in FIPS mode | |
| 533 | + | ||
| 534 | + #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 535 | + if (mode == EVP_CIPH_CCM_MODE && kind_ == kDecipher && | ||
| 536 | + EVP_default_properties_is_fips_enabled(nullptr)) { | ||
| 537 | + #else | ||
| 530 | 538 | if (mode == EVP_CIPH_CCM_MODE && kind_ == kDecipher && FIPS_mode()) { | |
| 539 | + #endif | ||
| 531 | 540 | THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env(), | |
| 532 | 541 | "CCM encryption not supported in FIPS mode"); | |
| 533 | 542 | return false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -138,7 +138,7 @@ Maybe<bool> GetDsaKeyDetail( | |||
| 138 | 138 | int type = EVP_PKEY_id(m_pkey.get()); | |
| 139 | 139 | CHECK(type == EVP_PKEY_DSA); | |
| 140 | 140 | ||
| 141 | - DSA* dsa = EVP_PKEY_get0_DSA(m_pkey.get()); | ||
| 141 | + const DSA* dsa = EVP_PKEY_get0_DSA(m_pkey.get()); | ||
| 142 | 142 | CHECK_NOT_NULL(dsa); | |
| 143 | 143 | ||
| 144 | 144 | DSA_get0_pqg(dsa, &p, &q, nullptr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -463,19 +463,22 @@ bool ECDHBitsTraits::DeriveBits( | |||
| 463 | 463 | ||
| 464 | 464 | char* data = nullptr; | |
| 465 | 465 | size_t len = 0; | |
| 466 | + ManagedEVPPKey m_privkey = params.private_->GetAsymmetricKey(); | ||
| 467 | + ManagedEVPPKey m_pubkey = params.public_->GetAsymmetricKey(); | ||
| 466 | 468 | ||
| 467 | 469 | switch (params.id_) { | |
| 468 | 470 | case EVP_PKEY_X25519: | |
| 469 | 471 | // Fall through | |
| 470 | 472 | case EVP_PKEY_X448: { | |
| 471 | - EVPKeyCtxPointer ctx( | ||
| 472 | - EVP_PKEY_CTX_new( | ||
| 473 | - params.private_->GetAsymmetricKey().get(), | ||
| 474 | - nullptr)); | ||
| 473 | + EVPKeyCtxPointer ctx = nullptr; | ||
| 474 | + { | ||
| 475 | + ctx.reset(EVP_PKEY_CTX_new(m_privkey.get(), nullptr)); | ||
| 476 | + } | ||
| 477 | + Mutex::ScopedLock pub_lock(*m_pubkey.mutex()); | ||
| 475 | 478 | if (EVP_PKEY_derive_init(ctx.get()) <= 0 || | |
| 476 | 479 | EVP_PKEY_derive_set_peer( | |
| 477 | 480 | ctx.get(), | |
| 478 | - params.public_->GetAsymmetricKey().get()) <= 0 || | ||
| 481 | + m_pubkey.get()) <= 0 || | ||
| 479 | 482 | EVP_PKEY_derive(ctx.get(), nullptr, &len) <= 0) { | |
| 480 | 483 | return false; | |
| 481 | 484 | } | |
@@ -492,10 +495,14 @@ bool ECDHBitsTraits::DeriveBits( | |||
| 492 | 495 | break; | |
| 493 | 496 | } | |
| 494 | 497 | default: { | |
| 495 | - const EC_KEY* private_key = | ||
| 496 | - EVP_PKEY_get0_EC_KEY(params.private_->GetAsymmetricKey().get()); | ||
| 497 | - const EC_KEY* public_key = | ||
| 498 | - EVP_PKEY_get0_EC_KEY(params.public_->GetAsymmetricKey().get()); | ||
| 498 | + const EC_KEY* private_key; | ||
| 499 | + { | ||
| 500 | + Mutex::ScopedLock priv_lock(*m_privkey.mutex()); | ||
| 501 | + private_key = EVP_PKEY_get0_EC_KEY(m_privkey.get()); | ||
| 502 | + } | ||
| 503 | + | ||
| 504 | + Mutex::ScopedLock pub_lock(*m_pubkey.mutex()); | ||
| 505 | + const EC_KEY* public_key = EVP_PKEY_get0_EC_KEY(m_pubkey.get()); | ||
| 499 | 506 | ||
| 500 | 507 | const EC_GROUP* group = EC_KEY_get0_group(private_key); | |
| 501 | 508 | if (group == nullptr) | |
@@ -607,7 +614,7 @@ WebCryptoKeyExportStatus EC_Raw_Export( | |||
| 607 | 614 | CHECK(m_pkey); | |
| 608 | 615 | Mutex::ScopedLock lock(*m_pkey.mutex()); | |
| 609 | 616 | ||
| 610 | - EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(m_pkey.get()); | ||
| 617 | + const EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(m_pkey.get()); | ||
| 611 | 618 | ||
| 612 | 619 | unsigned char* data; | |
| 613 | 620 | size_t len = 0; | |
@@ -627,10 +634,10 @@ WebCryptoKeyExportStatus EC_Raw_Export( | |||
| 627 | 634 | } | |
| 628 | 635 | CHECK_NOT_NULL(fn); | |
| 629 | 636 | // Get the size of the raw key data | |
| 630 | - if (fn(key_data->GetAsymmetricKey().get(), nullptr, &len) == 0) | ||
| 637 | + if (fn(m_pkey.get(), nullptr, &len) == 0) | ||
| 631 | 638 | return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; | |
| 632 | 639 | data = MallocOpenSSL<unsigned char>(len); | |
| 633 | - if (fn(key_data->GetAsymmetricKey().get(), data, &len) == 0) | ||
| 640 | + if (fn(m_pkey.get(), data, &len) == 0) | ||
| 634 | 641 | return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; | |
| 635 | 642 | } else { | |
| 636 | 643 | if (key_data->GetKeyType() != kKeyTypePublic) | |
@@ -696,7 +703,7 @@ Maybe<bool> ExportJWKEcKey( | |||
| 696 | 703 | Mutex::ScopedLock lock(*m_pkey.mutex()); | |
| 697 | 704 | CHECK_EQ(EVP_PKEY_id(m_pkey.get()), EVP_PKEY_EC); | |
| 698 | 705 | ||
| 699 | - EC_KEY* ec = EVP_PKEY_get0_EC_KEY(m_pkey.get()); | ||
| 706 | + const EC_KEY* ec = EVP_PKEY_get0_EC_KEY(m_pkey.get()); | ||
| 700 | 707 | CHECK_NOT_NULL(ec); | |
| 701 | 708 | ||
| 702 | 709 | const EC_POINT* pub = EC_KEY_get0_public_key(ec); | |
@@ -751,6 +758,7 @@ Maybe<bool> ExportJWKEdKey( | |||
| 751 | 758 | std::shared_ptr<KeyObjectData> key, | |
| 752 | 759 | Local<Object> target) { | |
| 753 | 760 | ManagedEVPPKey pkey = key->GetAsymmetricKey(); | |
| 761 | + Mutex::ScopedLock lock(*pkey.mutex()); | ||
| 754 | 762 | ||
| 755 | 763 | const char* curve = nullptr; | |
| 756 | 764 | switch (EVP_PKEY_id(pkey.get())) { | |
@@ -902,7 +910,7 @@ Maybe<bool> GetEcKeyDetail( | |||
| 902 | 910 | Mutex::ScopedLock lock(*m_pkey.mutex()); | |
| 903 | 911 | CHECK_EQ(EVP_PKEY_id(m_pkey.get()), EVP_PKEY_EC); | |
| 904 | 912 | ||
| 905 | - EC_KEY* ec = EVP_PKEY_get0_EC_KEY(m_pkey.get()); | ||
| 913 | + const EC_KEY* ec = EVP_PKEY_get0_EC_KEY(m_pkey.get()); | ||
| 906 | 914 | CHECK_NOT_NULL(ec); | |
| 907 | 915 | ||
| 908 | 916 | const EC_GROUP* group = EC_KEY_get0_group(ec); | |
@@ -919,8 +927,8 @@ Maybe<bool> GetEcKeyDetail( | |||
| 919 | 927 | // implementation here is a adapted from Chromium's impl here: | |
| 920 | 928 | // https://github.com/chromium/chromium/blob/7af6cfd/components/webcrypto/algorithms/ecdsa.cc | |
| 921 | 929 | ||
| 922 | - size_t GroupOrderSize(ManagedEVPPKey key) { | ||
| 923 | - EC_KEY* ec = EVP_PKEY_get0_EC_KEY(key.get()); | ||
| 930 | + size_t GroupOrderSize(const ManagedEVPPKey& key) { | ||
| 931 | + const EC_KEY* ec = EVP_PKEY_get0_EC_KEY(key.get()); | ||
| 924 | 932 | CHECK_NOT_NULL(ec); | |
| 925 | 933 | const EC_GROUP* group = EC_KEY_get0_group(ec); | |
| 926 | 934 | BignumPointer order(BN_new()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -110,15 +110,15 @@ bool HKDFTraits::DeriveBits( | |||
| 110 | 110 | !EVP_PKEY_CTX_set_hkdf_md(ctx.get(), params.digest) || | |
| 111 | 111 | !EVP_PKEY_CTX_set1_hkdf_salt( | |
| 112 | 112 | ctx.get(), | |
| 113 | - params.salt.get(), | ||
| 113 | + reinterpret_cast<const unsigned char*>(params.salt.get()), | ||
| 114 | 114 | params.salt.size()) || | |
| 115 | 115 | !EVP_PKEY_CTX_set1_hkdf_key( | |
| 116 | 116 | ctx.get(), | |
| 117 | - params.key->GetSymmetricKey(), | ||
| 117 | + reinterpret_cast<const unsigned char*>(params.key->GetSymmetricKey()), | ||
| 118 | 118 | params.key->GetSymmetricKeySize()) || | |
| 119 | 119 | !EVP_PKEY_CTX_add1_hkdf_info( | |
| 120 | 120 | ctx.get(), | |
| 121 | - params.info.get(), | ||
| 121 | + reinterpret_cast<const unsigned char*>(params.info.get()), | ||
| 122 | 122 | params.info.size())) { | |
| 123 | 123 | return false; | |
| 124 | 124 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -235,6 +235,9 @@ struct KeyPairGenConfig final : public MemoryRetainer { | |||
| 235 | 235 | AlgorithmParams params; | |
| 236 | 236 | ||
| 237 | 237 | KeyPairGenConfig() = default; | |
| 238 | + ~KeyPairGenConfig() { | ||
| 239 | + Mutex::ScopedLock priv_lock(*key.mutex()); | ||
| 240 | + } | ||
| 238 | 241 | ||
| 239 | 242 | explicit KeyPairGenConfig(KeyPairGenConfig&& other) noexcept | |
| 240 | 243 | : public_key_encoding(other.public_key_encoding), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -559,6 +559,8 @@ ManagedEVPPKey::ManagedEVPPKey(const ManagedEVPPKey& that) { | |||
| 559 | 559 | } | |
| 560 | 560 | ||
| 561 | 561 | ManagedEVPPKey& ManagedEVPPKey::operator=(const ManagedEVPPKey& that) { | |
| 562 | + Mutex::ScopedLock lock(*that.mutex_); | ||
| 563 | + | ||
| 562 | 564 | pkey_.reset(that.get()); | |
| 563 | 565 | ||
| 564 | 566 | if (pkey_) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,7 +74,7 @@ struct PrivateKeyEncodingConfig : public AsymmetricKeyEncodingConfig { | |||
| 74 | 74 | // use. | |
| 75 | 75 | class ManagedEVPPKey : public MemoryRetainer { | |
| 76 | 76 | public: | |
| 77 | - ManagedEVPPKey() = default; | ||
| 77 | + ManagedEVPPKey() : mutex_(std::make_shared<Mutex>()) {} | ||
| 78 | 78 | explicit ManagedEVPPKey(EVPKeyPointer&& pkey); | |
| 79 | 79 | ManagedEVPPKey(const ManagedEVPPKey& that); | |
| 80 | 80 | ManagedEVPPKey& operator=(const ManagedEVPPKey& that); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -371,11 +371,11 @@ Maybe<bool> ExportJWKRsaKey( | |||
| 371 | 371 | ||
| 372 | 372 | // TODO(tniessen): Remove the "else" branch once we drop support for OpenSSL | |
| 373 | 373 | // versions older than 1.1.1e via FIPS / dynamic linking. | |
| 374 | - RSA* rsa; | ||
| 374 | + const RSA* rsa; | ||
| 375 | 375 | if (OpenSSL_version_num() >= 0x1010105fL) { | |
| 376 | 376 | rsa = EVP_PKEY_get0_RSA(m_pkey.get()); | |
| 377 | 377 | } else { | |
| 378 | - rsa = static_cast<RSA*>(EVP_PKEY_get0(m_pkey.get())); | ||
| 378 | + rsa = static_cast<const RSA*>(EVP_PKEY_get0(m_pkey.get())); | ||
| 379 | 379 | } | |
| 380 | 380 | CHECK_NOT_NULL(rsa); | |
| 381 | 381 | ||
@@ -520,11 +520,11 @@ Maybe<bool> GetRsaKeyDetail( | |||
| 520 | 520 | ||
| 521 | 521 | // TODO(tniessen): Remove the "else" branch once we drop support for OpenSSL | |
| 522 | 522 | // versions older than 1.1.1e via FIPS / dynamic linking. | |
| 523 | - RSA* rsa; | ||
| 523 | + const RSA* rsa; | ||
| 524 | 524 | if (OpenSSL_version_num() >= 0x1010105fL) { | |
| 525 | 525 | rsa = EVP_PKEY_get0_RSA(m_pkey.get()); | |
| 526 | 526 | } else { | |
| 527 | - rsa = static_cast<RSA*>(EVP_PKEY_get0(m_pkey.get())); | ||
| 527 | + rsa = static_cast<const RSA*>(EVP_PKEY_get0(m_pkey.get())); | ||
| 528 | 528 | } | |
| 529 | 529 | CHECK_NOT_NULL(rsa); | |
| 530 | 530 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,8 +28,13 @@ namespace crypto { | |||
| 28 | 28 | namespace { | |
| 29 | 29 | bool ValidateDSAParameters(EVP_PKEY* key) { | |
| 30 | 30 | /* Validate DSA2 parameters from FIPS 186-4 */ | |
| 31 | + #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 32 | + if (EVP_default_properties_is_fips_enabled(nullptr) && | ||
| 33 | + EVP_PKEY_DSA == EVP_PKEY_base_id(key)) { | ||
| 34 | + #else | ||
| 31 | 35 | if (FIPS_mode() && EVP_PKEY_DSA == EVP_PKEY_base_id(key)) { | |
| 32 | - DSA* dsa = EVP_PKEY_get0_DSA(key); | ||
| 36 | + #endif | ||
| 37 | + const DSA* dsa = EVP_PKEY_get0_DSA(key); | ||
| 33 | 38 | const BIGNUM* p; | |
| 34 | 39 | DSA_get0_pqg(dsa, &p, nullptr, nullptr); | |
| 35 | 40 | size_t L = BN_num_bits(p); | |
@@ -103,11 +108,11 @@ unsigned int GetBytesOfRS(const ManagedEVPPKey& pkey) { | |||
| 103 | 108 | int bits, base_id = EVP_PKEY_base_id(pkey.get()); | |
| 104 | 109 | ||
| 105 | 110 | if (base_id == EVP_PKEY_DSA) { | |
| 106 | - DSA* dsa_key = EVP_PKEY_get0_DSA(pkey.get()); | ||
| 111 | + const DSA* dsa_key = EVP_PKEY_get0_DSA(pkey.get()); | ||
| 107 | 112 | // Both r and s are computed mod q, so their width is limited by that of q. | |
| 108 | 113 | bits = BN_num_bits(DSA_get0_q(dsa_key)); | |
| 109 | 114 | } else if (base_id == EVP_PKEY_EC) { | |
| 110 | - EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(pkey.get()); | ||
| 115 | + const EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(pkey.get()); | ||
| 111 | 116 | const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key); | |
| 112 | 117 | bits = EC_GROUP_order_bits(ec_group); | |
| 113 | 118 | } else { | |
@@ -873,7 +878,7 @@ bool SignTraits::DeriveBits( | |||
| 873 | 878 | case SignConfiguration::kSign: { | |
| 874 | 879 | size_t len; | |
| 875 | 880 | unsigned char* data = nullptr; | |
| 876 | - if (IsOneShot(params.key->GetAsymmetricKey())) { | ||
| 881 | + if (IsOneShot(m_pkey)) { | ||
| 877 | 882 | EVP_DigestSign( | |
| 878 | 883 | context.get(), | |
| 879 | 884 | nullptr, | |
@@ -905,10 +910,7 @@ bool SignTraits::DeriveBits( | |||
| 905 | 910 | return false; | |
| 906 | 911 | ||
| 907 | 912 | if (UseP1363Encoding(m_pkey, params.dsa_encoding)) { | |
| 908 | - *out = ConvertSignatureToP1363( | ||
| 909 | - env, | ||
| 910 | - params.key->GetAsymmetricKey(), | ||
| 911 | - buf); | ||
| 913 | + *out = ConvertSignatureToP1363(env, m_pkey, buf); | ||
| 912 | 914 | } else { | |
| 913 | 915 | buf.Resize(len); | |
| 914 | 916 | *out = std::move(buf); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments