Skip to content

Commit

Permalink
Merge branch 'master' into x509-crl-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrichorIT committed Nov 27, 2023
2 parents e9281fb + 9fd62de commit 81b1a26
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 55 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ jobs:
- name: openssl
version: vendored
- name: openssl
version: 3.2.0-beta1
dl-path: /
- name: openssl
version: 3.1.4
version: 3.2.0
dl-path: /
- name: openssl
version: 1.1.1w
Expand Down
15 changes: 14 additions & 1 deletion openssl-sys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

## [Unreleased]

## [v0.9.96] - 2023-11-22

### Changed

* `EVP_chacha20` is now available on LibreSSL

### Added

* Added `EVP_des_ede3_ecb`, `EVP_des_ede3_cfb8`, `EVP_des_ede3_ofb`, `EVP_camellia_128_ofb`, `EVP_camellia_192_ofb`, `EVP_camellia_256_ofb`, `EVP_cast5_ofb`, `EVP_idea_ofb`
* Added `X509_STORE_get1_all_certs`
* Added `SSL_CTRL_GET_PEER_TMP_KEY`, `SSL_CTRL_GET_TMP_KEY`, `SSL_get_peer_tmp_key`, `SSL_get_tmp_key`

## [v0.9.95] - 2023-11-03

### Changed
Expand Down Expand Up @@ -533,7 +545,8 @@ Fixed builds against OpenSSL built with `no-cast`.
* Added `X509_verify` and `X509_REQ_verify`.
* Added `EVP_MD_type` and `EVP_GROUP_get_curve_name`.

