Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap');
const {
SecureContext: NativeSecureContext
} = process.binding('crypto');
const {
tlsALPN,
tlsSNI
} = process.binding('config');
const {
ERR_INVALID_ARG_TYPE,
ERR_MULTIPLE_CALLBACK,
Expand Down Expand Up @@ -512,7 +516,7 @@ TLSSocket.prototype._init = function(socket, wrap) {
// If custom SNICallback was given, or if
// there're SNI contexts to perform match against -
// set `.onsniselect` callback.
if (process.features.tls_sni &&
if (tlsSNI &&
options.isServer &&
options.SNICallback &&
(options.SNICallback !== SNICallback ||
Expand All @@ -522,7 +526,7 @@ TLSSocket.prototype._init = function(socket, wrap) {
ssl.enableCertCb();
}

if (process.features.tls_alpn && options.ALPNProtocols) {
if (tlsALPN && options.ALPNProtocols) {
// keep reference in secureContext not to be GC-ed
ssl._secureContext.alpnBuffer = options.ALPNProtocols;
ssl.setALPNProtocols(ssl._secureContext.alpnBuffer);
Expand Down Expand Up @@ -620,11 +624,11 @@ TLSSocket.prototype._releaseControl = function() {
};

TLSSocket.prototype._finishInit = function() {
if (process.features.tls_alpn) {
if (tlsALPN) {
this.alpnProtocol = this._handle.getALPNNegotiatedProtocol();
}

if (process.features.tls_sni) {
if (tlsSNI) {
this.servername = this._handle.getServername();
}

Expand Down
3 changes: 2 additions & 1 deletion lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const {
Server: HttpServer,
_connectionListener
} = require('_http_server');
const { tlsALPN } = process.binding('config');
const { ClientRequest } = require('_http_client');
const { inherits } = util;
const debug = util.debuglog('https');
Expand All @@ -48,7 +49,7 @@ function Server(opts, requestListener) {
}
opts = util._extend({}, opts);

if (process.features.tls_alpn && !opts.ALPNProtocols) {
if (tlsALPN && !opts.ALPNProtocols) {
// http/1.0 is not defined as Protocol IDs in IANA
// http://www.iana.org/assignments/tls-extensiontype-values
// /tls-extensiontype-values.xhtml#alpn-protocol-ids
Expand Down
40 changes: 21 additions & 19 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2456,44 +2456,46 @@ static void GetParentProcessId(Local<Name> property,


static Local<Object> GetFeatures(Environment* env) {
EscapableHandleScope scope(env->isolate());
Isolate* isolate = env->isolate();
EscapableHandleScope scope(isolate);
Local<Boolean> true_value = True(isolate);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these two separate variables instead of using True(isolate) and False(isolate) inline like before?

Local<Boolean> false_value = False(isolate);

Local<Object> obj = Object::New(env->isolate());
Local<Object> obj = Object::New(isolate);
#if defined(DEBUG) && DEBUG
Local<Value> debug = True(env->isolate());
Local<Boolean> debug = true_value;
#else
Local<Value> debug = False(env->isolate());
Local<Boolean> debug = false_value;
Copy link
Contributor

@mscdex mscdex Jun 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making this change multiple times, what if we instead removed the temporary variables instead and just set the values directly in the obj->Set() calls? For example:

obj->Set(FIXED_ONE_BYTE_STRING(isolate, "debug"),
#if defined(DEBUG) && DEBUG
         True(isolate)
#else
         False(isolate)
#endif
        );

or something similar or maybe even write a macro for this?

#endif // defined(DEBUG) && DEBUG
obj->Set(FIXED_ONE_BYTE_STRING(isolate, "debug"), debug);

obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "debug"), debug);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "uv"), True(env->isolate()));
obj->Set(FIXED_ONE_BYTE_STRING(isolate, "uv"), true_value);
// TODO(bnoordhuis) ping libuv
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate()));
obj->Set(FIXED_ONE_BYTE_STRING(isolate, "ipv6"), true_value);

#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
Local<Boolean> tls_alpn = True(env->isolate());
Local<Boolean> tls_alpn = true_value;
#else
Local<Boolean> tls_alpn = False(env->isolate());
Local<Boolean> tls_alpn = false_value;
#endif
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"), tls_alpn);
obj->Set(FIXED_ONE_BYTE_STRING(isolate, "tls_alpn"), tls_alpn);

#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
Local<Boolean> tls_sni = True(env->isolate());
Local<Boolean> tls_sni = true_value;
#else
Local<Boolean> tls_sni = False(env->isolate());
Local<Boolean> tls_sni = false_value;
#endif
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"), tls_sni);
obj->Set(FIXED_ONE_BYTE_STRING(isolate, "tls_sni"), tls_sni);

#if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_set_tlsext_status_cb)
Local<Boolean> tls_ocsp = True(env->isolate());
Local<Boolean> tls_ocsp = true_value;
#else
Local<Boolean> tls_ocsp = False(env->isolate());
Local<Boolean> tls_ocsp = false_value;
#endif // !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_set_tlsext_status_cb)
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"), tls_ocsp);
obj->Set(FIXED_ONE_BYTE_STRING(isolate, "tls_ocsp"), tls_ocsp);

obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
Boolean::New(env->isolate(),
get_builtin_module("crypto") != nullptr));
obj->Set(FIXED_ONE_BYTE_STRING(isolate, "tls"),
Boolean::New(isolate, get_builtin_module("crypto") != nullptr));

return scope.Escape(obj);
}
Expand Down
12 changes: 12 additions & 0 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "util-inl.h"
#include "node_debug_options.h"

#if HAVE_OPENSSL
#include "node_crypto.h"
#endif

namespace node {

using v8::Boolean;
Expand Down Expand Up @@ -48,6 +52,14 @@ static void Initialize(Local<Object> target,
READONLY_BOOLEAN_PROPERTY("fipsForced");
#endif

#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
READONLY_BOOLEAN_PROPERTY("tlsALPN");
#endif

#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
READONLY_BOOLEAN_PROPERTY("tlsSNI");
#endif

#ifdef NODE_HAVE_I18N_SUPPORT

READONLY_BOOLEAN_PROPERTY("hasIntl");
Expand Down