rwebtransport 0.2.2 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/Cargo.lock +523 -140
  2. package/Cargo.toml +5 -5
  3. package/README.md +8 -4
  4. package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
  5. package/crates/native/Cargo.toml +2 -0
  6. package/crates/native/src/config.rs +69 -8
  7. package/crates/native/src/driver.rs +253 -90
  8. package/crates/native/src/lib.rs +80 -57
  9. package/crates/native/src/parser_memory.rs +203 -0
  10. package/crates/native/src/server.rs +215 -183
  11. package/crates/native/src/session.rs +1341 -243
  12. package/crates/native/src/test_support.rs +119 -0
  13. package/crates/wtcore/Cargo.toml +1 -0
  14. package/crates/wtcore/src/h3.rs +250 -46
  15. package/dist/index.js +218 -75
  16. package/dist/index.js.map +7 -1
  17. package/dist/index.mjs +214 -69
  18. package/dist/index.mjs.map +7 -1
  19. package/dist/native.d.ts +10 -4
  20. package/dist/server.d.ts +1 -0
  21. package/package.json +84 -78
  22. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  23. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  24. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  25. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  26. package/scripts/build-linux-prebuilt.sh +46 -0
  27. package/scripts/build-ts.js +41 -0
  28. package/scripts/build.js +10 -3
  29. package/vendor/quiche/AGENTS.md +10 -0
  30. package/vendor/quiche/Cargo.lock +239 -248
  31. package/vendor/quiche/Cargo.toml +23 -10
  32. package/vendor/quiche/examples/Makefile +4 -4
  33. package/vendor/quiche/examples/client.rs +10 -28
  34. package/vendor/quiche/examples/http3-client.rs +20 -34
  35. package/vendor/quiche/examples/http3-server.rs +47 -78
  36. package/vendor/quiche/examples/server.rs +19 -49
  37. package/vendor/quiche/include/quiche.h +35 -4
  38. package/vendor/quiche/src/build.rs +17 -0
  39. package/vendor/quiche/src/cid.rs +129 -61
  40. package/vendor/quiche/src/crypto/boringssl.rs +98 -86
  41. package/vendor/quiche/src/crypto/mod.rs +64 -77
  42. package/vendor/quiche/src/dgram.rs +2 -3
  43. package/vendor/quiche/src/error.rs +22 -20
  44. package/vendor/quiche/src/ffi.rs +558 -280
  45. package/vendor/quiche/src/flowcontrol.rs +0 -7
  46. package/vendor/quiche/src/frame.rs +134 -135
  47. package/vendor/quiche/src/h3/ffi.rs +73 -60
  48. package/vendor/quiche/src/h3/frame.rs +70 -90
  49. package/vendor/quiche/src/h3/mod.rs +1024 -593
  50. package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
  51. package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
  52. package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
  53. package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
  54. package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
  55. package/vendor/quiche/src/h3/stream.rs +1009 -194
  56. package/vendor/quiche/src/lib.rs +1361 -1195
  57. package/vendor/quiche/src/minmax.rs +2 -6
  58. package/vendor/quiche/src/packet.rs +420 -552
  59. package/vendor/quiche/src/path.rs +202 -72
  60. package/vendor/quiche/src/pmtud.rs +18 -16
  61. package/vendor/quiche/src/ranges.rs +184 -82
  62. package/vendor/quiche/src/recovery/AGENTS.md +5 -2
  63. package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
  64. package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
  65. package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
  66. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
  67. package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
  68. package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
  69. package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
  70. package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
  71. package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
  72. package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
  73. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
  74. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
  75. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
  76. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
  77. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
  78. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
  79. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
  80. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
  81. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
  82. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
  83. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
  84. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
  85. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
  86. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
  87. package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
  88. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
  89. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
  90. package/vendor/quiche/src/recovery/mod.rs +414 -173
  91. package/vendor/quiche/src/recovery/rtt.rs +8 -5
  92. package/vendor/quiche/src/stream/mod.rs +864 -133
  93. package/vendor/quiche/src/stream/recv_buf.rs +476 -172
  94. package/vendor/quiche/src/stream/send_buf.rs +343 -81
  95. package/vendor/quiche/src/test_utils.rs +78 -64
  96. package/vendor/quiche/src/tests.rs +2559 -1335
  97. package/vendor/quiche/src/tls/boringssl.rs +60 -63
  98. package/vendor/quiche/src/tls/mod.rs +146 -193
  99. package/vendor/quiche/src/transport_params.rs +87 -103
@@ -27,6 +27,7 @@
27
27
  use std::ffi;
28
28
  use std::mem::ManuallyDrop;
29
29
  use std::ptr;
30
+ use std::ptr::NonNull;
30
31
  use std::slice;
31
32
 
32
33
  use std::io::Write;
@@ -128,14 +129,14 @@ pub static QUICHE_EX_DATA_INDEX: LazyLock<c_int> = LazyLock::new(|| unsafe {
128
129
  SSL_get_ex_new_index(0, ptr::null(), ptr::null(), ptr::null(), ptr::null())
129
130
  });
130
131
 
