Skip to content

Commit a657984

Browse files
bnoordhuistargos
authored andcommitted
lib,src: remove openssl feature conditionals
Remove compile-time and run-time conditionals for features that OpenSSL 1.0.0 and 1.0.1 didn't support: ALPN, OCSP and/or SNI. They are no longer necessary since our baseline is OpenSSL 1.0.2. PR-URL: #21094 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 17954c2 commit a657984

13 files changed

+13
-99
lines changed

lib/_tls_wrap.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,7 @@ TLSSocket.prototype._init = function(socket, wrap) {
512512
// If custom SNICallback was given, or if
513513
// there're SNI contexts to perform match against -
514514
// set `.onsniselect` callback.
515-
if (process.features.tls_sni &&
516-
options.isServer &&
515+
if (options.isServer &&
517516
options.SNICallback &&
518517
(options.SNICallback !== SNICallback ||
519518
(options.server && options.server._contexts.length))) {
@@ -522,7 +521,7 @@ TLSSocket.prototype._init = function(socket, wrap) {
522521
ssl.enableCertCb();
523522
}
524523

525-
if (process.features.tls_alpn && options.ALPNProtocols) {
524+
if (options.ALPNProtocols) {
526525
// keep reference in secureContext not to be GC-ed
527526
ssl._secureContext.alpnBuffer = options.ALPNProtocols;
528527
ssl.setALPNProtocols(ssl._secureContext.alpnBuffer);
@@ -620,15 +619,9 @@ TLSSocket.prototype._releaseControl = function() {
620619
};
621620

622621
TLSSocket.prototype._finishInit = function() {
623-
if (process.features.tls_alpn) {
624-
this.alpnProtocol = this._handle.getALPNNegotiatedProtocol();
625-
}
626-
627-
if (process.features.tls_sni) {
628-
this.servername = this._handle.getServername();
629-
}
630-
631622
debug('secure established');
623+
this.alpnProtocol = this._handle.getALPNNegotiatedProtocol();
624+
this.servername = this._handle.getServername();
632625
this._secureEstablished = true;
633626
if (this._tlsOptions.handshakeTimeout > 0)
634627
this.setTimeout(0, this._handleTimeout);

lib/https.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function Server(opts, requestListener) {
4949
}
5050
opts = util._extend({}, opts);
5151

52-
if (process.features.tls_alpn && !opts.ALPNProtocols) {
52+
if (!opts.ALPNProtocols) {
5353
// http/1.0 is not defined as Protocol IDs in IANA
5454
// http://www.iana.org/assignments/tls-extensiontype-values
5555
// /tls-extensiontype-values.xhtml#alpn-protocol-ids

src/node.cc

+7-21
Original file line numberDiff line numberDiff line change
@@ -2383,30 +2383,16 @@ static Local<Object> GetFeatures(Environment* env) {
23832383
// TODO(bnoordhuis) ping libuv
23842384
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate()));
23852385

2386-
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
2387-
Local<Boolean> tls_alpn = True(env->isolate());
2386+
#ifdef HAVE_OPENSSL
2387+
Local<Boolean> have_openssl = True(env->isolate());
23882388
#else
2389-
Local<Boolean> tls_alpn = False(env->isolate());
2389+
Local<Boolean> have_openssl = False(env->isolate());
23902390
#endif
2391-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"), tls_alpn);
23922391

2393-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
2394-
Local<Boolean> tls_sni = True(env->isolate());
2395-
#else
2396-
Local<Boolean> tls_sni = False(env->isolate());
2397-
#endif
2398-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"), tls_sni);
2399-
2400-
#if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_set_tlsext_status_cb)
2401-
Local<Boolean> tls_ocsp = True(env->isolate());
2402-
#else
2403-
Local<Boolean> tls_ocsp = False(env->isolate());
2404-
#endif // !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_set_tlsext_status_cb)
2405-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"), tls_ocsp);
2406-
2407-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
2408-
Boolean::New(env->isolate(),
2409-
get_builtin_module("crypto") != nullptr));
2392+
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"), have_openssl);
2393+
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"), have_openssl);
2394+
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"), have_openssl);
2395+
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls"), have_openssl);
24102396

24112397
return scope.Escape(obj);
24122398
}

src/node_crypto.cc

+1-26
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,17 @@ template int SSLWrap<TLSWrap>::NewSessionCallback(SSL* s,
133133
template void SSLWrap<TLSWrap>::OnClientHello(
134134
void* arg,
135135
const ClientHelloParser::ClientHello& hello);
136-
137-
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
138136
template int SSLWrap<TLSWrap>::TLSExtStatusCallback(SSL* s, void* arg);
139-
#endif
140-
141137
template void SSLWrap<TLSWrap>::DestroySSL();
142138
template int SSLWrap<TLSWrap>::SSLCertCallback(SSL* s, void* arg);
143139
template void SSLWrap<TLSWrap>::WaitForCertCb(CertCb cb, void* arg);
144-
145-
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
146140
template int SSLWrap<TLSWrap>::SelectALPNCallback(
147141
SSL* s,
148142
const unsigned char** out,
149143
unsigned char* outlen,
150144
const unsigned char* in,
151145
unsigned int inlen,
152146
void* arg);
153-
#endif // TLSEXT_TYPE_application_layer_protocol_negotiation
154147

155148

156149
static int PasswordCallback(char* buf, int size, int rwflag, void* u) {
@@ -1387,11 +1380,9 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
13871380

13881381
template <class Base>
13891382
void SSLWrap<Base>::ConfigureSecureContext(SecureContext* sc) {
1390-
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
13911383
// OCSP stapling
13921384
SSL_CTX_set_tlsext_status_cb(sc->ctx_.get(), TLSExtStatusCallback);
13931385
SSL_CTX_set_tlsext_status_arg(sc->ctx_.get(), nullptr);
1394-
#endif // NODE__HAVE_TLSEXT_STATUS_CB
13951386
}
13961387

13971388

@@ -2019,7 +2010,6 @@ void SSLWrap<Base>::NewSessionDone(const FunctionCallbackInfo<Value>& args) {
20192010

20202011
template <class Base>
20212012
void SSLWrap<Base>::SetOCSPResponse(const FunctionCallbackInfo<Value>& args) {
2022-
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
20232013
Base* w;
20242014
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
20252015
Environment* env = w->env();
@@ -2030,18 +2020,15 @@ void SSLWrap<Base>::SetOCSPResponse(const FunctionCallbackInfo<Value>& args) {
20302020
THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "OCSP response");
20312021

20322022
w->ocsp_response_.Reset(args.GetIsolate(), args[0].As<Object>());
2033-
#endif // NODE__HAVE_TLSEXT_STATUS_CB
20342023
}
20352024

20362025

20372026
template <class Base>
20382027
void SSLWrap<Base>::RequestOCSP(const FunctionCallbackInfo<Value>& args) {
2039-
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
20402028
Base* w;
20412029
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
20422030

20432031
SSL_set_tlsext_status_type(w->ssl_.get(), TLSEXT_STATUSTYPE_ocsp);
2044-
#endif // NODE__HAVE_TLSEXT_STATUS_CB
20452032
}
20462033

20472034

@@ -2226,7 +2213,6 @@ void SSLWrap<Base>::GetProtocol(const FunctionCallbackInfo<Value>& args) {
22262213
}
22272214

22282215

2229-
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
22302216
template <class Base>
22312217
int SSLWrap<Base>::SelectALPNCallback(SSL* s,
22322218
const unsigned char** out,
@@ -2256,13 +2242,11 @@ int SSLWrap<Base>::SelectALPNCallback(SSL* s,
22562242
return status == OPENSSL_NPN_NEGOTIATED ? SSL_TLSEXT_ERR_OK
22572243
: SSL_TLSEXT_ERR_NOACK;
22582244
}
2259-
#endif // TLSEXT_TYPE_application_layer_protocol_negotiation
22602245

22612246

22622247
template <class Base>
22632248
void SSLWrap<Base>::GetALPNNegotiatedProto(
22642249
const FunctionCallbackInfo<Value>& args) {
2265-
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
22662250
Base* w;
22672251
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
22682252

@@ -2276,13 +2260,11 @@ void SSLWrap<Base>::GetALPNNegotiatedProto(
22762260

22772261
args.GetReturnValue().Set(
22782262
OneByteString(args.GetIsolate(), alpn_proto, alpn_proto_len));
2279-
#endif // TLSEXT_TYPE_application_layer_protocol_negotiation
22802263
}
22812264

22822265

22832266
template <class Base>
22842267
void SSLWrap<Base>::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) {
2285-
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
22862268
Base* w;
22872269
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
22882270
Environment* env = w->env();
@@ -2306,11 +2288,9 @@ void SSLWrap<Base>::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) {
23062288
SelectALPNCallback,
23072289
nullptr);
23082290
}
2309-
#endif // TLSEXT_TYPE_application_layer_protocol_negotiation
23102291
}
23112292

23122293

2313-
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
23142294
template <class Base>
23152295
int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) {
23162296
Base* w = static_cast<Base*>(SSL_get_app_data(s));
@@ -2354,7 +2334,6 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) {
23542334
return SSL_TLSEXT_ERR_OK;
23552335
}
23562336
}
2357-
#endif // NODE__HAVE_TLSEXT_STATUS_CB
23582337

23592338

23602339
template <class Base>
@@ -2396,11 +2375,7 @@ int SSLWrap<Base>::SSLCertCallback(SSL* s, void* arg) {
23962375
info->Set(context, env->servername_string(), str).FromJust();
23972376
}
23982377

2399-
bool ocsp = false;
2400-
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
2401-
ocsp = SSL_get_tlsext_status_type(s) == TLSEXT_STATUSTYPE_ocsp;
2402-
#endif
2403-
2378+
const bool ocsp = (SSL_get_tlsext_status_type(s) == TLSEXT_STATUSTYPE_ocsp);
24042379
info->Set(context, env->ocsp_request_string(),
24052380
Boolean::New(env->isolate(), ocsp)).FromJust();
24062381

src/node_crypto.h

-9
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
#include <openssl/rand.h>
5454
#include <openssl/pkcs12.h>
5555

56-
#if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_set_tlsext_status_cb)
57-
# define NODE__HAVE_TLSEXT_STATUS_CB
58-
#endif // !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_set_tlsext_status_cb)
59-
6056
namespace node {
6157
namespace crypto {
6258

@@ -331,13 +327,8 @@ class SSLWrap {
331327

332328
ClientHelloParser hello_parser_;
333329

334-
#ifdef NODE__HAVE_TLSEXT_STATUS_CB
335330
Persistent<v8::Object> ocsp_response_;
336-
#endif // NODE__HAVE_TLSEXT_STATUS_CB
337-
338-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
339331
Persistent<v8::Value> sni_context_;
340-
#endif
341332

342333
friend class SecureContext;
343334
};

src/tls_wrap.cc

-8
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,10 @@ void TLSWrap::InitSSL() {
131131
SSL_set_app_data(ssl_.get(), this);
132132
SSL_set_info_callback(ssl_.get(), SSLInfoCallback);
133133

134-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
135134
if (is_server()) {
136135
SSL_CTX_set_tlsext_servername_callback(sc_->ctx_.get(),
137136
SelectSNIContextCallback);
138137
}
139-
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
140138

141139
ConfigureSecureContext(sc_);
142140

@@ -779,7 +777,6 @@ void TLSWrap::OnClientHelloParseEnd(void* arg) {
779777
}
780778

781779

782-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
783780
void TLSWrap::GetServername(const FunctionCallbackInfo<Value>& args) {
784781
Environment* env = Environment::GetCurrent(args);
785782

@@ -811,10 +808,8 @@ void TLSWrap::SetServername(const FunctionCallbackInfo<Value>& args) {
811808

812809
CHECK_NOT_NULL(wrap->ssl_);
813810

814-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
815811
node::Utf8Value servername(env->isolate(), args[0].As<String>());
816812
SSL_set_tlsext_host_name(wrap->ssl_.get(), *servername);
817-
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
818813
}
819814

820815

@@ -853,7 +848,6 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
853848
p->SetSNIContext(sc);
854849
return SSL_TLSEXT_ERR_OK;
855850
}
856-
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
857851

858852

859853
void TLSWrap::GetWriteQueueSize(const FunctionCallbackInfo<Value>& info) {
@@ -904,10 +898,8 @@ void TLSWrap::Initialize(Local<Object> target,
904898
StreamBase::AddMethods<TLSWrap>(env, t, StreamBase::kFlagHasWritev);
905899
SSLWrap<TLSWrap>::AddMethods(env, t);
906900

907-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
908901
env->SetProtoMethod(t, "getServername", GetServername);
909902
env->SetProtoMethod(t, "setServername", SetServername);
910-
#endif // SSL_CRT_SET_TLSEXT_SERVERNAME_CB
911903

912904
env->set_tls_wrap_constructor_function(t->GetFunction());
913905

src/tls_wrap.h

-3
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,9 @@ class TLSWrap : public AsyncWrap,
138138
static void EnableCertCb(
139139
const v8::FunctionCallbackInfo<v8::Value>& args);
140140
static void DestroySSL(const v8::FunctionCallbackInfo<v8::Value>& args);
141-
142-
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
143141
static void GetServername(const v8::FunctionCallbackInfo<v8::Value>& args);
144142
static void SetServername(const v8::FunctionCallbackInfo<v8::Value>& args);
145143
static int SelectSNIContextCallback(SSL* s, int* ad, void* arg);
146-
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
147144

148145
crypto::SecureContext* sc_;
149146
BIO* enc_in_;

test/parallel/test-tls-alpn-server-client.js

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
66

7-
if (!process.features.tls_alpn) {
8-
common.skip(
9-
'Skipping because node compiled without ALPN feature of OpenSSL.');
10-
}
11-
127
const assert = require('assert');
138
const tls = require('tls');
149
const fixtures = require('../common/fixtures');

test/parallel/test-tls-empty-sni-context.js

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
66

7-
if (!process.features.tls_sni)
8-
common.skip('node compiled without OpenSSL or with old OpenSSL version.');
9-
107
const assert = require('assert');
118
const tls = require('tls');
129

test/parallel/test-tls-ocsp-callback.js

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
'use strict';
2323
const common = require('../common');
2424

25-
if (!process.features.tls_ocsp)
26-
common.skip('node compiled without OpenSSL or with old OpenSSL version.');
27-
2825
if (!common.opensslCli)
2926
common.skip('node compiled without OpenSSL CLI.');
3027

test/parallel/test-tls-sni-option.js

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ const common = require('../common');
2424
if (!common.hasCrypto)
2525
common.skip('missing crypto');
2626

27-
if (!process.features.tls_sni)
28-
common.skip('node compiled without OpenSSL or with old OpenSSL version.');
29-
3027
const assert = require('assert');
3128
const tls = require('tls');
3229
const fixtures = require('../common/fixtures');

test/parallel/test-tls-sni-server-client.js

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ const common = require('../common');
2424
if (!common.hasCrypto)
2525
common.skip('missing crypto');
2626

27-
if (!process.features.tls_sni)
28-
common.skip('node compiled without OpenSSL or with old OpenSSL version.');
29-
3027
const assert = require('assert');
3128
const tls = require('tls');
3229
const fixtures = require('../common/fixtures');

test/parallel/test-tls-socket-constructor-alpn-options-parsing.js

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ new tls.TLSSocket(null, {
1313
ALPNProtocols: ['http/1.1'],
1414
});
1515

16-
if (!process.features.tls_alpn)
17-
common.skip('node compiled without ALPN feature of OpenSSL');
18-
1916
const assert = require('assert');
2017
const net = require('net');
2118
const fixtures = require('../common/fixtures');

0 commit comments

Comments
 (0)