mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
crypto: handle DH operation failures
Report DH failures instead of aborting or returning an empty secret. Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64851 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
a4aa3c02cc
commit
a382db596d
1 file changed
+8
-4
@@ -337,6 +337,10 @@ void ComputeSecret(const FunctionCallbackInfo<Value>& args) {
|
||||
}
|
||||
|
||||
auto dp = dh.computeSecret(key);
|
||||
if (!dp) {
|
||||
return THROW_ERR_CRYPTO_OPERATION_FAILED(env,
|
||||
"Failed to compute shared secret");
|
||||
}
|
||||
|
||||
Local<Value> buffer;
|
||||
if (DataPointerToBuffer(env, std::move(dp)).ToLocal(&buffer)) {
|
||||
@@ -354,8 +358,8 @@ void SetPublicKey(const FunctionCallbackInfo<Value>& args) {
|
||||
if (!buf.CheckSizeInt32()) [[unlikely]]
|
||||
return THROW_ERR_OUT_OF_RANGE(env, "buf is too big");
|
||||
BignumPointer num(buf.data(), buf.size());
|
||||
CHECK(num);
|
||||
CHECK(dh.setPublicKey(std::move(num)));
|
||||
if (!num || !dh.setPublicKey(std::move(num)))
|
||||
return THROW_ERR_INVALID_ARG_VALUE(env, "Invalid public key");
|
||||
}
|
||||
|
||||
void SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
|
||||
@@ -368,8 +372,8 @@ void SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
|
||||
if (!buf.CheckSizeInt32()) [[unlikely]]
|
||||
return THROW_ERR_OUT_OF_RANGE(env, "buf is too big");
|
||||
BignumPointer num(buf.data(), buf.size());
|
||||
CHECK(num);
|
||||
CHECK(dh.setPrivateKey(std::move(num)));
|
||||
if (!num || !dh.setPrivateKey(std::move(num)))
|
||||
return THROW_ERR_INVALID_ARG_VALUE(env, "Invalid private key");
|
||||
}
|
||||
|
||||
void Check(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
Reference in new issue
Block a user