diff --git a/doc/api/errors.md b/doc/api/errors.md
index e050392fc65163..d5ab7569f11a27 100644
--- a/doc/api/errors.md
+++ b/doc/api/errors.md
@@ -1652,6 +1652,17 @@ recommended to use 2048 bits or larger for stronger security.
A TLS/SSL handshake timed out. In this case, the server must also abort the
connection.
+
+### ERR_TLS_INVALID_PROTOCOL_VERSION
+
+Valid TLS protocol versions are `'TLSv1'`, `'TLSv1.1'`, or `'TLSv1.2'`.
+
+
+### ERR_TLS_PROTOCOL_VERSION_CONFLICT
+
+Attempting to set a TLS protocol `minVersion` or `maxVersion` conflicts with an
+attempt to set the `secureProtocol` explicitly. Use one mechanism or the other.
+
### ERR_TLS_RENEGOTIATE
diff --git a/doc/api/tls.md b/doc/api/tls.md
index e66e7ffe719506..6aeb5817531545 100644
--- a/doc/api/tls.md
+++ b/doc/api/tls.md
@@ -1069,6 +1069,14 @@ changes:
passphrase: ]}`. The object form can only occur in an array.
`object.passphrase` is optional. Encrypted keys will be decrypted with
`object.passphrase` if provided, or `options.passphrase` if it is not.
+ * `maxVersion` {string} Optionally set the maximum TLS version to allow. One
+ of `TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
+ `secureProtocol` option, use one or the other. **Default:** `'TLSv1.2'`.
+ * `minVersion` {string} Optionally set the minimum TLS version to allow. One
+ of `TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
+ `secureProtocol` option, use one or the other. It is not recommended to use
+ less than TLSv1.2, but it may be required for interoperability.
+ **Default:** `'TLSv1'`.
* `passphrase` {string} Shared passphrase used for a single private key and/or
a PFX.
* `pfx` {string|string[]|Buffer|Buffer[]|Object[]} PFX or PKCS12 encoded
@@ -1084,9 +1092,12 @@ changes:
which is not usually necessary. This should be used carefully if at all!
Value is a numeric bitmask of the `SSL_OP_*` options from
[OpenSSL Options][].
- * `secureProtocol` {string} SSL method to use. The possible values are listed
- as [SSL_METHODS][], use the function names as strings. For example,
- `'TLSv1_2_method'` to force TLS version 1.2. **Default:** `'TLS_method'`.
+ * `secureProtocol` {string} The TLS protocol version to use. The possible
+ values are listed as [SSL_METHODS][], use the function names as strings. For
+ example, use `'TLSv1_1_method'` to force TLS version 1.1, or `'TLS_method'`
+ to allow any TLS protocol version. It is not recommended to use TLS versions
+ less than 1.2, but it may be required for interoperability. **Default:**
+ none, see `minVersion`.
* `sessionIdContext` {string} Opaque identifier used by servers to ensure
session state is not shared between applications. Unused by clients.
diff --git a/lib/_tls_common.js b/lib/_tls_common.js
index 1073f5d520e0b9..ee4e64f873c835 100644
--- a/lib/_tls_common.js
+++ b/lib/_tls_common.js
@@ -26,19 +26,35 @@ const { isArrayBufferView } = require('internal/util/types');
const tls = require('tls');
const {
ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED,
- ERR_INVALID_ARG_TYPE
+ ERR_INVALID_ARG_TYPE,
+ ERR_TLS_INVALID_PROTOCOL_VERSION,
+ ERR_TLS_PROTOCOL_VERSION_CONFLICT,
} = require('internal/errors').codes;
-const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;
+const {
+ SSL_OP_CIPHER_SERVER_PREFERENCE,
+ TLS1_VERSION,
+ TLS1_1_VERSION,
+ TLS1_2_VERSION,
+} = process.binding('constants').crypto;
// Lazily loaded
var crypto = null;
-const { SecureContext: NativeSecureContext } = internalBinding('crypto');
+function toV(which, v, def) {
+ if (v == null) v = def;
+ if (v === 'TLSv1') return TLS1_VERSION;
+ if (v === 'TLSv1.1') return TLS1_1_VERSION;
+ if (v === 'TLSv1.2') return TLS1_2_VERSION;
+ throw new ERR_TLS_INVALID_PROTOCOL_VERSION(v, which);
+}
-function SecureContext(secureProtocol, secureOptions, context) {
+const { SecureContext: NativeSecureContext } = internalBinding('crypto');
+function SecureContext(secureProtocol, secureOptions, context,
+ minVersion, maxVersion) {
if (!(this instanceof SecureContext)) {
- return new SecureContext(secureProtocol, secureOptions, context);
+ return new SecureContext(secureProtocol, secureOptions, context,
+ minVersion, maxVersion);
}
if (context) {
@@ -47,10 +63,15 @@ function SecureContext(secureProtocol, secureOptions, context) {
this.context = new NativeSecureContext();
if (secureProtocol) {
- this.context.init(secureProtocol);
- } else {
- this.context.init();
+ if (minVersion != null)
+ throw new ERR_TLS_PROTOCOL_VERSION_CONFLICT(minVersion, secureProtocol);
+ if (maxVersion != null)
+ throw new ERR_TLS_PROTOCOL_VERSION_CONFLICT(maxVersion, secureProtocol);
}
+
+ this.context.init(secureProtocol,
+ toV('minimum', minVersion, tls.DEFAULT_MIN_VERSION),
+ toV('maximum', maxVersion, tls.DEFAULT_MAX_VERSION));
}
if (secureOptions) this.context.setOptions(secureOptions);
@@ -76,7 +97,8 @@ exports.createSecureContext = function createSecureContext(options, context) {
if (options.honorCipherOrder)
secureOptions |= SSL_OP_CIPHER_SERVER_PREFERENCE;
- const c = new SecureContext(options.secureProtocol, secureOptions, context);
+ const c = new SecureContext(options.secureProtocol, secureOptions, context,
+ options.minVersion, options.maxVersion);
var i;
var val;
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
index 9bfdd4062fc762..88b7bad40255f1 100644
--- a/lib/_tls_wrap.js
+++ b/lib/_tls_wrap.js
@@ -877,6 +877,8 @@ function Server(options, listener) {
ciphers: this.ciphers,
ecdhCurve: this.ecdhCurve,
dhparam: this.dhparam,
+ minVersion: this.minVersion,
+ maxVersion: this.maxVersion,
secureProtocol: this.secureProtocol,
secureOptions: this.secureOptions,
honorCipherOrder: this.honorCipherOrder,
@@ -948,6 +950,8 @@ Server.prototype.setOptions = function(options) {
if (options.clientCertEngine)
this.clientCertEngine = options.clientCertEngine;
if (options.ca) this.ca = options.ca;
+ if (options.minVersion) this.minVersion = options.minVersion;
+ if (options.maxVersion) this.maxVersion = options.maxVersion;
if (options.secureProtocol) this.secureProtocol = options.secureProtocol;
if (options.crl) this.crl = options.crl;
if (options.ciphers) this.ciphers = options.ciphers;
diff --git a/lib/https.js b/lib/https.js
index c1053da1a13eb6..6f31315a559ef9 100644
--- a/lib/https.js
+++ b/lib/https.js
@@ -188,6 +188,14 @@ Agent.prototype.getName = function getName(options) {
if (options.servername && options.servername !== options.host)
name += options.servername;
+ name += ':';
+ if (options.minVersion)
+ name += options.minVersion;
+
+ name += ':';
+ if (options.maxVersion)
+ name += options.maxVersion;
+
name += ':';
if (options.secureProtocol)
name += options.secureProtocol;
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 71b4a87ca0d86f..b2eb16c1f854b3 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -870,6 +870,10 @@ E('ERR_TLS_CERT_ALTNAME_INVALID',
'Hostname/IP does not match certificate\'s altnames: %s', Error);
E('ERR_TLS_DH_PARAM_SIZE', 'DH parameter size %s is less than 2048', Error);
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout', Error);
+E('ERR_TLS_INVALID_PROTOCOL_VERSION',
+ '%j is not a valid %s TLS protocol version', TypeError);
+E('ERR_TLS_PROTOCOL_VERSION_CONFLICT',
+ 'TLS protocol version %j conflicts with secureProtocol %j', TypeError);
E('ERR_TLS_RENEGOTIATE', 'Attempt to renegotiate TLS session failed', Error);
E('ERR_TLS_RENEGOTIATION_DISABLED',
'TLS session renegotiation disabled for this socket', Error);
diff --git a/lib/tls.js b/lib/tls.js
index b8de6efc8e402d..1e8686c8efa315 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -52,6 +52,10 @@ exports.DEFAULT_CIPHERS =
exports.DEFAULT_ECDH_CURVE = 'auto';
+exports.DEFAULT_MAX_VERSION = 'TLSv1.2';
+
+exports.DEFAULT_MIN_VERSION = 'TLSv1';
+
exports.getCiphers = internalUtil.cachedResult(
() => internalUtil.filterDuplicateStrings(binding.getSSLCiphers(), true)
);
diff --git a/src/node_constants.cc b/src/node_constants.cc
index 753b8f8fe16602..9cd50fe4e9e87b 100644
--- a/src/node_constants.cc
+++ b/src/node_constants.cc
@@ -1237,6 +1237,10 @@ void DefineCryptoConstants(Local