Skip to content

Commit b81f702

Browse files
committed
Always define TLSv3
1 parent 1e65774 commit b81f702

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ libc = "0.2"
2424
tempfile = "3.1.0"
2525

2626
[target.'cfg(target_os = "windows")'.dependencies]
27-
schannel = "0.1.17"
27+
schannel = "0.1.20"
2828

2929
[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios")))'.dependencies]
3030
log = "0.4.5"

src/imp/openssl.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ fn supported_protocols(
2323
min: Option<Protocol>,
2424
max: Option<Protocol>,
2525
ctx: &mut SslContextBuilder,
26-
) -> Result<(), ErrorStack> {
26+
) -> Result<(), Error> {
2727
use self::openssl::ssl::SslVersion;
2828

29-
fn cvt(p: Protocol) -> SslVersion {
29+
fn cvt(p: Protocol) -> Result<SslVersion, Error> {
3030
match p {
31-
Protocol::Sslv3 => SslVersion::SSL3,
32-
Protocol::Tlsv10 => SslVersion::TLS1,
33-
Protocol::Tlsv11 => SslVersion::TLS1_1,
34-
Protocol::Tlsv12 => SslVersion::TLS1_2,
31+
Protocol::Sslv3 => Ok(SslVersion::SSL3),
32+
Protocol::Tlsv10 => Ok(SslVersion::TLS1),
33+
Protocol::Tlsv11 => Ok(SslVersion::TLS1_1),
34+
Protocol::Tlsv12 => Ok(SslVersion::TLS1_2),
3535
#[cfg(have_tls13_version)]
36-
Protocol::Tlsv13 => SslVersion::TLS1_3,
36+
Protocol::Tlsv13 => Ok(SslVersion::TLS1_3),
37+
#[cfg(not(have_tls13_version))]
38+
Protocol::Tlsv13 => Err(Error::UnsupportedTls13)
3739
}
3840
}
3941

40-
ctx.set_min_proto_version(min.map(cvt))?;
41-
ctx.set_max_proto_version(max.map(cvt))?;
42+
ctx.set_min_proto_version(min.map(cvt).transpose()?)?;
43+
ctx.set_max_proto_version(max.map(cvt).transpose()?)?;
4244

4345
Ok(())
4446
}
@@ -117,6 +119,7 @@ pub enum Error {
117119
Ssl(ssl::Error, X509VerifyResult),
118120
EmptyChain,
119121
NotPkcs8,
122+
UnsupportedTls13,
120123
}
121124

122125
impl error::Error for Error {
@@ -126,6 +129,7 @@ impl error::Error for Error {
126129
Error::Ssl(ref e, _) => error::Error::source(e),
127130
Error::EmptyChain => None,
128131
Error::NotPkcs8 => None,
132+
Error::UnsupportedTls13 => None,
129133
}
130134
}
131135
}
@@ -141,6 +145,7 @@ impl fmt::Display for Error {
141145
"at least one certificate must be provided to create an identity"
142146
),
143147
Error::NotPkcs8 => write!(fmt, "expected PKCS#8 PEM"),
148+
Error::UnsupportedTls13 => write!(fmt, "TLS version 1.3 not supported"),
144149
}
145150
}
146151
}

src/imp/schannel.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static PROTOCOLS: &'static [Protocol] = &[
1919
Protocol::Tls10,
2020
Protocol::Tls11,
2121
Protocol::Tls12,
22+
Protocol::Tls13,
2223
];
2324

2425
fn convert_protocols(min: Option<::Protocol>, max: Option<::Protocol>) -> &'static [Protocol] {

src/imp/security_framework.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ static SET_AT_EXIT: Once = Once::new();
4343
#[cfg(not(target_os = "ios"))]
4444
static TEMP_KEYCHAIN: Lazy<Mutex<Option<(SecKeychain, TempDir)>>> = Lazy::new(|| Mutex::new(None));
4545

46-
fn convert_protocol(protocol: Protocol) -> SslProtocol {
46+
fn convert_protocol(protocol: Protocol) -> Result<SslProtocol, Error> {
4747
match protocol {
48-
Protocol::Sslv3 => SslProtocol::SSL3,
49-
Protocol::Tlsv10 => SslProtocol::TLS1,
50-
Protocol::Tlsv11 => SslProtocol::TLS11,
51-
Protocol::Tlsv12 => SslProtocol::TLS12,
48+
Protocol::Sslv3 => Ok(SslProtocol::SSL3),
49+
Protocol::Tlsv10 => Ok(SslProtocol::TLS1),
50+
Protocol::Tlsv11 => Ok(SslProtocol::TLS11),
51+
Protocol::Tlsv12 => Ok(SslProtocol::TLS12),
52+
// Not supported in SecureTransport API used in security_framework
53+
Protocol::Tlsv13 => Err(Error(base::Error::from("TLS 1.3 is not supported")))
5254
}
5355
}
5456

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ pub enum Protocol {
324324
Tlsv12,
325325
/// The TLS 1.3 protocol.
326326
///
327-
/// Requires OpenSSL 1.1.1 or LibreSSL 3.4.0 or newer.
328-
#[cfg(have_tls13_version)]
327+
/// Only works on Windows, or with openssl >= 1.1.1 or libressl >= 3.4.0.
328+
/// It will fail at runtime when used in other situations.
329329
Tlsv13,
330330
}
331331

src/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ macro_rules! p {
1616
};
1717
}
1818

19-
#[cfg(have_tls13_version)]
19+
#[cfg(any(target_os = "windows", have_tls13_version))]
2020
#[test]
2121
fn connect_google_tls13() {
2222
let builder = p!(

0 commit comments

Comments
 (0)