Browse Source

tls: fix macro to check NPN feature

In order to check if NPN feature is enabled, use
`#ifndef OPENSSL_NO_NEXTPROTONEG` rather than
`#ifdef OPENSSL_NPN_NEGOTIATED` because the former is used in ssl.h.

Fixes: https://github.com/nodejs/node/issues/11650
PR-URL: https://github.com/nodejs/node/pull/11655
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
v6
Shigeki Ohtsu 8 years ago
parent
commit
02c98f480c
  1. 2
      src/node.cc
  2. 2
      src/node_constants.cc
  3. 16
      src/node_crypto.cc
  4. 6
      src/node_crypto.h

2
src/node.cc

@ -2913,7 +2913,7 @@ static Local<Object> GetFeatures(Environment* env) {
// TODO(bnoordhuis) ping libuv // TODO(bnoordhuis) ping libuv
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate())); obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate()));
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
Local<Boolean> tls_npn = True(env->isolate()); Local<Boolean> tls_npn = True(env->isolate());
#else #else
Local<Boolean> tls_npn = False(env->isolate()); Local<Boolean> tls_npn = False(env->isolate());

2
src/node_constants.cc

@ -942,7 +942,7 @@ void DefineOpenSSLConstants(Local<Object> target) {
NODE_DEFINE_CONSTANT(target, DH_NOT_SUITABLE_GENERATOR); NODE_DEFINE_CONSTANT(target, DH_NOT_SUITABLE_GENERATOR);
#endif #endif
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
#define NPN_ENABLED 1 #define NPN_ENABLED 1
NODE_DEFINE_CONSTANT(target, NPN_ENABLED); NODE_DEFINE_CONSTANT(target, NPN_ENABLED);
#endif #endif

16
src/node_crypto.cc

@ -147,7 +147,7 @@ template void SSLWrap<TLSWrap>::OnClientHello(
void* arg, void* arg,
const ClientHelloParser::ClientHello& hello); const ClientHelloParser::ClientHello& hello);
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
template int SSLWrap<TLSWrap>::AdvertiseNextProtoCallback( template int SSLWrap<TLSWrap>::AdvertiseNextProtoCallback(
SSL* s, SSL* s,
const unsigned char** data, const unsigned char** data,
@ -1314,11 +1314,11 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
env->SetProtoMethod(t, "setMaxSendFragment", SetMaxSendFragment); env->SetProtoMethod(t, "setMaxSendFragment", SetMaxSendFragment);
#endif // SSL_set_max_send_fragment #endif // SSL_set_max_send_fragment
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
env->SetProtoMethod(t, "getNegotiatedProtocol", GetNegotiatedProto); env->SetProtoMethod(t, "getNegotiatedProtocol", GetNegotiatedProto);
#endif // OPENSSL_NPN_NEGOTIATED #endif // OPENSSL_NO_NEXTPROTONEG
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
env->SetProtoMethod(t, "setNPNProtocols", SetNPNProtocols); env->SetProtoMethod(t, "setNPNProtocols", SetNPNProtocols);
#endif #endif
@ -1338,7 +1338,7 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) {
template <class Base> template <class Base>
void SSLWrap<Base>::InitNPN(SecureContext* sc) { void SSLWrap<Base>::InitNPN(SecureContext* sc) {
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
// Server should advertise NPN protocols // Server should advertise NPN protocols
SSL_CTX_set_next_protos_advertised_cb(sc->ctx_, SSL_CTX_set_next_protos_advertised_cb(sc->ctx_,
AdvertiseNextProtoCallback, AdvertiseNextProtoCallback,
@ -1346,7 +1346,7 @@ void SSLWrap<Base>::InitNPN(SecureContext* sc) {
// Client should select protocol from list of advertised // Client should select protocol from list of advertised
// If server supports NPN // If server supports NPN
SSL_CTX_set_next_proto_select_cb(sc->ctx_, SelectNextProtoCallback, nullptr); SSL_CTX_set_next_proto_select_cb(sc->ctx_, SelectNextProtoCallback, nullptr);
#endif // OPENSSL_NPN_NEGOTIATED #endif // OPENSSL_NO_NEXTPROTONEG
#ifdef NODE__HAVE_TLSEXT_STATUS_CB #ifdef NODE__HAVE_TLSEXT_STATUS_CB
// OCSP stapling // OCSP stapling
@ -2091,7 +2091,7 @@ void SSLWrap<Base>::GetProtocol(const FunctionCallbackInfo<Value>& args) {
} }
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
template <class Base> template <class Base>
int SSLWrap<Base>::AdvertiseNextProtoCallback(SSL* s, int SSLWrap<Base>::AdvertiseNextProtoCallback(SSL* s,
const unsigned char** data, const unsigned char** data,
@ -2231,7 +2231,7 @@ void SSLWrap<Base>::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
env->npn_buffer_private_symbol(), env->npn_buffer_private_symbol(),
args[0]).FromJust()); args[0]).FromJust());
} }
#endif // OPENSSL_NPN_NEGOTIATED #endif // OPENSSL_NO_NEXTPROTONEG
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
template <class Base> template <class Base>

6
src/node_crypto.h

@ -249,7 +249,7 @@ class SSLWrap {
const v8::FunctionCallbackInfo<v8::Value>& args); const v8::FunctionCallbackInfo<v8::Value>& args);
#endif // SSL_set_max_send_fragment #endif // SSL_set_max_send_fragment
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
static void GetNegotiatedProto( static void GetNegotiatedProto(
const v8::FunctionCallbackInfo<v8::Value>& args); const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetNPNProtocols(const v8::FunctionCallbackInfo<v8::Value>& args); static void SetNPNProtocols(const v8::FunctionCallbackInfo<v8::Value>& args);
@ -263,7 +263,7 @@ class SSLWrap {
const unsigned char* in, const unsigned char* in,
unsigned int inlen, unsigned int inlen,
void* arg); void* arg);
#endif // OPENSSL_NPN_NEGOTIATED #endif // OPENSSL_NO_NEXTPROTONEG
static void GetALPNNegotiatedProto( static void GetALPNNegotiatedProto(
const v8::FunctionCallbackInfo<v8::Value>& args); const v8::FunctionCallbackInfo<v8::Value>& args);
@ -328,7 +328,7 @@ class Connection : public AsyncWrap, public SSLWrap<Connection> {
static void Initialize(Environment* env, v8::Local<v8::Object> target); static void Initialize(Environment* env, v8::Local<v8::Object> target);
void NewSessionDoneCb(); void NewSessionDoneCb();
#ifdef OPENSSL_NPN_NEGOTIATED #ifndef OPENSSL_NO_NEXTPROTONEG
v8::Persistent<v8::Object> npnProtos_; v8::Persistent<v8::Object> npnProtos_;
v8::Persistent<v8::Value> selectedNPNProto_; v8::Persistent<v8::Value> selectedNPNProto_;
#endif #endif

Loading…
Cancel
Save