Skip to content

Commit dd8a2a2

Browse files
author
Shigeki Ohtsu
committed
tls: output warning of setDHParam to console.trace
To make it easy to figure out where the warning comes from. Also fix style and variable name that was made in nodejs#1739.
1 parent ffdd508 commit dd8a2a2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/_tls_common.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ exports.createSecureContext = function createSecureContext(options, context) {
9999
else if (options.ecdhCurve)
100100
c.context.setECDHCurve(options.ecdhCurve);
101101

102-
if (options.dhparam) c.context.setDHParam(options.dhparam);
102+
if (options.dhparam) {
103+
var warning = c.context.setDHParam(options.dhparam);
104+
if (warning)
105+
console.trace(warning);
106+
}
103107

104108
if (options.crl) {
105109
if (Array.isArray(options.crl)) {

src/node_crypto.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,13 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
757757
if (dh == nullptr)
758758
return;
759759

760-
const int keylen = BN_num_bits(dh->p);
761-
if (keylen < 1024)
760+
const int size = BN_num_bits(dh->p);
761+
if (size < 1024) {
762762
return env->ThrowError("DH parameter is less than 1024 bits");
763-
else if (keylen < 2048)
764-
fprintf(stderr, "WARNING: DH parameter is less than 2048 bits\n");
763+
} else if (size < 2048) {
764+
args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING(
765+
env->isolate(), "WARNING: DH parameter is less than 2048 bits"));
766+
}
765767

766768
SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_DH_USE);
767769
int r = SSL_CTX_set_tmp_dh(sc->ctx_, dh);

0 commit comments

Comments
 (0)