Skip to content

Commit

Permalink
Throw JavaScript exception if FIPS mode cannot be enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Staněk <[email protected]>
  • Loading branch information
danbev authored and khardix committed Dec 15, 2020
1 parent bd77fd3 commit cc5dca5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/crypto/crypto_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ void InitCryptoOnce() {
}
}
if (0 != err) {
fprintf(stderr,
"openssl fips failed: %s\n",
ERR_error_string(err, nullptr));
UNREACHABLE();
auto* isolate = Isolate::GetCurrent();
auto* env = Environment::GetCurrent(isolate);
return ThrowCryptoError(env, err);
}

// Turn off compression. Saves memory and protects against CRIME attacks.
Expand Down
10 changes: 8 additions & 2 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace node {
using v8::Context;
using v8::Local;
using v8::Object;
using v8::TryCatch;
using v8::Value;

namespace crypto {
Expand All @@ -39,10 +40,15 @@ void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv) {
Environment* env = Environment::GetCurrent(context);

static uv_once_t init_once = UV_ONCE_INIT;
TryCatch try_catch{env->isolate()};
uv_once(&init_once, InitCryptoOnce);

Environment* env = Environment::GetCurrent(context);
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
try_catch.ReThrow();
return;
}

AES::Initialize(env, target);
CipherBase::Initialize(env, target);
Expand Down

0 comments on commit cc5dca5

Please sign in to comment.