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 all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v2
- uses: sfackler/actions/rustup@master
with:
version: 1.53.0
version: 1.63.0
- run: echo "::set-output name=version::$(rustc --version)"
id: rust-version
- uses: actions/cache@v1
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ vendored = ["openssl/vendored"]
alpn = ["security-framework/alpn"]

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
security-framework = "2.0.0"
security-framework-sys = "2.0.0"
security-framework = "2.7.0"
security-framework-sys = "2.6.1"
lazy_static = "1.4.0"
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"
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,
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 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 @@ -48,6 +48,7 @@ fn convert_protocol(protocol: Protocol) -> SslProtocol {
Protocol::Tlsv10 => SslProtocol::TLS1,
Protocol::Tlsv11 => SslProtocol::TLS11,
Protocol::Tlsv12 => SslProtocol::TLS12,
Protocol::Tlsv13 => SslProtocol::TLS13,
Protocol::__NonExhaustive => unreachable!(),
}
}
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