@@ -1917,14 +1917,17 @@ int SSLWrap<Base>::AdvertiseNextProtoCallback(SSL* s,
1917
1917
HandleScope handle_scope (env->isolate ());
1918
1918
Context::Scope context_scope (env->context ());
1919
1919
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 ()) {
1921
1924
// No initialization - no NPN protocols
1922
1925
*data = reinterpret_cast <const unsigned char *>(" " );
1923
1926
*len = 0 ;
1924
1927
} 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 );
1928
1931
}
1929
1932
1930
1933
return SSL_TLSEXT_ERR_OK;
@@ -1943,25 +1946,27 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s,
1943
1946
HandleScope handle_scope (env->isolate ());
1944
1947
Context::Scope context_scope (env->context ());
1945
1948
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 () );
1948
1951
1949
- if (w-> npn_protos_ .IsEmpty ()) {
1952
+ if (npn_buffer .IsEmpty ()) {
1950
1953
// We should at least select one protocol
1951
1954
// If server is using NPN
1952
1955
*out = reinterpret_cast <unsigned char *>(const_cast <char *>(" http/1.1" ));
1953
1956
*outlen = 8 ;
1954
1957
1955
1958
// 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);
1957
1962
1958
1963
return SSL_TLSEXT_ERR_OK;
1959
1964
}
1960
1965
1961
- Local<Object> obj = PersistentToLocal (env-> isolate (), w-> npn_protos_ );
1966
+ CHECK ( Buffer::HasInstance (npn_buffer) );
1962
1967
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 );
1965
1970
1966
1971
int status = SSL_select_next_proto (out, outlen, in, inlen, npn_protos, len);
1967
1972
Local<Value> result;
@@ -1979,8 +1984,9 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s,
1979
1984
break ;
1980
1985
}
1981
1986
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);
1984
1990
1985
1991
return SSL_TLSEXT_ERR_OK;
1986
1992
}
@@ -1992,9 +1998,12 @@ void SSLWrap<Base>::GetNegotiatedProto(
1992
1998
Base* w = Unwrap<Base>(args.Holder ());
1993
1999
1994
2000
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
+
1998
2007
return ;
1999
2008
}
2000
2009
@@ -2014,11 +2023,14 @@ void SSLWrap<Base>::GetNegotiatedProto(
2014
2023
template <class Base >
2015
2024
void SSLWrap<Base>::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
2016
2025
Base* w = Unwrap<Base>(args.Holder ());
2026
+ Environment* env = w->env ();
2017
2027
2018
2028
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" );
2020
2030
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);
2022
2034
}
2023
2035
#endif // OPENSSL_NPN_NEGOTIATED
2024
2036
0 commit comments