| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 45692e9 commit 9624049
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1005,11 +1005,15 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) { | |||
| 1005 | 1005 | return ThrowCryptoError(env, ERR_get_error()); | |
| 1006 | 1006 | } | |
| 1007 | 1007 | ||
| 1008 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 1009 | + // RSA implicit rejection here is not supported by BoringSSL. | ||
| 1010 | + // Skip this check when boring is used. | ||
| 1008 | 1011 | if (!ctx.setRsaImplicitRejection()) { | |
| 1009 | 1012 | return THROW_ERR_INVALID_ARG_VALUE( | |
| 1010 | 1013 | env, | |
| 1011 | 1014 | "RSA_PKCS1_PADDING is no longer supported for private decryption"); | |
| 1012 | 1015 | } | |
| 1016 | + #endif | ||
| 1013 | 1017 | } | |
| 1014 | 1018 | ||
| 1015 | 1019 | const EVP_MD* digest = nullptr; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,9 @@ | |||
| 7 | 7 | #include "memory_tracker-inl.h" | |
| 8 | 8 | #include "ncrypto.h" | |
| 9 | 9 | #include "node_errors.h" | |
| 10 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 10 | 11 | #include "openssl/bnerr.h" | |
| 12 | + #endif | ||
| 11 | 13 | #include "openssl/dh.h" | |
| 12 | 14 | #include "threadpoolwork-inl.h" | |
| 13 | 15 | #include "v8.h" | |
@@ -88,11 +90,15 @@ void New(const FunctionCallbackInfo<Value>& args) { | |||
| 88 | 90 | if (args[0]->IsInt32()) { | |
| 89 | 91 | int32_t bits = args[0].As<Int32>()->Value(); | |
| 90 | 92 | if (bits < 2) { | |
| 93 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 91 | 94 | #if OPENSSL_VERSION_MAJOR >= 3 | |
| 92 | 95 | ERR_put_error(ERR_LIB_DH, 0, DH_R_MODULUS_TOO_SMALL, __FILE__, __LINE__); | |
| 93 | 96 | #else | |
| 94 | 97 | ERR_put_error(ERR_LIB_BN, 0, BN_R_BITS_TOO_SMALL, __FILE__, __LINE__); | |
| 95 | - #endif | ||
| 98 | + #endif // OPENSSL_VERSION_MAJOR >= 3 | ||
| 99 | + #else // OPENSSL_IS_BORINGSSL | ||
| 100 | + OPENSSL_PUT_ERROR(BN, BN_R_BITS_TOO_SMALL); | ||
| 101 | + #endif // OPENSSL_IS_BORINGSSL | ||
| 96 | 102 | return ThrowCryptoError(env, ERR_get_error(), "Invalid prime length"); | |
| 97 | 103 | } | |
| 98 | 104 | ||
@@ -105,7 +111,11 @@ void New(const FunctionCallbackInfo<Value>& args) { | |||
| 105 | 111 | } | |
| 106 | 112 | int32_t generator = args[1].As<Int32>()->Value(); | |
| 107 | 113 | if (generator < 2) { | |
| 114 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 108 | 115 | ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__); | |
| 116 | + #else | ||
| 117 | + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR); | ||
| 118 | + #endif | ||
| 109 | 119 | return ThrowCryptoError(env, ERR_get_error(), "Invalid generator"); | |
| 110 | 120 | } | |
| 111 | 121 | ||
@@ -134,12 +144,20 @@ void New(const FunctionCallbackInfo<Value>& args) { | |||
| 134 | 144 | if (args[1]->IsInt32()) { | |
| 135 | 145 | int32_t generator = args[1].As<Int32>()->Value(); | |
| 136 | 146 | if (generator < 2) { | |
| 147 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 137 | 148 | ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__); | |
| 149 | + #else | ||
| 150 | + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR); | ||
| 151 | + #endif | ||
| 138 | 152 | return ThrowCryptoError(env, ERR_get_error(), "Invalid generator"); | |
| 139 | 153 | } | |
| 140 | 154 | bn_g = BignumPointer::New(); | |
| 141 | 155 | if (!bn_g.setWord(generator)) { | |
| 156 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 142 | 157 | ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__); | |
| 158 | + #else | ||
| 159 | + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR); | ||
| 160 | + #endif | ||
| 143 | 161 | return ThrowCryptoError(env, ERR_get_error(), "Invalid generator"); | |
| 144 | 162 | } | |
| 145 | 163 | } else { | |
@@ -148,11 +166,19 @@ void New(const FunctionCallbackInfo<Value>& args) { | |||
| 148 | 166 | return THROW_ERR_OUT_OF_RANGE(env, "generator is too big"); | |
| 149 | 167 | bn_g = BignumPointer(reinterpret_cast<uint8_t*>(arg1.data()), arg1.size()); | |
| 150 | 168 | if (!bn_g) { | |
| 169 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 151 | 170 | ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__); | |
| 171 | + #else | ||
| 172 | + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR); | ||
| 173 | + #endif | ||
| 152 | 174 | return ThrowCryptoError(env, ERR_get_error(), "Invalid generator"); | |
| 153 | 175 | } | |
| 154 | 176 | if (bn_g.getWord() < 2) { | |
| 177 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 155 | 178 | ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__); | |
| 179 | + #else | ||
| 180 | + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR); | ||
| 181 | + #endif | ||
| 156 | 182 | return ThrowCryptoError(env, ERR_get_error(), "Invalid generator"); | |
| 157 | 183 | } | |
| 158 | 184 | } | |
@@ -398,14 +424,19 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) { | |||
| 398 | 424 | if (!dh) return {}; | |
| 399 | 425 | ||
| 400 | 426 | key_params = EVPKeyPointer::NewDH(std::move(dh)); | |
| 401 | - } else if (int* prime_size = std::get_if<int>(¶ms->params.prime)) { | ||
| 427 | + } else if (std::get_if<int>(¶ms->params.prime)) { | ||
| 402 | 428 | auto param_ctx = EVPKeyCtxPointer::NewFromID(EVP_PKEY_DH); | |
| 429 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 430 | + int* prime_size = std::get_if<int>(¶ms->params.prime); | ||
| 403 | 431 | if (!param_ctx.initForParamgen() || | |
| 404 | 432 | !param_ctx.setDhParameters(*prime_size, params->params.generator)) { | |
| 405 | 433 | return {}; | |
| 406 | 434 | } | |
| 407 | 435 | ||
| 408 | 436 | key_params = param_ctx.paramgen(); | |
| 437 | + #else | ||
| 438 | + return {}; | ||
| 439 | + #endif | ||
| 409 | 440 | } else { | |
| 410 | 441 | UNREACHABLE(); | |
| 411 | 442 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,10 @@ using v8::Value; | |||
| 28 | 28 | ||
| 29 | 29 | namespace crypto { | |
| 30 | 30 | EVPKeyCtxPointer DsaKeyGenTraits::Setup(DsaKeyPairGenConfig* params) { | |
| 31 | + #ifdef OPENSSL_IS_BORINGSSL | ||
| 32 | + // Operation is unsupported in BoringSSL | ||
| 33 | + return {}; | ||
| 34 | + #else | ||
| 31 | 35 | auto param_ctx = EVPKeyCtxPointer::NewFromID(EVP_PKEY_DSA); | |
| 32 | 36 | ||
| 33 | 37 | if (!param_ctx.initForParamgen() || | |
@@ -45,6 +49,7 @@ EVPKeyCtxPointer DsaKeyGenTraits::Setup(DsaKeyPairGenConfig* params) { | |||
| 45 | 49 | EVPKeyCtxPointer key_ctx = key_params.newCtx(); | |
| 46 | 50 | if (!key_ctx.initForKeygen()) return {}; | |
| 47 | 51 | return key_ctx; | |
| 52 | + #endif | ||
| 48 | 53 | } | |
| 49 | 54 | ||
| 50 | 55 | // Input arguments for DsaKeyPairGenJob | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -924,6 +924,10 @@ void KeyObjectHandle::GetAsymmetricKeyType( | |||
| 924 | 924 | } | |
| 925 | 925 | ||
| 926 | 926 | bool KeyObjectHandle::CheckEcKeyData() const { | |
| 927 | + #ifdef OPENSSL_IS_BORINGSSL | ||
| 928 | + // Operation is unsupported on BoringSSL | ||
| 929 | + return true; | ||
| 930 | + #else | ||
| 927 | 931 | MarkPopErrorOnReturn mark_pop_error_on_return; | |
| 928 | 932 | ||
| 929 | 933 | const auto& key = data_.GetAsymmetricKey(); | |
@@ -933,6 +937,7 @@ bool KeyObjectHandle::CheckEcKeyData() const { | |||
| 933 | 937 | ||
| 934 | 938 | return data_.GetKeyType() == kKeyTypePrivate ? ctx.privateCheck() | |
| 935 | 939 | : ctx.publicCheck(); | |
| 940 | + #endif | ||
| 936 | 941 | } | |
| 937 | 942 | ||
| 938 | 943 | void KeyObjectHandle::CheckEcKeyData(const FunctionCallbackInfo<Value>& args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -682,29 +682,46 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) { | |||
| 682 | 682 | CHECK(args[0]->IsUint32()); | |
| 683 | 683 | Environment* env = Environment::GetCurrent(args); | |
| 684 | 684 | uint32_t len = args[0].As<Uint32>()->Value(); | |
| 685 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 685 | 686 | void* data = OPENSSL_secure_zalloc(len); | |
| 687 | + #else | ||
| 688 | + void* data = OPENSSL_malloc(len); | ||
| 689 | + #endif | ||
| 686 | 690 | if (data == nullptr) { | |
| 687 | 691 | // There's no memory available for the allocation. | |
| 688 | 692 | // Return nothing. | |
| 689 | 693 | return; | |
| 690 | 694 | } | |
| 695 | + #ifdef OPENSSL_IS_BORINGSSL | ||
| 696 | + memset(data, 0, len); | ||
| 697 | + #endif | ||
| 691 | 698 | std::shared_ptr<BackingStore> store = | |
| 692 | 699 | ArrayBuffer::NewBackingStore( | |
| 693 | 700 | data, | |
| 694 | 701 | len, | |
| 695 | 702 | [](void* data, size_t len, void* deleter_data) { | |
| 703 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 696 | 704 | OPENSSL_secure_clear_free(data, len); | |
| 705 | + #else | ||
| 706 | + OPENSSL_clear_free(data, len); | ||
| 707 | + #endif | ||
| 697 | 708 | }, | |
| 698 | 709 | data); | |
| 699 | 710 | Local<ArrayBuffer> buffer = ArrayBuffer::New(env->isolate(), store); | |
| 700 | 711 | args.GetReturnValue().Set(Uint8Array::New(buffer, 0, len)); | |
| 701 | 712 | } | |
| 702 | 713 | ||
| 703 | 714 | void SecureHeapUsed(const FunctionCallbackInfo<Value>& args) { | |
| 715 | + #ifndef OPENSSL_IS_BORINGSSL | ||
| 704 | 716 | Environment* env = Environment::GetCurrent(args); | |
| 705 | 717 | if (CRYPTO_secure_malloc_initialized()) | |
| 706 | 718 | args.GetReturnValue().Set( | |
| 707 | 719 | BigInt::New(env->isolate(), CRYPTO_secure_used())); | |
| 720 | + #else | ||
| 721 | + // BoringSSL does not have the secure heap and therefore | ||
| 722 | + // will always return 0. | ||
| 723 | + args.GetReturnValue().Set(BigInt::New(args.GetIsolate(), 0)); | ||
| 724 | + #endif | ||
| 708 | 725 | } | |
| 709 | 726 | } // namespace | |
| 710 | 727 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments