Skip to content

Commit d523eb9

Browse files
committedFeb 20, 2017
tls: use emitWarning() for dhparam < 2048 bits
When a dhparam less than 2048 bits was used, a warning was being printed directly to console.error using an internalUtil.trace function that was not used anywhere else. This replaces it with a proper process warning and removes the internalUtil.trace function. PR-URL: #11447 Reviewed-By: Shigeki Ohtsu <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 0510472 commit d523eb9

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed
 

‎lib/_tls_common.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const internalUtil = require('internal/util');
43
const tls = require('tls');
54

65
const SSL_OP_CIPHER_SERVER_PREFERENCE =
@@ -99,7 +98,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
9998
if (options.dhparam) {
10099
const warning = c.context.setDHParam(options.dhparam);
101100
if (warning)
102-
internalUtil.trace(warning);
101+
process.emitWarning(warning, 'SecurityWarning');
103102
}
104103

105104
if (options.crl) {

‎lib/internal/util.js

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const binding = process.binding('util');
4-
const prefix = `(${process.release.name}:${process.pid}) `;
54

65
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
76
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
@@ -10,10 +9,6 @@ const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
109
// `util` module makes it accessible without having to `require('util')` there.
1110
exports.customInspectSymbol = Symbol('util.inspect.custom');
1211

13-
exports.trace = function(msg) {
14-
console.trace(`${prefix}${msg}`);
15-
};
16-
1712
// Mark that a method should not be used.
1813
// Returns a modified function which warns once by default.
1914
// If --no-deprecation is set, then it is a no-op.

‎src/node_crypto.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
933933
return env->ThrowError("DH parameter is less than 1024 bits");
934934
} else if (size < 2048) {
935935
args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING(
936-
env->isolate(), "WARNING: DH parameter is less than 2048 bits"));
936+
env->isolate(), "DH parameter is less than 2048 bits"));
937937
}
938938

939939
SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_DH_USE);

‎test/parallel/test-tls-dhe.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --no-warnings
12
'use strict';
23
const common = require('../common');
34
const assert = require('assert');
@@ -22,6 +23,9 @@ let nsuccess = 0;
2223
let ntests = 0;
2324
const ciphers = 'DHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
2425

26+
// Test will emit a warning because the DH parameter size is < 2048 bits
27+
common.expectWarning('SecurityWarning',
28+
'DH parameter is less than 2048 bits');
2529

2630
function loadDHParam(n) {
2731
let path = common.fixturesDir;

0 commit comments

Comments
 (0)
Please sign in to comment.