@@ -225,26 +225,17 @@ int SelectALPNCallback(
225
225
const unsigned char * in,
226
226
unsigned int inlen,
227
227
void * arg) {
228
- TLSWrap* w = static_cast <TLSWrap*>(SSL_get_app_data (s));
229
- Environment* env = w->env ();
230
- HandleScope handle_scope (env->isolate ());
231
- Context::Scope context_scope (env->context ());
228
+ TLSWrap* w = static_cast <TLSWrap*>(arg);
229
+ const std::vector<unsigned char >& alpn_protos = w->alpn_protos_ ;
232
230
233
- Local<Value> alpn_buffer =
234
- w->object ()->GetPrivate (
235
- env->context (),
236
- env->alpn_buffer_private_symbol ()).FromMaybe (Local<Value>());
237
- if (UNLIKELY (alpn_buffer.IsEmpty ()) || !alpn_buffer->IsArrayBufferView ())
238
- return SSL_TLSEXT_ERR_NOACK;
231
+ if (alpn_protos.empty ()) return SSL_TLSEXT_ERR_NOACK;
239
232
240
- ArrayBufferViewContents<unsigned char > alpn_protos (alpn_buffer);
241
- int status = SSL_select_next_proto (
242
- const_cast <unsigned char **>(out),
243
- outlen,
244
- alpn_protos.data (),
245
- alpn_protos.length (),
246
- in,
247
- inlen);
233
+ int status = SSL_select_next_proto (const_cast <unsigned char **>(out),
234
+ outlen,
235
+ alpn_protos.data (),
236
+ alpn_protos.size (),
237
+ in,
238
+ inlen);
248
239
249
240
// Previous versions of Node.js returned SSL_TLSEXT_ERR_NOACK if no protocol
250
241
// match was found. This would neither cause a fatal alert nor would it result
@@ -1529,20 +1520,14 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) {
1529
1520
if (args.Length () < 1 || !Buffer::HasInstance (args[0 ]))
1530
1521
return env->ThrowTypeError (" Must give a Buffer as first argument" );
1531
1522
1523
+ ArrayBufferViewContents<uint8_t > protos (args[0 ].As <ArrayBufferView>());
1532
1524
SSL* ssl = w->ssl_ .get ();
1533
1525
if (w->is_client ()) {
1534
- ArrayBufferViewContents<uint8_t > protos (args[0 ].As <ArrayBufferView>());
1535
1526
CHECK_EQ (0 , SSL_set_alpn_protos (ssl, protos.data (), protos.length ()));
1536
1527
} else {
1537
- CHECK (
1538
- w->object ()->SetPrivate (
1539
- env->context (),
1540
- env->alpn_buffer_private_symbol (),
1541
- args[0 ]).FromJust ());
1542
- // Server should select ALPN protocol from list of advertised by client
1543
- SSL_CTX_set_alpn_select_cb (SSL_get_SSL_CTX (ssl),
1544
- SelectALPNCallback,
1545
- nullptr );
1528
+ w->alpn_protos_ = std::vector<unsigned char >(
1529
+ protos.data (), protos.data () + protos.length ());
1530
+ SSL_CTX_set_alpn_select_cb (SSL_get_SSL_CTX (ssl), SelectALPNCallback, w);
1546
1531
}
1547
1532
}
1548
1533
0 commit comments