Skip to content

Commit f59a363

Browse files
committed
fix(Server): Set tls.DEFAULT_ECDH_CURVE to 'auto'
The default value of tls.DEFAULT_ECDH_CURVE is 'prime256v1', it breaks the connection when certificate is not compatible with the default curve since node 8.6.0. To fix this issue, we need set it to 'auto', makes OpenSSL select the curve automatically.
1 parent d2f4902 commit f59a363

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/Server.js

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ const createCertificate = require('./utils/createCertificate');
4040
const validateOptions = require('schema-utils');
4141
const schema = require('./options.json');
4242

43+
// Workaround for node ^8.6.0, ^9.0.0
44+
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
45+
// breaking connection when certificate is not signed with prime256v1
46+
// change it to auto allows OpenSSL to select the curve automatically
47+
// See https://github.com/nodejs/node/issues/16196 for more infomation
48+
const verMatch = process.version.match(/^v(\d+).(\d+)/);
49+
if (verMatch && (+verMatch[1] === 9 || (+verMatch[1] === 8 && +verMatch[2] >= 6))) {
50+
require('tls').DEFAULT_ECDH_CURVE = 'auto';
51+
}
52+
4353
const STATS = {
4454
all: false,
4555
hash: true,

0 commit comments

Comments
 (0)