wreq 1.3.2.1 → 1.3.2.3

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +40 -52
  3. data/Cargo.toml +11 -8
  4. data/README.md +12 -5
  5. data/VERSION +1 -1
  6. data/crates/README.md +5 -0
  7. data/crates/wreq-util/Cargo.toml +1 -0
  8. data/crates/wreq-util/src/emulate/macros.rs +31 -197
  9. data/crates/wreq-util/src/emulate/profile/chromium/chrome.rs +731 -0
  10. data/crates/wreq-util/src/emulate/profile/chromium/edge.rs +418 -0
  11. data/crates/wreq-util/src/emulate/profile/chromium/header.rs +74 -0
  12. data/crates/wreq-util/src/emulate/profile/chromium/http2.rs +59 -0
  13. data/crates/wreq-util/src/emulate/profile/chromium/opera.rs +312 -0
  14. data/crates/wreq-util/src/emulate/profile/{chrome → chromium}/tls.rs +146 -137
  15. data/crates/wreq-util/src/emulate/profile/chromium.rs +9 -0
  16. data/crates/wreq-util/src/emulate/profile/firefox/header.rs +48 -54
  17. data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +92 -102
  18. data/crates/wreq-util/src/emulate/profile/firefox/tls.rs +155 -146
  19. data/crates/wreq-util/src/emulate/profile/firefox.rs +312 -440
  20. data/crates/wreq-util/src/emulate/profile.rs +5 -7
  21. data/crates/wreq-util/src/emulate.rs +34 -1
  22. data/crates/wreq-util/tests/client.rs +187 -46
  23. data/crates/wreq-util/tests/emulate_chrome.rs +17 -0
  24. data/crates/wreq-util/tests/emulate_firefox.rs +15 -0
  25. data/crates/wreq-util/tests/emulate_opera.rs +24 -0
  26. data/lib/wreq_ruby/emulate.rb +28 -0
  27. data/src/emulate.rs +28 -5
  28. data/test/emulation_client_hello_test.rb +142 -0
  29. data/test/emulation_test.rb +21 -104
  30. data/wreq.gemspec +1 -1
  31. metadata +11 -10
  32. data/crates/wreq-util/src/emulate/profile/chrome/header.rs +0 -116
  33. data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +0 -65
  34. data/crates/wreq-util/src/emulate/profile/chrome.rs +0 -2269
  35. data/crates/wreq-util/src/emulate/profile/opera/header.rs +0 -29
  36. data/crates/wreq-util/src/emulate/profile/opera/http2.rs +0 -50
  37. data/crates/wreq-util/src/emulate/profile/opera/tls.rs +0 -103
  38. data/crates/wreq-util/src/emulate/profile/opera.rs +0 -299
@@ -1,59 +1,53 @@
1
- use super::*;
1
+ #[cfg(feature = "emulation-compression")]
2
+ use wreq::header::ACCEPT_ENCODING;
3
+ use wreq::header::{ACCEPT, ACCEPT_LANGUAGE, HeaderMap, HeaderValue, USER_AGENT};
2
4
 
3
- pub fn header_initializer(ua: &'static str) -> HeaderMap {
4
- let mut headers = HeaderMap::new();
5
- header_firefox_ua!(headers, ua);
6
- header_firefox_accept!(headers);
7
- headers.insert(
8
- HeaderName::from_static("upgrade-insecure-requests"),
9
- HeaderValue::from_static("1"),
10
- );
11
- header_firefox_sec_fetch!(headers);
12
- headers.insert(
13
- HeaderName::from_static("te"),
14
- HeaderValue::from_static("trailers"),
15
- );
16
- headers
17
- }
5
+ use super::Platform;
18
6
 
