Skip to content

Commit 7145fb9

Browse files
committed
Stub out a wedge of functions
Some of these certainly will be implemented later, others almost certainly will not.
1 parent a885fc5 commit 7145fb9

File tree

3 files changed

+227
-1
lines changed

3 files changed

+227
-1
lines changed

rustls-libssl/admin/format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# `entry!` with `mod entry`, and then restore it back afterwards.
1111

1212
sed -i -e 's/^entry! {/mod entry {/g' src/entry.rs
13+
sed -i -e 's/^entry_stub! {/mod entry_stub {/g' src/entry.rs
1314
cargo fmt "$@"
1415
rc=$?
1516
sed -i -e 's/^mod entry {/entry! {/g' src/entry.rs
17+
sed -i -e 's/^mod entry_stub {/entry_stub! {/g' src/entry.rs
1618
exit $rc

rustls-libssl/build.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,50 @@ const ENTRYPOINTS: &[&str] = &[
5757
"SSL_clear_options",
5858
"SSL_connect",
5959
"SSL_ctrl",
60+
"SSL_CTX_add_client_CA",
61+
"SSL_CTX_check_private_key",
6062
"SSL_CTX_clear_options",
6163
"SSL_CTX_ctrl",
6264
"SSL_CTX_free",
6365
"SSL_CTX_get_cert_store",
66+
"SSL_CTX_get_ex_data",
6467
"SSL_CTX_get_options",
6568
"SSL_CTX_load_verify_dir",
6669
"SSL_CTX_load_verify_file",
6770
"SSL_CTX_new",
71+
"SSL_CTX_sess_set_new_cb",
6872
"SSL_CTX_set_alpn_protos",
73+
"SSL_CTX_set_cipher_list",
74+
"SSL_CTX_set_ciphersuites",
75+
"SSL_CTX_set_default_passwd_cb",
76+
"SSL_CTX_set_default_passwd_cb_userdata",
77+
"SSL_CTX_set_ex_data",
78+
"SSL_CTX_set_keylog_callback",
79+
"SSL_CTX_set_msg_callback",
80+
"SSL_CTX_set_next_proto_select_cb",
6981
"SSL_CTX_set_options",
82+
"SSL_CTX_set_post_handshake_auth",
83+
"SSL_CTX_set_srp_password",
84+
"SSL_CTX_set_srp_username",
7085
"SSL_CTX_set_verify",
7186
"SSL_CTX_up_ref",
87+
"SSL_CTX_use_certificate",
88+
"SSL_CTX_use_certificate_chain_file",
89+
"SSL_CTX_use_certificate_file",
90+
"SSL_CTX_use_PrivateKey",
91+
"SSL_CTX_use_PrivateKey_file",
7292
"SSL_free",
7393
"SSL_get0_alpn_selected",
7494
"SSL_get0_peer_certificate",
7595
"SSL_get0_verified_chain",
7696
"SSL_get1_peer_certificate",
97+
"SSL_get_certificate",
7798
"SSL_get_current_cipher",
7899
"SSL_get_error",
100+
"SSL_get_ex_data",
79101
"SSL_get_options",
80102
"SSL_get_peer_cert_chain",
103+
"SSL_get_privatekey",
81104
"SSL_get_shutdown",
82105
"SSL_get_verify_result",
83106
"SSL_get_version",
@@ -86,15 +109,19 @@ const ENTRYPOINTS: &[&str] = &[
86109
"SSL_new",
87110
"SSL_pending",
88111
"SSL_read",
112+
"SSL_SESSION_free",
89113
"SSL_set0_rbio",
90114
"SSL_set0_wbio",
91115
"SSL_set1_host",
92116
"SSL_set_accept_state",
93117
"SSL_set_alpn_protos",
94118
"SSL_set_bio",
95119
"SSL_set_connect_state",
120+
"SSL_set_ex_data",
96121
"SSL_set_fd",
97122
"SSL_set_options",
123+
"SSL_set_post_handshake_auth",
124+
"SSL_set_session",
98125
"SSL_set_shutdown",
99126
"SSL_shutdown",
100127
"SSL_up_ref",

rustls-libssl/src/entry.rs

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use std::sync::Mutex;
99
use std::{fs, io, path::PathBuf};
1010

1111
use openssl_sys::{
12-
stack_st_X509, OPENSSL_malloc, X509, X509_STORE, X509_STORE_CTX, X509_V_ERR_UNSPECIFIED,
12+
stack_st_X509, OPENSSL_malloc, EVP_PKEY, X509, X509_STORE, X509_STORE_CTX,
13+
X509_V_ERR_UNSPECIFIED,
1314
};
1415

1516
use crate::bio::{Bio, BIO, BIO_METHOD};
@@ -901,6 +902,202 @@ num_enum! {
901902
}
902903
}
903904

905+
// --- unimplemented stubs below here ---
906+
907+
macro_rules! entry_stub {
908+
(pub fn $name:ident($($args:tt)*);) => {
909+
#[no_mangle]
910+
pub extern "C" fn $name($($args)*) {
911+
ffi_panic_boundary! {
912+
Error::not_supported(stringify!($name)).raise().into()
913+
}
914+
}
915+
};
916+
(pub fn $name:ident($($args:tt)*) -> $ret:ty;) => {
917+
#[no_mangle]
918+
pub extern "C" fn $name($($args)*) -> $ret {
919+
ffi_panic_boundary! {
920+
Error::not_supported(stringify!($name)).raise().into()
921+
}
922+
}
923+
};
924+
}
925+
926+
// things we support and should be able to implement to
927+
// some extent:
928+
929+
entry_stub! {
930+
pub fn _SSL_CTX_set_ex_data(_ssl: *mut SSL_CTX, _idx: c_int, _data: *mut c_void) -> c_int;
931+
}
932+
933+
entry_stub! {
934+
pub fn _SSL_CTX_get_ex_data(_ssl: *const SSL_CTX, _idx: c_int) -> *mut c_void;
935+
}
936+
937+
entry_stub! {
938+
pub fn _SSL_set_ex_data(_ssl: *mut SSL, _idx: c_int, _data: *mut c_void) -> c_int;
939+
}
940+
941+
entry_stub! {
942+
pub fn _SSL_get_ex_data(_ssl: *const SSL, _idx: c_int) -> *mut c_void;
943+
}
944+
945+
entry_stub! {
946+
pub fn _SSL_get_certificate(_ssl: *const SSL) -> *mut X509;
947+
}
948+
949+
entry_stub! {
950+
pub fn _SSL_get_privatekey(_ssl: *const SSL) -> *mut EVP_PKEY;
951+
}
952+
953+
entry_stub! {
954+
pub fn _SSL_set_session(_ssl: *mut SSL, _session: *mut SSL_SESSION) -> c_int;
955+
}
956+
957+
entry_stub! {
958+
pub fn _SSL_CTX_set_keylog_callback(_ctx: *mut SSL_CTX, _cb: SSL_CTX_keylog_cb_func);
959+
}
960+
961+
pub type SSL_CTX_keylog_cb_func =
962+
Option<unsafe extern "C" fn(ssl: *const SSL, line: *const c_char)>;
963+
964+
entry_stub! {
965+
pub fn _SSL_CTX_add_client_CA(_ctx: *mut SSL_CTX, _x: *mut X509) -> c_int;
966+
}
967+
968+
entry_stub! {
969+
pub fn _SSL_CTX_check_private_key(_ctx: *const SSL_CTX) -> c_int;
970+
}
971+
972+
entry_stub! {
973+
pub fn _SSL_CTX_sess_set_new_cb(_ctx: *mut SSL_CTX, _new_session_cb: SSL_CTX_new_session_cb);
974+
}
975+
976+
pub type SSL_CTX_new_session_cb =
977+
Option<unsafe extern "C" fn(_ssl: *mut SSL, _sess: *mut SSL_SESSION) -> c_int>;
978+
979+
entry_stub! {
980+
pub fn _SSL_CTX_set_cipher_list(_ctx: *mut SSL_CTX, _s: *const c_char) -> c_int;
981+
}
982+
983+
entry_stub! {
984+
pub fn _SSL_CTX_set_ciphersuites(_ctx: *mut SSL_CTX, _s: *const c_char) -> c_int;
985+
}
986+
987+
entry_stub! {
988+
pub fn _SSL_CTX_use_PrivateKey(_ctx: *mut SSL_CTX, _pkey: *mut EVP_PKEY) -> c_int;
989+
}
990+
991+
entry_stub! {
992+
pub fn _SSL_CTX_use_PrivateKey_file(
993+
_ctx: *mut SSL_CTX,
994+
_file: *const c_char,
995+
_type: c_int,
996+
) -> c_int;
997+
}
998+
999+
entry_stub! {
1000+
pub fn _SSL_CTX_use_certificate(_ctx: *mut SSL_CTX, _x: *mut X509) -> c_int;
1001+
}
1002+
1003+
entry_stub! {
1004+
pub fn _SSL_CTX_use_certificate_chain_file(_ctx: *mut SSL_CTX, _file: *const c_char) -> c_int;
1005+
}
1006+
1007+
entry_stub! {
1008+
pub fn _SSL_CTX_use_certificate_file(
1009+
_ctx: *mut SSL_CTX,
1010+
_file: *const c_char,
1011+
_type_: c_int,
1012+
) -> c_int;
1013+
}
1014+
1015+
pub struct SSL_SESSION;
1016+
1017+
entry_stub! {
1018+
pub fn _SSL_SESSION_free(_sess: *mut SSL_SESSION);
1019+
}
1020+
1021+
// no individual message logging
1022+
1023+
entry_stub! {
1024+
pub fn _SSL_CTX_set_msg_callback(_ctx: *mut SSL_CTX, _cb: SSL_CTX_msg_cb_func);
1025+
}
1026+
1027+
pub type SSL_CTX_msg_cb_func = Option<
1028+
unsafe extern "C" fn(
1029+
write_p: c_int,
1030+
version: c_int,
1031+
content_type: c_int,
1032+
buf: *const c_void,
1033+
len: usize,
1034+
ssl: *mut SSL,
1035+
arg: *mut c_void,
1036+
),
1037+
>;
1038+
1039+
// no NPN (obsolete precursor to ALPN)
1040+
1041+
entry_stub! {
1042+
pub fn _SSL_CTX_set_next_proto_select_cb(
1043+
_ctx: *mut SSL_CTX,
1044+
_cb: SSL_CTX_npn_select_cb_func,
1045+
_arg: *mut c_void,
1046+
);
1047+
}
1048+
1049+
pub type SSL_CTX_npn_select_cb_func = Option<
1050+
unsafe extern "C" fn(
1051+
s: *mut SSL,
1052+
out: *mut *mut c_uchar,
1053+
outlen: *mut c_uchar,
1054+
in_: *const c_uchar,
1055+
inlen: c_uint,
1056+
arg: *mut c_void,
1057+
) -> c_int,
1058+
>;
1059+
1060+
// no password-protected key loading
1061+
1062+
entry_stub! {
1063+
pub fn _SSL_CTX_set_default_passwd_cb(_ctx: *mut SSL_CTX, _cb: pem_password_cb);
1064+
}
1065+
1066+
pub type pem_password_cb = Option<
1067+
unsafe extern "C" fn(
1068+
buf: *mut c_char,
1069+
size: c_int,
1070+
rwflag: c_int,
1071+
userdata: *mut c_void,
1072+
) -> c_int,
1073+
>;
1074+
1075+
entry_stub! {
1076+
pub fn _SSL_CTX_set_default_passwd_cb_userdata(_ctx: *mut SSL_CTX, _u: *mut c_void);
1077+
}
1078+
1079+
// no SRP
1080+
1081+
entry_stub! {
1082+
pub fn _SSL_CTX_set_srp_password(_ctx: *mut SSL_CTX, _password: *mut c_char) -> c_int;
1083+
}
1084+
1085+
entry_stub! {
1086+
pub fn _SSL_CTX_set_srp_username(_ctx: *mut SSL_CTX, _name: *mut c_char) -> c_int;
1087+
}
1088+
1089+
// no post-handshake auth
1090+
1091+
entry_stub! {
1092+
pub fn _SSL_CTX_set_post_handshake_auth(_ctx: *mut SSL_CTX, _val: c_int);
1093+
}
1094+
1095+
entry_stub! {
1096+
pub fn _SSL_set_post_handshake_auth(_s: *mut SSL, _val: c_int);
1097+
}
1098+
1099+
// ---------------------
1100+
9041101
#[cfg(test)]
9051102
mod tests {
9061103
use super::*;

0 commit comments

Comments
 (0)