From 47362eed301a4954af94afe84df16ab6eddecf8d Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 18 May 2020 13:06:12 +0200 Subject: openpgp: Change PKESK::decrypt to return an Option<_>. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Returning rich errors from this function may compromise secret key material due to Bleichenbacher-style attacks. Change the API to prevent this. - Hat tip to Hanno Böck. - See #507. --- openpgp-ffi/src/packet/pkesk.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'openpgp-ffi/src') diff --git a/openpgp-ffi/src/packet/pkesk.rs b/openpgp-ffi/src/packet/pkesk.rs index 084505ff..bbecddb0 100644 --- a/openpgp-ffi/src/packet/pkesk.rs +++ b/openpgp-ffi/src/packet/pkesk.rs @@ -48,7 +48,7 @@ pub extern "C" fn pgp_pkesk_decrypt(errp: Option<&mut *mut crate::error::Error>, { Ok(mut keypair) => { match pkesk.decrypt(&mut keypair, None /* XXX */) { - Ok((a, k)) => { + Some((a, k)) => { *algo = a.into(); if !key.is_null() && *key_len >= k.len() { unsafe { @@ -60,7 +60,9 @@ pub extern "C" fn pgp_pkesk_decrypt(errp: Option<&mut *mut crate::error::Error>, *key_len = k.len(); Status::Success }, - Err(e) => ffi_try_status!(Err::<(), anyhow::Error>(e)), + None => ffi_try_status!(Err::<(), anyhow::Error>( + openpgp::Error::InvalidSessionKey( + "Decryption failed".into()).into())), } }, Err(e) => { -- cgit v1.2.3