Skip to content

Commit e0d2836

Browse files
bors[bot]Taowyoo
andauthored
Merge #309
309: [back-port][v0.9] fix: return error when verify empty cert chain r=xinyufort a=Taowyoo back-port #308 to 0.9.X Co-authored-by: Yuxiang Cao <[email protected]>
2 parents 95a2439 + 0eeea4e commit e0d2836

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

.travis.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,30 @@ addons:
1818
- clang-11
1919
- cmake
2020
- qemu-user
21+
before_script:
22+
- printenv
23+
- whereis clang && clang --version
24+
# remove clang-16 path from PATH
25+
- export PATH=$(echo $PATH | sed -e 's|:/usr/local/clang-16.0.0/bin||')
26+
# setup clang-11 as default clang
27+
- sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-11 100
28+
- whereis clang && clang --version
2129
rust:
2230
- stable
2331
env:
24-
jobs:
25-
# Matrix build of 3 targets against Rust stable
26-
- TARGET=x86_64-unknown-linux-gnu ZLIB_INSTALLED=true AES_NI_SUPPORT=true
27-
- TARGET=aarch64-unknown-linux-musl
28-
- TARGET=x86_64-fortanix-unknown-sgx
2932
global:
3033
- RUST_BACKTRACE=1
3134
jobs:
3235
include:
33-
# Test additional Rust toolchains on x86_64
34-
- rust: beta
35-
- rust: nightly
36+
- env: TARGET=x86_64-fortanix-unknown-sgx
37+
rust: stable
38+
- env: TARGET=aarch64-unknown-linux-musl
39+
rust: stable
40+
- env: TARGET=x86_64-unknown-linux-gnu ZLIB_INSTALLED=true AES_NI_SUPPORT=true
41+
rust: nightly
42+
- env: TARGET=x86_64-unknown-linux-gnu ZLIB_INSTALLED=true AES_NI_SUPPORT=true
43+
rust: beta
44+
- env: TARGET=x86_64-unknown-linux-gnu ZLIB_INSTALLED=true AES_NI_SUPPORT=true
45+
rust: stable
3646
script:
3747
- ./ct.sh

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mbedtls/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mbedtls"
3-
version = "0.9.1"
3+
version = "0.9.2"
44
authors = ["Jethro Beekman <[email protected]>"]
55
build = "build.rs"
66
edition = "2018"

mbedtls/src/ssl/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ impl Config {
306306
}
307307

308308
pub fn push_cert(&mut self, own_cert: Arc<MbedtlsList<Certificate>>, own_pk: Arc<Pk>) -> Result<()> {
309+
if own_cert.is_empty() {
310+
return Err(Error::SslBadInputData);
311+
}
309312
// Need to ensure own_cert/pk_key outlive the config.
310313
self.own_cert.push(own_cert.clone());
311314
self.own_pk.push(own_pk.clone());

mbedtls/src/ssl/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl HandshakeContext {
583583
key: Arc<Pk>,
584584
) -> Result<()> {
585585
// mbedtls_ssl_set_hs_own_cert does not check for NULL handshake.
586-
if self.inner.handshake as *const _ == ::core::ptr::null() {
586+
if self.inner.handshake as *const _ == ::core::ptr::null() || chain.is_empty() {
587587
return Err(Error::SslBadInputData);
588588
}
589589

mbedtls/src/x509/certificate.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ impl Certificate {
229229
where
230230
F: VerifyCallback + 'static,
231231
{
232+
if chain.is_empty() {
233+
return Err(Error::X509BadInputData);
234+
}
232235
let (f_vrfy, p_vrfy): (Option<unsafe extern "C" fn(_, _, _, _) -> _>, _) = if let Some(cb) = cb.as_ref() {
233236
(Some(x509::verify_callback::<F>),
234237
cb as *const _ as *mut c_void)
@@ -1420,6 +1423,34 @@ cYp0bH/RcPTC0Z+ZaqSWMtfxRrk63MJQF9EXpDCdvQRcTMD9D85DJrMKn8aumq0M
14201423
assert!(crate::tests::TestTrait::<dyn Sync, MbedtlsList<Certificate>>::new().impls_trait(), "MbedtlsList<Certificate> should be Sync");
14211424
}
14221425

1426+
#[test]
1427+
fn empty_cert_chain_test() {
1428+
const C_CERT: &'static str = concat!(include_str!("../../tests/data/certificate.crt"), "\0");
1429+
const C_ROOT: &'static str = concat!(include_str!("../../tests/data/root.crt"), "\0");
1430+
1431+
let mut certs = MbedtlsList::new();
1432+
certs.push(Certificate::from_pem(&C_CERT.as_bytes()).unwrap());
1433+
let mut roots = MbedtlsList::new();
1434+
roots.push(Certificate::from_pem(&C_ROOT.as_bytes()).unwrap());
1435+
1436+
assert!(Certificate::verify(&certs, &roots, None, None).is_ok());
1437+
1438+
let empty_certs = MbedtlsList::new();
1439+
1440+
assert_eq!(
1441+
Certificate::verify(&certs, &empty_certs, None, None).unwrap_err(),
1442+
Error::X509CertVerifyFailed
1443+
);
1444+
assert_eq!(
1445+
Certificate::verify(&empty_certs, &empty_certs, None, None).unwrap_err(),
1446+
Error::X509BadInputData
1447+
);
1448+
assert_eq!(
1449+
Certificate::verify(&empty_certs, &roots, None, None).unwrap_err(),
1450+
Error::X509BadInputData
1451+
);
1452+
}
1453+
14231454
#[test]
14241455
fn empty_crl_test() {
14251456
const C_CERT: &'static str = concat!(include_str!("../../tests/data/certificate.crt"), "\0");

0 commit comments

Comments
 (0)