Skip to content

Commit 75d5cc2

Browse files
authored
Merge branch 'sfackler:master' into timestamping
2 parents 00ba4b7 + 36dcae8 commit 75d5cc2

File tree

17 files changed

+145
-235
lines changed

17 files changed

+145
-235
lines changed

.github/workflows/ci.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
# Remember to also update `--rust-target` in `openssl-sys/build/run_bindgen.rs`
6363
- uses: sfackler/actions/rustup@master
6464
with:
65-
version: 1.56.0
65+
version: 1.63.0
6666
- run: echo "version=$(rustc --version)" >> $GITHUB_OUTPUT
6767
id: rust-version
6868
- uses: actions/cache@v4
@@ -72,8 +72,6 @@ jobs:
7272
restore-keys: |
7373
index-${{ runner.os }}-
7474
- run: cargo generate-lockfile
75-
- run: |
76-
cargo update -p cc --precise 1.0.94
7775
- uses: actions/cache@v4
7876
with:
7977
path: ~/.cargo/registry/cache

openssl-errors/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
name = "openssl-errors"
33
version = "0.2.0"
44
authors = ["Steven Fackler <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
description = "Custom error library support for the openssl crate."
88
repository = "https://github.com/sfackler/rust-openssl"
99
readme = "README.md"
1010
categories = ["api-bindings"]
11+
rust-version = "1.63.0"
1112

1213
[dependencies]
1314
cfg-if = "1.0"

openssl-macros/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[package]
22
name = "openssl-macros"
33
version = "0.1.1"
4-
edition = "2018"
4+
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "Internal macros used by the openssl crate."
77
repository = "https://github.com/sfackler/rust-openssl"
8+
rust-version = "1.63.0"
89

910
[lib]
1011
proc-macro = true

openssl-sys/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ readme = "README.md"
1212
categories = ["cryptography", "external-ffi-bindings"]
1313
links = "openssl"
1414
build = "build/main.rs"
15-
edition = "2018"
15+
edition = "2021"
16+
rust-version = "1.63.0"
1617

1718
[features]
1819
vendored = ['openssl-src']
@@ -23,7 +24,7 @@ libc = "0.2"
2324
bssl-sys = { version = "0.1.0", optional = true }
2425

2526
[build-dependencies]
26-
bindgen = { version = "0.65.0", optional = true, features = ["experimental"] }
27+
bindgen = { version = "0.69.0", optional = true, features = ["experimental"] }
2728
cc = "1.0.61"
2829
openssl-src = { version = "300.2.0", optional = true, features = ["legacy"] }
2930
pkg-config = "0.3.9"

openssl-sys/src/handwritten/evp.rs

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ extern "C" {
9393
pub fn EVP_DigestFinal(ctx: *mut EVP_MD_CTX, res: *mut u8, n: *mut u32) -> c_int;
9494
#[cfg(ossl111)]
9595
pub fn EVP_DigestFinalXOF(ctx: *mut EVP_MD_CTX, res: *mut u8, len: usize) -> c_int;
96+
#[cfg(ossl330)]
97+
pub fn EVP_DigestSqueeze(ctx: *mut EVP_MD_CTX, res: *mut u8, len: usize) -> c_int;
9698

9799
#[cfg(ossl300)]
98100
pub fn EVP_MD_fetch(

openssl-sys/src/handwritten/x509_vfy.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ extern "C" {
99
pub fn X509_LOOKUP_meth_free(method: *mut X509_LOOKUP_METHOD);
1010
}
1111

12+
const_ptr_api! {
13+
extern "C" {
14+
pub fn X509_LOOKUP_hash_dir() -> #[const_ptr_if(libressl400)] X509_LOOKUP_METHOD;
15+
pub fn X509_LOOKUP_file() -> #[const_ptr_if(libressl400)] X509_LOOKUP_METHOD;
16+
}
17+
}
1218
extern "C" {
1319
pub fn X509_LOOKUP_free(ctx: *mut X509_LOOKUP);
14-
pub fn X509_LOOKUP_hash_dir() -> *mut X509_LOOKUP_METHOD;
15-
pub fn X509_LOOKUP_file() -> *mut X509_LOOKUP_METHOD;
1620
pub fn X509_LOOKUP_ctrl(
1721
ctx: *mut X509_LOOKUP,
1822
cmd: c_int,
@@ -41,11 +45,6 @@ extern "C" {
4145

4246
pub fn X509_STORE_add_cert(store: *mut X509_STORE, x: *mut X509) -> c_int;
4347

44-
pub fn X509_STORE_add_lookup(
45-
store: *mut X509_STORE,
46-
meth: *mut X509_LOOKUP_METHOD,
47-
) -> *mut X509_LOOKUP;
48-
4948
pub fn X509_STORE_set_default_paths(store: *mut X509_STORE) -> c_int;
5049
pub fn X509_STORE_set_flags(store: *mut X509_STORE, flags: c_ulong) -> c_int;
5150
pub fn X509_STORE_set_purpose(ctx: *mut X509_STORE, purpose: c_int) -> c_int;
@@ -55,6 +54,10 @@ extern "C" {
5554

5655
const_ptr_api! {
5756
extern "C" {
57+
pub fn X509_STORE_add_lookup(
58+
store: *mut X509_STORE,
59+
meth: #[const_ptr_if(libressl400)] X509_LOOKUP_METHOD,
60+
) -> *mut X509_LOOKUP;
5861
pub fn X509_STORE_set1_param(store: *mut X509_STORE, pm: #[const_ptr_if(ossl300)] X509_VERIFY_PARAM) -> c_int;
5962
}
6063
}

openssl/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ repository = "https://github.com/sfackler/rust-openssl"
88
readme = "README.md"
99
keywords = ["crypto", "tls", "ssl", "dtls"]
1010
categories = ["cryptography", "api-bindings"]
11-
edition = "2018"
11+
edition = "2021"
12+
rust-version = "1.63.0"
1213

1314
# these are deprecated and don't do anything anymore
1415
[features]
@@ -33,4 +34,4 @@ openssl-macros = { version = "0.1.0", path = "../openssl-macros" }
3334
ffi = { package = "openssl-sys", version = "0.9.103", path = "../openssl-sys" }
3435

3536
[dev-dependencies]
36-
hex = "0.3"
37+
hex = "0.4"

openssl/src/cipher_ctx.rs

-4
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,6 @@ impl CipherCtxRef {
328328
///
329329
/// Panics if the context has not been initialized with a cipher or if the buffer is smaller than the cipher's key
330330
/// length.
331-
///
332-
/// This corresponds to [`EVP_CIPHER_CTX_rand_key`].
333-
///
334-
/// [`EVP_CIPHER_CTX_rand_key`]: https://www.openssl.org/docs/manmaster/man3/EVP_CIPHER_CTX_rand_key.html
335331
#[corresponds(EVP_CIPHER_CTX_rand_key)]
336332
#[cfg(not(boringssl))]
337333
pub fn rand_key(&self, buf: &mut [u8]) -> Result<(), ErrorStack> {

openssl/src/hash.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use std::ptr;
4141
use crate::error::ErrorStack;
4242
use crate::nid::Nid;
4343
use crate::{cvt, cvt_p};
44+
use openssl_macros::corresponds;
4445

4546
cfg_if! {
4647
if #[cfg(any(ossl110, boringssl, libressl382))] {
@@ -65,10 +66,7 @@ impl MessageDigest {
6566
}
6667

6768
/// Returns the `MessageDigest` corresponding to an `Nid`.
68-
///
69-
/// This corresponds to [`EVP_get_digestbynid`].
70-
///
71-
/// [`EVP_get_digestbynid`]: https://www.openssl.org/docs/manmaster/crypto/EVP_DigestInit.html
69+
#[corresponds(EVP_get_digestbynid)]
7270
pub fn from_nid(type_: Nid) -> Option<MessageDigest> {
7371
ffi::init();
7472
unsafe {
@@ -82,10 +80,7 @@ impl MessageDigest {
8280
}
8381

8482
/// Returns the `MessageDigest` corresponding to an algorithm name.
85-
///
86-
/// This corresponds to [`EVP_get_digestbyname`].
87-
///
88-
/// [`EVP_get_digestbyname`]: https://www.openssl.org/docs/manmaster/crypto/EVP_DigestInit.html
83+
#[corresponds(EVP_get_digestbyname)]
8984
pub fn from_name(name: &str) -> Option<MessageDigest> {
9085
ffi::init();
9186
let name = CString::new(name).ok()?;

openssl/src/md_ctx.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ use crate::error::ErrorStack;
8585
use crate::md::MdRef;
8686
use crate::pkey::{HasPrivate, HasPublic, PKeyRef};
8787
use crate::pkey_ctx::PkeyCtxRef;
88-
use crate::{cvt, cvt_n, cvt_p};
88+
use crate::{cvt, cvt_p};
8989
use cfg_if::cfg_if;
9090
use foreign_types::{ForeignType, ForeignTypeRef};
9191
use openssl_macros::corresponds;
@@ -309,12 +309,21 @@ impl MdCtxRef {
309309
#[inline]
310310
pub fn digest_verify_final(&mut self, signature: &[u8]) -> Result<bool, ErrorStack> {
311311
unsafe {
312-
let r = cvt_n(ffi::EVP_DigestVerifyFinal(
312+
let r = ffi::EVP_DigestVerifyFinal(
313313
self.as_ptr(),
314314
signature.as_ptr() as *mut _,
315315
signature.len(),
316-
))?;
317-
Ok(r == 1)
316+
);
317+
if r == 1 {
318+
Ok(true)
319+
} else {
320+
let errors = ErrorStack::get();
321+
if errors.errors().is_empty() {
322+
Ok(false)
323+
} else {
324+
Err(errors)
325+
}
326+
}
318327
}
319328
}
320329

@@ -424,8 +433,11 @@ mod test {
424433

425434
ctx.digest_verify_init(Some(md), &key1).unwrap();
426435
ctx.digest_verify_update(bad_data).unwrap();
427-
let valid = ctx.digest_verify_final(&signature).unwrap();
428-
assert!(!valid);
436+
assert!(matches!(
437+
ctx.digest_verify_final(&signature),
438+
Ok(false) | Err(_)
439+
));
440+
assert!(ErrorStack::get().errors().is_empty());
429441
}
430442

431443
#[test]

openssl/src/nid.rs

-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ impl Nid {
7979
}
8080

8181
/// Returns the `Nid`s of the digest and public key algorithms associated with a signature ID.
82-
///
83-
/// This corresponds to `OBJ_find_sigid_algs`.
8482
#[corresponds(OBJ_find_sigid_algs)]
8583
#[allow(clippy::trivially_copy_pass_by_ref)]
8684
pub fn signature_algorithms(&self) -> Option<SignatureAlgorithms> {

openssl/src/rsa.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,18 @@ where
234234

235235
/// Validates RSA parameters for correctness
236236
#[corresponds(RSA_check_key)]
237-
#[allow(clippy::unnecessary_cast)]
238237
pub fn check_key(&self) -> Result<bool, ErrorStack> {
239238
unsafe {
240-
let result = ffi::RSA_check_key(self.as_ptr()) as i32;
241-
if result == -1 {
242-
Err(ErrorStack::get())
239+
let result = ffi::RSA_check_key(self.as_ptr());
240+
if result != 1 {
241+
let errors = ErrorStack::get();
242+
if errors.errors().is_empty() {
243+
Ok(false)
244+
} else {
245+
Err(errors)
246+
}
243247
} else {
244-
Ok(result == 1)
248+
Ok(true)
245249
}
246250
}
247251
}
@@ -849,4 +853,21 @@ mod test {
849853
let e = BigNum::from_u32(0x10001).unwrap();
850854
Rsa::generate_with_e(2048, &e).unwrap();
851855
}
856+
857+
#[test]
858+
fn test_check_key() {
859+
let k = Rsa::private_key_from_pem_passphrase(
860+
include_bytes!("../test/rsa-encrypted.pem"),
861+
b"mypass",
862+
)
863+
.unwrap();
864+
assert!(matches!(k.check_key(), Ok(true)));
865+
assert!(ErrorStack::get().errors().is_empty());
866+
867+
// BoringSSL simply rejects this key, because its corrupted!
868+
if let Ok(k) = Rsa::private_key_from_pem(include_bytes!("../test/corrupted-rsa.pem")) {
869+
assert!(matches!(k.check_key(), Ok(false) | Err(_)));
870+
assert!(ErrorStack::get().errors().is_empty());
871+
}
872+
}
852873
}

0 commit comments

Comments
 (0)