Skip to content

Commit 70efb19

Browse files
committed
Implement SSL_CTX_add_server_custom_ext
1 parent a809b0c commit 70efb19

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

MATRIX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
| `SSL_CTX_add_client_CA` | :white_check_mark: | | | :exclamation: [^stub] |
6666
| `SSL_CTX_add_client_custom_ext` | | | | |
6767
| `SSL_CTX_add_custom_ext` | | :white_check_mark: | :white_check_mark: | :exclamation: [^stub] |
68-
| `SSL_CTX_add_server_custom_ext` | | | :white_check_mark: | |
68+
| `SSL_CTX_add_server_custom_ext` | | | :white_check_mark: | :white_check_mark: |
6969
| `SSL_CTX_add_session` | | | | |
7070
| `SSL_CTX_callback_ctrl` | | :white_check_mark: | :white_check_mark: | :white_check_mark: |
7171
| `SSL_CTX_check_private_key` | :white_check_mark: | | :white_check_mark: | :white_check_mark: |

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const ENTRYPOINTS: &[&str] = &[
7878
"SSL_ctrl",
7979
"SSL_CTX_add_client_CA",
8080
"SSL_CTX_add_custom_ext",
81+
"SSL_CTX_add_server_custom_ext",
8182
"SSL_CTX_callback_ctrl",
8283
"SSL_CTX_check_private_key",
8384
"SSL_CTX_clear_options",

src/entry.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,73 @@ entry! {
769769
}
770770
}
771771

772+
entry! {
773+
pub fn _SSL_CTX_add_server_custom_ext(
774+
ctx: *mut SSL_CTX,
775+
ext_type: c_uint,
776+
_add_cb: custom_ext_add_cb,
777+
_free_cb: custom_ext_free_cb,
778+
_add_arg: *mut c_void,
779+
_parse_cb: custom_ext_parse_cb,
780+
_parse_arg: *mut c_void,
781+
) -> c_int {
782+
let _null_check = try_ref_from_ptr!(ctx);
783+
784+
match ext_type {
785+
// Previously rustls had support for this extension, but removed it as
786+
// the SCT-via-TLS-extension method was never widely deployed. Instead,
787+
// SCTs are delivered via an X.509v3 extension.
788+
//
789+
// If rustls retained that support, here is a sketch of how we could
790+
// proceed here:
791+
//
792+
// - store the callbacks and arguments, in a SCT-specific location,
793+
// inside the ctx's `sign::CertifiedKeySet`,
794+
// - when making a new `ServerConfig`, call `add_cb` to extract the
795+
// SCT extension body,
796+
// - decode the SCT extension body, and store the SCTs in our selected
797+
// `CertifiedKey::sct_list`,
798+
// - call `free_cb`.
799+
//
800+
// Instead, we say this call is successful, never call the callbacks,
801+
// and do not attach their data to an extension.
802+
EXTENSION_TYPE_SCT => C_INT_SUCCESS,
803+
other => {
804+
log::warn!("SSL_CTX_add_server_custom_ext for 0x{other:x?} failed");
805+
0
806+
}
807+
}
808+
}
809+
}
810+
811+
const EXTENSION_TYPE_SCT: u32 = 0x0012;
812+
813+
pub type custom_ext_add_cb = Option<
814+
unsafe extern "C" fn(
815+
s: *mut SSL,
816+
ext_type: c_uint,
817+
out: *mut *const c_uchar,
818+
outlen: *mut usize,
819+
al: *mut c_int,
820+
add_arg: *mut c_void,
821+
) -> c_int,
822+
>;
823+
824+
pub type custom_ext_free_cb = Option<
825+
unsafe extern "C" fn(s: *mut SSL, ext_type: c_uint, out: *const c_uchar, add_arg: *mut c_void),
826+
>;
827+
828+
pub type custom_ext_parse_cb = Option<
829+
unsafe extern "C" fn(
830+
s: *mut SSL,
831+
ext_type: c_uint,
832+
in_: *const c_uchar,
833+
inlen: usize,
834+
al: *mut c_int,
835+
parse_arg: *mut c_void,
836+
) -> c_int,
837+
>;
838+
772839
impl Castable for SSL_CTX {
773840
type Ownership = OwnershipArc;
774841
type RustType = NotThreadSafe<Self>;

0 commit comments

Comments
 (0)