Skip to content
This repository was archived by the owner on May 9, 2020. It is now read-only.

Commit f6d64b6

Browse files
authored
Merge pull request #212 from pro-src/211_ssl_ciphers
Backport TLSv1.3 secure ciphers
2 parents 84c0bce + 3443aad commit f6d64b6

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const requestModule = require('request-promise');
44
const sandbox = require('./lib/sandbox');
55
const decodeEmails = require('./lib/email-decode.js');
66
const getDefaultHeaders = require('./lib/headers');
7+
const agentOptions = require('./lib/agent-options');
78
const brotli = require('./lib/brotli');
89

910
const {
@@ -35,7 +36,9 @@ function defaults (params) {
3536
// Remove Cloudflare's email protection
3637
decodeEmails: false,
3738
// Support gzip encoded responses
38-
gzip: true
39+
gzip: true,
40+
// Adds secure TLSv1.3 ciphers when using older openssl versions
41+
agentOptions
3942
};
4043

4144
// Object.assign requires at least nodejs v4, request only test/supports v6+

lib/agent-options.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const tls = require('tls');
4+
5+
const ciphers = getCiphers();
6+
7+
if (ciphers !== -1) {
8+
module.exports.ciphers = ciphers;
9+
}
10+
11+
function getCiphers () {
12+
// SSL_CTX_set_cipher_list will simply ignore any unsupported ciphers
13+
const defaults = [
14+
'TLS_AES_128_CCM_8_SHA256',
15+
'TLS_AES_128_CCM_SHA256',
16+
'TLS_AES_128_GCM_SHA256',
17+
'TLS_AES_256_GCM_SHA384',
18+
'TLS_CHACHA20_POLY1305_SHA256'
19+
];
20+
21+
// We already have these defaults if using openssl v1.1.1 and later
22+
const v = process.versions.openssl.match(/(\d)+\.(\d+)\.(\d+)/);
23+
if (v[1] >= 1 && v[2] >= 1 && v[3] >= 1) {
24+
return -1;
25+
}
26+
27+
const suites = tls.getCiphers()
28+
.map(function (s) {
29+
return s.toUpperCase();
30+
});
31+
32+
let missing = false;
33+
// Add the default TLSv1.3 cipher suites if missing
34+
for (let i = 0; i < defaults.length; i++) {
35+
if (suites.indexOf(defaults[i]) === -1) {
36+
missing = true;
37+
suites.push(defaults[i]);
38+
}
39+
}
40+
41+
return missing ? suites.join(':') : -1;
42+
}

test/helper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var express = require('express');
77

88
// Clone the default headers for tests
99
var defaultHeaders = Object.assign({}, require('../').defaultParams.headers);
10+
var agentOptions = require('../lib/agent-options');
1011

1112
// Cache fixtures so they're only read from fs but once
1213
var cache = {};
@@ -31,7 +32,8 @@ var helper = {
3132
cloudflareMaxTimeout: 30000,
3233
challengesToSolve: 3,
3334
decodeEmails: false,
34-
gzip: true
35+
gzip: true,
36+
agentOptions
3537
};
3638
},
3739
getFixture: function (fileName) {

0 commit comments

Comments
 (0)