Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5029f41

Browse filesBrowse files
Shigeki Ohtsurvagg
authored andcommitted
tls,crypto: move NPN protcol data to hidden value
This fix is to be consistent implementation with ALPN. Tow NPN protocol data in the persistent memebers move to hidden variables in the wrap object. PR-URL: #2564 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 62ad1d0 commit 5029f41
Copy full SHA for 5029f41

File tree

Expand file treeCollapse file tree

3 files changed

+32
-27
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+32
-27
lines changed
Open diff view settings
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ namespace node {
131131
V(netmask_string, "netmask") \
132132
V(nice_string, "nice") \
133133
V(nlink_string, "nlink") \
134+
V(npn_buffer_string, "npnBuffer") \
134135
V(nsname_string, "nsname") \
135136
V(ocsp_request_string, "OCSPRequest") \
136137
V(offset_string, "offset") \
@@ -181,6 +182,7 @@ namespace node {
181182
V(serial_string, "serial") \
182183
V(scavenge_string, "scavenge") \
183184
V(scopeid_string, "scopeid") \
185+
V(selected_npn_buffer_string, "selectedNpnBuffer") \
184186
V(sent_shutdown_string, "sentShutdown") \
185187
V(serial_number_string, "serialNumber") \
186188
V(service_string, "service") \
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+30-18Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,14 +1917,17 @@ int SSLWrap<Base>::AdvertiseNextProtoCallback(SSL* s,
19171917
HandleScope handle_scope(env->isolate());
19181918
Context::Scope context_scope(env->context());
19191919

1920-
if (w->npn_protos_.IsEmpty()) {
1920+
Local<Value> npn_buffer =
1921+
w->object()->GetHiddenValue(env->npn_buffer_string());
1922+
1923+
if (npn_buffer.IsEmpty()) {
19211924
// No initialization - no NPN protocols
19221925
*data = reinterpret_cast<const unsigned char*>("");
19231926
*len = 0;
19241927
} else {
1925-
Local<Object> obj = PersistentToLocal(env->isolate(), w->npn_protos_);
1926-
*data = reinterpret_cast<const unsigned char*>(Buffer::Data(obj));
1927-
*len = Buffer::Length(obj);
1928+
CHECK(Buffer::HasInstance(npn_buffer));
1929+
*data = reinterpret_cast<const unsigned char*>(Buffer::Data(npn_buffer));
1930+
*len = Buffer::Length(npn_buffer);
19281931
}
19291932

19301933
return SSL_TLSEXT_ERR_OK;
@@ -1943,25 +1946,27 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s,
19431946
HandleScope handle_scope(env->isolate());
19441947
Context::Scope context_scope(env->context());
19451948

1946-
// Release old protocol handler if present
1947-
w->selected_npn_proto_.Reset();
1949+
Local<Value> npn_buffer =
1950+
w->object()->GetHiddenValue(env->npn_buffer_string());
19481951

1949-
if (w->npn_protos_.IsEmpty()) {
1952+
if (npn_buffer.IsEmpty()) {
19501953
// We should at least select one protocol
19511954
// If server is using NPN
19521955
*out = reinterpret_cast<unsigned char*>(const_cast<char*>("http/1.1"));
19531956
*outlen = 8;
19541957

19551958
// set status: unsupported
1956-
w->selected_npn_proto_.Reset(env->isolate(), False(env->isolate()));
1959+
bool r = w->object()->SetHiddenValue(env->selected_npn_buffer_string(),
1960+
False(env->isolate()));
1961+
CHECK(r);
19571962

19581963
return SSL_TLSEXT_ERR_OK;
19591964
}
19601965

1961-
Local<Object> obj = PersistentToLocal(env->isolate(), w->npn_protos_);
1966+
CHECK(Buffer::HasInstance(npn_buffer));
19621967
const unsigned char* npn_protos =
1963-
reinterpret_cast<const unsigned char*>(Buffer::Data(obj));
1964-
size_t len = Buffer::Length(obj);
1968+
reinterpret_cast<const unsigned char*>(Buffer::Data(npn_buffer));
1969+
size_t len = Buffer::Length(npn_buffer);
19651970

19661971
int status = SSL_select_next_proto(out, outlen, in, inlen, npn_protos, len);
19671972
Local<Value> result;
@@ -1979,8 +1984,9 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s,
19791984
break;
19801985
}
19811986

1982-
if (!result.IsEmpty())
1983-
w->selected_npn_proto_.Reset(env->isolate(), result);
1987+
bool r = w->object()->SetHiddenValue(env->selected_npn_buffer_string(),
1988+
result);
1989+
CHECK(r);
19841990

19851991
return SSL_TLSEXT_ERR_OK;
19861992
}
@@ -1992,9 +1998,12 @@ void SSLWrap<Base>::GetNegotiatedProto(
19921998
Base* w = Unwrap<Base>(args.Holder());
19931999

19942000
if (w->is_client()) {
1995-
if (w->selected_npn_proto_.IsEmpty() == false) {
1996-
args.GetReturnValue().Set(w->selected_npn_proto_);
1997-
}
2001+
Local<Value> selected_npn_buffer =
2002+
w->object()->GetHiddenValue(w->env()->selected_npn_buffer_string());
2003+
2004+
if (selected_npn_buffer.IsEmpty() == false)
2005+
args.GetReturnValue().Set(selected_npn_buffer);
2006+
19982007
return;
19992008
}
20002009

@@ -2014,11 +2023,14 @@ void SSLWrap<Base>::GetNegotiatedProto(
20142023
template <class Base>
20152024
void SSLWrap<Base>::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
20162025
Base* w = Unwrap<Base>(args.Holder());
2026+
Environment* env = w->env();
20172027

20182028
if (args.Length() < 1 || !Buffer::HasInstance(args[0]))
2019-
return w->env()->ThrowTypeError("Must give a Buffer as first argument");
2029+
return env->ThrowTypeError("Must give a Buffer as first argument");
20202030

2021-
w->npn_protos_.Reset(args.GetIsolate(), args[0].As<Object>());
2031+
Local<Value> npn_buffer = Local<Value>::New(env->isolate(), args[0]);
2032+
bool r = w->object()->SetHiddenValue(env->npn_buffer_string(), npn_buffer);
2033+
CHECK(r);
20222034
}
20232035
#endif // OPENSSL_NPN_NEGOTIATED
20242036

Collapse file

‎src/node_crypto.h‎

Copy file name to clipboardExpand all lines: src/node_crypto.h
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ class SSLWrap {
178178
next_sess_ = nullptr;
179179
}
180180

181-
#ifdef OPENSSL_NPN_NEGOTIATED
182-
npn_protos_.Reset();
183-
selected_npn_proto_.Reset();
184-
#endif
185181
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
186182
sni_context_.Reset();
187183
#endif
@@ -298,11 +294,6 @@ class SSLWrap {
298294
v8::Persistent<v8::Object> ocsp_response_;
299295
#endif // NODE__HAVE_TLSEXT_STATUS_CB
300296

301-
#ifdef OPENSSL_NPN_NEGOTIATED
302-
v8::Persistent<v8::Object> npn_protos_;
303-
v8::Persistent<v8::Value> selected_npn_proto_;
304-
#endif // OPENSSL_NPN_NEGOTIATED
305-
306297
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
307298
v8::Persistent<v8::Value> sni_context_;
308299
#endif

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.