19
- pub fn header_initializer_with_zstd(ua: &'static str) -> HeaderMap {
20
- let mut headers = HeaderMap::new();
21
- header_firefox_ua!(headers, ua);
22
- header_firefox_accept!(zstd, headers);
23
- headers.insert(
24
- HeaderName::from_static("upgrade-insecure-requests"),
25
- HeaderValue::from_static("1"),
26
- );
27
- header_firefox_sec_fetch!(headers);
28
- headers.insert(
29
- HeaderName::from_static("priority"),
30
- HeaderValue::from_static("u=0, i"),
31
- );
32
- headers.insert(
33
- HeaderName::from_static("te"),
34
- HeaderValue::from_static("trailers"),
35
- );
36
- headers
7
+ #[derive(Clone, Copy)]
8
+ pub(super) enum Preset {
9
+ Legacy,
10
+ ZstdWithPriority,
11
+ LanguageQ09,
12
+ LanguageQ09WithAndroidLocale,
37
13
  }
38
14
 
39
- /// Firefox 147 and later. Identical to [`header_initializer_with_zstd`] apart from the
40
- /// `Accept-Language` q-value, which Firefox changed in 147 (Bugzilla 2000765).
41
- pub fn header_initializer_with_zstd_q09(ua: &'static str) -> HeaderMap {
42
- let mut headers = HeaderMap::new();
43
- header_firefox_ua!(headers, ua);
44
- header_firefox_accept!(zstd_q09, headers);
45
- headers.insert(
46
- HeaderName::from_static("upgrade-insecure-requests"),
47
- HeaderValue::from_static("1"),
48
- );
49
- header_firefox_sec_fetch!(headers);
50
- headers.insert(
51
- HeaderName::from_static("priority"),
52
- HeaderValue::from_static("u=0, i"),
53
- );
54
- headers.insert(
55
- HeaderName::from_static("te"),
56
- HeaderValue::from_static("trailers"),
57
- );
58
- headers
15
+ impl Preset {
16
+ pub(super) fn build(self, platform: Platform, ua: &'static str) -> HeaderMap {
17
+ // Firefox 147 switched to decrementing the q-value by 0.1 per entry (Bugzilla 2000765).
18
+ let language = match (self, platform) {
19
+ (Self::Legacy | Self::ZstdWithPriority, _) => "en-US,en;q=0.5",
20
+ // GeckoView uses Android's locale list without adding a fallback (Bugzilla 2042376).
21
+ (Self::LanguageQ09WithAndroidLocale, Platform::Android) => "en-US",
22
+ (Self::LanguageQ09 | Self::LanguageQ09WithAndroidLocale, _) => "en-US,en;q=0.9",
23
+ };
24
+
25
+ let mut headers = HeaderMap::new();
26
+ headers.insert(USER_AGENT, HeaderValue::from_static(ua));
27
+ headers.insert(
28
+ ACCEPT,
29
+ HeaderValue::from_static(
30
+ "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
31
+ ),
32
+ );
33
+ headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static(language));
34
+ #[cfg(feature = "emulation-compression")]
35
+ headers.insert(
36
+ ACCEPT_ENCODING,
37
+ HeaderValue::from_static(match self {
38
+ Self::Legacy => "gzip, deflate, br",
39
+ _ => "gzip, deflate, br, zstd",
40
+ }),
41
+ );
42
+ headers.insert("upgrade-insecure-requests", HeaderValue::from_static("1"));
43
+ headers.insert("sec-fetch-dest", HeaderValue::from_static("document"));
44
+ headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate"));
45
+ headers.insert("sec-fetch-site", HeaderValue::from_static("none"));
46
+ headers.insert("sec-fetch-user", HeaderValue::from_static("?1"));
47
+ if !matches!(self, Self::Legacy) {
48
+ headers.insert("priority", HeaderValue::from_static("u=0, i"));
49
+ }
50
+ headers.insert("te", HeaderValue::from_static("trailers"));
51
+ headers
52
+ }
59
53
  }
@@ -1,113 +1,103 @@
1
- macro_rules! headers_stream_dependency {
2
- (1) => {
3
- StreamDependency::new(StreamId::zero(), 41, false)
4
- };
5
- (2) => {
6
- StreamDependency::new(StreamId::from(13), 41, false)
7
- };
8
- }
9
-
10
- macro_rules! pseudo_order {
11
- () => {
12
- PseudoOrder::builder()
13
- .extend([
14
- PseudoId::Method,
15
- PseudoId::Path,
16
- PseudoId::Authority,
17
- PseudoId::Scheme,
18
- ])
19
- .build()
20
- };
21
- }
1
+ use wreq::http2::{
2
+ HeadersDependency, HeadersPriority, Http2Options, Priorities, Priority, PseudoId, PseudoOrder,
3
+ SettingId, SettingsOrder, StreamDependency, StreamId,
4
+ };
22
5
 
23
- macro_rules! settings_order {
24
- () => {
25
- SettingsOrder::builder()
26
- .extend([
27
- SettingId::HeaderTableSize,
28
- SettingId::EnablePush,
29
- SettingId::MaxConcurrentStreams,
30
- SettingId::InitialWindowSize,
31
- SettingId::MaxFrameSize,
32
- SettingId::MaxHeaderListSize,
33
- SettingId::EnableConnectProtocol,
34
- SettingId::NoRfc7540Priorities,
35
- ])
36
- .build()
37
- };
6
+ #[derive(Clone, Copy)]
7
+ pub(super) enum Preset {
8
+ NoPush,
9
+ PriorityTree,
10
+ ZeroConcurrentStreams,
11
+ AndroidWindow,
38
12
  }
39
13
 
40
- macro_rules! http2_options {
41
- (@base $builder:expr) => {
42
- $builder
43
- .initial_window_size(131072)
44
- .max_frame_size(16384)
45
- .initial_connection_window_size(12517377 + 65535)
46
- .headers_pseudo_order(pseudo_order!())
47
- .settings_order(settings_order!())
48
- };
14
+ impl Preset {
15
+ pub(super) fn build(self) -> Http2Options {
16
+ let (initial_window_size, header_table_size) = if matches!(self, Self::AndroidWindow) {
17
+ (32_768, 4_096)
18
+ } else {
19
+ (131_072, 65_536)
20
+ };
49
21
 
50
- (1) => {
51
- http2_options!(@base Http2Options::builder())
52
- .initial_stream_id(3)
53
- .header_table_size(65536)
54
- .enable_push(false)
55
- .headers_stream_dependency(headers_stream_dependency!(1))
56
- .build()
57
- };
58
- (2) => {
59
- http2_options!(@base Http2Options::builder())
60
- .initial_stream_id(15)
61
- .header_table_size(65536)
62
- .headers_stream_dependency(headers_stream_dependency!(2))
63
- .priorities(
64
- Priorities::builder()
22
+ let builder = Http2Options::builder()
23
+ .initial_window_size(initial_window_size)
24
+ .max_frame_size(16_384)
25
+ .initial_connection_window_size(12_517_377 + 65_535)
26
+ .header_table_size(header_table_size)
27
+ .headers_pseudo_order(
28
+ PseudoOrder::builder()
65
29
  .extend([
66
- Priority::new(
67
- StreamId::from(3),
68
- StreamDependency::new(StreamId::zero(), 200, false),
69
- ),
70
- Priority::new(
71
- StreamId::from(5),
72
- StreamDependency::new(StreamId::zero(), 100, false),
73
- ),
74
- Priority::new(
75
- StreamId::from(7),
76
- StreamDependency::new(StreamId::zero(), 0, false),
77
- ),
78
- Priority::new(
79
- StreamId::from(9),
80
- StreamDependency::new(StreamId::from(7), 0, false),
81
- ),
82
- Priority::new(
83
- StreamId::from(11),
84
- StreamDependency::new(StreamId::from(3), 0, false),
85
- ),
86
- Priority::new(
87
- StreamId::from(13),
88
- StreamDependency::new(StreamId::zero(), 240, false),
89
- ),
30
+ PseudoId::Method,
31
+ PseudoId::Path,
32
+ PseudoId::Authority,
33
+ PseudoId::Scheme,
90
34
  ])
91
35
  .build(),
92
36
  )
93
- .build()
94
- };
95
- (3) => {
96
- http2_options!(@base Http2Options::builder())
97
- .initial_stream_id(3)
98
- .header_table_size(65536)
99
- .enable_push(false)
100
- .max_concurrent_streams(0)
101
- .headers_stream_dependency(headers_stream_dependency!(1))
102
- .build()
103
- };
104
- (4) => {
105
- http2_options!(@base Http2Options::builder())
37
+ .settings_order(
38
+ SettingsOrder::builder()
39
+ .extend([
40
+ SettingId::HeaderTableSize,
41
+ SettingId::EnablePush,
42
+ SettingId::MaxConcurrentStreams,
43
+ SettingId::InitialWindowSize,
44
+ SettingId::MaxFrameSize,
45
+ SettingId::MaxHeaderListSize,
46
+ SettingId::EnableConnectProtocol,
47
+ SettingId::NoRfc7540Priorities,
48
+ ])
49
+ .build(),
50
+ );
51
+
52
+ // The priority-tree preset omits SETTINGS_ENABLE_PUSH.
53
+ if matches!(self, Self::PriorityTree) {
54
+ return builder
55
+ .initial_stream_id(15)
56
+ .headers_priority(HeadersPriority::new(
57
+ HeadersDependency::Declared(13_u32.into()),
58
+ 41,
59
+ false,
60
+ ))
61
+ .priorities(
62
+ Priorities::builder()
63
+ .extend([
64
+ Priority::new(
65
+ StreamId::from(3),
66
+ StreamDependency::new(StreamId::from(0), 200, false),
67
+ ),
68
+ Priority::new(
69
+ StreamId::from(5),
70
+ StreamDependency::new(StreamId::from(0), 100, false),
71
+ ),
72
+ Priority::new(
73
+ StreamId::from(7),
74
+ StreamDependency::new(StreamId::from(0), 0, false),
75
+ ),
76
+ Priority::new(
77
+ StreamId::from(9),
78
+ StreamDependency::new(StreamId::from(7), 0, false),
79
+ ),
80
+ Priority::new(
81
+ StreamId::from(11),
82
+ StreamDependency::new(StreamId::from(3), 0, false),
83
+ ),
84
+ Priority::new(
85
+ StreamId::from(13),
86
+ StreamDependency::new(StreamId::from(0), 240, false),
87
+ ),
88
+ ])
89
+ .build(),
90
+ )
91
+ .build();
92
+ }
93
+
94
+ let mut builder = builder
106
95
  .initial_stream_id(3)
107
- .header_table_size(4096)
108
96
  .enable_push(false)
109
- .initial_window_size(32768)
110
- .headers_stream_dependency(headers_stream_dependency!(1))
111
- .build()
112
- };
97
+ .headers_priority(HeadersPriority::new(HeadersDependency::Root, 41, false));
98
+ if matches!(self, Self::ZeroConcurrentStreams) {
99
+ builder = builder.max_concurrent_streams(0);
100
+ }
101
+ builder.build()
102
+ }
113
103
  }
@@ -1,64 +1,148 @@
1
- use super::*;
1
+ use super::super::{
2
+ AlpnProtocol, BrotliCompressor, CertificateCompressor, EchGrease, ExtensionType, KeyShare,
3
+ Tls13Cipher, TlsOptions, TlsVersion, ZlibCompressor, ZstdCompressor,
4
+ };
5
+
6
+ #[derive(Clone, Copy)]
7
+ pub(super) enum Preset {
8
+ Legacy,
9
+ EchWithoutResumption,
10
+ MlkemResumption,
11
+ MlkemResumptionWithSct,
12
+ PrivateBrowsing,
13
+ AndroidResumption,
14
+ NoEcdsaAes128Cbc,
15
+ NoEcdsaCbc,
16
+ Nss3127Grease,
17
+ NoFfdhe,
18
+ }
19
+
20
+ struct Settings {
21
+ curves: &'static str,
22
+ ciphers: &'static str,
23
+ key_shares: Option<&'static [KeyShare]>,
24
+ session_ticket: bool,
25
+ ech_grease: Option<EchGrease>,
26
+ signed_cert_timestamps: bool,
27
+ pre_shared_key: bool,
28
+ psk_skip_session_ticket: bool,
29
+ psk_dhe_ke: bool,
30
+ certificate_compression: bool,
31
+ }
2
32
 
3
- macro_rules! tls_options {
4
- (@build $builder:expr) => {
5
- $builder.build().into()
6
- };
33
+ impl Preset {
34
+ pub(super) fn build(self) -> TlsOptions {
35
+ const LEGACY: Settings = Settings {
36
+ curves: CLASSIC_FFDHE_GROUPS,
37
+ ciphers: CIPHERS_WITH_ECDSA_CBC,
38
+ key_shares: None,
39
+ session_ticket: true,
40
+ ech_grease: None,
41
+ signed_cert_timestamps: false,
42
+ pre_shared_key: false,
43
+ psk_skip_session_ticket: false,
44
+ psk_dhe_ke: true,
45
+ certificate_compression: false,
46
+ };
47
+
48
+ const ECH: Settings = Settings {
49
+ key_shares: Some(CLASSIC_KEY_SHARES),
50
+ ech_grease: Some(EchGrease::NssPre3127),
51
+ ..LEGACY
52
+ };
53
+
54
+ const RESUMPTION: Settings = Settings {
55
+ pre_shared_key: true,
56
+ psk_skip_session_ticket: true,
57
+ certificate_compression: true,
58
+ ..ECH
59
+ };
60
+
61
+ const MLKEM_RESUMPTION: Settings = Settings {
62
+ curves: MLKEM_FFDHE_GROUPS,
63
+ key_shares: Some(MLKEM_KEY_SHARES),
64
+ ..RESUMPTION
65
+ };
66
+
67
+ const MLKEM_RESUMPTION_WITH_SCT: Settings = Settings {
68
+ signed_cert_timestamps: true,
69
+ ..MLKEM_RESUMPTION
70
+ };
71
+
72
+ const NO_ECDSA_CBC: Settings = Settings {
73
+ ciphers: CIPHERS_WITHOUT_ECDSA_CBC,
74
+ ..MLKEM_RESUMPTION_WITH_SCT
75
+ };
76
+
77
+ const NSS_3127_GREASE: Settings = Settings {
78
+ ech_grease: Some(EchGrease::Nss3127),
79
+ ..NO_ECDSA_CBC
80
+ };
81
+
82
+ let settings = match self {
83
+ Self::Legacy => LEGACY,
84
+ Self::EchWithoutResumption => Settings {
85
+ ciphers: CIPHERS_WITHOUT_ECDSA_CBC,
86
+ session_ticket: false,
87
+ psk_dhe_ke: false,
88
+ ..ECH
89
+ },
90
+ Self::MlkemResumption => MLKEM_RESUMPTION,
91
+ Self::MlkemResumptionWithSct => MLKEM_RESUMPTION_WITH_SCT,
92
+ Self::PrivateBrowsing => Settings {
93
+ curves: MLKEM_FFDHE_GROUPS,
94
+ key_shares: Some(MLKEM_KEY_SHARES),
95
+ session_ticket: false,
96
+ signed_cert_timestamps: true,
97
+ psk_dhe_ke: false,
98
+ certificate_compression: true,
99
+ ..ECH
100
+ },
101
+ Self::AndroidResumption => RESUMPTION,
102
+ Self::NoEcdsaAes128Cbc => Settings {
103
+ ciphers: CIPHERS_WITHOUT_ECDSA_AES_128_CBC,
104
+ ..MLKEM_RESUMPTION_WITH_SCT
105
+ },
106
+ Self::NoEcdsaCbc => NO_ECDSA_CBC,
107
+ Self::Nss3127Grease => NSS_3127_GREASE,
108
+ Self::NoFfdhe => Settings {
109
+ curves: MLKEM_GROUPS,
110
+ ..NSS_3127_GREASE
111
+ },
112
+ };
7
113
 
8
- (@base $builder:expr, $cipher_list:expr, $curves:expr) => {
9
- $builder
10
- .cipher_list($cipher_list)
11
- .curves_list($curves)
12
- };
114
+ let mut builder = TlsOptions::builder()
115
+ .curves_list(settings.curves)
116
+ .sigalgs_list(SIGALGS_LIST)
117
+ .cipher_list(settings.ciphers)
118
+ .tls13_cipher_list(TLS13_CIPHER_LIST)
119
+ .session_ticket(settings.session_ticket)
120
+ .delegated_credentials(DELEGATED_CREDENTIALS)
121
+ .record_size_limit(RECORD_SIZE_LIMIT)
122
+ .enable_ocsp_stapling(true)
123
+ .ech_grease(settings.ech_grease)
124
+ .enable_signed_cert_timestamps(settings.signed_cert_timestamps)
125
+ .alpn_protocols([AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])
126
+ .min_tls_version(TlsVersion::TLS_1_2)
127
+ .max_tls_version(TlsVersion::TLS_1_3)
128
+ .pre_shared_key(settings.pre_shared_key)
129
+ .psk_skip_session_ticket(settings.psk_skip_session_ticket)
130
+ .psk_dhe_ke(settings.psk_dhe_ke)
131
+ .extension_permutation(EXTENSION_PERMUTATION_INDICES);
13
132
 
14
- (1, $cipher_list:expr, $curves:expr, $key_shares:expr) => {
15
- tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves)
16
- .enable_ech_grease(true)
17
- .pre_shared_key(true)
18
- .psk_skip_session_tickets(true)
19
- .key_shares($key_shares)
20
- .certificate_compressors(CERTIFICATE_COMPRESSORS))
21
- };
22
- (2, $cipher_list:expr, $curves:expr) => {
23
- tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves))
24
- };
25
- (3, $cipher_list:expr, $curves:expr, $key_shares:expr) => {
26
- tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves)
27
- .session_ticket(false)
28
- .enable_ech_grease(true)
29
- .psk_dhe_ke(false)
30
- .key_shares($key_shares))
31
- };
32
- (4, $cipher_list:expr, $curves:expr, $key_shares:expr) => {
33
- tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves)
34
- .enable_ech_grease(true)
35
- .enable_signed_cert_timestamps(true)
36
- .session_ticket(true)
37
- .pre_shared_key(true)
38
- .psk_skip_session_tickets(true)
39
- .key_shares($key_shares)
40
- .certificate_compressors(CERTIFICATE_COMPRESSORS))
41
- };
42
- (5, $cipher_list:expr, $curves:expr, $key_shares:expr) => {
43
- tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves)
44
- .enable_ech_grease(true)
45
- .pre_shared_key(true)
46
- .psk_skip_session_tickets(true)
47
- .key_shares($key_shares)
48
- .certificate_compressors(CERTIFICATE_COMPRESSORS))
49
- };
50
- (6, $cipher_list:expr, $curves:expr, $key_shares:expr) => {
51
- tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves)
52
- .enable_ech_grease(true)
53
- .enable_signed_cert_timestamps(true)
54
- .session_ticket(false)
55
- .psk_dhe_ke(false)
56
- .key_shares($key_shares)
57
- .certificate_compressors(CERTIFICATE_COMPRESSORS))
58
- };
133
+ if let Some(key_shares) = settings.key_shares {
134
+ builder = builder.key_shares(key_shares);
135
+ }
136
+
137
+ if settings.certificate_compression {
138
+ builder = builder.certificate_compressors(CERTIFICATE_COMPRESSORS);
139
+ }
140
+
141
+ builder.build()
142
+ }
59
143
  }
