Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: turn impossible DH errors into assertions #31934

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5868,11 +5868,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {

ClearErrorOnReturn clear_error_on_return;

if (args.Length() == 0) {
return THROW_ERR_MISSING_ARGS(
env, "Other party's public key argument is mandatory");
}

CHECK_EQ(args.Length(), 1);
THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Other party's public key");
ArrayBufferViewContents<unsigned char> key_buf(args[0].As<ArrayBufferView>());
BignumPointer key(BN_bin2bn(key_buf.data(), key_buf.length(), nullptr));
Expand Down Expand Up @@ -5923,11 +5919,7 @@ void DiffieHellman::SetKey(const FunctionCallbackInfo<Value>& args,

char errmsg[64];

if (args.Length() == 0) {
snprintf(errmsg, sizeof(errmsg), "%s argument is mandatory", what);
return THROW_ERR_MISSING_ARGS(env, errmsg);
}

CHECK_EQ(args.Length(), 1);
if (!Buffer::HasInstance(args[0])) {
snprintf(errmsg, sizeof(errmsg), "%s must be a buffer", what);
return THROW_ERR_INVALID_ARG_TYPE(env, errmsg);
Expand Down