Skip to content

Commit a809b0c

Browse files
committed
Implement SSL_SESSION_set1_id
1 parent 372aa3e commit a809b0c

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

MATRIX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
| `SSL_SESSION_print_keylog` | | | | |
243243
| `SSL_SESSION_set1_alpn_selected` | | | | |
244244
| `SSL_SESSION_set1_hostname` | | | | |
245-
| `SSL_SESSION_set1_id` | | | :white_check_mark: | |
245+
| `SSL_SESSION_set1_id` | | | :white_check_mark: | :white_check_mark: |
246246
| `SSL_SESSION_set1_id_context` | | :white_check_mark: | :white_check_mark: | :white_check_mark: |
247247
| `SSL_SESSION_set1_master_key` | | | | |
248248
| `SSL_SESSION_set1_ticket_appdata` | | | | |

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ const ENTRYPOINTS: &[&str] = &[
211211
"SSL_SESSION_get_time",
212212
"SSL_SESSION_get_timeout",
213213
"SSL_session_reused",
214+
"SSL_SESSION_set1_id",
214215
"SSL_SESSION_set1_id_context",
215216
"SSL_SESSION_set_time",
216217
"SSL_SESSION_set_timeout",

src/entry.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,20 @@ entry! {
17001700
}
17011701
}
17021702

1703+
entry! {
1704+
pub fn _SSL_SESSION_set1_id(
1705+
sess: *mut SSL_SESSION,
1706+
sid: *const c_uchar,
1707+
sid_len: c_uint,
1708+
) -> c_int {
1709+
let slice = try_slice!(sid, c_uint_into_usize(sid_len));
1710+
match try_clone_arc!(sess).get_mut().set_id(slice) {
1711+
Ok(()) => C_INT_SUCCESS,
1712+
Err(err) => err.raise().into(),
1713+
}
1714+
}
1715+
}
1716+
17031717
entry! {
17041718
pub fn _SSL_SESSION_up_ref(sess: *mut SSL_SESSION) -> c_int {
17051719
let sess = try_clone_arc!(sess);

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,16 @@ impl SslSession {
357357
&self.id.0
358358
}
359359

360+
pub fn set_id(&mut self, new_value: &[u8]) -> Result<(), error::Error> {
361+
match new_value.len() {
362+
0..=SslSessionLookup::MAX_LEN => {
363+
self.id = SslSessionLookup::for_id(new_value);
364+
Ok(())
365+
}
366+
_ => Err(error::Error::bad_data("excess SSL_SESSION id length")),
367+
}
368+
}
369+
360370
pub fn get_creation_time(&self) -> u64 {
361371
self.creation_time.0
362372
}
@@ -425,6 +435,8 @@ impl SslSessionLookup {
425435
pub fn for_id(id: &[u8]) -> Self {
426436
Self(id.to_vec())
427437
}
438+
439+
const MAX_LEN: usize = 32;
428440
}
429441

430442
pub struct SslContext {

0 commit comments

Comments
 (0)