Skip to content

Commit

Permalink
Update API after discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cruceru committed Dec 1, 2020
1 parent 775dc56 commit cd9eb8e
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 225 deletions.
2 changes: 1 addition & 1 deletion mbedtls/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use support::keys;
fn result_main(addr: &str) -> TlsResult<()> {
let entropy = Arc::new(entropy_new());
let rng = Arc::new(CtrDrbg::new(entropy, None)?);
let cert = Arc::new(MbedtlsList::<Certificate>::from_pem(keys::PEM_CERT)?);
let cert = Arc::new(Certificate::from_pem(keys::PEM_CERT)?);
let mut config = Config::new(Endpoint::Client, Transport::Stream, Preset::Default);
config.set_rng(rng);
config.set_ca_list(cert, None);
Expand Down
2 changes: 1 addition & 1 deletion mbedtls/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn listen<E, F: FnMut(TcpStream) -> Result<(), E>>(mut handle_client: F) -> Resu
fn result_main() -> TlsResult<()> {
let entropy = entropy_new();
let rng = Arc::new(CtrDrbg::new(Arc::new(entropy), None)?);
let cert = Arc::new(MbedtlsList::<Certificate>::from_pem(keys::PEM_CERT)?);
let cert = Arc::new(Certificate::from_pem(keys::PEM_CERT)?);
let key = Arc::new(Pk::from_private_key(keys::PEM_KEY, None)?);
let mut config = Config::new(Endpoint::Server, Transport::Stream, Preset::Default);
config.set_rng(rng);
Expand Down
6 changes: 3 additions & 3 deletions mbedtls/src/ssl/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::pk::dhparam::Dhm;
use crate::x509::Profile;
use crate::ssl::Context;
use crate::private::UnsafeFrom;
use crate::x509::certificate::MbedtlsList;
use crate::x509::MbedtlsList;

extern "C" {
fn calloc(n: usize, size: usize) -> *mut c_void;
Expand Down Expand Up @@ -291,7 +291,7 @@ impl Config {
pub fn set_ca_list(&mut self, ca_cert: Arc<MbedtlsList<Certificate>>, crl: Option<Arc<Crl>>) {
// This will override internal pointers to what we provide.

unsafe { ssl_conf_ca_chain(self.into(), (&**ca_cert).into(), crl.as_ref().map(|crl| (&(**crl)).into()).unwrap_or(::core::ptr::null_mut())); }
unsafe { ssl_conf_ca_chain(self.into(), (&*ca_cert).into(), crl.as_ref().map(|crl| (&(**crl)).into()).unwrap_or(::core::ptr::null_mut())); }

self.ca_cert = Some(ca_cert);
self.crl = crl;
Expand All @@ -303,7 +303,7 @@ impl Config {
self.own_pk.push(own_pk.clone());

// This will append pointers to our certificates inside mbedtls
unsafe { ssl_conf_own_cert(self.into(), (&**own_cert).into(), (&*own_pk).into())
unsafe { ssl_conf_own_cert(self.into(), (&*own_cert).into(), (&*own_pk).into())
.into_result()
.map(|_| ())
}
Expand Down
9 changes: 4 additions & 5 deletions mbedtls/src/ssl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use crate::x509::VerifyError;
use crate::pk::Pk;
use crate::x509::Crl;
use std::any::Any;
use crate::x509::certificate::MbedtlsList;
use crate::x509::Certificate;
use crate::x509::{MbedtlsList, Certificate};

pub trait IoCallback {
unsafe extern "C" fn call_recv(user_data: *mut c_void, data: *mut c_uchar, len: size_t) -> c_int where Self: Sized;
Expand Down Expand Up @@ -267,7 +266,7 @@ impl Context {
return Err(Error::SslBadInputData);
}

let cert = MbedtlsList::<Certificate>::from_cert(&*peer_cert);
let cert = Certificate::from_cert(&*peer_cert);
Ok(Some(cert))
}
}
Expand Down Expand Up @@ -354,7 +353,7 @@ impl<'ctx> HandshakeContext<'ctx> {
unsafe {
ssl_set_hs_ca_chain(
self.context.into(),
(&**chain).into(),
(&*chain).into(),
crl.as_ref().map(|crl| (&(**crl)).into()).unwrap_or(::core::ptr::null_mut()),
);
}
Expand Down Expand Up @@ -382,7 +381,7 @@ impl<'ctx> HandshakeContext<'ctx> {

// This will append provided certificate pointers in internal structures.
unsafe {
ssl_set_hs_own_cert(self.context.into(), (&**chain).into(), (&*key).into()).into_result()?;
ssl_set_hs_own_cert(self.context.into(), (&*chain).into(), (&*key).into()).into_result()?;
}
self.context.handshake_cert.push(chain);
self.context.handshake_pk.push(key);
Expand Down
Loading

0 comments on commit cd9eb8e

Please sign in to comment.