60
144
 
61
- pub const CURVES_1: &str = join!(
145
+ const CLASSIC_FFDHE_GROUPS: &str = join!(
62
146
  ":",
63
147
  "X25519",
64
148
  "P-256",
@@ -68,7 +152,7 @@ pub const CURVES_1: &str = join!(
68
152
  "ffdhe3072"
69
153
  );
70
154
 
71
- pub const CURVES_2: &str = join!(
155
+ const MLKEM_FFDHE_GROUPS: &str = join!(
72
156
  ":",
73
157
  "X25519MLKEM768",
74
158
  "X25519",
@@ -79,12 +163,15 @@ pub const CURVES_2: &str = join!(
79
163
  "ffdhe3072"
80
164
  );
81
165
 
82
- pub const KEY_SHARES_1: &[KeyShare] = &[KeyShare::X25519, KeyShare::P256];
166
+ // Firefox 156 stopped advertising FFDHE groups by default.
167
+ const MLKEM_GROUPS: &str = join!(":", "X25519MLKEM768", "X25519", "P-256", "P-384", "P-521");
168
+
169
+ const CLASSIC_KEY_SHARES: &[KeyShare] = &[KeyShare::X25519, KeyShare::P256];
83
170
 
84
- pub const KEY_SHARES_2: &[KeyShare] =
171
+ const MLKEM_KEY_SHARES: &[KeyShare] =
85
172
  &[KeyShare::X25519_MLKEM768, KeyShare::X25519, KeyShare::P256];
86
173
 
87
- pub const CIPHER_LIST_1: &str = join!(
174
+ const CIPHERS_WITH_ECDSA_CBC: &str = join!(
88
175
  ":",
89
176
  "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
90
177
  "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
@@ -102,7 +189,7 @@ pub const CIPHER_LIST_1: &str = join!(
102
189
  "TLS_RSA_WITH_AES_256_CBC_SHA"
103
190
  );
104
191
 
105
- pub const CIPHER_LIST_2: &str = join!(
192
+ const CIPHERS_WITHOUT_ECDSA_CBC: &str = join!(
106
193
  ":",
107
194
  "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
108
195
  "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
@@ -118,7 +205,7 @@ pub const CIPHER_LIST_2: &str = join!(
118
205
  "TLS_RSA_WITH_AES_256_CBC_SHA"
119
206
  );
120
207
 
121
- pub const CIPHER_LIST_3: &str = join!(
208
+ const CIPHERS_WITHOUT_ECDSA_AES_128_CBC: &str = join!(
122
209
  ":",
123
210
  "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
124
211
  "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
@@ -135,7 +222,7 @@ pub const CIPHER_LIST_3: &str = join!(
135
222
  "TLS_RSA_WITH_AES_256_CBC_SHA"
136
223
  );
137
224
 
138
- pub const SIGALGS_LIST: &str = join!(
225
+ const SIGALGS_LIST: &str = join!(
139
226
  ":",
140
227
  "ecdsa_secp256r1_sha256",
141
228
  "ecdsa_secp384r1_sha384",
@@ -150,16 +237,16 @@ pub const SIGALGS_LIST: &str = join!(
150
237
  "rsa_pkcs1_sha1"
151
238
  );
152
239
 
153
- pub const TLS13_CIPHER_LIST: &[Tls13Cipher] = &[
240
+ const TLS13_CIPHER_LIST: &[Tls13Cipher] = &[
154
241
  Tls13Cipher::AES_128_GCM_SHA256,
155
242
  Tls13Cipher::CHACHA20_POLY1305_SHA256,
156
243
  Tls13Cipher::AES_256_GCM_SHA384,
157
244
  ];
158
245
 
159
- pub const CERTIFICATE_COMPRESSORS: &[&'static dyn CertificateCompressor] =
246
+ const CERTIFICATE_COMPRESSORS: &[&'static dyn CertificateCompressor] =
160
247
  &[&ZlibCompressor, &BrotliCompressor, &ZstdCompressor];
161
248
 
162
- pub const DELEGATED_CREDENTIALS: &str = join!(
249
+ const DELEGATED_CREDENTIALS: &str = join!(
163
250
  ":",
164
251
  "ecdsa_secp256r1_sha256",
165
252
  "ecdsa_secp384r1_sha384",
@@ -167,9 +254,9 @@ pub const DELEGATED_CREDENTIALS: &str = join!(
167
254
  "ecdsa_sha1"
168
255
  );
169
256
 
170
- pub const RECORD_SIZE_LIMIT: u16 = 0x4001;
257
+ const RECORD_SIZE_LIMIT: u16 = 0x4001;
171
258
 
172
- pub const EXTENSION_PERMUTATION_INDICES: &[ExtensionType] = &[
259
+ const EXTENSION_PERMUTATION_INDICES: &[ExtensionType] = &[
173
260
  ExtensionType::SERVER_NAME,
174
261
  ExtensionType::EXTENDED_MASTER_SECRET,
175
262
  ExtensionType::RENEGOTIATE,
@@ -188,81 +275,3 @@ pub const EXTENSION_PERMUTATION_INDICES: &[ExtensionType] = &[
188
275
  ExtensionType::CERT_COMPRESSION,
189
276
  ExtensionType::ENCRYPTED_CLIENT_HELLO,
190
277
  ];
191
-
192
- #[derive(TypedBuilder)]
193
- pub struct FirefoxTlsConfig {
194
- #[builder(default = SIGALGS_LIST)]
195
- sigalgs_list: &'static str,
196
-
197
- #[builder(setter(into))]
198
- cipher_list: &'static str,
199
-
200
- #[builder(setter(into))]
201
- curves_list: &'static str,
202
-
203
- #[builder(default, setter(into))]
204
- key_shares: Option<&'static [KeyShare]>,
205
-
206
- #[builder(default = true)]
207
- session_ticket: bool,
208
-
209
- #[builder(default = false, setter(into))]
210
- enable_ech_grease: bool,
211
-
212
- #[builder(default = false, setter(into))]
213
- enable_signed_cert_timestamps: bool,
214
-
215
- #[builder(default = false, setter(into))]
216
- pre_shared_key: bool,
217
-
218
- #[builder(default = false, setter(into))]
219
- psk_skip_session_tickets: bool,
220
-
221
- #[builder(default = DELEGATED_CREDENTIALS, setter(into))]
222
- delegated_credentials: &'static str,
223
-
224
- #[builder(default = RECORD_SIZE_LIMIT, setter(into))]
225
- record_size_limit: u16,
226
-
227
- #[builder(default = true, setter(into))]
228
- psk_dhe_ke: bool,
229
-
230
- #[builder(default, setter(into))]
231
- certificate_compressors: Option<&'static [&'static dyn CertificateCompressor]>,
232
-
233
- #[builder(default = EXTENSION_PERMUTATION_INDICES, setter(into))]
234
- extension_permutation: &'static [ExtensionType],
235
- }
236
-
237
- impl From<FirefoxTlsConfig> for TlsOptions {
238
- fn from(val: FirefoxTlsConfig) -> Self {
239
- let mut builder = TlsOptions::builder()
240
- .curves_list(val.curves_list)
241
- .sigalgs_list(val.sigalgs_list)
242
- .cipher_list(val.cipher_list)
243
- .tls13_cipher_list(TLS13_CIPHER_LIST)
244
- .session_ticket(val.session_ticket)
245
- .delegated_credentials(val.delegated_credentials)
246
- .record_size_limit(val.record_size_limit)
247
- .enable_ocsp_stapling(true)
248
- .ech_grease(val.enable_ech_grease.then_some(EchGrease::NssPre3127))
249
- .enable_signed_cert_timestamps(val.enable_signed_cert_timestamps)
250
- .alpn_protocols([AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])
251
- .min_tls_version(TlsVersion::TLS_1_2)
252
- .max_tls_version(TlsVersion::TLS_1_3)
253
- .pre_shared_key(val.pre_shared_key)
254
- .psk_skip_session_ticket(val.psk_skip_session_tickets)
255
- .psk_dhe_ke(val.psk_dhe_ke)
256
- .extension_permutation(val.extension_permutation);
257
-
258
- if let Some(key_shares) = val.key_shares {
259
- builder = builder.key_shares(key_shares)
260
- }
261
-
262
- if let Some(certificate_compressors) = val.certificate_compressors {
263
- builder = builder.certificate_compressors(certificate_compressors)
264
- }
265
-
266
- builder.build()
267
- }
268
- }