@@ -75,87 +75,21 @@ void QuicSetCallbacks(const FunctionCallbackInfo<Value>& args) {
75
75
// Sets QUIC specific configuration options for the SecureContext.
76
76
// It's entirely likely that there's a better way to do this, but
77
77
// for now this works.
78
+ template <ngtcp2_crypto_side side>
78
79
void QuicInitSecureContext (const FunctionCallbackInfo<Value>& args) {
79
80
Environment* env = Environment::GetCurrent (args);
80
81
CHECK (args[0 ]->IsObject ()); // Secure Context
81
82
CHECK (args[1 ]->IsString ()); // groups
82
83
SecureContext* sc;
83
84
ASSIGN_OR_RETURN_UNWRAP (&sc, args[0 ].As <Object>(),
84
85
args.GetReturnValue ().Set (UV_EBADF));
85
-
86
- constexpr auto ssl_opts = (SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) |
87
- SSL_OP_SINGLE_ECDH_USE |
88
- SSL_OP_CIPHER_SERVER_PREFERENCE |
89
- SSL_OP_NO_ANTI_REPLAY;
90
- SSL_CTX_set_options (**sc, ssl_opts);
91
- SSL_CTX_clear_options (**sc, SSL_OP_ENABLE_MIDDLEBOX_COMPAT);
92
- SSL_CTX_set_mode (**sc, SSL_MODE_RELEASE_BUFFERS | SSL_MODE_QUIC_HACK);
93
- SSL_CTX_set_default_verify_paths (**sc);
94
- SSL_CTX_set_max_early_data (**sc, std::numeric_limits<uint32_t >::max ());
95
- SSL_CTX_set_alpn_select_cb (**sc, ALPN_Select_Proto_CB, nullptr );
96
- SSL_CTX_set_client_hello_cb (**sc, Client_Hello_CB, nullptr );
97
- SSL_CTX_set_tlsext_status_cb (**sc, TLS_Status_Callback);
98
- SSL_CTX_set_tlsext_status_arg (**sc, nullptr );
99
- CHECK_EQ (
100
- SSL_CTX_add_custom_ext (
101
- **sc,
102
- NGTCP2_TLSEXT_QUIC_TRANSPORT_PARAMETERS,
103
- SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS,
104
- Server_Transport_Params_Add_CB,
105
- Transport_Params_Free_CB, nullptr ,
106
- Server_Transport_Params_Parse_CB,
107
- nullptr ), 1 );
108
-
109
86
const node::Utf8Value groups (env->isolate (), args[1 ]);
110
- if (!SSL_CTX_set1_groups_list (**sc, *groups)) {
111
- unsigned long err = ERR_get_error (); // NOLINT(runtime/int)
112
- if (!err)
113
- return env->ThrowError (" Failed to set groups" );
114
- return crypto::ThrowCryptoError (env, err);
115
- }
116
- }
117
-
118
- void QuicInitSecureContextClient (const FunctionCallbackInfo<Value>& args) {
119
- Environment* env = Environment::GetCurrent (args);
120
- CHECK (args[0 ]->IsObject ()); // Secure Context
121
- CHECK (args[1 ]->IsString ()); // groups
122
- SecureContext* sc;
123
- ASSIGN_OR_RETURN_UNWRAP (&sc, args[0 ].As <Object>(),
124
- args.GetReturnValue ().Set (UV_EBADF));
125
-
126
- SSL_CTX_set_mode (**sc, SSL_MODE_QUIC_HACK);
127
- SSL_CTX_clear_options (**sc, SSL_OP_ENABLE_MIDDLEBOX_COMPAT);
128
- SSL_CTX_set_default_verify_paths (**sc);
129
- SSL_CTX_set_tlsext_status_cb (**sc, TLS_Status_Callback);
130
- SSL_CTX_set_tlsext_status_arg (**sc, nullptr );
131
87
132
- CHECK_EQ (SSL_CTX_add_custom_ext (
133
- **sc,
134
- NGTCP2_TLSEXT_QUIC_TRANSPORT_PARAMETERS,
135
- SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS,
136
- Client_Transport_Params_Add_CB,
137
- Transport_Params_Free_CB,
138
- nullptr ,
139
- Client_Transport_Params_Parse_CB,
140
- nullptr ), 1 );
141
-
142
-
143
- const node::Utf8Value groups (env->isolate (), args[1 ]);
144
- if (!SSL_CTX_set1_groups_list (**sc, *groups)) {
145
- unsigned long err = ERR_get_error (); // NOLINT(runtime/int)
146
- if (!err)
147
- return env->ThrowError (" Failed to set groups" );
148
- return crypto::ThrowCryptoError (env, err);
149
- }
88
+ InitializeSecureContext (sc, side);
150
89
151
- SSL_CTX_set_session_cache_mode (
152
- **sc, SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_NO_INTERNAL_STORE);
153
- SSL_CTX_sess_set_new_cb (**sc, [](SSL* ssl, SSL_SESSION* session) {
154
- QuicClientSession* s =
155
- static_cast <QuicClientSession*>(
156
- SSL_get_app_data (ssl));
157
- return s->SetSession (session);
158
- });
90
+ // TODO(@jasnell): Throw a proper node.js error with code
91
+ if (!SetGroups (sc, *groups))
92
+ return env->ThrowError (" Failed to set groups" );
159
93
}
160
94
} // namespace
161
95
@@ -191,10 +125,10 @@ void Initialize(Local<Object> target,
191
125
QuicSetCallbacks);
192
126
env->SetMethod (target,
193
127
" initSecureContext" ,
194
- QuicInitSecureContext);
128
+ QuicInitSecureContext<NGTCP2_CRYPTO_SIDE_SERVER> );
195
129
env->SetMethod (target,
196
130
" initSecureContextClient" ,
197
- QuicInitSecureContextClient );
131
+ QuicInitSecureContext<NGTCP2_CRYPTO_SIDE_CLIENT> );
198
132
199
133
Local<Object> constants = Object::New (env->isolate ());
200
134
NODE_DEFINE_CONSTANT (constants, AF_INET);
0 commit comments