Skip to content

Commit

Permalink
Implement SSL_use_PrivateKey & SSL_use_certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Apr 15, 2024
1 parent 06f546d commit 5a23acb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rustls-libssl/MATRIX.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,14 @@
| `SSL_test_functions` [^unit_test] | | | |
| `SSL_trace` [^ssl_trace] | | | |
| `SSL_up_ref` | | | :white_check_mark: |
| `SSL_use_PrivateKey` | | :white_check_mark: | |
| `SSL_use_PrivateKey` | | :white_check_mark: | :white_check_mark: |
| `SSL_use_PrivateKey_ASN1` | | | |
| `SSL_use_PrivateKey_file` | | | |
| `SSL_use_RSAPrivateKey` [^deprecatedin_3_0] | | | |
| `SSL_use_RSAPrivateKey_ASN1` [^deprecatedin_3_0] | | | |
| `SSL_use_RSAPrivateKey_file` [^deprecatedin_3_0] | | | |
| `SSL_use_cert_and_key` | | | |
| `SSL_use_certificate` | | :white_check_mark: | |
| `SSL_use_certificate` | | :white_check_mark: | :white_check_mark: |
| `SSL_use_certificate_ASN1` | | | |
| `SSL_use_certificate_chain_file` | | | |
| `SSL_use_certificate_file` | | | |
Expand Down
2 changes: 2 additions & 0 deletions rustls-libssl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ const ENTRYPOINTS: &[&str] = &[
"SSL_set_SSL_CTX",
"SSL_shutdown",
"SSL_up_ref",
"SSL_use_certificate",
"SSL_use_PrivateKey",
"SSL_want",
"SSL_write",
"TLS_client_method",
Expand Down
43 changes: 43 additions & 0 deletions rustls-libssl/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,49 @@ entry! {
}
}

entry! {
pub fn _SSL_use_certificate(ssl: *mut SSL, x: *mut X509) -> c_int {
let ssl = try_clone_arc!(ssl);

if x.is_null() {
return Error::null_pointer().raise().into();
}

let x509 = OwnedX509::new_incref(x);
let ee = CertificateDer::from(x509.der_bytes());

match ssl
.lock()
.map_err(|_| Error::cannot_lock())
.map(|mut ssl| ssl.stage_certificate_end_entity(ee))
{
Err(e) => e.raise().into(),
Ok(()) => C_INT_SUCCESS,
}
}
}

entry! {
pub fn _SSL_use_PrivateKey(ssl: *mut SSL, pkey: *mut EVP_PKEY) -> c_int {
let ssl = try_clone_arc!(ssl);

if pkey.is_null() {
return Error::null_pointer().raise().into();
}

let pkey = EvpPkey::new_incref(pkey);

match ssl
.lock()
.map_err(|_| Error::cannot_lock())
.and_then(|mut ssl| ssl.commit_private_key(pkey))
{
Err(e) => e.raise().into(),
Ok(()) => C_INT_SUCCESS,
}
}
}

impl Castable for SSL {
type Ownership = OwnershipArc;
type RustType = Mutex<SSL>;
Expand Down

0 comments on commit 5a23acb

Please sign in to comment.