wreq-rb 0.3.0

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 (167) hide show
  1. checksums.yaml +7 -0
  2. data/Cargo.lock +2688 -0
  3. data/Cargo.toml +6 -0
  4. data/README.md +179 -0
  5. data/ext/wreq_rb/Cargo.toml +39 -0
  6. data/ext/wreq_rb/extconf.rb +22 -0
  7. data/ext/wreq_rb/src/client.rs +565 -0
  8. data/ext/wreq_rb/src/error.rs +25 -0
  9. data/ext/wreq_rb/src/lib.rs +20 -0
  10. data/ext/wreq_rb/src/response.rs +132 -0
  11. data/lib/wreq-rb/version.rb +5 -0
  12. data/lib/wreq-rb.rb +17 -0
  13. data/patches/0001-add-transfer-size-tracking.patch +292 -0
  14. data/vendor/wreq/Cargo.toml +306 -0
  15. data/vendor/wreq/LICENSE +202 -0
  16. data/vendor/wreq/README.md +122 -0
  17. data/vendor/wreq/examples/cert_store.rs +77 -0
  18. data/vendor/wreq/examples/connect_via_lower_priority_tokio_runtime.rs +258 -0
  19. data/vendor/wreq/examples/emulation.rs +118 -0
  20. data/vendor/wreq/examples/form.rs +14 -0
  21. data/vendor/wreq/examples/http1_websocket.rs +37 -0
  22. data/vendor/wreq/examples/http2_websocket.rs +45 -0
  23. data/vendor/wreq/examples/json_dynamic.rs +41 -0
  24. data/vendor/wreq/examples/json_typed.rs +47 -0
  25. data/vendor/wreq/examples/keylog.rs +16 -0
  26. data/vendor/wreq/examples/request_with_emulation.rs +115 -0
  27. data/vendor/wreq/examples/request_with_interface.rs +37 -0
  28. data/vendor/wreq/examples/request_with_local_address.rs +16 -0
  29. data/vendor/wreq/examples/request_with_proxy.rs +13 -0
  30. data/vendor/wreq/examples/request_with_redirect.rs +22 -0
  31. data/vendor/wreq/examples/request_with_version.rs +15 -0
  32. data/vendor/wreq/examples/tor_socks.rs +24 -0
  33. data/vendor/wreq/examples/unix_socket.rs +33 -0
  34. data/vendor/wreq/src/client/body.rs +304 -0
  35. data/vendor/wreq/src/client/conn/conn.rs +231 -0
  36. data/vendor/wreq/src/client/conn/connector.rs +549 -0
  37. data/vendor/wreq/src/client/conn/http.rs +1023 -0
  38. data/vendor/wreq/src/client/conn/proxy/socks.rs +233 -0
  39. data/vendor/wreq/src/client/conn/proxy/tunnel.rs +260 -0
  40. data/vendor/wreq/src/client/conn/proxy.rs +39 -0
  41. data/vendor/wreq/src/client/conn/tls_info.rs +98 -0
  42. data/vendor/wreq/src/client/conn/uds.rs +44 -0
  43. data/vendor/wreq/src/client/conn/verbose.rs +149 -0
  44. data/vendor/wreq/src/client/conn.rs +323 -0
  45. data/vendor/wreq/src/client/core/body/incoming.rs +485 -0
  46. data/vendor/wreq/src/client/core/body/length.rs +118 -0
  47. data/vendor/wreq/src/client/core/body.rs +34 -0
  48. data/vendor/wreq/src/client/core/common/buf.rs +149 -0
  49. data/vendor/wreq/src/client/core/common/rewind.rs +141 -0
  50. data/vendor/wreq/src/client/core/common/watch.rs +76 -0
  51. data/vendor/wreq/src/client/core/common.rs +3 -0
  52. data/vendor/wreq/src/client/core/conn/http1.rs +342 -0
  53. data/vendor/wreq/src/client/core/conn/http2.rs +307 -0
  54. data/vendor/wreq/src/client/core/conn.rs +11 -0
  55. data/vendor/wreq/src/client/core/dispatch.rs +299 -0
  56. data/vendor/wreq/src/client/core/error.rs +435 -0
  57. data/vendor/wreq/src/client/core/ext.rs +201 -0
  58. data/vendor/wreq/src/client/core/http1.rs +178 -0
  59. data/vendor/wreq/src/client/core/http2.rs +483 -0
  60. data/vendor/wreq/src/client/core/proto/h1/conn.rs +988 -0
  61. data/vendor/wreq/src/client/core/proto/h1/decode.rs +1170 -0
  62. data/vendor/wreq/src/client/core/proto/h1/dispatch.rs +684 -0
  63. data/vendor/wreq/src/client/core/proto/h1/encode.rs +580 -0
  64. data/vendor/wreq/src/client/core/proto/h1/io.rs +879 -0
  65. data/vendor/wreq/src/client/core/proto/h1/role.rs +694 -0
  66. data/vendor/wreq/src/client/core/proto/h1.rs +104 -0
  67. data/vendor/wreq/src/client/core/proto/h2/client.rs +650 -0
  68. data/vendor/wreq/src/client/core/proto/h2/ping.rs +539 -0
  69. data/vendor/wreq/src/client/core/proto/h2.rs +379 -0
  70. data/vendor/wreq/src/client/core/proto/headers.rs +138 -0
  71. data/vendor/wreq/src/client/core/proto.rs +58 -0
  72. data/vendor/wreq/src/client/core/rt/bounds.rs +57 -0
  73. data/vendor/wreq/src/client/core/rt/timer.rs +150 -0
  74. data/vendor/wreq/src/client/core/rt/tokio.rs +99 -0
  75. data/vendor/wreq/src/client/core/rt.rs +25 -0
  76. data/vendor/wreq/src/client/core/upgrade.rs +267 -0
  77. data/vendor/wreq/src/client/core.rs +16 -0
  78. data/vendor/wreq/src/client/emulation.rs +161 -0
  79. data/vendor/wreq/src/client/http/client/error.rs +142 -0
  80. data/vendor/wreq/src/client/http/client/exec.rs +29 -0
  81. data/vendor/wreq/src/client/http/client/extra.rs +77 -0
  82. data/vendor/wreq/src/client/http/client/lazy.rs +79 -0
  83. data/vendor/wreq/src/client/http/client/pool.rs +1105 -0
  84. data/vendor/wreq/src/client/http/client/util.rs +104 -0
  85. data/vendor/wreq/src/client/http/client.rs +1003 -0
  86. data/vendor/wreq/src/client/http/future.rs +99 -0
  87. data/vendor/wreq/src/client/http.rs +1629 -0
  88. data/vendor/wreq/src/client/layer/config/options.rs +156 -0
  89. data/vendor/wreq/src/client/layer/config.rs +116 -0
  90. data/vendor/wreq/src/client/layer/cookie.rs +161 -0
  91. data/vendor/wreq/src/client/layer/decoder.rs +139 -0
  92. data/vendor/wreq/src/client/layer/redirect/future.rs +270 -0
  93. data/vendor/wreq/src/client/layer/redirect/policy.rs +63 -0
  94. data/vendor/wreq/src/client/layer/redirect.rs +145 -0
  95. data/vendor/wreq/src/client/layer/retry/classify.rs +105 -0
  96. data/vendor/wreq/src/client/layer/retry/scope.rs +51 -0
  97. data/vendor/wreq/src/client/layer/retry.rs +151 -0
  98. data/vendor/wreq/src/client/layer/timeout/body.rs +233 -0
  99. data/vendor/wreq/src/client/layer/timeout/future.rs +90 -0
  100. data/vendor/wreq/src/client/layer/timeout.rs +177 -0
  101. data/vendor/wreq/src/client/layer.rs +15 -0
  102. data/vendor/wreq/src/client/multipart.rs +717 -0
  103. data/vendor/wreq/src/client/request.rs +818 -0
  104. data/vendor/wreq/src/client/response.rs +534 -0
  105. data/vendor/wreq/src/client/ws/json.rs +99 -0
  106. data/vendor/wreq/src/client/ws/message.rs +453 -0
  107. data/vendor/wreq/src/client/ws.rs +714 -0
  108. data/vendor/wreq/src/client.rs +27 -0
  109. data/vendor/wreq/src/config.rs +140 -0
  110. data/vendor/wreq/src/cookie.rs +579 -0
  111. data/vendor/wreq/src/dns/gai.rs +249 -0
  112. data/vendor/wreq/src/dns/hickory.rs +78 -0
  113. data/vendor/wreq/src/dns/resolve.rs +180 -0
  114. data/vendor/wreq/src/dns.rs +69 -0
  115. data/vendor/wreq/src/error.rs +502 -0
  116. data/vendor/wreq/src/ext.rs +398 -0
  117. data/vendor/wreq/src/hash.rs +143 -0
  118. data/vendor/wreq/src/header.rs +506 -0
  119. data/vendor/wreq/src/into_uri.rs +187 -0
  120. data/vendor/wreq/src/lib.rs +586 -0
  121. data/vendor/wreq/src/proxy/mac.rs +82 -0
  122. data/vendor/wreq/src/proxy/matcher.rs +806 -0
  123. data/vendor/wreq/src/proxy/uds.rs +66 -0
  124. data/vendor/wreq/src/proxy/win.rs +31 -0
  125. data/vendor/wreq/src/proxy.rs +569 -0
  126. data/vendor/wreq/src/redirect.rs +575 -0
  127. data/vendor/wreq/src/retry.rs +198 -0
  128. data/vendor/wreq/src/sync.rs +129 -0
  129. data/vendor/wreq/src/tls/conn/cache.rs +123 -0
  130. data/vendor/wreq/src/tls/conn/cert_compression.rs +125 -0
  131. data/vendor/wreq/src/tls/conn/ext.rs +82 -0
  132. data/vendor/wreq/src/tls/conn/macros.rs +34 -0
  133. data/vendor/wreq/src/tls/conn/service.rs +138 -0
  134. data/vendor/wreq/src/tls/conn.rs +681 -0
  135. data/vendor/wreq/src/tls/keylog/handle.rs +64 -0
  136. data/vendor/wreq/src/tls/keylog.rs +99 -0
  137. data/vendor/wreq/src/tls/options.rs +464 -0
  138. data/vendor/wreq/src/tls/x509/identity.rs +122 -0
  139. data/vendor/wreq/src/tls/x509/parser.rs +71 -0
  140. data/vendor/wreq/src/tls/x509/store.rs +228 -0
  141. data/vendor/wreq/src/tls/x509.rs +68 -0
  142. data/vendor/wreq/src/tls.rs +154 -0
  143. data/vendor/wreq/src/trace.rs +55 -0
  144. data/vendor/wreq/src/util.rs +122 -0
  145. data/vendor/wreq/tests/badssl.rs +228 -0
  146. data/vendor/wreq/tests/brotli.rs +350 -0
  147. data/vendor/wreq/tests/client.rs +1098 -0
  148. data/vendor/wreq/tests/connector_layers.rs +227 -0
  149. data/vendor/wreq/tests/cookie.rs +306 -0
  150. data/vendor/wreq/tests/deflate.rs +347 -0
  151. data/vendor/wreq/tests/emulation.rs +260 -0
  152. data/vendor/wreq/tests/gzip.rs +347 -0
  153. data/vendor/wreq/tests/layers.rs +261 -0
  154. data/vendor/wreq/tests/multipart.rs +165 -0
  155. data/vendor/wreq/tests/proxy.rs +438 -0
  156. data/vendor/wreq/tests/redirect.rs +629 -0
  157. data/vendor/wreq/tests/retry.rs +135 -0
  158. data/vendor/wreq/tests/support/delay_server.rs +117 -0
  159. data/vendor/wreq/tests/support/error.rs +16 -0
  160. data/vendor/wreq/tests/support/layer.rs +183 -0
  161. data/vendor/wreq/tests/support/mod.rs +9 -0
  162. data/vendor/wreq/tests/support/server.rs +232 -0
  163. data/vendor/wreq/tests/timeouts.rs +281 -0
  164. data/vendor/wreq/tests/unix_socket.rs +135 -0
  165. data/vendor/wreq/tests/upgrade.rs +98 -0
  166. data/vendor/wreq/tests/zstd.rs +559 -0
  167. metadata +225 -0
