Skip to content

Commit 9c13e8e

Browse files
committed
Implement SSL_use_PrivateKey & SSL_use_certificate
1 parent 4119ccd commit 9c13e8e

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

rustls-libssl/MATRIX.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,14 @@
485485
| `SSL_test_functions` [^unit_test] | | | |
486486
| `SSL_trace` [^ssl_trace] | | | |
487487
| `SSL_up_ref` | | | :white_check_mark: |
488-
| `SSL_use_PrivateKey` | | :white_check_mark: | |
488+
| `SSL_use_PrivateKey` | | :white_check_mark: | :white_check_mark: |
489489
| `SSL_use_PrivateKey_ASN1` | | | |
490490
| `SSL_use_PrivateKey_file` | | | |
491491
| `SSL_use_RSAPrivateKey` [^deprecatedin_3_0] | | | |
492492
| `SSL_use_RSAPrivateKey_ASN1` [^deprecatedin_3_0] | | | |
493493
| `SSL_use_RSAPrivateKey_file` [^deprecatedin_3_0] | | | |
494494
| `SSL_use_cert_and_key` | | | |
495-
| `SSL_use_certificate` | | :white_check_mark: | |
495+
| `SSL_use_certificate` | | :white_check_mark: | :white_check_mark: |
496496
| `SSL_use_certificate_ASN1` | | | |
497497
| `SSL_use_certificate_chain_file` | | | |
498498
| `SSL_use_certificate_file` | | | |

rustls-libssl/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ const ENTRYPOINTS: &[&str] = &[
151151
"SSL_set_SSL_CTX",
152152
"SSL_shutdown",
153153
"SSL_up_ref",
154+
"SSL_use_certificate",
155+
"SSL_use_PrivateKey",
154156
"SSL_want",
155157
"SSL_write",
156158
"TLS_client_method",

rustls-libssl/src/entry.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,49 @@ entry! {
11141114
}
11151115
}
11161116

1117+
entry! {
1118+
pub fn _SSL_use_certificate(ssl: *mut SSL, x: *mut X509) -> c_int {
1119+
let ssl = try_clone_arc!(ssl);
1120+
1121+
if x.is_null() {
1122+
return Error::null_pointer().raise().into();
1123+
}
1124+
1125+
let x509 = OwnedX509::new_incref(x);
1126+
let ee = CertificateDer::from(x509.der_bytes());
1127+
1128+
match ssl
1129+
.lock()
1130+
.map_err(|_| Error::cannot_lock())
1131+
.map(|mut ssl| ssl.stage_certificate_end(ee))
1132+
{
1133+
Err(e) => e.raise().into(),
1134+
Ok(()) => C_INT_SUCCESS,
1135+
}
1136+
}
1137+
}
1138+
1139+
entry! {
1140+
pub fn _SSL_use_PrivateKey(ssl: *mut SSL, pkey: *mut EVP_PKEY) -> c_int {
1141+
let ssl = try_clone_arc!(ssl);
1142+
1143+
if pkey.is_null() {
1144+
return Error::null_pointer().raise().into();
1145+
}
1146+
1147+
let pkey = EvpPkey::new_incref(pkey);
1148+
1149+
match ssl
1150+
.lock()
1151+
.map_err(|_| Error::cannot_lock())
1152+
.and_then(|mut ssl| ssl.commit_private_key(pkey))
1153+
{
1154+
Err(e) => e.raise().into(),
1155+
Ok(()) => C_INT_SUCCESS,
1156+
}
1157+
}
1158+
}
1159+
11171160
impl Castable for SSL {
11181161
type Ownership = OwnershipArc;
11191162
type RustType = Mutex<SSL>;

0 commit comments

Comments
 (0)