Skip to content

Commit cc5dca5

Browse files
danbevkhardix
authored andcommitted
Throw JavaScript exception if FIPS mode cannot be enabled
Signed-off-by: Jan Staněk <[email protected]>
1 parent bd77fd3 commit cc5dca5

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/crypto/crypto_util.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ void InitCryptoOnce() {
120120
}
121121
}
122122
if (0 != err) {
123-
fprintf(stderr,
124-
"openssl fips failed: %s\n",
125-
ERR_error_string(err, nullptr));
126-
UNREACHABLE();
123+
auto* isolate = Isolate::GetCurrent();
124+
auto* env = Environment::GetCurrent(isolate);
125+
return ThrowCryptoError(env, err);
127126
}
128127

129128
// Turn off compression. Saves memory and protects against CRIME attacks.

src/node_crypto.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace node {
3131
using v8::Context;
3232
using v8::Local;
3333
using v8::Object;
34+
using v8::TryCatch;
3435
using v8::Value;
3536

3637
namespace crypto {
@@ -39,10 +40,15 @@ void Initialize(Local<Object> target,
3940
Local<Value> unused,
4041
Local<Context> context,
4142
void* priv) {
43+
Environment* env = Environment::GetCurrent(context);
44+
4245
static uv_once_t init_once = UV_ONCE_INIT;
46+
TryCatch try_catch{env->isolate()};
4347
uv_once(&init_once, InitCryptoOnce);
44-
45-
Environment* env = Environment::GetCurrent(context);
48+
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
49+
try_catch.ReThrow();
50+
return;
51+
}
4652

4753
AES::Initialize(env, target);
4854
CipherBase::Initialize(env, target);

0 commit comments

Comments
 (0)