@@ -1960,14 +1960,17 @@ int SSLWrap<Base>::AdvertiseNextProtoCallback(SSL* s,
1960
1960
HandleScope handle_scope (env->isolate ());
1961
1961
Context::Scope context_scope (env->context ());
1962
1962
1963
- if (w->npn_protos_ .IsEmpty ()) {
1963
+ Local<Value> npn_buffer =
1964
+ w->object ()->GetHiddenValue (env->npn_buffer_string ());
1965
+
1966
+ if (npn_buffer.IsEmpty ()) {
1964
1967
// No initialization - no NPN protocols
1965
1968
*data = reinterpret_cast <const unsigned char *>(" " );
1966
1969
*len = 0 ;
1967
1970
} else {
1968
- Local<Object> obj = PersistentToLocal (env-> isolate (), w-> npn_protos_ );
1969
- *data = reinterpret_cast <const unsigned char *>(Buffer::Data (obj ));
1970
- *len = Buffer::Length (obj );
1971
+ CHECK ( Buffer::HasInstance (npn_buffer) );
1972
+ *data = reinterpret_cast <const unsigned char *>(Buffer::Data (npn_buffer ));
1973
+ *len = Buffer::Length (npn_buffer );
1971
1974
}
1972
1975
1973
1976
return SSL_TLSEXT_ERR_OK;
@@ -1986,25 +1989,27 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s,
1986
1989
HandleScope handle_scope (env->isolate ());
1987
1990
Context::Scope context_scope (env->context ());
1988
1991
1989
- // Release old protocol handler if present
1990
- w->selected_npn_proto_ . Reset ( );
1992
+ Local<Value> npn_buffer =
1993
+ w->object ()-> GetHiddenValue (env-> npn_buffer_string () );
1991
1994
1992
- if (w-> npn_protos_ .IsEmpty ()) {
1995
+ if (npn_buffer .IsEmpty ()) {
1993
1996
// We should at least select one protocol
1994
1997
// If server is using NPN
1995
1998
*out = reinterpret_cast <unsigned char *>(const_cast <char *>(" http/1.1" ));
1996
1999
*outlen = 8 ;
1997
2000
1998
2001
// set status: unsupported
1999
- w->selected_npn_proto_ .Reset (env->isolate (), False (env->isolate ()));
2002
+ bool r = w->object ()->SetHiddenValue (env->selected_npn_buffer_string (),
2003
+ False (env->isolate ()));
2004
+ CHECK (r);
2000
2005
2001
2006
return SSL_TLSEXT_ERR_OK;
2002
2007
}
2003
2008
2004
- Local<Object> obj = PersistentToLocal (env-> isolate (), w-> npn_protos_ );
2009
+ CHECK ( Buffer::HasInstance (npn_buffer) );
2005
2010
const unsigned char * npn_protos =
2006
- reinterpret_cast <const unsigned char *>(Buffer::Data (obj ));
2007
- size_t len = Buffer::Length (obj );
2011
+ reinterpret_cast <const unsigned char *>(Buffer::Data (npn_buffer ));
2012
+ size_t len = Buffer::Length (npn_buffer );
2008
2013
2009
2014
int status = SSL_select_next_proto (out, outlen, in, inlen, npn_protos, len);
2010
2015
Local<Value> result;
@@ -2022,8 +2027,9 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s,
2022
2027
break ;
2023
2028
}
2024
2029
2025
- if (!result.IsEmpty ())
2026
- w->selected_npn_proto_ .Reset (env->isolate (), result);
2030
+ bool r = w->object ()->SetHiddenValue (env->selected_npn_buffer_string (),
2031
+ result);
2032
+ CHECK (r);
2027
2033
2028
2034
return SSL_TLSEXT_ERR_OK;
2029
2035
}
@@ -2036,9 +2042,12 @@ void SSLWrap<Base>::GetNegotiatedProto(
2036
2042
ASSIGN_OR_RETURN_UNWRAP (&w, args.Holder ());
2037
2043
2038
2044
if (w->is_client ()) {
2039
- if (w->selected_npn_proto_ .IsEmpty () == false ) {
2040
- args.GetReturnValue ().Set (w->selected_npn_proto_ );
2041
- }
2045
+ Local<Value> selected_npn_buffer =
2046
+ w->object ()->GetHiddenValue (w->env ()->selected_npn_buffer_string ());
2047
+
2048
+ if (selected_npn_buffer.IsEmpty () == false )
2049
+ args.GetReturnValue ().Set (selected_npn_buffer);
2050
+
2042
2051
return ;
2043
2052
}
2044
2053
@@ -2062,9 +2071,11 @@ void SSLWrap<Base>::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
2062
2071
Environment* env = w->ssl_env ();
2063
2072
2064
2073
if (args.Length () < 1 || !Buffer::HasInstance (args[0 ]))
2065
- return w-> env () ->ThrowTypeError (" Must give a Buffer as first argument" );
2074
+ return env->ThrowTypeError (" Must give a Buffer as first argument" );
2066
2075
2067
- w->npn_protos_ .Reset (args.GetIsolate (), args[0 ].As <Object>());
2076
+ Local<Value> npn_buffer = Local<Value>::New (env->isolate (), args[0 ]);
2077
+ bool r = w->object ()->SetHiddenValue (env->npn_buffer_string (), npn_buffer);
2078
+ CHECK (r);
2068
2079
}
2069
2080
#endif // OPENSSL_NPN_NEGOTIATED
2070
2081
0 commit comments