Skip to content

Commit

Permalink
Add TLS1.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanMeulenkamp authored and amousset committed Aug 16, 2023
1 parent 7d04b8a commit 8986c3c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/imp/openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn supported_protocols(
Protocol::Tlsv10 => SslVersion::TLS1,
Protocol::Tlsv11 => SslVersion::TLS1_1,
Protocol::Tlsv12 => SslVersion::TLS1_2,
Protocol::Tlsv13 => SslVersion::TLS1_3,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/imp/schannel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static PROTOCOLS: &'static [Protocol] = &[
Protocol::Tls10,
Protocol::Tls11,
Protocol::Tls12,
Protocol::Tls13,
];

fn convert_protocols(min: Option<::Protocol>, max: Option<::Protocol>) -> &'static [Protocol] {
Expand Down
1 change: 1 addition & 0 deletions src/imp/security_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn convert_protocol(protocol: Protocol) -> SslProtocol {
Protocol::Tlsv10 => SslProtocol::TLS1,
Protocol::Tlsv11 => SslProtocol::TLS11,
Protocol::Tlsv12 => SslProtocol::TLS12,
Protocol::Tlsv13 => SslProtocol::TLS13,
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ pub enum Protocol {
Tlsv11,
/// The TLS 1.2 protocol.
Tlsv12,
/// The TLS 1.3 protocol.
Tlsv13,
}

/// A builder for `TlsConnector`s.
Expand Down
19 changes: 19 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ macro_rules! p {
};
}

#[test]
fn connect_google_tls13() {
let builder = p!(
TlsConnector::builder()
.min_protocol_version(Some(Protocol::Tlsv13))
.max_protocol_version(Some(Protocol::Tlsv13))
.build());
let s = p!(TcpStream::connect("google.com:443"));
let mut socket = p!(builder.connect("google.com", s));

p!(socket.write_all(b"GET / HTTP/1.0\r\n\r\n"));
let mut result = vec![];
p!(socket.read_to_end(&mut result));

println!("{}", String::from_utf8_lossy(&result));
assert!(result.starts_with(b"HTTP/1.0"));
assert!(result.ends_with(b"</HTML>\r\n") || result.ends_with(b"</html>"));
}

#[test]
fn connect_google() {
let builder = p!(TlsConnector::new());
Expand Down

0 comments on commit 8986c3c

Please sign in to comment.