Skip to content

Commit 23f185b

Browse files
committed
Implement SSL_get_early_data_status
1 parent 70efb19 commit 23f185b

5 files changed

Lines changed: 48 additions & 1 deletion

File tree

MATRIX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
| `SSL_get_default_passwd_cb` | | | | |
335335
| `SSL_get_default_passwd_cb_userdata` | | | | |
336336
| `SSL_get_default_timeout` | | | | |
337-
| `SSL_get_early_data_status` | | | :white_check_mark: | |
337+
| `SSL_get_early_data_status` | | | :white_check_mark: | :white_check_mark: |
338338
| `SSL_get_error` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
339339
| `SSL_get_ex_data` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
340340
| `SSL_get_ex_data_X509_STORE_CTX_idx` | | :white_check_mark: | :white_check_mark: | :exclamation: [^stub] |

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ const ENTRYPOINTS: &[&str] = &[
162162
"SSL_get_client_random",
163163
"SSL_get_current_cipher",
164164
"SSL_get_current_compression",
165+
"SSL_get_early_data_status",
165166
"SSL_get_error",
166167
"SSL_get_ex_data",
167168
"SSL_get_ex_data_X509_STORE_CTX_idx",

src/entry.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,12 @@ entry! {
10071007
}
10081008
}
10091009

1010+
entry! {
1011+
pub fn _SSL_get_early_data_status(ssl: *const SSL) -> c_int {
1012+
try_clone_arc!(ssl).get_mut().get_early_data_status().into()
1013+
}
1014+
}
1015+
10101016
entry! {
10111017
pub fn _SSL_set_alpn_protos(
10121018
ssl: *mut SSL,

src/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,27 @@ impl Ssl {
858858
self.max_early_data = max;
859859
}
860860

861+
fn get_early_data_status(&mut self) -> EarlyDataStatus {
862+
// XXX: unfortunately `ClientConnection::early_data()` and
863+
// `ServerConnection::early_data()` both require a mut self;
864+
// which means this getter is mut too.
865+
match self.conn_mut() {
866+
Some(Connection::Server(server)) => match server.early_data() {
867+
Some(_) => EarlyDataStatus::Accepted,
868+
None => EarlyDataStatus::NotSent,
869+
},
870+
Some(Connection::Client(client)) => {
871+
let accepted = client.is_early_data_accepted();
872+
match (client.early_data(), accepted) {
873+
(_, true) => EarlyDataStatus::Accepted,
874+
(None, false) => EarlyDataStatus::Rejected,
875+
(Some(_), _) => EarlyDataStatus::NotSent,
876+
}
877+
}
878+
None => EarlyDataStatus::NotSent,
879+
}
880+
}
881+
861882
fn clear_options(&mut self, clear: u64) -> u64 {
862883
self.raw_options &= !clear;
863884
self.raw_options
@@ -1722,6 +1743,24 @@ impl EnabledVersions {
17221743
}
17231744
}
17241745

1746+
#[derive(Debug)]
1747+
enum EarlyDataStatus {
1748+
NotSent,
1749+
Rejected,
1750+
Accepted,
1751+
}
1752+
1753+
impl From<EarlyDataStatus> for c_int {
1754+
fn from(e: EarlyDataStatus) -> Self {
1755+
// refer to OpenSSL SSL_EARLY_DATA_NOT_SENT et al.
1756+
match e {
1757+
EarlyDataStatus::NotSent => 0,
1758+
EarlyDataStatus::Rejected => 1,
1759+
EarlyDataStatus::Accepted => 2,
1760+
}
1761+
}
1762+
}
1763+
17251764
pub(crate) const SSL_OP_NO_TICKET: u64 = 1 << 14; // See ssl.h
17261765

17271766
#[cfg(test)]

tests/client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ int main(int argc, char **argv) {
101101
printf("SSL_get_min_proto_version 0x%lx\n", SSL_get_min_proto_version(ssl));
102102
printf("SSL_get_max_proto_version 0x%lx\n", SSL_get_max_proto_version(ssl));
103103
printf("SSL_renegotiate_pending %d\n", SSL_renegotiate_pending(ssl));
104+
printf("SSL_get_early_data_status %d\n", SSL_get_early_data_status(ssl));
104105
printf("SSL_get_servername: %s (%d)\n",
105106
SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name),
106107
SSL_get_servername_type(ssl));

0 commit comments

Comments
 (0)