@@ -0,0 +1,64 @@
1
+ use std::{
2
+ fs::OpenOptions,
3
+ io::{Result, Write},
4
+ path::Path,
5
+ sync::{
6
+ Arc,
7
+ mpsc::{self, Sender},
8
+ },
9
+ };
10
+
11
+ /// Handle for writing to a key log file.
12
+ #[derive(Debug, Clone)]
13
+ pub struct Handle {
14
+ #[allow(unused)]
15
+ filepath: Arc<Path>,
16
+ sender: Sender<String>,
17
+ }
18
+
19
+ impl Handle {
20
+ /// Create a new [`Handle`] with the specified path and sender.
21
+ pub fn new(filepath: Arc<Path>) -> Result<Self> {
22
+ if let Some(parent) = filepath.parent() {
23
+ std::fs::create_dir_all(parent)?;
24
+ }
25
+
26
+ let mut file = OpenOptions::new()
27
+ .create(true)
28
+ .append(true)
29
+ .open(&filepath)?;
30
+
31
+ let (sender, receiver) = mpsc::channel::<String>();
32
+
33
+ let _path_name = filepath.clone();
34
+ std::thread::spawn(move || {
35
+ trace!(
36
+ file = ?_path_name,
37
+ "Handle: receiver task up and running",
38
+ );
39
+ while let Ok(line) = receiver.recv() {
40
+ if let Err(_err) = file.write_all(line.as_bytes()) {
41
+ error!(
42
+ file = ?_path_name,
43
+ error = %_err,
44
+ "Handle: failed to write file",
45
+ );
46
+ }
47
+ }
48
+ });
49
+
50
+ Ok(Handle { filepath, sender })
51
+ }
52
+
53
+ /// Write a line to the keylogger.
54
+ pub fn write(&self, line: &str) {
55
+ let line = format!("{line}\n");
56
+ if let Err(_err) = self.sender.send(line) {
57
+ error!(
58
+ file = ?self.filepath,
59
+ error = %_err,
60
+ "Handle: failed to send log line for writing",
61
+ );
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,99 @@
1
+ //! TLS Key Log Management
2
+ //!
3
+ //! This module provides utilities for managing TLS key logging, allowing session keys to be
4
+ //! written to a file for debugging or analysis (e.g., with Wireshark).
5
+ //!
6
+ //! The [`KeyLog`] enum lets you control key log behavior, either by respecting the
7
+ //! `SSLKEYLOGFILE` environment variable or by specifying a custom file path. Handles are cached
8
+ //! globally to avoid duplicate file access.
9
+ //!
10
+ //! Use [`KeyLog::handle`] to obtain a [`Handle`] for writing keys.
11
+
12
+ mod handle;
13
+
14
+ use std::{
15
+ borrow::Cow,
16
+ collections::{HashMap, hash_map::Entry},
17
+ io::{Error, ErrorKind, Result},
18
+ path::{Component, Path, PathBuf},
19
+ sync::{Arc, OnceLock},
20
+ };
21
+
22
+ use handle::Handle;
23
+
24
+ use crate::sync::RwLock;
25
+
26
+ /// Specifies the intent for a (TLS) keylogger.
27
+ #[derive(Debug, Clone)]
28
+ pub struct KeyLog(Option<Arc<Path>>);
29
+
30
+ impl KeyLog {
31
+ /// Creates a [`KeyLog`] based on the `SSLKEYLOGFILE` environment variable.
32
+ pub fn from_env() -> KeyLog {
33
+ match std::env::var("SSLKEYLOGFILE") {
34
+ Ok(ref s) if !s.trim().is_empty() => {
35
+ KeyLog(Some(Arc::from(normalize_path(Path::new(s)))))
36
+ }
37
+ _ => KeyLog(None),
38
+ }
39
+ }
40
+
41
+ /// Creates a [`KeyLog`] that writes to the specified file path.
42
+ pub fn from_file<P: AsRef<Path>>(path: P) -> KeyLog {
43
+ KeyLog(Some(Arc::from(normalize_path(path.as_ref()))))
44
+ }
45
+
46
+ /// Creates a new key log file [`Handle`] based on the policy.
47
+ pub(crate) fn handle(self) -> Result<Handle> {
48
+ static GLOBAL_KEYLOG_CACHE: OnceLock<RwLock<HashMap<Arc<Path>, Handle>>> = OnceLock::new();
49
+
50
+ let path = self
51
+ .0
52
+ .ok_or_else(|| Error::new(ErrorKind::NotFound, "KeyLog: file path is not specified"))?;
53
+
54
+ let cache = GLOBAL_KEYLOG_CACHE.get_or_init(Default::default);
55
+ if let Some(handle) = cache.read().get(path.as_ref()).cloned() {
56
+ return Ok(handle);
57
+ }
58
+
59
+ match cache.write().entry(path.clone()) {
60
+ Entry::Occupied(entry) => Ok(entry.get().clone()),
61
+ Entry::Vacant(entry) => {
62
+ let handle = Handle::new(path)?;
63
+ entry.insert(handle.clone());
64
+ Ok(handle)
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ fn normalize_path<'a, P>(path: P) -> PathBuf
71
+ where
72
+ P: Into<Cow<'a, Path>>,
73
+ {
74
+ let path = path.into();
75
+ let mut components = path.components().peekable();
76
+ let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
77
+ components.next();
78
+ PathBuf::from(c.as_os_str())
79
+ } else {
80
+ PathBuf::new()
81
+ };
82
+
83
+ for component in components {
84
+ match component {
85
+ Component::Prefix(..) => unreachable!(),
86
+ Component::RootDir => {
87
+ ret.push(component.as_os_str());
88
+ }
89
+ Component::CurDir => {}
90
+ Component::ParentDir => {
91
+ ret.pop();
92
+ }
93
+ Component::Normal(c) => {
94
+ ret.push(c);
95
+ }
96
+ }
97
+ }
98
+ ret
99
+ }
@@ -0,0 +1,464 @@
1
+ use std::borrow::Cow;
2
+
3
+ use super::{
4
+ AlpnProtocol, AlpsProtocol, CertificateCompressionAlgorithm, ExtensionType, TlsVersion,
5
+ };
6
+
7
+ /// Builder for `[`TlsOptions`]`.
8
+ #[must_use]
9
+ #[derive(Debug, Clone)]
10
+ pub struct TlsOptionsBuilder {
11
+ config: TlsOptions,
12
+ }
13
+
14
+ /// TLS connection configuration options.
15
+ ///
16
+ /// This struct provides fine-grained control over the behavior of TLS
17
+ /// connections, including:
18
+ /// - **Protocol negotiation** (ALPN, ALPS, TLS versions)
19
+ /// - **Session management** (tickets, PSK, key shares)
20
+ /// - **Security & privacy** (OCSP, GREASE, ECH, delegated credentials)
21
+ /// - **Performance tuning** (record size, cipher preferences, hardware overrides)
22
+ ///
23
+ /// All fields are optional or have defaults. See each field for details.
24
+ #[derive(Debug, Clone, Hash, PartialEq, Eq)]
25
+ #[non_exhaustive]
26
+ pub struct TlsOptions {
27
+ /// Application-Layer Protocol Negotiation ([RFC 7301](https://datatracker.ietf.org/doc/html/rfc7301)).
28
+ ///
29
+ /// Specifies which application protocols (e.g., HTTP/2, HTTP/1.1) may be negotiated
30
+ /// over a single TLS connection.
31
+ ///
32
+ /// **Default:** `Some([HTTP/2, HTTP/1.1])`
33
+ pub alpn_protocols: Option<Cow<'static, [AlpnProtocol]>>,
34
+
35
+ /// Application-Layer Protocol Settings (ALPS).
36
+ ///
37
+ /// Enables exchanging application-layer settings during the handshake
38
+ /// for protocols negotiated via ALPN.
39
+ ///
40
+ /// **Default:** `None`
41
+ pub alps_protocols: Option<Cow<'static, [AlpsProtocol]>>,
42
+
43
+ /// Whether to use an alternative ALPS codepoint for compatibility.
44
+ ///
45
+ /// Useful when larger ALPS payloads are required.
46
+ ///
47
+ /// **Default:** `false`
48
+ pub alps_use_new_codepoint: bool,
49
+
50
+ /// Enables TLS Session Tickets ([RFC 5077](https://tools.ietf.org/html/rfc5077)).
51
+ ///
52
+ /// Allows session resumption without requiring server-side state.
53
+ ///
54
+ /// **Default:** `true`
55
+ pub session_ticket: bool,
56
+
57
+ /// Minimum TLS version allowed for the connection.
58
+ ///
59
+ /// **Default:** `None` (library default applied)
60
+ pub min_tls_version: Option<TlsVersion>,
61
+
62
+ /// Maximum TLS version allowed for the connection.
63
+ ///
64
+ /// **Default:** `None` (library default applied)
65
+ pub max_tls_version: Option<TlsVersion>,
66
+
67
+ /// Enables Pre-Shared Key (PSK) cipher suites ([RFC 4279](https://datatracker.ietf.org/doc/html/rfc4279)).
68
+ ///
69
+ /// Authentication relies on out-of-band pre-shared keys instead of certificates.
70
+ ///
71
+ /// **Default:** `false`
72
+ pub pre_shared_key: bool,
73
+
74
+ /// Controls whether to send a GREASE Encrypted ClientHello (ECH) extension
75
+ /// when no supported ECH configuration is available.
76
+ ///
77
+ /// GREASE prevents protocol ossification by sending unknown extensions.
78
+ ///
79
+ /// **Default:** `false`
80
+ pub enable_ech_grease: bool,
81
+
82
+ /// Controls whether ClientHello extensions should be permuted.
83
+ ///
84
+ /// **Default:** `None` (implementation default)
85
+ pub permute_extensions: Option<bool>,
86
+
87
+ /// Controls whether GREASE extensions ([RFC 8701](https://datatracker.ietf.org/doc/html/rfc8701))
88
+ /// are enabled in general.
89
+ ///
90
+ /// **Default:** `None` (implementation default)
91
+ pub grease_enabled: Option<bool>,
92
+
93
+ /// Enables OCSP stapling for the connection.
94
+ ///
95
+ /// **Default:** `false`
96
+ pub enable_ocsp_stapling: bool,
97
+
98
+ /// Enables Signed Certificate Timestamps (SCT).
99
+ ///
100
+ /// **Default:** `false`
101
+ pub enable_signed_cert_timestamps: bool,
102
+
103
+ /// Sets the maximum TLS record size.
104
+ ///
105
+ /// **Default:** `None`
106
+ pub record_size_limit: Option<u16>,
107
+
108
+ /// Whether to skip session tickets when using PSK.
109
+ ///
110
+ /// **Default:** `false`
111
+ pub psk_skip_session_ticket: bool,
112
+
113
+ /// Maximum number of key shares to include in ClientHello.
114
+ ///
115
+ /// **Default:** `None`
116
+ pub key_shares_limit: Option<u8>,
117
+
118
+ /// Enables PSK with (EC)DHE key establishment (`psk_dhe_ke`).
119
+ ///
120
+ /// **Default:** `true`
121
+ pub psk_dhe_ke: bool,
122
+
123
+ /// Enables TLS renegotiation by sending the `renegotiation_info` extension.
124
+ ///
125
+ /// **Default:** `true`
126
+ pub renegotiation: bool,
127
+
128
+ /// Delegated Credentials ([RFC 9345](https://datatracker.ietf.org/doc/html/rfc9345)).
129
+ ///
130
+ /// Allows TLS 1.3 endpoints to use temporary delegated credentials
131
+ /// for authentication with reduced long-term key exposure.
132
+ ///
133
+ /// **Default:** `None`
134
+ pub delegated_credentials: Option<Cow<'static, str>>,
135
+
136
+ /// List of supported elliptic curves.
137
+ ///
138
+ /// **Default:** `None`
139
+ pub curves_list: Option<Cow<'static, str>>,
140
+
141
+ /// Cipher suite configuration string.
142
+ ///
143
+ /// Uses BoringSSL's mini-language to select, enable, and prioritize ciphers.
144
+ ///
145
+ /// **Default:** `None`
146
+ pub cipher_list: Option<Cow<'static, str>>,
147
+
148
+ /// List of supported signature algorithms.
149
+ ///
150
+ /// **Default:** `None`
151
+ pub sigalgs_list: Option<Cow<'static, str>>,
152
+
153
+ /// Supported certificate compression algorithms ([RFC 8879](https://datatracker.ietf.org/doc/html/rfc8879)).
154
+ ///
155
+ /// **Default:** `None`
156
+ pub certificate_compression_algorithms: Option<Cow<'static, [CertificateCompressionAlgorithm]>>,
157
+
158
+ /// Supported TLS extensions, used for extension ordering/permutation.
159
+ ///
160
+ /// **Default:** `None`
161
+ pub extension_permutation: Option<Cow<'static, [ExtensionType]>>,
162
+
163
+ /// Overrides AES hardware acceleration.
164
+ ///
165
+ /// **Default:** `None`
166
+ pub aes_hw_override: Option<bool>,
167
+
168
+ /// Sets whether to preserve the TLS 1.3 cipher list as configured by [`Self::cipher_list`].
169
+ ///
170
+ /// **Default:** `None`
171
+ pub preserve_tls13_cipher_list: Option<bool>,
172
+
173
+ /// Overrides the random AES hardware acceleration.
174
+ ///
175
+ /// **Default:** `false`
176
+ pub random_aes_hw_override: bool,
177
+ }
178
+
179
+ impl TlsOptionsBuilder {
180
+ /// Sets the ALPN protocols to use.
181
+ #[inline]
182
+ pub fn alpn_protocols<I>(mut self, alpn: I) -> Self
183
+ where
184
+ I: IntoIterator<Item = AlpnProtocol>,
185
+ {
186
+ self.config.alpn_protocols = Some(Cow::Owned(alpn.into_iter().collect()));
187
+ self
188
+ }
189
+
190
+ /// Sets the ALPS protocols to use.
191
+ #[inline]
192
+ pub fn alps_protocols<I>(mut self, alps: I) -> Self
193
+ where
194
+ I: IntoIterator<Item = AlpsProtocol>,
195
+ {
196
+ self.config.alps_protocols = Some(Cow::Owned(alps.into_iter().collect()));
197
+ self
198
+ }
199
+
200
+ /// Sets whether to use a new codepoint for ALPS.
201
+ #[inline]
202
+ pub fn alps_use_new_codepoint(mut self, enabled: bool) -> Self {
203
+ self.config.alps_use_new_codepoint = enabled;
204
+ self
205
+ }
206
+ /// Sets the session ticket flag.
207
+ #[inline]
208
+ pub fn session_ticket(mut self, enabled: bool) -> Self {
209
+ self.config.session_ticket = enabled;
210
+ self
211
+ }
212
+
213
+ /// Sets the minimum TLS version to use.
214
+ #[inline]
215
+ pub fn min_tls_version<T>(mut self, version: T) -> Self
216
+ where
217
+ T: Into<Option<TlsVersion>>,
218
+ {
219
+ self.config.min_tls_version = version.into();
220
+ self
221
+ }
222
+
223
+ /// Sets the maximum TLS version to use.
224
+ #[inline]
225
+ pub fn max_tls_version<T>(mut self, version: T) -> Self
226
+ where
227
+ T: Into<Option<TlsVersion>>,
228
+ {
229
+ self.config.max_tls_version = version.into();
230
+ self
231
+ }
232
+
233
+ /// Sets the pre-shared key flag.
234
+ #[inline]
235
+ pub fn pre_shared_key(mut self, enabled: bool) -> Self {
236
+ self.config.pre_shared_key = enabled;
237
+ self
238
+ }
239
+
240
+ /// Sets the GREASE ECH extension flag.
241
+ #[inline]
242
+ pub fn enable_ech_grease(mut self, enabled: bool) -> Self {
243
+ self.config.enable_ech_grease = enabled;
244
+ self
245
+ }
246
+
247
+ /// Sets whether to permute ClientHello extensions.
248
+ #[inline]
249
+ pub fn permute_extensions<T>(mut self, permute: T) -> Self
250
+ where
251
+ T: Into<Option<bool>>,
252
+ {
253
+ self.config.permute_extensions = permute.into();
254
+ self
255
+ }
256
+
257
+ /// Sets the GREASE enabled flag.
258
+ #[inline]
259
+ pub fn grease_enabled<T>(mut self, enabled: T) -> Self
260
+ where
261
+ T: Into<Option<bool>>,
262
+ {
263
+ self.config.grease_enabled = enabled.into();
264
+ self
265
+ }
266
+
267
+ /// Sets the OCSP stapling flag.
268
+ #[inline]
269
+ pub fn enable_ocsp_stapling(mut self, enabled: bool) -> Self {
270
+ self.config.enable_ocsp_stapling = enabled;
271
+ self
272
+ }
273
+
274
+ /// Sets the signed certificate timestamps flag.
275
+ #[inline]
276
+ pub fn enable_signed_cert_timestamps(mut self, enabled: bool) -> Self {
277
+ self.config.enable_signed_cert_timestamps = enabled;
278
+ self
279
+ }
280
+
281
+ /// Sets the record size limit.
282
+ #[inline]
283
+ pub fn record_size_limit<U: Into<Option<u16>>>(mut self, limit: U) -> Self {
284
+ self.config.record_size_limit = limit.into();
285
+ self
286
+ }
287
+
288
+ /// Sets the PSK skip session ticket flag.
289
+ #[inline]
290
+ pub fn psk_skip_session_ticket(mut self, skip: bool) -> Self {
291
+ self.config.psk_skip_session_ticket = skip;
292
+ self
293
+ }
294
+
295
+ /// Sets the key shares length limit.
296
+ #[inline]
297
+ pub fn key_shares_limit<T>(mut self, limit: T) -> Self
298
+ where
299
+ T: Into<Option<u8>>,
300
+ {
301
+ self.config.key_shares_limit = limit.into();
302
+ self
303
+ }
304
+
305
+ /// Sets the PSK DHE key establishment flag.
306
+ #[inline]
307
+ pub fn psk_dhe_ke(mut self, enabled: bool) -> Self {
308
+ self.config.psk_dhe_ke = enabled;
309
+ self
310
+ }
311
+
312
+ /// Sets the renegotiation flag.
313
+ #[inline]
314
+ pub fn renegotiation(mut self, enabled: bool) -> Self {
315
+ self.config.renegotiation = enabled;
316
+ self
317
+ }
318
+
319
+ /// Sets the delegated credentials.
320
+ #[inline]
321
+ pub fn delegated_credentials<T>(mut self, creds: T) -> Self
322
+ where
323
+ T: Into<Cow<'static, str>>,
324
+ {
325
+ self.config.delegated_credentials = Some(creds.into());
326
+ self
327
+ }
328
+
329
+ /// Sets the supported curves list.
330
+ #[inline]
331
+ pub fn curves_list<T>(mut self, curves: T) -> Self
332
+ where
333
+ T: Into<Cow<'static, str>>,
334
+ {
335
+ self.config.curves_list = Some(curves.into());
336
+ self
337
+ }
338
+
339
+ /// Sets the cipher list.
340
+ #[inline]
341
+ pub fn cipher_list<T>(mut self, ciphers: T) -> Self
342
+ where
343
+ T: Into<Cow<'static, str>>,
344
+ {
345
+ self.config.cipher_list = Some(ciphers.into());
346
+ self
347
+ }
348
+
349
+ /// Sets the supported signature algorithms.
350
+ #[inline]
351
+ pub fn sigalgs_list<T>(mut self, sigalgs: T) -> Self
352
+ where
353
+ T: Into<Cow<'static, str>>,
354
+ {
355
+ self.config.sigalgs_list = Some(sigalgs.into());
356
+ self
357
+ }
358
+
359
+ /// Sets the certificate compression algorithms.
360
+ #[inline]
361
+ pub fn certificate_compression_algorithms<T>(mut self, algs: T) -> Self
362
+ where
363
+ T: Into<Cow<'static, [CertificateCompressionAlgorithm]>>,
364
+ {
365
+ self.config.certificate_compression_algorithms = Some(algs.into());
366
+ self
367
+ }
368
+
369
+ /// Sets the extension permutation.
370
+ #[inline]
371
+ pub fn extension_permutation<T>(mut self, permutation: T) -> Self
372
+ where
373
+ T: Into<Cow<'static, [ExtensionType]>>,
374
+ {
375
+ self.config.extension_permutation = Some(permutation.into());
376
+ self
377
+ }
378
+
379
+ /// Sets the AES hardware override flag.
380
+ #[inline]
381
+ pub fn aes_hw_override<T>(mut self, enabled: T) -> Self
382
+ where
383
+ T: Into<Option<bool>>,
384
+ {
385
+ self.config.aes_hw_override = enabled.into();
386
+ self
387
+ }
388
+
389
+ /// Sets the random AES hardware override flag.
390
+ #[inline]
391
+ pub fn random_aes_hw_override(mut self, enabled: bool) -> Self {
392
+ self.config.random_aes_hw_override = enabled;
393
+ self
394
+ }
395
+
396
+ /// Sets whether to preserve the TLS 1.3 cipher list as configured by [`Self::cipher_list`].
397
+ ///
398
+ /// By default, BoringSSL does not preserve the TLS 1.3 cipher list. When this option is
399
+ /// disabled (the default), BoringSSL uses its internal default TLS 1.3 cipher suites in its
400
+ /// default order, regardless of what is set via [`Self::cipher_list`].
401
+ ///
402
+ /// When enabled, this option ensures that the TLS 1.3 cipher suites explicitly set via
403
+ /// [`Self::cipher_list`] are retained in their original order, without being reordered or
404
+ /// modified by BoringSSL's internal logic. This is useful for maintaining specific cipher suite
405
+ /// priorities for TLS 1.3. Note that if [`Self::cipher_list`] does not include any TLS 1.3
406
+ /// cipher suites, BoringSSL will still fall back to its default TLS 1.3 cipher suites and
407
+ /// order.
408
+ #[inline]
409
+ pub fn preserve_tls13_cipher_list<T>(mut self, enabled: T) -> Self
410
+ where
411
+ T: Into<Option<bool>>,
412
+ {
413
+ self.config.preserve_tls13_cipher_list = enabled.into();
414
+ self
415
+ }
416
+
417
+ /// Builds the `TlsOptions` from the builder.
418
+ #[inline]
419
+ pub fn build(self) -> TlsOptions {
420
+ self.config
421
+ }
422
+ }
423
+
424
+ impl TlsOptions {
425
+ /// Creates a new `TlsOptionsBuilder` instance.
426
+ pub fn builder() -> TlsOptionsBuilder {
427
+ TlsOptionsBuilder {
428
+ config: TlsOptions::default(),
429
+ }
430
+ }
431
+ }
432
+
433
+ impl Default for TlsOptions {
434
+ fn default() -> Self {
435
+ TlsOptions {
436
+ alpn_protocols: Some(Cow::Borrowed(&[AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])),
437
+ alps_protocols: None,
438
+ alps_use_new_codepoint: false,
439
+ session_ticket: true,
440
+ min_tls_version: None,
441
+ max_tls_version: None,
442
+ pre_shared_key: false,
443
+ enable_ech_grease: false,
444
+ permute_extensions: None,
445
+ grease_enabled: None,
446
+ enable_ocsp_stapling: false,
447
+ enable_signed_cert_timestamps: false,
448
+ record_size_limit: None,
449
+ psk_skip_session_ticket: false,
450
+ key_shares_limit: None,
451
+ psk_dhe_ke: true,
452
+ renegotiation: true,
453
+ delegated_credentials: None,
454
+ curves_list: None,
455
+ cipher_list: None,
456
+ sigalgs_list: None,
457
+ certificate_compression_algorithms: None,
458
+ extension_permutation: None,
459
+ aes_hw_override: None,
460
+ preserve_tls13_cipher_list: None,
461
+ random_aes_hw_override: false,
462
+ }
463
+ }
464
+ }