Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TLS 1.3 #235

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ libc = "0.2"
tempfile = "3.1.0"

[target.'cfg(target_os = "windows")'.dependencies]
schannel = "0.1.17"
schannel = "0.1.20"

[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios")))'.dependencies]
log = "0.4.5"
openssl = "0.10.29"
openssl-sys = "0.9.55"
openssl-probe = "0.1"
openssl = "0.10.41"
openssl-sys = "0.9.75"
openssl-probe = "0.1.5"

[dev-dependencies]
tempfile = "3.0"
test-cert-gen = "0.7"
test-cert-gen = "0.9"
14 changes: 12 additions & 2 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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will break compilation against OpenSSL 1.1.0, which has set_min_proto_version but does not have TLS 1.3 support. You'll need to add some extra version logic in the build script and here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a feature flag? Feels like this could get merged quicker by letting the users decide

Protocol::__NonExhaustive => unreachable!(),
}
}
Expand All @@ -54,7 +55,8 @@ fn supported_protocols(
| SslOptions::NO_SSLV3
| SslOptions::NO_TLSV1
| SslOptions::NO_TLSV1_1
| SslOptions::NO_TLSV1_2;
| SslOptions::NO_TLSV1_2
| SslOptions::NO_TLSV1_3;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenSSL versions too old for set_min_proto_version won't have TLSV1_3 support afaik.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean. The OpenSSL versions that don't have min protocol config are very old and no longer supported I think (< v1.1.0), while TLS1.3 was introduced at OpenSSL v1.1.1, also pretty old by now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is only used for old versions of OpenSSL that won't have a NO_TLSV1_3 symbol.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Didn't notice this is inside a #[cfg()] block.


ctx.clear_options(no_ssl_mask);
let mut options = SslOptions::empty();
Expand All @@ -71,10 +73,18 @@ fn supported_protocols(
| SslOptions::NO_TLSV1
| SslOptions::NO_TLSV1_1
}
Some(Protocol::Tlsv13) => {
SslOptions::NO_SSLV2
| SslOptions::NO_SSLV3
| SslOptions::NO_TLSV1
| SslOptions::NO_TLSV1_1
| SslOptions::NO_TLSV1_2
}
Some(Protocol::__NonExhaustive) => unreachable!(),
};
options |= match max {
None | Some(Protocol::Tlsv12) => SslOptions::empty(),
None | Some(Protocol::Tlsv13) => SslOptions::empty(),
Some(Protocol::Tlsv12) => SslOptions::NO_TLSV1_3,
Some(Protocol::Tlsv11) => SslOptions::NO_TLSV1_2,
Some(Protocol::Tlsv10) => SslOptions::NO_TLSV1_1 | SslOptions::NO_TLSV1_2,
Some(Protocol::Sslv3) => {
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
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ pub enum Protocol {
Tlsv11,
/// The TLS 1.2 protocol.
Tlsv12,
/// The TLS 1.3 protocol.
Tlsv13,
#[doc(hidden)]
__NonExhaustive,
}
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