Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit bea002a

Browse files
committed
quic: coalesce QuicClientSession and QuicServerSession
Eliminate the subclasses at the C++ level. Coalesce into a single QuicSession class to help keep things more manageable in preparation for the http3 enablement PR-URL: #168 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
1 parent 369e67d commit bea002a

File tree

9 files changed

+736
-835
lines changed

9 files changed

+736
-835
lines changed

src/node_quic.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ void Initialize(Local<Object> target,
116116
env->set_quic_state(std::move(state));
117117

118118
QuicSocket::Initialize(env, target, context);
119-
QuicServerSession::Initialize(env, target, context);
120-
QuicClientSession::Initialize(env, target, context);
119+
QuicSession::Initialize(env, target, context);
121120
QuicStream::Initialize(env, target, context);
122121

123122
env->SetMethod(target,

src/node_quic_crypto.cc

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bool GenerateRandData(uint8_t* buf, size_t len) {
126126
Local<Array> GetClientHelloCiphers(QuicSession* session) {
127127
const unsigned char* buf;
128128
Environment* env = session->env();
129-
auto ctx = session->CryptoContext();
129+
QuicCryptoContext* ctx = session->CryptoContext();
130130
size_t len = SSL_client_hello_get0_ciphers(**ctx, &buf);
131131
std::vector<Local<Value>> ciphers_array;
132132
for (size_t n = 0; n < len; n += 2) {
@@ -135,14 +135,14 @@ Local<Array> GetClientHelloCiphers(QuicSession* session) {
135135
const char* cipher_name = SSL_CIPHER_get_name(cipher);
136136
const char* cipher_version = SSL_CIPHER_get_version(cipher);
137137
Local<Object> obj = Object::New(env->isolate());
138-
USE(obj->Set(
138+
obj->Set(
139139
env->context(),
140140
env->name_string(),
141-
OneByteString(env->isolate(), cipher_name)));
142-
USE(obj->Set(
141+
OneByteString(env->isolate(), cipher_name)).FromJust();
142+
obj->Set(
143143
env->context(),
144144
env->version_string(),
145-
OneByteString(env->isolate(), cipher_version)));
145+
OneByteString(env->isolate(), cipher_version)).FromJust();
146146
ciphers_array.push_back(obj);
147147
}
148148
return Array::New(env->isolate(), ciphers_array.data(), ciphers_array.size());
@@ -153,7 +153,7 @@ const char* GetClientHelloServerName(QuicSession* session) {
153153
size_t len;
154154
size_t rem;
155155

156-
auto ctx = session->CryptoContext();
156+
QuicCryptoContext* ctx = session->CryptoContext();
157157

158158
if (!SSL_client_hello_get0_ext(
159159
**ctx,
@@ -187,7 +187,7 @@ const char* GetClientHelloALPN(QuicSession* session) {
187187
size_t len;
188188
size_t rem;
189189

190-
auto ctx = session->CryptoContext();
190+
QuicCryptoContext* ctx = session->CryptoContext();
191191

192192
if (!SSL_client_hello_get0_ext(
193193
**ctx,
@@ -707,7 +707,7 @@ int VerifyHostnameIdentity(SSL* ssl, const char* hostname) {
707707
}
708708

709709
const char* GetServerName(QuicSession* session) {
710-
auto ctx = session->CryptoContext();
710+
QuicCryptoContext* ctx = session->CryptoContext();
711711
return SSL_get_servername(**ctx, TLSEXT_NAMETYPE_host_name);
712712
}
713713

@@ -731,7 +731,7 @@ Local<Value> GetALPNProtocol(QuicSession* session) {
731731
Local<Value> alpn;
732732
const unsigned char* alpn_buf = nullptr;
733733
unsigned int alpnlen;
734-
auto ctx = session->CryptoContext();
734+
QuicCryptoContext* ctx = session->CryptoContext();
735735

736736
SSL_get0_alpn_selected(**ctx, &alpn_buf, &alpnlen);
737737
if (alpnlen == sizeof(NGTCP2_ALPN_H3) - 2 &&
@@ -745,7 +745,7 @@ Local<Value> GetALPNProtocol(QuicSession* session) {
745745

746746
Local<Value> GetCertificate(QuicSession* session) {
747747
crypto::ClearErrorOnReturn clear_error_on_return;
748-
auto ctx = session->CryptoContext();
748+
QuicCryptoContext* ctx = session->CryptoContext();
749749
Local<Value> value = v8::Undefined(session->env()->isolate());
750750
X509* cert = SSL_get_certificate(**ctx);
751751
if (cert != nullptr)
@@ -758,7 +758,7 @@ Local<Value> GetEphemeralKey(QuicSession* session) {
758758
Local<Context> context = env->context();
759759

760760
Local<Object> info = Object::New(env->isolate());
761-
auto ctx = session->CryptoContext();
761+
QuicCryptoContext* ctx = session->CryptoContext();
762762

763763
EVP_PKEY* raw_key;
764764
if (SSL_get_server_tmp_key(**ctx, &raw_key)) {
@@ -785,12 +785,18 @@ Local<Value> GetEphemeralKey(QuicSession* session) {
785785
} else {
786786
curve_name = OBJ_nid2sn(kid);
787787
}
788-
USE(info->Set(context, env->type_string(),
789-
FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH")));
790-
USE(info->Set(context, env->name_string(),
791-
OneByteString(env->isolate(), curve_name)));
792-
USE(info->Set(context, env->size_string(),
793-
Integer::New(env->isolate(), EVP_PKEY_bits(key.get()))));
788+
info->Set(context, env->type_string(),
789+
FIXED_ONE_BYTE_STRING(
790+
env->isolate(),
791+
"ECDH")).FromJust();
792+
info->Set(context, env->name_string(),
793+
OneByteString(
794+
env->isolate(),
795+
curve_name)).FromJust();
796+
info->Set(context, env->size_string(),
797+
Integer::New(
798+
env->isolate(),
799+
EVP_PKEY_bits(key.get()))).FromJust();
794800
}
795801
break;
796802
default:
@@ -802,7 +808,7 @@ Local<Value> GetEphemeralKey(QuicSession* session) {
802808

803809
Local<Value> GetCipherName(QuicSession* session) {
804810
Local<Value> cipher;
805-
auto ctx = session->CryptoContext();
811+
QuicCryptoContext* ctx = session->CryptoContext();
806812
const SSL_CIPHER* c = SSL_get_current_cipher(**ctx);
807813
if (c != nullptr) {
808814
const char* cipher_name = SSL_CIPHER_get_name(c);
@@ -813,7 +819,7 @@ Local<Value> GetCipherName(QuicSession* session) {
813819

814820
Local<Value> GetCipherVersion(QuicSession* session) {
815821
Local<Value> version;
816-
auto ctx = session->CryptoContext();
822+
QuicCryptoContext* ctx = session->CryptoContext();
817823
const SSL_CIPHER* c = SSL_get_current_cipher(**ctx);
818824
if (c != nullptr) {
819825
const char* cipher_version = SSL_CIPHER_get_version(c);
@@ -839,7 +845,7 @@ Local<Value> GetPeerCertificate(
839845
bool abbreviated) {
840846
crypto::ClearErrorOnReturn clear_error_on_return;
841847

842-
auto ctx = session->CryptoContext();
848+
QuicCryptoContext* ctx = session->CryptoContext();
843849

844850
Local<Value> result = v8::Undefined(session->env()->isolate());
845851
Local<Object> issuer_chain;
@@ -955,8 +961,7 @@ int TLS_Status_Callback(SSL* ssl, void* arg) {
955961
}
956962

957963
int New_Session_Callback(SSL* ssl, SSL_SESSION* session) {
958-
QuicClientSession* s =
959-
static_cast<QuicClientSession*>(SSL_get_app_data(ssl));
964+
QuicSession* s = static_cast<QuicSession*>(SSL_get_app_data(ssl));
960965
return s->SetSession(session);
961966
}
962967

@@ -1056,7 +1061,7 @@ SSL_QUIC_METHOD quic_method = SSL_QUIC_METHOD{
10561061
} // namespace
10571062

10581063
void InitializeTLS(QuicSession* session) {
1059-
auto ctx = session->CryptoContext();
1064+
QuicCryptoContext* ctx = session->CryptoContext();
10601065

10611066
SSL_set_app_data(**ctx, session);
10621067
SSL_set_cert_cb(**ctx, CertCB, session);
@@ -1146,7 +1151,7 @@ bool SetCryptoSecrets(
11461151
SessionIV tx_iv;
11471152
SessionKey tx_hp;
11481153

1149-
auto ctx = session->CryptoContext();
1154+
QuicCryptoContext* ctx = session->CryptoContext();
11501155

11511156
if (NGTCP2_ERR(ngtcp2_crypto_derive_and_install_key(
11521157
session->Connection(),

src/node_quic_crypto.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ void InitializeSecureContext(
4444
crypto::SecureContext* sc,
4545
ngtcp2_crypto_side side);
4646

47-
// Called in the QuicServerSession::Init and
48-
// QuicClientSession::Init to configure the
47+
// Called in the QuicSession::InitServer and
48+
// QuicSession::InitClient to configure the
4949
// appropriate settings for the SSL* associated
5050
// with the session.
5151
void InitializeTLS(QuicSession* session);
5252

53-
// Called when the QuicClientSession is created and
54-
// when the QuicServerSession first receives the
53+
// Called when the client QuicSession is created and
54+
// when the server QuicSession first receives the
5555
// client hello.
5656
bool DeriveAndInstallInitialKey(
5757
QuicSession* session,
@@ -72,8 +72,6 @@ const char* GetClientHelloALPN(QuicSession* session);
7272
const char* GetServerName(QuicSession* session);
7373

7474
// Replaces the SecureContext to be used in the handshake.
75-
// This is currently used only within the QuicServerSession::OnCertDone
76-
// callback.
7775
int UseSNIContext(SSL* ssl, crypto::SecureContext* context);
7876

7977
bool GenerateRetryToken(

0 commit comments

Comments
 (0)