| 1 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 2 |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 3 |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 4 |
// option. This file may not be copied, modified, or distributed |
| 5 |
// except according to those terms. |
| 6 |
|
| 7 |
#![allow( |
| 8 |
clippy::allow_attributes, |
| 9 |
dead_code, |
| 10 |
non_upper_case_globals, |
| 11 |
non_snake_case, |
| 12 |
clippy::cognitive_complexity, |
| 13 |
clippy::too_many_lines, |
| 14 |
reason = "For included bindgen code." |
| 15 |
)] |
| 16 |
|
| 17 |
use std::os::raw::{c_uint, c_void}; |
| 18 |
|
| 19 |
use crate::{ |
| 20 |
constants::Epoch, |
| 21 |
err::{secstatus_to_res, Res}, |
| 22 |
}; |
| 23 |
|
| 24 |
include!(concat!(env!("OUT_DIR"), "/nss_ssl.rs")); |
| 25 |
#[expect(non_snake_case, reason = "OK here.")] |
| 26 |
mod SSLOption { |
| 27 |
include!(concat!(env!("OUT_DIR"), "/nss_sslopt.rs")); |
| 28 |
} |
| 29 |
|
| 30 |
pub enum PRFileDesc {} |
| 31 |
|
| 32 |
// Remap some constants. |
| 33 |
#[expect(non_upper_case_globals, reason = "OK here.")] |
| 34 |
pub const SECSuccess: SECStatus = _SECStatus_SECSuccess; |
| 35 |
#[expect(non_upper_case_globals, reason = "OK here.")] |
| 36 |
pub const SECFailure: SECStatus = _SECStatus_SECFailure; |
| 37 |
|
| 38 |
#[derive(Debug, Copy, Clone)] |
| 39 |
#[repr(u32)] |
| 40 |
pub enum Opt { |
| 41 |
Locking = SSLOption::SSL_NO_LOCKS, |
| 42 |
Tickets = SSLOption::SSL_ENABLE_SESSION_TICKETS, |
| 43 |
OcspStapling = SSLOption::SSL_ENABLE_OCSP_STAPLING, |
| 44 |
Alpn = SSLOption::SSL_ENABLE_ALPN, |
| 45 |
ExtendedMasterSecret = SSLOption::SSL_ENABLE_EXTENDED_MASTER_SECRET, |
| 46 |
SignedCertificateTimestamps = SSLOption::SSL_ENABLE_SIGNED_CERT_TIMESTAMPS, |
| 47 |
EarlyData = SSLOption::SSL_ENABLE_0RTT_DATA, |
| 48 |
RecordSizeLimit = SSLOption::SSL_RECORD_SIZE_LIMIT, |
| 49 |
Tls13CompatMode = SSLOption::SSL_ENABLE_TLS13_COMPAT_MODE, |
| 50 |
HelloDowngradeCheck = SSLOption::SSL_ENABLE_HELLO_DOWNGRADE_CHECK, |
| 51 |
SuppressEndOfEarlyData = SSLOption::SSL_SUPPRESS_END_OF_EARLY_DATA, |
| 52 |
Grease = SSLOption::SSL_ENABLE_GREASE, |
| 53 |
EnableChExtensionPermutation = SSLOption::SSL_ENABLE_CH_EXTENSION_PERMUTATION, |
| 54 |
} |
| 55 |
|
| 56 |
impl Opt { |
| 57 |
#[must_use] |
| 58 |
pub const fn as_int(self) -> PRInt32 { |
| 59 |
self as PRInt32 |
| 60 |
} |
| 61 |
|
| 62 |
// Some options are backwards, like SSL_NO_LOCKS, so use this to manage that. |
| 63 |
fn map_enabled(self, enabled: bool) -> PRIntn { |
| 64 |
let v = match self { |
| 65 |
Self::Locking => !enabled, |
| 66 |
_ => enabled, |
| 67 |
}; |
| 68 |
PRIntn::from(v) |
| 69 |
} |
| 70 |
|
| 71 |
pub(crate) fn set(self, fd: *mut PRFileDesc, value: bool) -> Res<()> { |
| 72 |
secstatus_to_res(unsafe { SSL_OptionSet(fd, self.as_int(), self.map_enabled(value)) }) |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
experimental_api!(SSL_HelloRetryRequestCallback( |
| 77 |
fd: *mut PRFileDesc, |
| 78 |
cb: SSLHelloRetryRequestCallback, |
| 79 |
arg: *mut c_void, |
| 80 |
)); |
| 81 |
experimental_api!(SSL_RecordLayerWriteCallback( |
| 82 |
fd: *mut PRFileDesc, |
| 83 |
cb: SSLRecordWriteCallback, |
| 84 |
arg: *mut c_void, |
| 85 |
)); |
| 86 |
experimental_api!(SSL_RecordLayerData( |
| 87 |
fd: *mut PRFileDesc, |
| 88 |
epoch: Epoch, |
| 89 |
ct: SSLContentType::Type, |
| 90 |
data: *const u8, |
| 91 |
len: c_uint, |
| 92 |
)); |
| 93 |
experimental_api!(SSL_SendSessionTicket( |
| 94 |
fd: *mut PRFileDesc, |
| 95 |
extra: *const u8, |
| 96 |
len: c_uint, |
| 97 |
)); |
| 98 |
experimental_api!(SSL_SetMaxEarlyDataSize(fd: *mut PRFileDesc, size: u32)); |
| 99 |
experimental_api!(SSL_SetResumptionToken( |
| 100 |
fd: *mut PRFileDesc, |
| 101 |
token: *const u8, |
| 102 |
len: c_uint, |
| 103 |
)); |
| 104 |
experimental_api!(SSL_SetResumptionTokenCallback( |
| 105 |
fd: *mut PRFileDesc, |
| 106 |
cb: SSLResumptionTokenCallback, |
| 107 |
arg: *mut c_void, |
| 108 |
)); |
| 109 |
|
| 110 |
experimental_api!(SSL_GetResumptionTokenInfo( |
| 111 |
token: *const u8, |
| 112 |
token_len: c_uint, |
| 113 |
info: *mut SSLResumptionTokenInfo, |
| 114 |
len: c_uint, |
| 115 |
)); |
| 116 |
|
| 117 |
experimental_api!(SSL_DestroyResumptionTokenInfo( |
| 118 |
info: *mut SSLResumptionTokenInfo, |
| 119 |
)); |
| 120 |
|
| 121 |
#[cfg(test)] |
| 122 |
mod tests { |
| 123 |
use super::{SSL_GetNumImplementedCiphers, SSL_NumImplementedCiphers}; |
| 124 |
|
| 125 |
#[test] |
| 126 |
fn num_ciphers() { |
| 127 |
assert!(unsafe { SSL_NumImplementedCiphers } > 0); |
| 128 |
assert!(unsafe { SSL_GetNumImplementedCiphers() } > 0); |
| 129 |
assert_eq!(unsafe { SSL_NumImplementedCiphers }, unsafe { |
| 130 |
SSL_GetNumImplementedCiphers() |
| 131 |
}); |
| 132 |
} |
| 133 |
} |