Skip to content

Commit cf9681a

Browse files
committed
fixes #2096 -- deprecate X509StoreRef::objects, it is unsound
Introduce `X509StoreRef::all_certificates` as a replacement.
1 parent 2d9458e commit cf9681a

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

openssl-sys/src/handwritten/x509.rs

+2
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ const_ptr_api! {
644644
extern "C" {
645645
#[cfg(any(ossl110, libressl270))]
646646
pub fn X509_STORE_get0_objects(ctx: #[const_ptr_if(ossl300)] X509_STORE) -> *mut stack_st_X509_OBJECT;
647+
#[cfg(ossl300)]
648+
pub fn X509_STORE_get1_all_certs(ctx: *mut X509_STORE) -> *mut stack_st_X509;
647649
}
648650
}
649651

openssl/src/cipher_ctx.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ impl CipherCtxRef {
581581
/// output size check removed. It can be used when the exact
582582
/// buffer size control is maintained by the caller.
583583
///
584-
/// SAFETY: The caller is expected to provide `output` buffer
584+
/// # Safety
585+
/// The caller is expected to provide `output` buffer
585586
/// large enough to contain correct number of bytes. For streaming
586587
/// ciphers the output buffer size should be at least as big as
587588
/// the input buffer. For block ciphers the size of the output
@@ -693,7 +694,8 @@ impl CipherCtxRef {
693694
/// This function is the same as [`Self::cipher_final`] but with
694695
/// the output buffer size check removed.
695696
///
696-
/// SAFETY: The caller is expected to provide `output` buffer
697+
/// # Safety
698+
/// The caller is expected to provide `output` buffer
697699
/// large enough to contain correct number of bytes. For streaming
698700
/// ciphers the output buffer can be empty, for block ciphers the
699701
/// output buffer should be at least as big as the block.

openssl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
//! ```
120120
#![doc(html_root_url = "https://docs.rs/openssl/0.10")]
121121
#![warn(rust_2018_idioms)]
122-
#![allow(clippy::uninlined_format_args)]
122+
#![allow(clippy::uninlined_format_args, clippy::needless_doctest_main)]
123123

124124
#[doc(inline)]
125125
pub use ffi::init;

openssl/src/x509/store.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242
//! ```
4343
4444
use cfg_if::cfg_if;
45-
use foreign_types::ForeignTypeRef;
45+
use foreign_types::{ForeignType, ForeignTypeRef};
4646
use std::mem;
4747

4848
use crate::error::ErrorStack;
4949
#[cfg(not(boringssl))]
5050
use crate::ssl::SslFiletype;
51+
#[cfg(ossl300)]
52+
use crate::stack::Stack;
5153
use crate::stack::StackRef;
5254
#[cfg(any(ossl102, libressl261))]
5355
use crate::x509::verify::{X509VerifyFlags, X509VerifyParamRef};
@@ -260,10 +262,24 @@ foreign_type_and_impl_send_sync! {
260262

261263
impl X509StoreRef {
262264
/// Get a reference to the cache of certificates in this store.
265+
///
266+
/// This method is deprecated. It is **unsound** and will be removed in a
267+
/// future version of rust-openssl. `X509StoreRef::all_certificates`
268+
/// should be used instead.
269+
#[deprecated(
270+
note = "This method is unsound, and will be removed in a future version of rust-openssl. X509StoreRef::all_certificates should be used instead."
271+
)]
263272
#[corresponds(X509_STORE_get0_objects)]
264273
pub fn objects(&self) -> &StackRef<X509Object> {
265274
unsafe { StackRef::from_ptr(X509_STORE_get0_objects(self.as_ptr())) }
266275
}
276+
277+
/// Returns a stack of all the certificates in this store.
278+
#[corresponds(X509_STORE_get1_all_certs)]
279+
#[cfg(ossl300)]
280+
pub fn all_certificates(&self) -> Stack<X509> {
281+
unsafe { Stack::from_ptr(ffi::X509_STORE_get1_all_certs(self.as_ptr())) }
282+
}
267283
}
268284

269285
cfg_if! {

openssl/src/x509/tests.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1177,3 +1177,18 @@ fn test_dist_point_null() {
11771177
let cert = X509::from_pem(cert).unwrap();
11781178
assert!(cert.crl_distribution_points().is_none());
11791179
}
1180+
1181+
#[test]
1182+
#[cfg(ossl300)]
1183+
fn test_store_all_certificates() {
1184+
let cert = include_bytes!("../../test/cert.pem");
1185+
let cert = X509::from_pem(cert).unwrap();
1186+
1187+
let store = {
1188+
let mut b = X509StoreBuilder::new().unwrap();
1189+
b.add_cert(cert).unwrap();
1190+
b.build()
1191+
};
1192+
1193+
assert_eq!(store.all_certificates().len(), 1);
1194+
}

0 commit comments

Comments
 (0)