[Unreleased]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.95..master
[Unreleased]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.96..master
[v0.9.96]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.95...openssl-sys-v0.9.96
[v0.9.95]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.94...openssl-sys-v0.9.95
[v0.9.94]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.93...openssl-sys-v0.9.94
[v0.9.93]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.92...openssl-sys-v0.9.93
Expand Down
4 changes: 2 additions & 2 deletions openssl-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openssl-sys"
version = "0.9.95"
version = "0.9.96"
authors = [
"Alex Crichton <[email protected]>",
"Steven Fackler <[email protected]>",
Expand All @@ -23,7 +23,7 @@ libc = "0.2"
bssl-sys = { version = "0.1.0", optional = true }

[build-dependencies]
bindgen = { version = "0.64.0", optional = true, features = ["experimental"] }
bindgen = { version = "0.65.0", optional = true, features = ["experimental"] }
cc = "1.0.61"
openssl-src = { version = "300.1.2", optional = true, features = ["legacy"] }
pkg-config = "0.3.9"
Expand Down
2 changes: 1 addition & 1 deletion openssl-sys/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn main() {
|| env::var("CARGO_CFG_TARGET_OS").unwrap() == "android")
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
{
println!("cargo:rustc-link-lib=dylib=atomic");
println!("cargo:rustc-link-lib=atomic");
}

if kind == "static" && target.contains("windows") {
Expand Down
36 changes: 14 additions & 22 deletions openssl-sys/build/run_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ pub fn run(include_dirs: &[PathBuf]) {
#[cfg(feature = "bindgen")]
pub fn run_boringssl(include_dirs: &[PathBuf]) {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

fs::File::create(out_dir.join("boring_static_wrapper.h"))
.expect("Failed to create boring_static_wrapper.h")
.write_all(INCLUDES.as_bytes())
.expect("Failed to write contents to boring_static_wrapper.h");

let mut builder = bindgen::builder()
.rust_target(RustTarget::Stable_1_47)
.ctypes_prefix("::libc")
Expand All @@ -119,14 +125,19 @@ pub fn run_boringssl(include_dirs: &[PathBuf]) {
.enable_function_attribute_detection()
.default_macro_constant_type(MacroTypeVariation::Signed)
.rustified_enum("point_conversion_form_t")
.allowlist_file(".*/openssl/[^/]+\\.h")
.allowlist_file(".*[/\\\\]openssl/[^/]+\\.h")
.allowlist_recursively(false)
.blocklist_function("BIO_vsnprintf")
.blocklist_function("OPENSSL_vasprintf")
.wrap_static_fns(true)
.wrap_static_fns_path(out_dir.join("boring_static_wrapper").display().to_string())
.layout_tests(false)
.header_contents("includes.h", INCLUDES);
.header(
out_dir
.join("boring_static_wrapper.h")
.display()
.to_string(),
);

for include_dir in include_dirs {
builder = builder
Expand All @@ -140,21 +151,9 @@ pub fn run_boringssl(include_dirs: &[PathBuf]) {
.write_to_file(out_dir.join("bindgen.rs"))
.unwrap();

fs::File::create(out_dir.join("boring_static_wrapper.h"))
.expect("Failed to create boring_static_wrapper.h")
.write_all(INCLUDES.as_bytes())
.expect("Failed to write contents to boring_static_wrapper.h");

cc::Build::new()
.file(out_dir.join("boring_static_wrapper.c"))
.includes(include_dirs)
.flag("-include")
.flag(
&out_dir
.join("boring_static_wrapper.h")
.display()
.to_string(),
)
.compile("boring_static_wrapper");
}

Expand All @@ -180,7 +179,7 @@ pub fn run_boringssl(include_dirs: &[PathBuf]) {
.arg("--enable-function-attribute-detection")
.arg("--default-macro-constant-type=signed")
.arg("--rustified-enum=point_conversion_form_t")
.arg("--allowlist-file=.*/openssl/[^/]+\\.h")
.arg("--allowlist-file=.*[/\\\\]openssl/[^/]+\\.h")
.arg("--no-recursive-allowlist")
.arg("--blocklist-function=BIO_vsnprintf")
.arg("--blocklist-function=OPENSSL_vasprintf")
Expand All @@ -203,13 +202,6 @@ pub fn run_boringssl(include_dirs: &[PathBuf]) {
cc::Build::new()
.file(out_dir.join("boring_static_wrapper.c"))
.includes(include_dirs)
.flag("-include")
.flag(
&out_dir
.join("boring_static_wrapper.h")
.display()
.to_string(),
)
.compile("boring_static_wrapper");
}

Expand Down
2 changes: 2 additions & 0 deletions openssl-sys/src/handwritten/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ const_ptr_api! {
extern "C" {
#[cfg(any(ossl110, libressl270))]
pub fn X509_STORE_get0_objects(ctx: #[const_ptr_if(ossl300)] X509_STORE) -> *mut stack_st_X509_OBJECT;
#[cfg(ossl300)]
pub fn X509_STORE_get1_all_certs(ctx: *mut X509_STORE) -> *mut stack_st_X509;
}
}

Expand Down
26 changes: 25 additions & 1 deletion openssl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

## [Unreleased]

## [v0.10.60] - 2023-11-22

### Deprecated

* Deprecated `X509StoreRef::objects`. It is unsound. All callers should migrate to using `X509StoreRef::all_certificates` instead.

### Fixed

* Fixed a memory leak when calling `SslContextBuilder::set_ex_data` and `SslRef::set_ex_data` multiple times with the same index.

### Added

* Added `X509StoreRef::all_certificates`
* Added `cipher::Cipher::{camellia128_cbc,camellia192_cbc,camellia256_cbc,cast5_cbc,idea_cbc}`
* Added `symm::Cipher::{des_ede3_ecb,des_ede3_cfb8,des_ede3_ofb,camellia_128_ecb,camellia_128_ofb,camellia_128_cfb128,camellia_192_ecb,camellia_192_ofb,camellia_192_cfb128,camellia_256_ecb,camellia_256_ofb,camellia_256_cfb128,cast5_ecb,cast5_ofb,cast5_cfb64,idea_ecb,idea_ofb,idea_cfb64}`
* Added `Crypter::update_unchecked`
* Added `SslRef::{peer_tmp_key,tmp_key}`

### Changed

* `cipher::Cipher::chacha20` is now available on LibreSSL
* `symm::Cipher::chacha20` is now available on LibreSSL

## [v0.10.59] - 2023-11-03

### Added
Expand Down Expand Up @@ -825,7 +848,8 @@

Look at the [release tags] for information about older releases.

[Unreleased]: https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.59...master
[Unreleased]: https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.60...master
[v0.10.60]: https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.59...openssl-v0.10.60
[v0.10.59]: https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.58...openssl-v0.10.59
[v0.10.58]: https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.57...openssl-v0.10.58
[v0.10.57]: https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.56...openssl-v0.10.57
Expand Down
4 changes: 2 additions & 2 deletions openssl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openssl"
version = "0.10.59"
version = "0.10.60"
authors = ["Steven Fackler <[email protected]>"]
license = "Apache-2.0"
description = "OpenSSL bindings"
Expand Down Expand Up @@ -30,7 +30,7 @@ libc = "0.2"
once_cell = "1.5.2"

openssl-macros = { version = "0.1.0", path = "../openssl-macros" }
ffi = { package = "openssl-sys", version = "0.9.95", path = "../openssl-sys" }
ffi = { package = "openssl-sys", version = "0.9.96", path = "../openssl-sys" }

[dev-dependencies]
hex = "0.3"
8 changes: 6 additions & 2 deletions openssl/src/cipher_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ impl CipherCtxRef {
/// output size check removed. It can be used when the exact
/// buffer size control is maintained by the caller.
///
/// SAFETY: The caller is expected to provide `output` buffer
/// # Safety
///
/// The caller is expected to provide `output` buffer
/// large enough to contain correct number of bytes. For streaming
/// ciphers the output buffer size should be at least as big as
/// the input buffer. For block ciphers the size of the output
Expand Down Expand Up @@ -693,7 +695,9 @@ impl CipherCtxRef {
/// This function is the same as [`Self::cipher_final`] but with
/// the output buffer size check removed.
///
/// SAFETY: The caller is expected to provide `output` buffer
/// # Safety
///
/// The caller is expected to provide `output` buffer
/// large enough to contain correct number of bytes. For streaming
/// ciphers the output buffer can be empty, for block ciphers the
/// output buffer should be at least as big as the block.
Expand Down
2 changes: 1 addition & 1 deletion openssl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
//! ```
#![doc(html_root_url = "https://docs.rs/openssl/0.10")]
#![warn(rust_2018_idioms)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::uninlined_format_args, clippy::needless_doctest_main)]

#[doc(inline)]
pub use ffi::init;
Expand Down
42 changes: 32 additions & 10 deletions openssl/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,16 +1572,34 @@ impl SslContextBuilder {
///
/// This can be used to provide data to callbacks registered with the context. Use the
/// `SslContext::new_ex_index` method to create an `Index`.
// FIXME should return a result
#[corresponds(SSL_CTX_set_ex_data)]
pub fn set_ex_data<T>(&mut self, index: Index<SslContext, T>, data: T) {
self.set_ex_data_inner(index, data);
}

fn set_ex_data_inner<T>(&mut self, index: Index<SslContext, T>, data: T) -> *mut c_void {
match self.ex_data_mut(index) {
Some(v) => {
*v = data;
(v as *mut T).cast()
}
_ => unsafe {
let data = Box::into_raw(Box::new(data)) as *mut c_void;
ffi::SSL_CTX_set_ex_data(self.as_ptr(), index.as_raw(), data);
data
},
}
}

fn ex_data_mut<T>(&mut self, index: Index<SslContext, T>) -> Option<&mut T> {
unsafe {
let data = Box::into_raw(Box::new(data)) as *mut c_void;
ffi::SSL_CTX_set_ex_data(self.as_ptr(), index.as_raw(), data);
data
let data = ffi::SSL_CTX_get_ex_data(self.as_ptr(), index.as_raw());
if data.is_null() {
None
} else {
Some(&mut *data.cast())
}
}
}

Expand Down Expand Up @@ -2965,15 +2983,19 @@ impl SslRef {
///
/// This can be used to provide data to callbacks registered with the context. Use the
/// `Ssl::new_ex_index` method to create an `Index`.
// FIXME should return a result
#[corresponds(SSL_set_ex_data)]
pub fn set_ex_data<T>(&mut self, index: Index<Ssl, T>, data: T) {
unsafe {
let data = Box::new(data);
ffi::SSL_set_ex_data(
self.as_ptr(),
index.as_raw(),
Box::into_raw(data) as *mut c_void,
);
match self.ex_data_mut(index) {
Some(v) => *v = data,
None => unsafe {
let data = Box::new(data);
ffi::SSL_set_ex_data(
self.as_ptr(),
index.as_raw(),
Box::into_raw(data) as *mut c_void,
);
},
}
}

Expand Down
49 changes: 48 additions & 1 deletion openssl/src/ssl/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::net::UdpSocket;
use std::net::{SocketAddr, TcpListener, TcpStream};
use std::path::Path;
use std::process::{Child, ChildStdin, Command, Stdio};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::thread;
use std::time::Duration;

Expand Down Expand Up @@ -1638,3 +1638,50 @@ fn set_security_level() {
let ssl = ssl;
assert_eq!(4, ssl.security_level());
}

#[test]
fn ssl_ctx_ex_data_leak() {
static DROPS: AtomicUsize = AtomicUsize::new(0);

struct DropTest;

impl Drop for DropTest {
fn drop(&mut self) {
DROPS.fetch_add(1, Ordering::Relaxed);
}
}

let idx = SslContext::new_ex_index().unwrap();

let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
ctx.set_ex_data(idx, DropTest);
ctx.set_ex_data(idx, DropTest);
assert_eq!(DROPS.load(Ordering::Relaxed), 1);

drop(ctx);
assert_eq!(DROPS.load(Ordering::Relaxed), 2);
}

#[test]
fn ssl_ex_data_leak() {
static DROPS: AtomicUsize = AtomicUsize::new(0);

struct DropTest;

impl Drop for DropTest {
fn drop(&mut self) {
DROPS.fetch_add(1, Ordering::Relaxed);
}
}

let idx = Ssl::new_ex_index().unwrap();

let ctx = SslContext::builder(SslMethod::tls()).unwrap().build();
let mut ssl = Ssl::new(&ctx).unwrap();
ssl.set_ex_data(idx, DropTest);
ssl.set_ex_data(idx, DropTest);
assert_eq!(DROPS.load(Ordering::Relaxed), 1);

drop(ssl);
assert_eq!(DROPS.load(Ordering::Relaxed), 2);
}
21 changes: 21 additions & 0 deletions openssl/src/symm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,27 @@ impl Crypter {
self.ctx.cipher_update(input, Some(output))
}

/// Feeds data from `input` through the cipher, writing encrypted/decrypted
/// bytes into `output`.
///
/// The number of bytes written to `output` is returned. Note that this may
/// not be equal to the length of `input`.
///
/// # Safety
///
/// The caller must provide an `output` buffer large enough to contain
/// correct number of bytes. For streaming ciphers the output buffer size
/// should be at least as big as the input buffer. For block ciphers the
/// size of the output buffer depends on the state of partially updated
/// blocks.
pub unsafe fn update_unchecked(
&mut self,
input: &[u8],
output: &mut [u8],
) -> Result<usize, ErrorStack> {
self.ctx.cipher_update_unchecked(input, Some(output))
}

/// Finishes the encryption/decryption process, writing any remaining data
/// to `output`.
///
Expand Down
Loading

0 comments on commit 81b1a26

Please sign in to comment.