Skip to content

Commit fc8226e

Browse files
committed
fix: verify empty candidate cert chain
- Verify empty candidate cert chain - Add other necessary empty List check
1 parent 95a2439 commit fc8226e

File tree

6 files changed

+38
-3
lines changed

6 files changed

+38
-3
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ branches:
66
- trying
77
# Not really necessary, just to get a green badge on “master”
88
- master
9+
- v0.9
910
language: rust
1011
os: linux
1112
dist: focal

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)