|
6 | 6 | #include "node_buffer.h"
|
7 | 7 | #include "node_internals.h"
|
8 | 8 | #include "node_process-inl.h"
|
| 9 | +#include "node_revert.h" |
9 | 10 | #include "v8.h"
|
10 | 11 |
|
11 | 12 | namespace node {
|
@@ -1052,6 +1053,33 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
|
1052 | 1053 | uint32_t padding;
|
1053 | 1054 | if (!args[offset + 1]->Uint32Value(env->context()).To(&padding)) return;
|
1054 | 1055 |
|
| 1056 | + if (EVP_PKEY_cipher == EVP_PKEY_decrypt && |
| 1057 | + operation == PublicKeyCipher::kPrivate && padding == RSA_PKCS1_PADDING && |
| 1058 | + !IsReverted(SECURITY_REVERT_CVE_2023_46809)) { |
| 1059 | + EVPKeyCtxPointer ctx(EVP_PKEY_CTX_new(pkey.get(), nullptr)); |
| 1060 | + CHECK(ctx); |
| 1061 | + |
| 1062 | + if (EVP_PKEY_decrypt_init(ctx.get()) <= 0) { |
| 1063 | + return ThrowCryptoError(env, ERR_get_error()); |
| 1064 | + } |
| 1065 | + |
| 1066 | + int rsa_pkcs1_implicit_rejection = |
| 1067 | + EVP_PKEY_CTX_ctrl_str(ctx.get(), "rsa_pkcs1_implicit_rejection", "1"); |
| 1068 | + // From the doc -2 means that the option is not supported. |
| 1069 | + // The default for the option is enabled and if it has been |
| 1070 | + // specifically disabled we want to respect that so we will |
| 1071 | + // not throw an error if the option is supported regardless |
| 1072 | + // of how it is set. The call to set the value |
| 1073 | + // will not affect what is used since a different context is |
| 1074 | + // used in the call if the option is supported |
| 1075 | + if (rsa_pkcs1_implicit_rejection <= 0) { |
| 1076 | + return THROW_ERR_INVALID_ARG_VALUE( |
| 1077 | + env, |
| 1078 | + "RSA_PKCS1_PADDING is no longer supported for private decryption," |
| 1079 | + " this can be reverted with --security-revert=CVE-2023-46809"); |
| 1080 | + } |
| 1081 | + } |
| 1082 | + |
1055 | 1083 | const EVP_MD* digest = nullptr;
|
1056 | 1084 | if (args[offset + 2]->IsString()) {
|
1057 | 1085 | const Utf8Value oaep_str(env->isolate(), args[offset + 2]);
|
|
0 commit comments