Skip to content

Commit

Permalink
feat(bindings): enable application owned certs (#4937)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmayclin authored Dec 9, 2024
1 parent b6446c7 commit aaae641
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 50 deletions.
50 changes: 49 additions & 1 deletion bindings/rust/s2n-tls/src/callbacks/pkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mod tests {
testing::{self, *},
};
use core::task::{Poll, Waker};
use futures_test::task::new_count_waker;
use futures_test::task::{new_count_waker, noop_waker};
use openssl::{ec::EcKey, ecdsa::EcdsaSig};

type Error = Box<dyn std::error::Error>;
Expand Down Expand Up @@ -350,4 +350,52 @@ mod tests {
assert_test_error(err, ERROR);
Ok(())
}

/// pkey offload should also work with public certs created from
/// [CertificateChain::from_public_pems].
#[test]
fn app_owned_public_cert() -> Result<(), Error> {
struct TestPkeyCallback;
impl PrivateKeyCallback for TestPkeyCallback {
fn handle_operation(
&self,
conn: &mut connection::Connection,
op: PrivateKeyOperation,
) -> Result<Option<Pin<Box<dyn ConnectionFuture>>>, error::Error> {
ecdsa_sign(op, conn, KEY)?;
Ok(None)
}
}

let public_chain = {
let mut chain = crate::cert_chain::Builder::new()?;
chain.load_public_pem(CERT)?;
chain.build()?
};

let server_config = {
let mut config = config::Builder::new();
config
.set_security_policy(&security::DEFAULT_TLS13)?
.load_chain(public_chain)?
.set_private_key_callback(TestPkeyCallback)?;
config.build()?
};

let client_config = {
let mut config = config::Builder::new();
config
.set_security_policy(&security::DEFAULT_TLS13)?
.set_verify_host_callback(InsecureAcceptAllCertificatesHandler {})?
.trust_pem(CERT)?;
config.build()?
};

let mut pair = TestPair::from_configs(&client_config, &server_config);
pair.server.set_waker(Some(&noop_waker()))?;

assert!(pair.handshake().is_ok());

Ok(())
}
}
Loading

0 comments on commit aaae641

Please sign in to comment.