Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions boring-sys/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,10 @@ fn generate_bindings(config: &Config) -> Result<PathBuf, Box<dyn std::error::Err
.layout_tests(config.env.debug.is_some())
.merge_extern_blocks(true)
.prepend_enum_name(true)
.allowlist_item("[A-Z].*|.*_.*|tm.*|time.*") // Exclude unprefixed stdlib and POSIX functions
.blocklist_item("rusage.*|RLIMIT.*|USE_CLANG.*|__?v?snprintf.*|.*DEPRECATED.*|sig[a-z0-9]*_t|__sig.*|_?sigaction.*|__darwin_(arm_|[um]context).*|[um]context_t|__arm_.*|__AVAIL.*|MAC_OS_(X_)?VER.*")
.blocklist_type("max_align_t") // Not supported by bindgen on all targets, not used by BoringSSL
.opaque_type("__?opaque_.*")
.clang_args(get_extra_clang_args_for_bindgen(config))
.clang_arg("-I")
.clang_arg(include_path.display().to_string());
Expand Down
1 change: 1 addition & 0 deletions boring-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn init() {

// CBS_init is inline in BoringSSL, so bindgen can't generate bindings for it.
#[inline]
#[must_use]
pub fn cbs_init(data: &[u8]) -> CBS {
CBS {
data: data.as_ptr(),
Expand Down
4 changes: 2 additions & 2 deletions boring/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,8 @@ mod tests {
assert!(a != c_ref);
assert!(b_ref == a);
assert!(c_ref != a);
assert!(a_ref == b_ref);
assert!(a_ref != c_ref);
assert_eq!(a_ref, b_ref);
assert_ne!(a_ref, c_ref);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions boring/src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ impl<T> ToOwned for EcKeyRef<T> {
fn to_owned(&self) -> EcKey<T> {
unsafe {
let r = ffi::EC_KEY_up_ref(self.as_ptr());
assert!(r == 1);
assert_eq!(r, 1);
EcKey::from_ptr(self.as_ptr())
}
}
Expand Down Expand Up @@ -878,7 +878,7 @@ mod test {
EcKey::from_private_components(&group, key.private_key(), key.public_key()).unwrap();
dup_key.check_key().unwrap();

assert!(key.private_key() == dup_key.private_key());
assert_eq!(key.private_key(), dup_key.private_key());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion boring/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl Error {
}

fn is_internal(&self) -> bool {
std::ptr::eq(self.file, BORING_INTERNAL.as_ptr())
ptr::eq(self.file, BORING_INTERNAL.as_ptr())
}
}

Expand Down
2 changes: 1 addition & 1 deletion boring/src/memcmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use crate::ffi;
/// ```
#[must_use]
pub fn eq(a: &[u8], b: &[u8]) -> bool {
assert!(a.len() == b.len());
assert_eq!(a.len(), b.len());
let ret = unsafe { ffi::CRYPTO_memcmp(a.as_ptr().cast(), b.as_ptr().cast(), a.len()) };
ret == 0
}
Expand Down
1 change: 1 addition & 0 deletions boring/src/pkcs12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub struct ParsedPkcs12_2 {
}

impl ParsedPkcs12_2 {
#[must_use]
pub fn chain(&self) -> Option<&StackRef<X509>> {
self.ca.as_deref()
}
Expand Down
4 changes: 2 additions & 2 deletions boring/src/pkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ where
let mut size = 0;
_ = cvt_0i(ffi::EVP_PKEY_get_raw_public_key(
self.as_ptr(),
std::ptr::null_mut(),
ptr::null_mut(),
&mut size,
))?;
Ok(size)
Expand Down Expand Up @@ -305,7 +305,7 @@ where
let mut size = 0;
_ = cvt_0i(ffi::EVP_PKEY_get_raw_private_key(
self.as_ptr(),
std::ptr::null_mut(),
ptr::null_mut(),
&mut size,
))?;
Ok(size)
Expand Down
16 changes: 8 additions & 8 deletions boring/src/ssl/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where

// SAFETY: The callback won't outlive the context it's associated with
// because there is no `X509StoreContextRef::ssl_mut(&mut self)` method.
let verify = unsafe { &*std::ptr::from_ref::<F>(verify) };
let verify = unsafe { &*ptr::from_ref::<F>(verify) };

c_int::from(verify(preverify_ok != 0, ctx))
}
Expand Down Expand Up @@ -90,7 +90,7 @@ where
// SAFETY: The callback won't outlive the context it's associated with
// because there is no way to get a mutable reference to the `SslContext`,
// so the callback can't replace itself.
let verify = unsafe { &*std::ptr::from_ref::<F>(verify) };
let verify = unsafe { &*ptr::from_ref::<F>(verify) };

c_int::from(verify(ctx))
}
Expand Down Expand Up @@ -442,7 +442,7 @@ where
// SAFETY: We can make `callback` outlive `ssl` because it is a callback
// stored in the session context set in `Ssl::new` so it is always
// guaranteed to outlive the lifetime of this function's scope.
let callback = unsafe { &*std::ptr::from_ref::<F>(callback) };
let callback = unsafe { &*ptr::from_ref::<F>(callback) };

callback(ssl, session);

Expand Down Expand Up @@ -495,7 +495,7 @@ where
// SAFETY: We can make `callback` outlive `ssl` because it is a callback
// stored in the session context set in `Ssl::new` so it is always
// guaranteed to outlive the lifetime of this function's scope.
let callback = unsafe { &*std::ptr::from_ref::<F>(callback) };
let callback = unsafe { &*ptr::from_ref::<F>(callback) };

match callback(ssl, data) {
Ok(Some(session)) => {
Expand Down Expand Up @@ -666,7 +666,7 @@ where
.ex_data(SslContext::cached_ex_index::<C>())
.expect("BUG: certificate compression missed");

let input_slice = unsafe { std::slice::from_raw_parts(input, input_len) };
let input_slice = unsafe { slice::from_raw_parts(input, input_len) };
let mut writer = CryptoByteBuilder::from_ptr(out);
if compressor.compress(input_slice, &mut writer).is_err() {
return 0;
Expand Down Expand Up @@ -701,7 +701,7 @@ where
return 0;
};

let input_slice = unsafe { std::slice::from_raw_parts(input, input_len) };
let input_slice = unsafe { slice::from_raw_parts(input, input_len) };

if compressor
.decompress(input_slice, decompression_buffer.as_writer())
Expand Down Expand Up @@ -751,11 +751,11 @@ struct CryptoBufferBuilder<'a> {

impl<'a> CryptoBufferBuilder<'a> {
fn with_capacity(capacity: usize) -> Result<CryptoBufferBuilder<'a>, ErrorStack> {
let mut data: *mut u8 = std::ptr::null_mut();
let mut data: *mut u8 = ptr::null_mut();
let buffer = unsafe { crate::cvt_p(ffi::CRYPTO_BUFFER_alloc(&mut data, capacity))? };
Ok(CryptoBufferBuilder {
buffer,
cursor: std::io::Cursor::new(unsafe { std::slice::from_raw_parts_mut(data, capacity) }),
cursor: std::io::Cursor::new(unsafe { slice::from_raw_parts_mut(data, capacity) }),
})
}

Expand Down
4 changes: 2 additions & 2 deletions boring/src/ssl/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl SslCredentialRef {
if data.is_null() {
None
} else {
Some(&mut *(data as *mut T))
Some(&mut *data.cast::<T>())
}
}

Expand All @@ -114,7 +114,7 @@ impl SslCredentialRef {
}

unsafe {
let data = Box::into_raw(Box::new(data)) as *mut c_void;
let data = Box::into_raw(Box::new(data)).cast::<c_void>();
ffi::SSL_CREDENTIAL_set_ex_data(self.as_ptr(), index.as_raw(), data);
}

Expand Down
12 changes: 7 additions & 5 deletions boring/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ impl SslContextBuilder {
unsafe {
cvt_0i(ffi::SSL_CTX_set1_accepted_peer_cert_types(
self.as_ptr(),
types.as_ptr() as *const u8,
types.as_ptr().cast::<u8>(),
types.len(),
))
.map(|_| ())
Expand Down Expand Up @@ -2434,7 +2434,7 @@ impl SslContextRef {
}

Some(slice::from_raw_parts(
types as *const CertificateType,
types.cast::<CertificateType>(),
types_len,
))
}
Expand Down Expand Up @@ -3024,6 +3024,7 @@ impl SslRef {
}

/// Returns whether the TLS 1.3 HelloRetryRequest was used
#[must_use]
pub fn used_hello_retry_request(&self) -> bool {
unsafe { ffi::SSL_used_hello_retry_request(self.as_ptr()) == 1 }
}
Expand Down Expand Up @@ -3956,6 +3957,7 @@ impl SslRef {
/// Returns the public key sent by the other peer, `None` if there is no ongoing handshake.
#[corresponds(SSL_get0_peer_pubkey)]
#[cfg(feature = "rpk")]
#[must_use]
pub fn peer_pubkey(&self) -> Option<&PKeyRef<Public>> {
unsafe {
let pubkey = ffi::SSL_get0_peer_pubkey(self.as_ptr());
Expand All @@ -3964,7 +3966,7 @@ impl SslRef {
return None;
}

Some(PKeyRef::from_ptr(pubkey as *mut _))
Some(PKeyRef::from_ptr(pubkey.cast_mut()))
}
}

Expand All @@ -3987,7 +3989,7 @@ impl SslRef {
unsafe {
cvt_0i(ffi::SSL_set1_accepted_peer_cert_types(
self.as_ptr(),
types.as_ptr() as *const u8,
types.as_ptr().cast::<u8>(),
types.len(),
))
.map(|_| ())
Expand Down Expand Up @@ -4016,7 +4018,7 @@ impl SslRef {
}

Some(slice::from_raw_parts(
types as *const CertificateType,
types.cast::<CertificateType>(),
types_len,
))
}
Expand Down
2 changes: 1 addition & 1 deletion boring/src/ssl/test/cert_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn callback_receives_correct_chain() {
assert!(x509.current_cert().is_some());
assert!(x509.verify_result().is_ok());
let chain = x509.chain().unwrap();
assert!(chain.len() == 2);
assert_eq!(chain.len(), 2);
let leaf_cert = chain.get(0).unwrap();
let leaf_digest = leaf_cert.digest(MessageDigest::sha1()).unwrap();
assert_eq!(hex::encode(leaf_digest), leaf_sha1);
Expand Down
24 changes: 12 additions & 12 deletions boring/src/ssl/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ fn flush_panic() {
fn refcount_ssl_context() {
let mut ssl = {
let ctx = SslContext::builder(SslMethod::tls()).unwrap();
ssl::Ssl::new(&ctx.build()).unwrap()
Ssl::new(&ctx.build()).unwrap()
};

{
Expand Down Expand Up @@ -1011,7 +1011,7 @@ fn psk_ciphers() {
let mut server = Server::builder();
server.ctx().set_cipher_list(CIPHER).unwrap();
server.ctx().set_psk_server_callback(|_, identity, psk| {
assert!(identity.unwrap_or(&[]) == CLIENT_IDENT);
assert_eq!(identity.unwrap_or(&[]), CLIENT_IDENT);
psk[..PSK.len()].copy_from_slice(PSK);
SERVER_CALLED.store(true, Ordering::SeqCst);
Ok(PSK.len())
Expand All @@ -1021,7 +1021,7 @@ fn psk_ciphers() {

let mut client = server.client();
// This test relies on TLS 1.2 suites
client.ctx().set_options(super::SslOptions::NO_TLSV1_3);
client.ctx().set_options(SslOptions::NO_TLSV1_3);
client.ctx().set_cipher_list(CIPHER).unwrap();
client
.ctx()
Expand Down Expand Up @@ -1338,7 +1338,7 @@ fn peer_signature_algorithm_mtls_server_sees_client() {
// Observe from a server-side HANDSHAKE_DONE info callback so the capture
// happens synchronously during the server's accept, before the client's
// connect() returns.
let captured = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
let captured = std::sync::Arc::new(AtomicBool::new(false));

let mut server_builder = Server::builder();
{
Expand All @@ -1356,7 +1356,7 @@ fn peer_signature_algorithm_mtls_server_sees_client() {
if mode == SslInfoCallbackMode::HANDSHAKE_DONE {
if let Some(sa) = ssl.peer_signature_algorithm() {
assert!(sa.name().is_some(), "client sig scheme should have a name");
captured_cb.store(true, std::sync::atomic::Ordering::SeqCst);
captured_cb.store(true, Ordering::SeqCst);
}
}
});
Expand All @@ -1375,7 +1375,7 @@ fn peer_signature_algorithm_mtls_server_sees_client() {
let _ = client_builder.connect();

assert!(
captured.load(std::sync::atomic::Ordering::SeqCst),
captured.load(Ordering::SeqCst),
"server should observe client signature scheme during mTLS",
);
}
Expand All @@ -1384,7 +1384,7 @@ fn peer_signature_algorithm_mtls_server_sees_client() {
fn signature_algorithm_used_server_default() {
// BoringSSL only retains signature_algorithm_used during the handshake, so we
// capture it from a HANDSHAKE_DONE info callback.
let captured = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
let captured = std::sync::Arc::new(AtomicBool::new(false));

let mut server_builder = Server::builder();
{
Expand All @@ -1395,7 +1395,7 @@ fn signature_algorithm_used_server_default() {
if mode == SslInfoCallbackMode::HANDSHAKE_DONE {
if let Some(sa) = ssl.signature_algorithm_used() {
assert!(sa.name().is_some());
captured_cb.store(true, std::sync::atomic::Ordering::SeqCst);
captured_cb.store(true, Ordering::SeqCst);
}
}
});
Expand All @@ -1404,7 +1404,7 @@ fn signature_algorithm_used_server_default() {
let _ = server.client_with_root_ca().connect();

assert!(
captured.load(std::sync::atomic::Ordering::SeqCst),
captured.load(Ordering::SeqCst),
"server should observe signature_algorithm_used at HANDSHAKE_DONE",
);
}
Expand Down Expand Up @@ -1437,7 +1437,7 @@ fn signature_algorithm_used_mtls_client() {
}
let server = server_builder.build();

let captured = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
let captured = std::sync::Arc::new(AtomicBool::new(false));
let captured_cb = std::sync::Arc::clone(&captured);

let mut client_builder = server.client_with_root_ca();
Expand All @@ -1455,14 +1455,14 @@ fn signature_algorithm_used_mtls_client() {
if mode == SslInfoCallbackMode::HANDSHAKE_DONE {
if let Some(sa) = ssl.signature_algorithm_used() {
assert!(sa.name().is_some());
captured_cb.store(true, std::sync::atomic::Ordering::SeqCst);
captured_cb.store(true, Ordering::SeqCst);
}
}
});
let _ = client_builder.connect();

assert!(
captured.load(std::sync::atomic::Ordering::SeqCst),
captured.load(Ordering::SeqCst),
"client should observe signature_algorithm_used at HANDSHAKE_DONE in mTLS",
);
}
Expand Down
Loading
Loading