Skip to content

Commit 85b7faf

Browse files
committed
Refactored: Moved TLSGroups to new branch feature/named_group
1 parent 515f1bc commit 85b7faf

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

src/constants.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,17 @@ pub fn named_group_to_tls_name(id: NamedGroup) -> Option<&'static CStr> {
144144
pub fn named_group_to_nid(group: NamedGroup) -> Option<c_int> {
145145
use NamedGroup::*;
146146

147-
// See TLSEXT_nid_unknown from tls1.h - openssl-sys does not
148-
// have a constant for this to import.
149-
const TLSEXT_NID_UNKNOWN: c_int = 0x1000000;
150147
// See NID_ffhdhe* from obj_mac.h - openssl-sys does not have
151148
// constants for these to import.
152149
const NID_FFDHE2048: c_int = 1126;
153150
const NID_FFDHE3072: c_int = 1127;
154151
const NID_FFDHE4096: c_int = 1128;
155152
const NID_FFDHE6144: c_int = 1129;
156153
const NID_FFDHE8192: c_int = 1130;
157-
// See NID_ML_KEM_* from obj_mac.h - openssl-sys does not have
158-
// constants for these to import.
159-
const NID_ML_KEM_512: c_int = 1454;
160-
const NID_ML_KEM_768: c_int = 1455;
161-
const NID_ML_KEM_1024: c_int = 1456;
154+
155+
// See TLSEXT_nid_unknown from tls1.h - openssl-sys does not
156+
// have a constant for this to import.
157+
const TLSEXT_NID_UNKNOWN: c_int = 0x1000000;
162158

163159
match group {
164160
secp256r1 => Some(NID_X9_62_prime256v1),
@@ -171,9 +167,6 @@ pub fn named_group_to_nid(group: NamedGroup) -> Option<c_int> {
171167
FFDHE4096 => Some(NID_FFDHE4096),
172168
FFDHE6144 => Some(NID_FFDHE6144),
173169
FFDHE8192 => Some(NID_FFDHE8192),
174-
MLKEM512 => Some(NID_ML_KEM_512),
175-
MLKEM768 => Some(NID_ML_KEM_768),
176-
MLKEM1024 => Some(NID_ML_KEM_1024),
177170
other => Some(TLSEXT_NID_UNKNOWN | u16::from(other) as c_int),
178171
}
179172
}

src/lib.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use openssl_sys::{
1313
};
1414

1515
use rustls::client::Resumption;
16-
use rustls::crypto::{aws_lc_rs as provider, SupportedKxGroup};
16+
use rustls::crypto::aws_lc_rs as provider;
17+
use rustls::crypto::aws_lc_rs::Ticketer;
18+
use rustls::crypto::SupportedKxGroup;
1719
use rustls::pki_types::{CertificateDer, ServerName};
1820
use rustls::server::{Accepted, Acceptor, ProducesTickets};
1921
use rustls::{
@@ -101,7 +103,7 @@ pub struct SslCipher {
101103
pub standard_name: &'static CStr,
102104
pub version: &'static CStr,
103105
pub description: &'static CStr,
104-
rustls: &'static rustls::SupportedCipherSuite,
106+
pub rustls: CipherSuite,
105107
}
106108

107109
impl SslCipher {
@@ -133,7 +135,7 @@ impl SslCipher {
133135
}
134136

135137
pub fn protocol_id(&self) -> u16 {
136-
u16::from(self.rustls.suite())
138+
u16::from(self.rustls)
137139
}
138140

139141
pub fn openssl_id(&self) -> u32 {
@@ -142,102 +144,102 @@ impl SslCipher {
142144
}
143145

144146
static TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: SslCipher = SslCipher {
145-
rustls: &provider::cipher_suite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
146147
auth: constants::NID_AUTH_ECDSA,
147148
kx: constants::NID_KX_ECDHE,
148149
bits: 128,
149150
openssl_name: c"ECDHE-ECDSA-AES128-GCM-SHA256",
150151
standard_name: c"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
151152
version: c"TLSv1.2",
152153
description: c"ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(128) Mac=AEAD\n",
154+
rustls: CipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
153155
};
154156

155157
static TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: SslCipher = SslCipher {
156-
rustls: &provider::cipher_suite::TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
157158
auth: constants::NID_AUTH_ECDSA,
158159
kx: constants::NID_KX_ECDHE,
159160
bits: 256,
160161
openssl_name: c"ECDHE-ECDSA-AES256-GCM-SHA384",
161162
standard_name: c"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
162163
version: c"TLSv1.2",
163164
description: c"ECDHE-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(256) Mac=AEAD\n",
165+
rustls: CipherSuite::TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
164166
};
165167

166168
static TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256: SslCipher = SslCipher {
167-
rustls: &provider::cipher_suite::TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
168169
auth: constants::NID_AUTH_ECDSA,
169170
kx: constants::NID_KX_ECDHE,
170171
bits: 256,
171172
openssl_name: c"ECDHE-ECDSA-CHACHA20-POLY1305",
172173
standard_name: c"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
174+
rustls: CipherSuite::TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
173175
version: c"TLSv1.2",
174176
description: c"ECDHE-ECDSA-CHACHA20-POLY1305 TLSv1.2 Kx=ECDH Au=ECDSA Enc=CHACHA20/POLY1305(256) Mac=AEAD\n",
175177
};
176178

177179
static TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: SslCipher = SslCipher {
178-
rustls: &provider::cipher_suite::TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
179180
auth: constants::NID_AUTH_RSA,
180181
kx: constants::NID_KX_ECDHE,
181182
bits: 128,
182183
openssl_name: c"ECDHE-RSA-AES128-GCM-SHA256",
183184
standard_name: c"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
184185
version: c"TLSv1.2",
185186
description: c"ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(128) Mac=AEAD\n",
187+
rustls: CipherSuite::TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
186188
};
187189

188190
static TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: SslCipher = SslCipher {
189-
rustls: &provider::cipher_suite::TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
190191
auth: constants::NID_AUTH_RSA,
191192
kx: constants::NID_KX_ECDHE,
192193
bits: 256,
193194
openssl_name: c"ECDHE-RSA-AES256-GCM-SHA384",
194195
standard_name: c"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
195196
version: c"TLSv1.2",
196197
description: c"ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD\n",
198+
rustls: CipherSuite::TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
197199
};
198200

199201
static TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256: SslCipher = SslCipher {
200-
rustls: &provider::cipher_suite::TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
201202
auth: constants::NID_AUTH_RSA,
202203
kx: constants::NID_KX_ECDHE,
203204
bits: 256,
204205
openssl_name: c"ECDHE-RSA-CHACHA20-POLY1305",
205206
standard_name: c"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
206207
version: c"TLSv1.2",
207208
description: c"ECDHE-RSA-CHACHA20-POLY1305 TLSv1.2 Kx=ECDH Au=RSA Enc=CHACHA20/POLY1305(256) Mac=AEAD\n",
209+
rustls: CipherSuite::TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
208210
};
209211

210212
static TLS13_AES_128_GCM_SHA256: SslCipher = SslCipher {
211-
rustls: &provider::cipher_suite::TLS13_AES_128_GCM_SHA256,
212213
auth: constants::NID_AUTH_ANY,
213214
kx: constants::NID_KX_ANY,
214215
bits: 128,
215216
openssl_name: c"TLS_AES_128_GCM_SHA256",
216217
standard_name: c"TLS_AES_128_GCM_SHA256",
217218
version: c"TLSv1.3",
218219
description: c"TLS_AES_128_GCM_SHA256 TLSv1.3 Kx=any Au=any Enc=AESGCM(128) Mac=AEAD\n",
220+
rustls: CipherSuite::TLS13_AES_128_GCM_SHA256,
219221
};
220222

221223
static TLS13_AES_256_GCM_SHA384: SslCipher = SslCipher {
222-
rustls: &provider::cipher_suite::TLS13_AES_256_GCM_SHA384,
223224
auth: constants::NID_AUTH_ANY,
224225
kx: constants::NID_KX_ANY,
225226
bits: 256,
226227
openssl_name: c"TLS_AES_256_GCM_SHA384",
227228
standard_name: c"TLS_AES_256_GCM_SHA384",
228229
version: c"TLSv1.3",
229230
description: c"TLS_AES_256_GCM_SHA384 TLSv1.3 Kx=any Au=any Enc=AESGCM(256) Mac=AEAD\n",
231+
rustls: CipherSuite::TLS13_AES_256_GCM_SHA384,
230232
};
231233

232234
static TLS13_CHACHA20_POLY1305_SHA256: SslCipher = SslCipher {
233-
rustls: &provider::cipher_suite::TLS13_CHACHA20_POLY1305_SHA256,
234235
auth: constants::NID_AUTH_ANY,
235236
kx: constants::NID_KX_ANY,
236237
bits: 256,
237238
openssl_name: c"TLS_CHACHA20_POLY1305_SHA256",
238239
standard_name: c"TLS_CHACHA20_POLY1305_SHA256",
239240
version: c"TLSv1.3",
240241
description: c"TLS_CHACHA20_POLY1305_SHA256 TLSv1.3 Kx=any Au=any Enc=CHACHA20/POLY1305(256) Mac=AEAD\n",
242+
rustls: CipherSuite::TLS13_CHACHA20_POLY1305_SHA256,
241243
};
242244

243245
/// Backs a server-side SSL_SESSION object
@@ -470,7 +472,7 @@ impl SslContext {
470472
// a ticketer. Doing so is wasteful for a client, and incompatible with miri
471473
// (due to calls to a foreign function, `RAND_bytes`).
472474
let ticketer = match !method.server_versions.is_empty() && cfg!(not(miri)) {
473-
true => provider::Ticketer::new().ok(),
475+
true => Ticketer::new().ok(),
474476
false => None,
475477
};
476478
Self {
@@ -1109,7 +1111,6 @@ impl Ssl {
11091111
if let ConnMode::Unknown = self.mode {
11101112
self.set_client_mode();
11111113
}
1112-
11131114
if matches!(self.conn, ConnState::Nothing) {
11141115
self.init_client_conn()?;
11151116
}

0 commit comments

Comments
 (0)