Skip to content

Commit 02dd0bc

Browse files
fix: use tls1.2 only website for tls12 test suites (#129)
* fix: use tls1.2 only website for tls12 test suites
1 parent 0450141 commit 02dd0bc

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

src/helper_v2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::util::prelude::*;
2626

2727
pub(crate) const HMAC_SIZE_V2: usize = 8;
2828

29+
#[allow(unused)]
2930
pub(crate) trait HashedStream {
3031
fn hash_stream(&self) -> [u8; 20];
3132
}
@@ -98,6 +99,7 @@ impl<S> HashedWriteStream<S> {
9899
})
99100
}
100101

102+
#[allow(unused)]
101103
pub(crate) fn hash(&self) -> [u8; 20] {
102104
self.hmac
103105
.borrow()

src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub(crate) fn get_sip003_arg() -> Option<Args> {
252252
let opts: HashMap<_, _> = opts.into_iter().collect();
253253

254254
let threads = opts.get("threads").map(|s| s.parse::<u8>().unwrap());
255-
let v3 = opts.get("v3").is_some();
255+
let v3 = opts.contains_key("v3");
256256
let passwd = opts
257257
.get("passwd")
258258
.expect("need passwd param(like passwd=123456)");
@@ -262,15 +262,17 @@ pub(crate) fn get_sip003_arg() -> Option<Args> {
262262
v3,
263263
..Default::default()
264264
};
265-
let args = if opts.get("server").is_some() {
265+
let args = if opts.contains_key("server") {
266266
let tls_addr = opts
267267
.get("tls")
268268
.expect("tls param must be specified(like tls=xxx.com:443)");
269269
let tls_addrs = parse_server_addrs(tls_addr)
270270
.expect("tls param parse failed(like tls=xxx.com:443 or tls=yyy.com:1.2.3.4:443;zzz.com:443;xxx.com)");
271-
let wildcard_sni =
272-
WildcardSNI::from_str(opts.get("wildcard-sni").map(AsRef::as_ref).unwrap_or("off"), true)
273-
.expect("wildcard_sni format error");
271+
let wildcard_sni = WildcardSNI::from_str(
272+
opts.get("wildcard-sni").map(AsRef::as_ref).unwrap_or("off"),
273+
true,
274+
)
275+
.expect("wildcard_sni format error");
274276
Args {
275277
cmd: crate::Commands::Server {
276278
listen: format!("{ss_remote_host}:{ss_remote_port}"),

src/sip003.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn parse_sip003_options(s: &str) -> Result<Vec<(String, String)>, anyhow::Er
66
let mut i = 0;
77
while i < s.len() {
88
// read key
9-
let (offset, key) = index_unescaped(&s[i..], &[b'=', b';']).context("read key")?;
9+
let (offset, key) = index_unescaped(&s[i..], b"=;").context("read key")?;
1010
if key.is_empty() {
1111
bail!("empty key in {}", &s[i..]);
1212
}
@@ -21,7 +21,7 @@ pub fn parse_sip003_options(s: &str) -> Result<Vec<(String, String)>, anyhow::Er
2121
// skip equals
2222
i += 1;
2323
// read value
24-
let (offset, value) = index_unescaped(&s[i..], &[b'=', b';']).context("read value")?;
24+
let (offset, value) = index_unescaped(&s[i..], b"=;").context("read value")?;
2525
i += offset;
2626
opts.push((key, value));
2727
// Skip the semicolon.
@@ -36,7 +36,7 @@ fn index_unescaped(s: &str, term: &[u8]) -> Result<(usize, String), anyhow::Erro
3636

3737
while i < s.len() {
3838
let mut b: u8 = s.as_bytes()[i];
39-
if term.iter().any(|&e| b == e) {
39+
if term.contains(&b) {
4040
break;
4141
}
4242
if b == b'\\' {

src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ pub(crate) async fn resolve(addr: &str) -> std::io::Result<std::net::SocketAddr>
599599
addr_iter.next().ok_or_else(|| {
600600
std::io::Error::new(
601601
std::io::ErrorKind::InvalidInput,
602-
format!("unable to resolve addr: {}", addr),
602+
format!("unable to resolve addr: {addr}"),
603603
)
604604
})
605605
}

tests/tls12.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use shadow_tls::{RunningArgs, TlsAddrs, TlsExtConfig, TlsNames, V3Mode};
44
mod utils;
55
use utils::*;
66

7-
// handshake: bing.com(tls1.2 only)
7+
// handshake: badssl.com(tls1.2 only)
88
// data: captive.apple.com:80
99
// protocol: v2
1010
#[test]
1111
fn tls12_v2() {
1212
let client = RunningArgs::Client {
1313
listen_addr: "127.0.0.1:30000".to_string(),
1414
target_addr: "127.0.0.1:30001".to_string(),
15-
tls_names: TlsNames::try_from("bing.com").unwrap(),
15+
tls_names: TlsNames::try_from("badssl.com").unwrap(),
1616
tls_ext: TlsExtConfig::new(None),
1717
password: "test".to_string(),
1818
nodelay: true,
@@ -22,7 +22,7 @@ fn tls12_v2() {
2222
let server = RunningArgs::Server {
2323
listen_addr: "127.0.0.1:30001".to_string(),
2424
target_addr: "captive.apple.com:80".to_string(),
25-
tls_addr: TlsAddrs::try_from("bing.com").unwrap(),
25+
tls_addr: TlsAddrs::try_from("badssl.com").unwrap(),
2626
password: "test".to_string(),
2727
nodelay: true,
2828
fastopen: true,
@@ -31,15 +31,15 @@ fn tls12_v2() {
3131
test_ok(client, server, CAPTIVE_HTTP_REQUEST, CAPTIVE_HTTP_RESP);
3232
}
3333

34-
// handshake: bing.com(tls1.2 only)
34+
// handshake: badssl.com(tls1.2 only)
3535
// data: captive.apple.com:80
3636
// protocol: v3 lossy
3737
#[test]
3838
fn tls12_v3_lossy() {
3939
let client = RunningArgs::Client {
4040
listen_addr: "127.0.0.1:30002".to_string(),
4141
target_addr: "127.0.0.1:30003".to_string(),
42-
tls_names: TlsNames::try_from("bing.com").unwrap(),
42+
tls_names: TlsNames::try_from("badssl.com").unwrap(),
4343
tls_ext: TlsExtConfig::new(None),
4444
password: "test".to_string(),
4545
nodelay: true,
@@ -49,7 +49,7 @@ fn tls12_v3_lossy() {
4949
let server = RunningArgs::Server {
5050
listen_addr: "127.0.0.1:30003".to_string(),
5151
target_addr: "captive.apple.com:80".to_string(),
52-
tls_addr: TlsAddrs::try_from("bing.com").unwrap(),
52+
tls_addr: TlsAddrs::try_from("badssl.com").unwrap(),
5353
password: "test".to_string(),
5454
nodelay: true,
5555
fastopen: true,
@@ -58,7 +58,7 @@ fn tls12_v3_lossy() {
5858
utils::test_ok(client, server, CAPTIVE_HTTP_REQUEST, CAPTIVE_HTTP_RESP);
5959
}
6060

61-
// handshake: bing.com(tls1.2 only)
61+
// handshake: badssl.com(tls1.2 only)
6262
// data: captive.apple.com:80
6363
// protocol: v3 strict
6464
// v3 strict cannot work with tls1.2, so it must fail
@@ -68,7 +68,7 @@ fn tls12_v3_strict() {
6868
let client = RunningArgs::Client {
6969
listen_addr: "127.0.0.1:30004".to_string(),
7070
target_addr: "127.0.0.1:30005".to_string(),
71-
tls_names: TlsNames::try_from("bing.com").unwrap(),
71+
tls_names: TlsNames::try_from("badssl.com").unwrap(),
7272
tls_ext: TlsExtConfig::new(None),
7373
password: "test".to_string(),
7474
nodelay: true,
@@ -78,7 +78,7 @@ fn tls12_v3_strict() {
7878
let server = RunningArgs::Server {
7979
listen_addr: "127.0.0.1:30005".to_string(),
8080
target_addr: "captive.apple.com:80".to_string(),
81-
tls_addr: TlsAddrs::try_from("bing.com").unwrap(),
81+
tls_addr: TlsAddrs::try_from("badssl.com").unwrap(),
8282
password: "test".to_string(),
8383
nodelay: true,
8484
fastopen: true,
@@ -87,8 +87,8 @@ fn tls12_v3_strict() {
8787
utils::test_ok(client, server, CAPTIVE_HTTP_REQUEST, CAPTIVE_HTTP_RESP);
8888
}
8989

90-
// handshake: bing.com(tls1.2 only)
91-
// data: bing.com:443
90+
// handshake: badssl.com(tls1.2 only)
91+
// data: badssl.com:443
9292
// protocol: v2
9393
// Note: v2 can not defend against hijack attack.
9494
// Here hijack means directly connect to the handshake server.
@@ -98,8 +98,8 @@ fn tls12_v3_strict() {
9898
fn tls12_v2_hijack() {
9999
let client = RunningArgs::Client {
100100
listen_addr: "127.0.0.1:30006".to_string(),
101-
target_addr: "bing.com:443".to_string(),
102-
tls_names: TlsNames::try_from("bing.com").unwrap(),
101+
target_addr: "badssl.com:443".to_string(),
102+
tls_names: TlsNames::try_from("badssl.com").unwrap(),
103103
tls_ext: TlsExtConfig::new(None),
104104
password: "test".to_string(),
105105
nodelay: true,
@@ -109,7 +109,7 @@ fn tls12_v2_hijack() {
109109
test_hijack(client);
110110
}
111111

112-
// handshake: bing.com(tls1.2 only)
112+
// handshake: badssl.com(tls1.2 only)
113113
// data: captive.apple.com:80
114114
// protocol: v3 lossy
115115
// (v3 strict can not work with tls1.2)
@@ -121,8 +121,8 @@ fn tls12_v2_hijack() {
121121
fn tls12_v3_lossy_hijack() {
122122
let client = RunningArgs::Client {
123123
listen_addr: "127.0.0.1:30007".to_string(),
124-
target_addr: "bing.com:443".to_string(),
125-
tls_names: TlsNames::try_from("bing.com").unwrap(),
124+
target_addr: "badssl.com:443".to_string(),
125+
tls_names: TlsNames::try_from("badssl.com").unwrap(),
126126
tls_ext: TlsExtConfig::new(None),
127127
password: "test".to_string(),
128128
nodelay: true,

0 commit comments

Comments
 (0)