Skip to content

Commit

Permalink
Correct ownership semantics of SSL_{CTX_,}use_certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Apr 9, 2024
1 parent 1297a9c commit 16f975c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rustls-libssl/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,10 @@ entry! {
return Error::null_pointer().raise().into();
}

let ee = CertificateDer::from(OwnedX509::new(x).der_bytes());
let x509 = OwnedX509::new(x);
// `x` belongs to caller.
x509.up_ref();
let ee = CertificateDer::from(x509.der_bytes());

match ctx
.lock()
Expand Down Expand Up @@ -1487,12 +1490,15 @@ entry! {
return Error::null_pointer().raise().into();
}

let chain = vec![CertificateDer::from(OwnedX509::new(x).der_bytes())];
let x509 = OwnedX509::new(x);
// `x` belongs to caller.
x509.up_ref();
let ee = CertificateDer::from(x509.der_bytes());

match ssl
.lock()
.map_err(|_| Error::cannot_lock())
.map(|mut ssl| ssl.stage_certificate_chain(chain))
.map(|mut ssl| ssl.stage_certificate_end(ee))
{
Err(e) => e.raise().into(),
Ok(()) => C_INT_SUCCESS,
Expand Down
4 changes: 4 additions & 0 deletions rustls-libssl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ impl Ssl {
.unwrap_or_default();
}

fn stage_certificate_end(&mut self, end: CertificateDer<'static>) {
self.auth_keys.stage_certificate_end(end)
}

fn stage_certificate_chain(&mut self, chain: Vec<CertificateDer<'static>>) {
self.auth_keys.stage_certificate_chain(chain)
}
Expand Down

0 comments on commit 16f975c

Please sign in to comment.