Skip to content

Commit 0c80064

Browse files
jasnelljuanarbol
authored andcommitted
quic: move to ngtcp2_crypto
PR-URL: nodejs#138 Reviewed-By: Anna Henningsen <[email protected]>
1 parent b27020c commit 0c80064

13 files changed

+1130
-2545
lines changed

deps/ngtcp2/ngtcp2.gyp

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88
{
99
'target_name': 'ngtcp2',
1010
'type': 'static_library',
11-
'include_dirs': ['lib/includes'],
11+
'include_dirs': [
12+
'lib/includes',
13+
'crypto/includes',
14+
'lib',
15+
],
1216
'defines': [
1317
'BUILDING_NGTCP2',
1418
'NGTCP2_STATICLIB',
1519
],
20+
'dependencies': [
21+
'../openssl/openssl.gyp:openssl'
22+
],
1623
'conditions': [
1724
['OS=="win"', {
1825
'defines': [
@@ -29,37 +36,73 @@
2936
],
3037
'direct_dependent_settings': {
3138
'defines': [ 'NGTCP2_STATICLIB' ],
32-
'include_dirs': [ 'lib/includes' ]
39+
'include_dirs': [
40+
'lib/includes',
41+
'crypto/includes'
42+
]
3343
},
3444
'sources': [
35-
'lib/ngtcp2_acktr.c',
36-
'lib/ngtcp2_addr.c',
37-
'lib/ngtcp2_buf.c',
38-
'lib/ngtcp2_cc.c',
39-
'lib/ngtcp2_cid.c',
40-
'lib/ngtcp2_conn.c',
41-
'lib/ngtcp2_conv.c',
42-
'lib/ngtcp2_crypto.c',
43-
'lib/ngtcp2_err.c',
44-
'lib/ngtcp2_gaptr.c',
45-
'lib/ngtcp2_idtr.c',
46-
'lib/ngtcp2_ksl.c',
47-
'lib/ngtcp2_log.c',
48-
'lib/ngtcp2_map.c',
49-
'lib/ngtcp2_mem.c',
50-
'lib/ngtcp2_path.c',
51-
'lib/ngtcp2_pkt.c',
52-
'lib/ngtcp2_ppe.c',
53-
'lib/ngtcp2_pq.c',
54-
'lib/ngtcp2_psl.c',
55-
'lib/ngtcp2_pv.c',
56-
'lib/ngtcp2_range.c',
57-
'lib/ngtcp2_ringbuf.c',
58-
'lib/ngtcp2_rob.c',
59-
'lib/ngtcp2_rtb.c',
60-
'lib/ngtcp2_str.c',
61-
'lib/ngtcp2_strm.c',
62-
'lib/ngtcp2_vec.c',
45+
'lib/ngtcp2_acktr.c',
46+
'lib/ngtcp2_acktr.h',
47+
'lib/ngtcp2_addr.c',
48+
'lib/ngtcp2_addr.h',
49+
'lib/ngtcp2_buf.c',
50+
'lib/ngtcp2_buf.h',
51+
'lib/ngtcp2_cc.c',
52+
'lib/ngtcp2_cc.h',
53+
'lib/ngtcp2_cid.c',
54+
'lib/ngtcp2_cid.h',
55+
'lib/ngtcp2_conn.c',
56+
'lib/ngtcp2_conn.h',
57+
'lib/ngtcp2_conv.c',
58+
'lib/ngtcp2_conv.h',
59+
'lib/ngtcp2_crypto.c',
60+
'lib/ngtcp2_crypto.h',
61+
'lib/ngtcp2_err.c',
62+
'lib/ngtcp2_err.h',
63+
'lib/ngtcp2_gaptr.c',
64+
'lib/ngtcp2_gaptr.h',
65+
'lib/ngtcp2_idtr.c',
66+
'lib/ngtcp2_idtr.h',
67+
'lib/ngtcp2_ksl.c',
68+
'lib/ngtcp2_ksl.h',
69+
'lib/ngtcp2_log.c',
70+
'lib/ngtcp2_log.h',
71+
'lib/ngtcp2_macro.h',
72+
'lib/ngtcp2_map.c',
73+
'lib/ngtcp2_map.h',
74+
'lib/ngtcp2_mem.c',
75+
'lib/ngtcp2_mem.h',
76+
'lib/ngtcp2_net.h',
77+
'lib/ngtcp2_path.c',
78+
'lib/ngtcp2_path.h',
79+
'lib/ngtcp2_pkt.c',
80+
'lib/ngtcp2_pkt.h',
81+
'lib/ngtcp2_ppe.c',
82+
'lib/ngtcp2_ppe.h',
83+
'lib/ngtcp2_pq.c',
84+
'lib/ngtcp2_pq.h',
85+
'lib/ngtcp2_psl.c',
86+
'lib/ngtcp2_psl.h',
87+
'lib/ngtcp2_pv.c',
88+
'lib/ngtcp2_pv.h',
89+
'lib/ngtcp2_range.c',
90+
'lib/ngtcp2_range.h',
91+
'lib/ngtcp2_ringbuf.c',
92+
'lib/ngtcp2_ringbuf.h',
93+
'lib/ngtcp2_rob.c',
94+
'lib/ngtcp2_rob.h',
95+
'lib/ngtcp2_rtb.c',
96+
'lib/ngtcp2_rtb.h',
97+
'lib/ngtcp2_str.c',
98+
'lib/ngtcp2_str.h',
99+
'lib/ngtcp2_strm.c',
100+
'lib/ngtcp2_strm.h',
101+
'lib/ngtcp2_vec.c',
102+
'lib/ngtcp2_vec.h',
103+
'lib/ngtcp2_version.c',
104+
'crypto/shared.c',
105+
'crypto/openssl/openssl.c',
63106
]
64107
}
65108
]

node.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@
859859
'src/node_quic_socket.cc',
860860
'src/node_quic_stream.cc',
861861
'src/node_quic_util.cc',
862-
'src/node_quic.cc',
862+
'src/node_quic.cc'
863863
]
864864
}
865865
],

src/node_quic.cc

Lines changed: 7 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -75,87 +75,21 @@ void QuicSetCallbacks(const FunctionCallbackInfo<Value>& args) {
7575
// Sets QUIC specific configuration options for the SecureContext.
7676
// It's entirely likely that there's a better way to do this, but
7777
// for now this works.
78+
template <ngtcp2_crypto_side side>
7879
void QuicInitSecureContext(const FunctionCallbackInfo<Value>& args) {
7980
Environment* env = Environment::GetCurrent(args);
8081
CHECK(args[0]->IsObject()); // Secure Context
8182
CHECK(args[1]->IsString()); // groups
8283
SecureContext* sc;
8384
ASSIGN_OR_RETURN_UNWRAP(&sc, args[0].As<Object>(),
8485
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-
10986
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);
13187

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);
15089

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");
15993
}
16094
} // namespace
16195

@@ -191,10 +125,10 @@ void Initialize(Local<Object> target,
191125
QuicSetCallbacks);
192126
env->SetMethod(target,
193127
"initSecureContext",
194-
QuicInitSecureContext);
128+
QuicInitSecureContext<NGTCP2_CRYPTO_SIDE_SERVER>);
195129
env->SetMethod(target,
196130
"initSecureContextClient",
197-
QuicInitSecureContextClient);
131+
QuicInitSecureContext<NGTCP2_CRYPTO_SIDE_CLIENT>);
198132

199133
Local<Object> constants = Object::New(env->isolate());
200134
NODE_DEFINE_CONSTANT(constants, AF_INET);

0 commit comments

Comments
 (0)