011-fix-use-tls1-2-only-website-for-tls12-test-suites-129.patch 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. From 02dd0bc7bae8a2011729f95021690e694fd8e43e Mon Sep 17 00:00:00 2001
  2. From: V <[email protected]>
  3. Date: Fri, 25 Apr 2025 18:27:13 +0200
  4. Subject: [PATCH] fix: use tls1.2 only website for tls12 test suites (#129)
  5. * fix: use tls1.2 only website for tls12 test suites
  6. ---
  7. src/helper_v2.rs | 2 ++
  8. src/main.rs | 12 +++++++-----
  9. src/sip003.rs | 6 +++---
  10. src/util.rs | 2 +-
  11. tests/tls12.rs | 32 ++++++++++++++++----------------
  12. 5 files changed, 29 insertions(+), 25 deletions(-)
  13. --- a/src/helper_v2.rs
  14. +++ b/src/helper_v2.rs
  15. @@ -26,6 +26,7 @@ use crate::util::prelude::*;
  16. pub(crate) const HMAC_SIZE_V2: usize = 8;
  17. +#[allow(unused)]
  18. pub(crate) trait HashedStream {
  19. fn hash_stream(&self) -> [u8; 20];
  20. }
  21. @@ -98,6 +99,7 @@ impl<S> HashedWriteStream<S> {
  22. })
  23. }
  24. + #[allow(unused)]
  25. pub(crate) fn hash(&self) -> [u8; 20] {
  26. self.hmac
  27. .borrow()
  28. --- a/src/main.rs
  29. +++ b/src/main.rs
  30. @@ -252,7 +252,7 @@ pub(crate) fn get_sip003_arg() -> Option
  31. let opts: HashMap<_, _> = opts.into_iter().collect();
  32. let threads = opts.get("threads").map(|s| s.parse::<u8>().unwrap());
  33. - let v3 = opts.get("v3").is_some();
  34. + let v3 = opts.contains_key("v3");
  35. let passwd = opts
  36. .get("passwd")
  37. .expect("need passwd param(like passwd=123456)");
  38. @@ -262,15 +262,17 @@ pub(crate) fn get_sip003_arg() -> Option
  39. v3,
  40. ..Default::default()
  41. };
  42. - let args = if opts.get("server").is_some() {
  43. + let args = if opts.contains_key("server") {
  44. let tls_addr = opts
  45. .get("tls")
  46. .expect("tls param must be specified(like tls=xxx.com:443)");
  47. let tls_addrs = parse_server_addrs(tls_addr)
  48. .expect("tls param parse failed(like tls=xxx.com:443 or tls=yyy.com:1.2.3.4:443;zzz.com:443;xxx.com)");
  49. - let wildcard_sni =
  50. - WildcardSNI::from_str(opts.get("wildcard-sni").map(AsRef::as_ref).unwrap_or("off"), true)
  51. - .expect("wildcard_sni format error");
  52. + let wildcard_sni = WildcardSNI::from_str(
  53. + opts.get("wildcard-sni").map(AsRef::as_ref).unwrap_or("off"),
  54. + true,
  55. + )
  56. + .expect("wildcard_sni format error");
  57. Args {
  58. cmd: crate::Commands::Server {
  59. listen: format!("{ss_remote_host}:{ss_remote_port}"),
  60. --- a/src/sip003.rs
  61. +++ b/src/sip003.rs
  62. @@ -6,7 +6,7 @@ pub fn parse_sip003_options(s: &str) ->
  63. let mut i = 0;
  64. while i < s.len() {
  65. // read key
  66. - let (offset, key) = index_unescaped(&s[i..], &[b'=', b';']).context("read key")?;
  67. + let (offset, key) = index_unescaped(&s[i..], b"=;").context("read key")?;
  68. if key.is_empty() {
  69. bail!("empty key in {}", &s[i..]);
  70. }
  71. @@ -21,7 +21,7 @@ pub fn parse_sip003_options(s: &str) ->
  72. // skip equals
  73. i += 1;
  74. // read value
  75. - let (offset, value) = index_unescaped(&s[i..], &[b'=', b';']).context("read value")?;
  76. + let (offset, value) = index_unescaped(&s[i..], b"=;").context("read value")?;
  77. i += offset;
  78. opts.push((key, value));
  79. // Skip the semicolon.
  80. @@ -36,7 +36,7 @@ fn index_unescaped(s: &str, term: &[u8])
  81. while i < s.len() {
  82. let mut b: u8 = s.as_bytes()[i];
  83. - if term.iter().any(|&e| b == e) {
  84. + if term.contains(&b) {
  85. break;
  86. }
  87. if b == b'\\' {
  88. --- a/src/util.rs
  89. +++ b/src/util.rs
  90. @@ -599,7 +599,7 @@ pub(crate) async fn resolve(addr: &str)
  91. addr_iter.next().ok_or_else(|| {
  92. std::io::Error::new(
  93. std::io::ErrorKind::InvalidInput,
  94. - format!("unable to resolve addr: {}", addr),
  95. + format!("unable to resolve addr: {addr}"),
  96. )
  97. })
  98. }
  99. --- a/tests/tls12.rs
  100. +++ b/tests/tls12.rs
  101. @@ -4,7 +4,7 @@ use shadow_tls::{RunningArgs, TlsAddrs,
  102. mod utils;
  103. use utils::*;
  104. -// handshake: bing.com(tls1.2 only)
  105. +// handshake: badssl.com(tls1.2 only)
  106. // data: captive.apple.com:80
  107. // protocol: v2
  108. #[test]
  109. @@ -12,7 +12,7 @@ fn tls12_v2() {
  110. let client = RunningArgs::Client {
  111. listen_addr: "127.0.0.1:30000".to_string(),
  112. target_addr: "127.0.0.1:30001".to_string(),
  113. - tls_names: TlsNames::try_from("bing.com").unwrap(),
  114. + tls_names: TlsNames::try_from("badssl.com").unwrap(),
  115. tls_ext: TlsExtConfig::new(None),
  116. password: "test".to_string(),
  117. nodelay: true,
  118. @@ -22,7 +22,7 @@ fn tls12_v2() {
  119. let server = RunningArgs::Server {
  120. listen_addr: "127.0.0.1:30001".to_string(),
  121. target_addr: "captive.apple.com:80".to_string(),
  122. - tls_addr: TlsAddrs::try_from("bing.com").unwrap(),
  123. + tls_addr: TlsAddrs::try_from("badssl.com").unwrap(),
  124. password: "test".to_string(),
  125. nodelay: true,
  126. fastopen: true,
  127. @@ -31,7 +31,7 @@ fn tls12_v2() {
  128. test_ok(client, server, CAPTIVE_HTTP_REQUEST, CAPTIVE_HTTP_RESP);
  129. }
  130. -// handshake: bing.com(tls1.2 only)
  131. +// handshake: badssl.com(tls1.2 only)
  132. // data: captive.apple.com:80
  133. // protocol: v3 lossy
  134. #[test]
  135. @@ -39,7 +39,7 @@ fn tls12_v3_lossy() {
  136. let client = RunningArgs::Client {
  137. listen_addr: "127.0.0.1:30002".to_string(),
  138. target_addr: "127.0.0.1:30003".to_string(),
  139. - tls_names: TlsNames::try_from("bing.com").unwrap(),
  140. + tls_names: TlsNames::try_from("badssl.com").unwrap(),
  141. tls_ext: TlsExtConfig::new(None),
  142. password: "test".to_string(),
  143. nodelay: true,
  144. @@ -49,7 +49,7 @@ fn tls12_v3_lossy() {
  145. let server = RunningArgs::Server {
  146. listen_addr: "127.0.0.1:30003".to_string(),
  147. target_addr: "captive.apple.com:80".to_string(),
  148. - tls_addr: TlsAddrs::try_from("bing.com").unwrap(),
  149. + tls_addr: TlsAddrs::try_from("badssl.com").unwrap(),
  150. password: "test".to_string(),
  151. nodelay: true,
  152. fastopen: true,
  153. @@ -58,7 +58,7 @@ fn tls12_v3_lossy() {
  154. utils::test_ok(client, server, CAPTIVE_HTTP_REQUEST, CAPTIVE_HTTP_RESP);
  155. }
  156. -// handshake: bing.com(tls1.2 only)
  157. +// handshake: badssl.com(tls1.2 only)
  158. // data: captive.apple.com:80
  159. // protocol: v3 strict
  160. // v3 strict cannot work with tls1.2, so it must fail
  161. @@ -68,7 +68,7 @@ fn tls12_v3_strict() {
  162. let client = RunningArgs::Client {
  163. listen_addr: "127.0.0.1:30004".to_string(),
  164. target_addr: "127.0.0.1:30005".to_string(),
  165. - tls_names: TlsNames::try_from("bing.com").unwrap(),
  166. + tls_names: TlsNames::try_from("badssl.com").unwrap(),
  167. tls_ext: TlsExtConfig::new(None),
  168. password: "test".to_string(),
  169. nodelay: true,
  170. @@ -78,7 +78,7 @@ fn tls12_v3_strict() {
  171. let server = RunningArgs::Server {
  172. listen_addr: "127.0.0.1:30005".to_string(),
  173. target_addr: "captive.apple.com:80".to_string(),
  174. - tls_addr: TlsAddrs::try_from("bing.com").unwrap(),
  175. + tls_addr: TlsAddrs::try_from("badssl.com").unwrap(),
  176. password: "test".to_string(),
  177. nodelay: true,
  178. fastopen: true,
  179. @@ -87,8 +87,8 @@ fn tls12_v3_strict() {
  180. utils::test_ok(client, server, CAPTIVE_HTTP_REQUEST, CAPTIVE_HTTP_RESP);
  181. }
  182. -// handshake: bing.com(tls1.2 only)
  183. -// data: bing.com:443
  184. +// handshake: badssl.com(tls1.2 only)
  185. +// data: badssl.com:443
  186. // protocol: v2
  187. // Note: v2 can not defend against hijack attack.
  188. // Here hijack means directly connect to the handshake server.
  189. @@ -98,8 +98,8 @@ fn tls12_v3_strict() {
  190. fn tls12_v2_hijack() {
  191. let client = RunningArgs::Client {
  192. listen_addr: "127.0.0.1:30006".to_string(),
  193. - target_addr: "bing.com:443".to_string(),
  194. - tls_names: TlsNames::try_from("bing.com").unwrap(),
  195. + target_addr: "badssl.com:443".to_string(),
  196. + tls_names: TlsNames::try_from("badssl.com").unwrap(),
  197. tls_ext: TlsExtConfig::new(None),
  198. password: "test".to_string(),
  199. nodelay: true,
  200. @@ -109,7 +109,7 @@ fn tls12_v2_hijack() {
  201. test_hijack(client);
  202. }
  203. -// handshake: bing.com(tls1.2 only)
  204. +// handshake: badssl.com(tls1.2 only)
  205. // data: captive.apple.com:80
  206. // protocol: v3 lossy
  207. // (v3 strict can not work with tls1.2)
  208. @@ -121,8 +121,8 @@ fn tls12_v2_hijack() {
  209. fn tls12_v3_lossy_hijack() {
  210. let client = RunningArgs::Client {
  211. listen_addr: "127.0.0.1:30007".to_string(),
  212. - target_addr: "bing.com:443".to_string(),
  213. - tls_names: TlsNames::try_from("bing.com").unwrap(),
  214. + target_addr: "badssl.com:443".to_string(),
  215. + tls_names: TlsNames::try_from("badssl.com").unwrap(),
  216. tls_ext: TlsExtConfig::new(None),
  217. password: "test".to_string(),
  218. nodelay: true,