131
- pub struct Context(*mut SSL_CTX);
132
+ pub struct Context(NonNull<SSL_CTX>);
132
133
 
133
134
  impl Context {
134
135
  // Note: some vendor-specific methods are implemented in the boringssl
135
136
  // submodule.
136
137
  pub fn new() -> Result<Context> {
137
138
  unsafe {
138
- let ctx_raw = SSL_CTX_new(TLS_method());
139
+ let ctx_raw = NonNull::new(SSL_CTX_new(TLS_method())).ok_or(Error::TlsFail)?;
139
140
 
140
141
  let mut ctx = Context(ctx_raw);
141
142
 
@@ -148,20 +149,22 @@ impl Context {
148
149
  }
149
150
 
150
151
  #[cfg(feature = "boringssl-boring-crate")]
151
- pub fn from_boring(
152
- ssl_ctx_builder: boring::ssl::SslContextBuilder,
153
- ) -> Context {
152
+ pub fn from_boring(ssl_ctx_builder: boring::ssl::SslContextBuilder) -> Result<Context> {
154
153
  use foreign_types_shared::ForeignType;
155
154
 
156
- let mut ctx = Context(ssl_ctx_builder.build().into_ptr() as _);
155
+ let ctx_raw =
156
+ NonNull::new(ssl_ctx_builder.build().into_ptr() as _).ok_or(Error::TlsFail)?;
157
+
158
+ let mut ctx = Context(ctx_raw);
157
159
  ctx.set_session_callback();
158
160
 
159
- ctx
161
+ Ok(ctx)
160
162
  }
161
163
 
162
164
  pub fn new_handshake(&mut self) -> Result<Handshake> {
163
165
  unsafe {
164
- let ssl = SSL_new(self.as_mut_ptr());
166
+ let ssl = NonNull::new(SSL_new(self.as_mut_ptr())).ok_or(Error::TlsFail)?;
167
+
165
168
  Ok(Handshake::new(ssl))
166
169
  }
167
170
  }
@@ -169,39 +172,25 @@ impl Context {
169
172
  pub fn load_verify_locations_from_file(&mut self, file: &str) -> Result<()> {
170
173
  let file = ffi::CString::new(file).map_err(|_| Error::TlsFail)?;
171
174
  map_result(unsafe {
172
- SSL_CTX_load_verify_locations(
173
- self.as_mut_ptr(),
174
- file.as_ptr(),
175
- ptr::null(),
176
- )
175
+ SSL_CTX_load_verify_locations(self.as_mut_ptr(), file.as_ptr(), ptr::null())
177
176
  })
178
177
  }
179
178
 
180
- pub fn load_verify_locations_from_directory(
181
- &mut self, path: &str,
182
- ) -> Result<()> {
179
+ pub fn load_verify_locations_from_directory(&mut self, path: &str) -> Result<()> {
183
180
  let path = ffi::CString::new(path).map_err(|_| Error::TlsFail)?;
184
181
  map_result(unsafe {
185
- SSL_CTX_load_verify_locations(
186
- self.as_mut_ptr(),
187
- ptr::null(),
188
- path.as_ptr(),
189
- )
182
+ SSL_CTX_load_verify_locations(self.as_mut_ptr(), ptr::null(), path.as_ptr())
190
183
  })
191
184
  }
192
185
 
193
186
  pub fn use_certificate_chain_file(&mut self, file: &str) -> Result<()> {
194
187
  let cstr = ffi::CString::new(file).map_err(|_| Error::TlsFail)?;
195
- map_result(unsafe {
196
- SSL_CTX_use_certificate_chain_file(self.as_mut_ptr(), cstr.as_ptr())
197
- })
188
+ map_result(unsafe { SSL_CTX_use_certificate_chain_file(self.as_mut_ptr(), cstr.as_ptr()) })
198
189
  }
199
190
 
200
191
  pub fn use_privkey_file(&mut self, file: &str) -> Result<()> {
201
192
  let cstr = ffi::CString::new(file).map_err(|_| Error::TlsFail)?;
202
- map_result(unsafe {
203
- SSL_CTX_use_PrivateKey_file(self.as_mut_ptr(), cstr.as_ptr(), 1)
204
- })
193
+ map_result(unsafe { SSL_CTX_use_PrivateKey_file(self.as_mut_ptr(), cstr.as_ptr(), 1) })
205
194
  }
206
195
 
207
196
  #[cfg(not(windows))]
@@ -213,11 +202,10 @@ impl Context {
213
202
  fn load_ca_certs(&mut self) -> Result<()> {
214
203
  unsafe {
215
204
  let cstr = ffi::CString::new("Root").map_err(|_| Error::TlsFail)?;
216
- let sys_store =
217
- windows_sys::Win32::Security::Cryptography::CertOpenSystemStoreA(
218
- 0,
219
- cstr.as_ptr() as windows_sys::core::PCSTR,
220
- );
205
+ let sys_store = windows_sys::Win32::Security::Cryptography::CertOpenSystemStoreA(
206
+ 0,
207
+ cstr.as_ptr() as windows_sys::core::PCSTR,
208
+ );
221
209
  if sys_store.is_null() {
222
210
  return Err(Error::TlsFail);
223
211
  }
@@ -235,11 +223,7 @@ impl Context {
235
223
  while !ctx_p.is_null() {
236
224
  let in_p = (*ctx_p).pbCertEncoded as *const u8;
237
225
 
238
- let cert = d2i_X509(
239
- ptr::null_mut(),
240
- &in_p,
241
- (*ctx_p).cbCertEncoded as i32,
242
- );
226
+ let cert = d2i_X509(ptr::null_mut(), &in_p, (*ctx_p).cbCertEncoded as i32);
243
227
  if !cert.is_null() {
244
228
  X509_STORE_add_cert(ctx_store, cert);
245
229
  }
@@ -253,9 +237,7 @@ impl Context {
253
237
 
254
238
  // tidy up
255
239
  windows_sys::Win32::Security::Cryptography::CertFreeCertificateContext(ctx_p);
256
- windows_sys::Win32::Security::Cryptography::CertCloseStore(
257
- sys_store, 0,
258
- );
240
+ windows_sys::Win32::Security::Cryptography::CertCloseStore(sys_store, 0);
259
241
  }
260
242
 
261
243
  Ok(())
@@ -279,8 +261,8 @@ impl Context {
279
261
  // false -> 0x00 SSL_VERIFY_NONE
280
262
  let mode = i32::from(verify);
281
263
 
282
- // Note: Base on two used modes(see above), it seems ok for both, bssl and
283
- // ossl. If mode needs to be ored then it may need to be adjusted.
264
+ // The two modes above work for both BoringSSL and OpenSSL. This may
265
+ // need adjustment if modes must be combined.
284
266
  unsafe {
285
267
  SSL_CTX_set_verify(self.as_mut_ptr(), mode, None);
286
268
  }
@@ -302,43 +284,39 @@ impl Context {
302
284
 
303
285
  // Configure ALPN for servers.
304
286
  unsafe {
305
- SSL_CTX_set_alpn_select_cb(
306
- self.as_mut_ptr(),
307
- Some(select_alpn),
308
- ptr::null_mut(),
309
- );
287
+ SSL_CTX_set_alpn_select_cb(self.as_mut_ptr(), Some(select_alpn), ptr::null_mut());
310
288
  }
311
289
 
312
290
  // Configure ALPN for clients.
313
291
  map_result_zero_is_success(unsafe {
314
- SSL_CTX_set_alpn_protos(
315
- self.as_mut_ptr(),
316
- protos.as_ptr(),
317
- protos.len(),
318
- )
292
+ SSL_CTX_set_alpn_protos(self.as_mut_ptr(), protos.as_ptr(), protos.len())
319
293
  })
320
294
  }
321
295
 
322
296
  pub fn set_ticket_key(&mut self, key: &[u8]) -> Result<()> {
323
297
  map_result(unsafe {
324
- SSL_CTX_set_tlsext_ticket_keys(
325
- self.as_mut_ptr(),
326
- key.as_ptr(),
327
- key.len(),
328
- )
298
+ SSL_CTX_set_tlsext_ticket_keys(self.as_mut_ptr(), key.as_ptr(), key.len())
329
299
  })
330
300
  }
331
301
 
302
+ pub fn set_curves_list(&mut self, curves: &str) -> Result<()> {
303
+ // Note: BoringSSL exports `SSL_CTX_set1_groups_list` as a real
304
+ // function; OpenSSL (and openssl-quictls) defines it as a macro
305
+ // that expands to `SSL_CTX_ctrl`. Each backend provides a
306
+ // `SSL_CTX_set1_groups_list` shim in the per-vendor module so this
307
+ // call site can be backend-agnostic.
308
+ let cstr = ffi::CString::new(curves).map_err(|_| Error::TlsFail)?;
309
+ map_result(unsafe { SSL_CTX_set1_groups_list(self.as_mut_ptr(), cstr.as_ptr()) })
310
+ }
311
+
332
312
  fn as_mut_ptr(&mut self) -> *mut SSL_CTX {
333
- self.0
313
+ self.0.as_ptr()
334
314
  }
335
315
  }
336
316
 
337
- // NOTE: These traits are not automatically implemented for Context due to the
338
- // raw pointer it wraps. However, the underlying data is not aliased (as Context
339
- // should be its only owner), and there is no interior mutability, as the
340
- // pointer is not accessed directly outside of this module, and the Context
341
- // object API should preserve Rust's borrowing guarantees.
317
+ // These traits are not automatically implemented because NonNull does not
318
+ // convey ownership. Context uniquely owns the underlying data, and its API
319
+ // preserves Rust's borrowing guarantees.
342
320
  unsafe impl Send for Context {}
343
321
  unsafe impl Sync for Context {}
344
322
 
@@ -349,8 +327,7 @@ impl Drop for Context {
349
327
  }
350
328
 
351
329
  pub struct Handshake {
352
- /// Raw pointer
353
- ptr: *mut SSL,
330
+ ptr: NonNull<SSL>,
354
331
  /// SSL_process_quic_post_handshake should be called when whenever
355
332
  /// SSL_provide_quic_data is called to process the provided data.
356
333
  provided_data_outstanding: bool,
@@ -360,11 +337,13 @@ impl Handshake {
360
337
  // Note: some vendor-specific methods are implemented in the boringssl
361
338
  // submodule.
362
339
  #[cfg(any(feature = "ffi", feature = "boringssl-boring-crate"))]
363
- pub unsafe fn from_ptr(ssl: *mut c_void) -> Handshake {
364
- Handshake::new(ssl as *mut SSL)
340
+ pub unsafe fn from_ptr(ssl: *mut c_void) -> Result<Handshake> {
341
+ let ptr = NonNull::new(ssl.cast()).ok_or(Error::TlsFail)?;
342
+
343
+ Ok(Handshake::new(ptr))
365
344
  }
366
345
 
367
- fn new(ptr: *mut SSL) -> Handshake {
346
+ fn new(ptr: NonNull<SSL>) -> Handshake {
368
347
  Handshake {
369
348
  ptr,
370
349
  provided_data_outstanding: false,
@@ -394,10 +373,7 @@ impl Handshake {
394
373
 
395
374
  pub fn use_legacy_codepoint(&mut self, use_legacy: bool) {
396
375
  unsafe {
397
- SSL_set_quic_use_legacy_codepoint(
398
- self.as_mut_ptr(),
399
- use_legacy as c_int,
400
- );
376
+ SSL_set_quic_use_legacy_codepoint(self.as_mut_ptr(), use_legacy as c_int);
401
377
  }
402
378
  }
403
379
 
@@ -419,21 +395,15 @@ impl Handshake {
419
395
  }
420
396
 
421
397
  pub fn set_quic_method(&mut self) -> Result<()> {
422
- map_result(unsafe {
423
- SSL_set_quic_method(self.as_mut_ptr(), &QUICHE_STREAM_METHOD)
424
- })
398
+ map_result(unsafe { SSL_set_quic_method(self.as_mut_ptr(), &QUICHE_STREAM_METHOD) })
425
399
  }
426
400
 
427
401
  pub fn set_min_proto_version(&mut self, version: u16) -> Result<()> {
428
- map_result(unsafe {
429
- SSL_set_min_proto_version(self.as_mut_ptr(), version)
430
- })
402
+ map_result(unsafe { SSL_set_min_proto_version(self.as_mut_ptr(), version) })
431
403
  }
432
404
 
433
405
  pub fn set_max_proto_version(&mut self, version: u16) -> Result<()> {
434
- map_result(unsafe {
435
- SSL_set_max_proto_version(self.as_mut_ptr(), version)
436
- })
406
+ map_result(unsafe { SSL_set_max_proto_version(self.as_mut_ptr(), version) })
437
407
  }
438
408
 
439
409
  pub fn set_quiet_shutdown(&mut self, mode: bool) {
@@ -442,31 +412,25 @@ impl Handshake {
442
412
 
443
413
  pub fn set_host_name(&mut self, name: &str) -> Result<()> {
444
414
  let cstr = ffi::CString::new(name).map_err(|_| Error::TlsFail)?;
445
- let rc =
446
- unsafe { SSL_set_tlsext_host_name(self.as_mut_ptr(), cstr.as_ptr()) };
415
+ let rc = unsafe { SSL_set_tlsext_host_name(self.as_mut_ptr(), cstr.as_ptr()) };
447
416
  self.map_result_ssl(rc)?;
448
417
 
449
418
  let param = unsafe { SSL_get0_param(self.as_mut_ptr()) };
450
419
 
451
- map_result(unsafe {
452
- X509_VERIFY_PARAM_set1_host(param, cstr.as_ptr(), name.len())
453
- })
420
+ map_result(unsafe { X509_VERIFY_PARAM_set1_host(param, cstr.as_ptr(), name.len()) })
454
421
  }
455
422
 
456
423
  pub fn set_quic_transport_params(
457
- &mut self, params: &crate::TransportParams, is_server: bool,
424
+ &mut self,
425
+ params: &crate::TransportParams,
426
+ is_server: bool,
458
427
  ) -> Result<()> {
459
428
  let mut raw_params = [0; 128];
460
429
 
461
- let raw_params =
462
- crate::TransportParams::encode(params, is_server, &mut raw_params)?;
430
+ let raw_params = crate::TransportParams::encode(params, is_server, &mut raw_params)?;
463
431
 
464
432
  let rc = unsafe {
465
- SSL_set_quic_transport_params(
466
- self.as_mut_ptr(),
467
- raw_params.as_ptr(),
468
- raw_params.len(),
469
- )
433
+ SSL_set_quic_transport_params(self.as_mut_ptr(), raw_params.as_ptr(), raw_params.len())
470
434
  };
471
435
  self.map_result_ssl(rc)
472
436
  }
@@ -518,18 +482,10 @@ impl Handshake {
518
482
  s.to_str().ok()
519
483
  }
520
484
 
521
- pub fn provide_data(
522
- &mut self, level: crypto::Level, buf: &[u8],
523
- ) -> Result<()> {
485
+ pub fn provide_data(&mut self, level: crypto::Level, buf: &[u8]) -> Result<()> {
524
486
  self.provided_data_outstanding = true;
525
- let rc = unsafe {
526
- SSL_provide_quic_data(
527
- self.as_mut_ptr(),
528
- level,
529
- buf.as_ptr(),
530
- buf.len(),
531
- )
532
- };
487
+ let rc =
488
+ unsafe { SSL_provide_quic_data(self.as_mut_ptr(), level, buf.as_ptr(), buf.len()) };
533
489
  self.map_result_ssl(rc)
534
490
  }
535
491
 
@@ -563,8 +519,7 @@ impl Handshake {
563
519
  }
564
520
 
565
521
  pub fn cipher(&self) -> Option<crypto::Algorithm> {
566
- let cipher =
567
- map_result_ptr(unsafe { SSL_get_current_cipher(self.as_ptr()) });
522
+ let cipher = map_result_ptr(unsafe { SSL_get_current_cipher(self.as_ptr()) });
568
523
 
569
524
  get_cipher_from_ptr(cipher.ok()?).ok()
570
525
  }
@@ -590,11 +545,11 @@ impl Handshake {
590
545
  }
591
546
 
592
547
  fn as_ptr(&self) -> *const SSL {
593
- self.ptr
548
+ self.ptr.as_ptr()
594
549
  }
595
550
 
596
551
  fn as_mut_ptr(&mut self) -> *mut SSL {
597
- self.ptr
552
+ self.ptr.as_ptr()
598
553
  }
599
554
 
600
555
  fn map_result_ssl(&mut self, bssl_result: c_int) -> Result<()> {
@@ -609,7 +564,7 @@ impl Handshake {
609
564
  log_ssl_error();
610
565
 
611
566
  Err(Error::TlsFail)
612
- },
567
+ }
613
568
 
614
569
  // SSL_ERROR_WANT_READ
615
570
  2 => Err(Error::Done),
@@ -639,14 +594,14 @@ impl Handshake {
639
594
  15 => {
640
595
  self.reset_early_data_reject();
641
596
  Err(Error::Done)
642
- },
597
+ }
643
598
 
644
599
  // SSL_ERROR_WANT_CERTIFICATE_VERIFY
645
600
  16 => Err(Error::Done),
646
601
 
647
602
  _ => Err(Error::TlsFail),
648
603
  }
649
- },
604
+ }
650
605
  }
651
606
  }
652
607
 
@@ -671,7 +626,10 @@ impl Handshake {
671
626
  /// Fills `out` with `out.len()` bytes derived from `label` and the optional
672
627
  /// `context`. Fails if the handshake has not completed.
673
628
  pub fn export_keying_material(
674
- &mut self, out: &mut [u8], label: &[u8], context: Option<&[u8]>,
629
+ &mut self,
630
+ out: &mut [u8],
631
+ label: &[u8],
632
+ context: Option<&[u8]>,
675
633
  ) -> Result<()> {
676
634
  let (context, context_len, use_context) = match context {
677
635
  Some(c) => (c.as_ptr(), c.len(), 1),
@@ -706,11 +664,9 @@ impl Handshake {
706
664
  }
707
665
  }
708
666
 
709
- // NOTE: These traits are not automatically implemented for Handshake due to the
710
- // raw pointer it wraps. However, the underlying data is not aliased (as
711
- // Handshake should be its only owner), and there is no interior mutability, as
712
- // the pointer is not accessed directly outside of this module, and the
713
- // Handshake object API should preserve Rust's borrowing guarantees.
667
+ // These traits are not automatically implemented because NonNull does not
668
+ // convey ownership. Handshake uniquely owns the underlying data, and its API
669
+ // preserves Rust's borrowing guarantees.
714
670
  unsafe impl Send for Handshake {}
715
671
  unsafe impl Sync for Handshake {}
716
672
 
@@ -739,13 +695,12 @@ pub struct ExData<'a> {
739
695
 
740
696
  pub tx_cap_factor: f64,
741
697
 
698
+ pub max_outstanding_sent_packets: Option<std::num::NonZeroUsize>,
699
+
742
700
  /// PMTUD configuration: (enable, max_probes)
743
701
  pub pmtud: Option<(bool, u8)>,
744
702
 
745
703
  pub is_server: bool,
746
-
747
- /// see [`Connection::use_initial_max_data_as_flow_control_win`]
748
- pub use_initial_max_data_as_flow_control_win: bool,
749
704
  }
750
705
 
751
706
  impl<'a> ExData<'a> {
@@ -787,8 +742,11 @@ fn get_cipher_from_ptr(cipher: *const SSL_CIPHER) -> Result<crypto::Algorithm> {
787
742
  }
788
743
 
789
744
  extern "C" fn set_read_secret(
790
- ssl: *mut SSL, level: crypto::Level, cipher: *const SSL_CIPHER,
791
- secret: *const u8, secret_len: usize,
745
+ ssl: *mut SSL,
746
+ level: crypto::Level,
747
+ cipher: *const SSL_CIPHER,
748
+ secret: *const u8,
749
+ secret_len: usize,
792
750
  ) -> c_int {
793
751
  let ex_data = match ExData::from_ssl_ptr(ssl) {
794
752
  Some(v) => v,
@@ -800,12 +758,9 @@ extern "C" fn set_read_secret(
800
758
 
801
759
  let space = match level {
802
760
  crypto::Level::Initial => &mut ex_data.crypto_ctx[packet::Epoch::Initial],
803
- crypto::Level::ZeroRTT =>
804
- &mut ex_data.crypto_ctx[packet::Epoch::Application],
805
- crypto::Level::Handshake =>
806
- &mut ex_data.crypto_ctx[packet::Epoch::Handshake],
807
- crypto::Level::OneRTT =>
808
- &mut ex_data.crypto_ctx[packet::Epoch::Application],
761
+ crypto::Level::ZeroRTT => &mut ex_data.crypto_ctx[packet::Epoch::Application],
762
+ crypto::Level::Handshake => &mut ex_data.crypto_ctx[packet::Epoch::Handshake],
763
+ crypto::Level::OneRTT => &mut ex_data.crypto_ctx[packet::Epoch::Application],
809
764
  };
810
765
 
811
766
  let aead = match get_cipher_from_ptr(cipher) {
@@ -836,8 +791,11 @@ extern "C" fn set_read_secret(
836
791
  }
837
792
 
838
793
  extern "C" fn set_write_secret(
839
- ssl: *mut SSL, level: crypto::Level, cipher: *const SSL_CIPHER,
840
- secret: *const u8, secret_len: usize,
794
+ ssl: *mut SSL,
795
+ level: crypto::Level,
796
+ cipher: *const SSL_CIPHER,
797
+ secret: *const u8,
798
+ secret_len: usize,
841
799
  ) -> c_int {
842
800
  let ex_data = match ExData::from_ssl_ptr(ssl) {
843
801
  Some(v) => v,
@@ -849,12 +807,9 @@ extern "C" fn set_write_secret(
849
807
 
850
808
  let space = match level {
851
809
  crypto::Level::Initial => &mut ex_data.crypto_ctx[packet::Epoch::Initial],
852
- crypto::Level::ZeroRTT =>
853
- &mut ex_data.crypto_ctx[packet::Epoch::Application],
854
- crypto::Level::Handshake =>
855
- &mut ex_data.crypto_ctx[packet::Epoch::Handshake],
856
- crypto::Level::OneRTT =>
857
- &mut ex_data.crypto_ctx[packet::Epoch::Application],
810
+ crypto::Level::ZeroRTT => &mut ex_data.crypto_ctx[packet::Epoch::Application],
811
+ crypto::Level::Handshake => &mut ex_data.crypto_ctx[packet::Epoch::Handshake],
812
+ crypto::Level::OneRTT => &mut ex_data.crypto_ctx[packet::Epoch::Application],
858
813
  };
859
814
 
860
815
  let aead = match get_cipher_from_ptr(cipher) {
@@ -880,7 +835,10 @@ extern "C" fn set_write_secret(
880
835
  }
881
836
 
882
837
  extern "C" fn add_handshake_data(
883
- ssl: *mut SSL, level: crypto::Level, data: *const u8, len: usize,
838
+ ssl: *mut SSL,
839
+ level: crypto::Level,
840
+ data: *const u8,
841
+ len: usize,
884
842
  ) -> c_int {
885
843
  let ex_data = match ExData::from_ssl_ptr(ssl) {
886
844
  Some(v) => v,
@@ -900,10 +858,8 @@ extern "C" fn add_handshake_data(
900
858
  let space = match level {
901
859
  crypto::Level::Initial => &mut ex_data.crypto_ctx[packet::Epoch::Initial],
902
860
  crypto::Level::ZeroRTT => unreachable!(),
903
- crypto::Level::Handshake =>
904
- &mut ex_data.crypto_ctx[packet::Epoch::Handshake],
905
- crypto::Level::OneRTT =>
906
- &mut ex_data.crypto_ctx[packet::Epoch::Application],
861
+ crypto::Level::Handshake => &mut ex_data.crypto_ctx[packet::Epoch::Handshake],
862
+ crypto::Level::OneRTT => &mut ex_data.crypto_ctx[packet::Epoch::Application],
907
863
  };
908
864
 
909
865
  if space.crypto_stream.send.write(buf, false).is_err() {
@@ -920,9 +876,7 @@ extern "C" fn flush_flight(_ssl: *mut SSL) -> c_int {
920
876
  1
921
877
  }
922
878
 
923
- extern "C" fn send_alert(
924
- ssl: *mut SSL, level: crypto::Level, alert: u8,
925
- ) -> c_int {
879
+ extern "C" fn send_alert(ssl: *mut SSL, level: crypto::Level, alert: u8) -> c_int {
926
880
  let ex_data = match ExData::from_ssl_ptr(ssl) {
927
881
  Some(v) => v,
928
882
 
@@ -966,8 +920,12 @@ extern "C" fn keylog(ssl: *const SSL, line: *const c_char) {
966
920
  }
967
921
 
968
922
  extern "C" fn select_alpn(
969
- ssl: *mut SSL, out: *mut *const u8, out_len: *mut u8, inp: *mut u8,
970
- in_len: c_uint, _arg: *mut c_void,
923
+ ssl: *mut SSL,
924
+ out: *mut *const u8,
925
+ out_len: *mut u8,
926
+ inp: *mut u8,
927
+ in_len: c_uint,
928
+ _arg: *mut c_void,
971
929
  ) -> c_int {
972
930
  // SSL_TLSEXT_ERR_OK 0
973
931
  // SSL_TLSEXT_ERR_ALERT_WARNING 1
@@ -987,9 +945,8 @@ extern "C" fn select_alpn(
987
945
  return TLS_ERROR;
988
946
  }
989
947
 
990
- let mut protos = octets::Octets::with_slice(unsafe {
991
- slice::from_raw_parts(inp, in_len as usize)
992
- });
948
+ let mut protos =
949
+ octets::Octets::with_slice(unsafe { slice::from_raw_parts(inp, in_len as usize) });
993
950
 
994
951
  while let Ok(proto) = protos.get_bytes_with_u8_length() {
995
952
  let found = ex_data.application_protos.iter().any(|expected| {
@@ -999,9 +956,7 @@ extern "C" fn select_alpn(
999
956
  std::str::from_utf8(expected.as_slice())
1000
957
  );
1001
958
 
1002
- if expected.len() == proto.len() &&
1003
- expected.as_slice() == proto.as_ref()
1004
- {
959
+ if expected.len() == proto.len() && expected.as_slice() == proto.as_ref() {
1005
960
  unsafe {
1006
961
  *out = expected.as_slice().as_ptr();
1007
962
  *out_len = expected.len() as u8;
@@ -1022,7 +977,13 @@ extern "C" fn select_alpn(
1022
977
  }
1023
978
 
1024
979
  extern "C" fn new_session(ssl: *mut SSL, session: *mut SSL_SESSION) -> c_int {
1025
- let ex_data = match ExData::from_ssl_ptr(ssl) {
980
+ let ssl = match NonNull::new(ssl) {
981
+ Some(v) => v,
982
+
983
+ None => return 0,
984
+ };
985
+
986
+ let ex_data = match ExData::from_ssl_ptr(ssl.as_ptr()) {
1026
987
  Some(v) => v,
1027
988
 
1028
989
  None => return 0,
@@ -1039,8 +1000,7 @@ extern "C" fn new_session(ssl: *mut SSL, session: *mut SSL_SESSION) -> c_int {
1039
1000
  Err(_) => return 0,
1040
1001
  };
1041
1002
 
1042
- let mut buffer =
1043
- Vec::with_capacity(8 + peer_params.len() + 8 + session_bytes.len());
1003
+ let mut buffer = Vec::with_capacity(8 + peer_params.len() + 8 + session_bytes.len());
1044
1004
 
1045
1005
  let session_bytes_len = session_bytes.len() as u64;
1046
1006
 
@@ -1117,16 +1077,14 @@ extern "C" {
1117
1077
  fn SSL_CTX_new(method: *const SSL_METHOD) -> *mut SSL_CTX;
1118
1078
  fn SSL_CTX_free(ctx: *mut SSL_CTX);
1119
1079
 
1120
- fn SSL_CTX_use_certificate_chain_file(
1121
- ctx: *mut SSL_CTX, file: *const c_char,
1122
- ) -> c_int;
1080
+ fn SSL_CTX_use_certificate_chain_file(ctx: *mut SSL_CTX, file: *const c_char) -> c_int;
1123
1081
 
1124
- fn SSL_CTX_use_PrivateKey_file(
1125
- ctx: *mut SSL_CTX, file: *const c_char, ty: c_int,
1126
- ) -> c_int;
1082
+ fn SSL_CTX_use_PrivateKey_file(ctx: *mut SSL_CTX, file: *const c_char, ty: c_int) -> c_int;
1127
1083
 
1128
1084
  fn SSL_CTX_load_verify_locations(
1129
- ctx: *mut SSL_CTX, file: *const c_char, path: *const c_char,
1085
+ ctx: *mut SSL_CTX,
1086
+ file: *const c_char,
1087
+ path: *const c_char,
1130
1088
  ) -> c_int;
1131
1089
 
1132
1090
  #[cfg(not(windows))]
@@ -1136,13 +1094,9 @@ extern "C" {
1136
1094
  fn SSL_CTX_get_cert_store(ctx: *mut SSL_CTX) -> *mut X509_STORE;
1137
1095
 
1138
1096
  fn SSL_CTX_set_verify(
1139
- ctx: *mut SSL_CTX, mode: c_int,
1140
- cb: Option<
1141
- unsafe extern "C" fn(
1142
- ok: c_int,
1143
- store_ctx: *mut X509_STORE_CTX,
1144
- ) -> c_int,
1145
- >,
1097
+ ctx: *mut SSL_CTX,
1098
+ mode: c_int,
1099
+ cb: Option<unsafe extern "C" fn(ok: c_int, store_ctx: *mut X509_STORE_CTX) -> c_int>,
1146
1100
  );
1147
1101
 
1148
1102
  fn SSL_CTX_set_keylog_callback(
@@ -1150,9 +1104,7 @@ extern "C" {
1150
1104
  cb: Option<unsafe extern "C" fn(ssl: *const SSL, line: *const c_char)>,
1151
1105
  );
1152
1106
 
1153
- fn SSL_CTX_set_alpn_protos(
1154
- ctx: *mut SSL_CTX, protos: *const u8, protos_len: usize,
1155
- ) -> c_int;
1107
+ fn SSL_CTX_set_alpn_protos(ctx: *mut SSL_CTX, protos: *const u8, protos_len: usize) -> c_int;
1156
1108
 
1157
1109
  fn SSL_CTX_set_alpn_select_cb(
1158
1110
  ctx: *mut SSL_CTX,
@@ -1171,12 +1123,7 @@ extern "C" {
1171
1123
 
1172
1124
  fn SSL_CTX_sess_set_new_cb(
1173
1125
  ctx: *mut SSL_CTX,
1174
- cb: Option<
1175
- unsafe extern "C" fn(
1176
- ssl: *mut SSL,
1177
- session: *mut SSL_SESSION,
1178
- ) -> c_int,
1179
- >,
1126
+ cb: Option<unsafe extern "C" fn(ssl: *mut SSL, session: *mut SSL_SESSION) -> c_int>,
1180
1127
  );
1181
1128
 
1182
1129
  fn SSL_new(ctx: *mut SSL_CTX) -> *mut SSL;
@@ -1199,13 +1146,9 @@ extern "C" {
1199
1146
 
1200
1147
  fn SSL_set_quiet_shutdown(ssl: *mut SSL, mode: c_int);
1201
1148
 
1202
- fn SSL_set_quic_transport_params(
1203
- ssl: *mut SSL, params: *const u8, params_len: usize,
1204
- ) -> c_int;
1149
+ fn SSL_set_quic_transport_params(ssl: *mut SSL, params: *const u8, params_len: usize) -> c_int;
1205
1150
 
1206
- fn SSL_set_quic_method(
1207
- ssl: *mut SSL, quic_method: *const SSL_QUIC_METHOD,
1208
- ) -> c_int;
1151
+ fn SSL_set_quic_method(ssl: *mut SSL, quic_method: *const SSL_QUIC_METHOD) -> c_int;
1209
1152
 
1210
1153
  fn SSL_set_quic_use_legacy_codepoint(ssl: *mut SSL, use_legacy: c_int);
1211
1154
 
@@ -1213,17 +1156,20 @@ extern "C" {
1213
1156
  fn SSL_set_options(ssl: *mut SSL, opts: u32) -> u32;
1214
1157
 
1215
1158
  fn SSL_get_peer_quic_transport_params(
1216
- ssl: *const SSL, out_params: *mut *const u8, out_params_len: *mut usize,
1159
+ ssl: *const SSL,
1160
+ out_params: *mut *const u8,
1161
+ out_params_len: *mut usize,
1217
1162
  );
1218
1163
 
1219
- fn SSL_get0_alpn_selected(
1220
- ssl: *const SSL, out: *mut *const u8, out_len: *mut u32,
1221
- );
1164
+ fn SSL_get0_alpn_selected(ssl: *const SSL, out: *mut *const u8, out_len: *mut u32);
1222
1165
 
1223
1166
  fn SSL_get_servername(ssl: *const SSL, ty: c_int) -> *const c_char;
1224
1167
 
1225
1168
  fn SSL_provide_quic_data(
1226
- ssl: *mut SSL, level: crypto::Level, data: *const u8, len: usize,
1169
+ ssl: *mut SSL,
1170
+ level: crypto::Level,
1171
+ data: *const u8,
1172
+ len: usize,
1227
1173
  ) -> c_int;
1228
1174
 
1229
1175
  fn SSL_process_quic_post_handshake(ssl: *mut SSL) -> c_int;
@@ -1239,8 +1185,13 @@ extern "C" {
1239
1185
  fn SSL_clear(ssl: *mut SSL) -> c_int;
1240
1186
 
1241
1187
  fn SSL_export_keying_material(
1242
- ssl: *mut SSL, out: *mut u8, out_len: usize, label: *const c_char,
1243
- label_len: usize, context: *const u8, context_len: usize,
1188
+ ssl: *mut SSL,
1189
+ out: *mut u8,
1190
+ out_len: usize,
1191
+ label: *const c_char,
1192
+ label_len: usize,
1193
+ context: *const u8,
1194
+ context_len: usize,
1244
1195
  use_context: c_int,
1245
1196
  ) -> c_int;
1246
1197
 
@@ -1255,7 +1206,9 @@ extern "C" {
1255
1206
 
1256
1207
  // X509_VERIFY_PARAM
1257
1208
  fn X509_VERIFY_PARAM_set1_host(
1258
- param: *mut X509_VERIFY_PARAM, name: *const c_char, namelen: usize,
1209
+ param: *mut X509_VERIFY_PARAM,
1210
+ name: *const c_char,
1211
+ namelen: usize,
1259
1212
  ) -> c_int;
1260
1213
 
1261
1214
  // X509_STORE