Skip to content

Commit

Permalink
Backport zeroize fix (#266)
Browse files Browse the repository at this point in the history
* Backport `zeroize` fix

* Update version

* Fix CI

* Remove bench for CI MSRV

* Downgrade rustyline for MSRV

* Downgrade proptest for MSRV

* Downgrade zeroize for MSRV
  • Loading branch information
daxpedda authored Jan 31, 2022
1 parent 349329c commit 1012439
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 122 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,6 @@ jobs:
- name: Run expect (which then runs cargo run)
run: expect -f scripts/digital_locker.exp

benches:
name: cargo bench compilation
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo bench --no-run
uses: actions-rs/cargo@v1
with:
command: bench
args: --features "bench" --no-run

clippy:
name: cargo clippy
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.6.1 (January 25, 2022)

* Fix `zeroize` implementing `Drop` on `enum`s now

## 0.6.0 (June 30, 2021)

* Synced implementation with draft-irtf-cfrg-opaque-05, which changes
Expand Down
14 changes: 4 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opaque-ke"
version = "0.6.0"
version = "0.6.1"
repository = "https://github.com/novifinancial/opaque-ke"
keywords = ["cryptography", "crypto", "opaque", "passwords", "authentication"]
description = "An implementation of the OPAQUE password-authenticated key exchange protocol"
Expand Down Expand Up @@ -31,22 +31,16 @@ rand = "0.8"
serde = { version = "1", features = ["derive"], optional = true }
subtle = { version = "2.3.0", default-features = false }
thiserror = "1.0.22"
zeroize = { version = "1.1.1", features = ["zeroize_derive"] }
zeroize = { version = "~1.1", features = ["zeroize_derive"] }

[dev-dependencies]
anyhow = "1.0.35"
base64 = "0.13.0"
bincode = "1"
chacha20poly1305 = "0.7.1"
criterion = "0.3.3"
hex = "0.4.2"
lazy_static = "1.4.0"
serde_json = "1.0.60"
sha2 = "0.9.2"
proptest = "0.10.1"
rustyline = "6.3.0"

[[bench]]
name = "oprf"
harness = false
required-features = ["bench"]
proptest = "0.3"
rustyline = "1"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Installation
Add the following line to the dependencies of your `Cargo.toml`:

```
opaque-ke = "0.6.0"
opaque-ke = "0.6.1"
```

Resources
Expand Down
68 changes: 0 additions & 68 deletions benches/oprf.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn recover_keys_internal<CS: CipherSuite>(
Ok(client_static_keypair)
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Zeroize)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Zeroize)]
#[zeroize(drop)]
pub(crate) enum InnerEnvelopeMode {
Zero = 0,
Expand Down Expand Up @@ -98,7 +98,7 @@ pub(crate) struct Envelope<CS: CipherSuite> {
impl<CS: CipherSuite> Clone for Envelope<CS> {
fn clone(&self) -> Self {
Self {
mode: self.mode,
mode: self.mode.clone(),
nonce: self.nonce.clone(),
hmac: self.hmac.clone(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/key_exchange/tripledh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<D: Hash, G: Group> KeyExchange<D, G> for TripleDH {
));
}

transcript_hasher.update(ke2_message.mac.to_vec());
transcript_hasher.update(ke2_message.mac);

let mut client_mac =
Hmac::<D>::new_from_slice(&km3).map_err(|_| InternalPakeError::HmacError)?;
Expand Down
16 changes: 8 additions & 8 deletions src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ impl<G: Group + Debug> KeyPair<G> {
fn uniform_keypair_strategy() -> BoxedStrategy<Self> {
// The no_shrink is because keypairs should be fixed -- shrinking would cause a different
// keypair to be generated, which appears to not be very useful.
any::<[u8; 32]>()
.prop_filter_map("valid random keypair", |seed| {
prop::array::uniform32(0_u8..)
.prop_map(|seed| {
let mut rng = StdRng::from_seed(seed);
Some(Self::generate_random(&mut rng))
Self::generate_random(&mut rng)
})
.no_shrink()
.boxed()
Expand Down Expand Up @@ -281,21 +281,21 @@ mod tests {

proptest! {
#[test]
fn test_ristretto_check(kp in KeyPair::<RistrettoPoint>::uniform_keypair_strategy()) {
fn test_ristretto_check(ref kp in KeyPair::<RistrettoPoint>::uniform_keypair_strategy()) {
let pk = kp.public();
prop_assert!(KeyPair::<RistrettoPoint>::check_public_key(pk.clone()).is_ok());
}

#[test]
fn test_ristretto_pub_from_priv(kp in KeyPair::<RistrettoPoint>::uniform_keypair_strategy()) {
fn test_ristretto_pub_from_priv(ref kp in KeyPair::<RistrettoPoint>::uniform_keypair_strategy()) {
let pk = kp.public();
let sk = kp.private();
prop_assert_eq!(&KeyPair::<RistrettoPoint>::public_from_private(sk), pk);
}

#[test]
fn test_ristretto_dh(kp1 in KeyPair::<RistrettoPoint>::uniform_keypair_strategy(),
kp2 in KeyPair::<RistrettoPoint>::uniform_keypair_strategy()) {
fn test_ristretto_dh(ref kp1 in KeyPair::<RistrettoPoint>::uniform_keypair_strategy(),
ref kp2 in KeyPair::<RistrettoPoint>::uniform_keypair_strategy()) {

let dh1 = KeyPair::<RistrettoPoint>::diffie_hellman(kp1.public().clone(), kp2.private().clone())?;
let dh2 = KeyPair::<RistrettoPoint>::diffie_hellman(kp2.public().clone(), kp1.private().clone())?;
Expand All @@ -304,7 +304,7 @@ mod tests {
}

#[test]
fn test_private_key_slice(kp in KeyPair::<RistrettoPoint>::uniform_keypair_strategy()) {
fn test_private_key_slice(ref kp in KeyPair::<RistrettoPoint>::uniform_keypair_strategy()) {
let sk_bytes = kp.private().to_vec();

let kp2 = KeyPair::<RistrettoPoint>::from_private_key_slice(&sk_bytes)?;
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ compile_error!(
please enable one of: u64_backend, u32_backend"
);

#[cfg(test)]
#[macro_use]
extern crate proptest;

// Error types
pub mod errors;

Expand Down
24 changes: 12 additions & 12 deletions src/serialization/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,57 +346,57 @@ fn ke3_message_roundtrip() {
proptest! {

#[test]
fn test_i2osp_os2ip(bytes in vec(any::<u8>(), 0..std::mem::size_of::<usize>())) {
assert_eq!(i2osp(os2ip(&bytes)?, bytes.len()), bytes);
fn test_i2osp_os2ip(ref bytes in vec(prop::num::u8::ANY, 0..std::mem::size_of::<usize>())) {
assert_eq!(&i2osp(os2ip(&bytes)?, bytes.len()), bytes);
}

#[test]
fn test_nocrash_registration_request(bytes in vec(any::<u8>(), 0..200)) {
fn test_nocrash_registration_request(ref bytes in vec(prop::num::u8::ANY, 0..200)) {
RegistrationRequest::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_registration_response(bytes in vec(any::<u8>(), 0..200)) {
fn test_nocrash_registration_response(ref bytes in vec(prop::num::u8::ANY, 0..200)) {
RegistrationResponse::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_registration_upload(bytes in vec(any::<u8>(), 0..200)) {
fn test_nocrash_registration_upload(ref bytes in vec(prop::num::u8::ANY, 0..200)) {
RegistrationUpload::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_credential_request(bytes in vec(any::<u8>(), 0..500)) {
fn test_nocrash_credential_request(ref bytes in vec(prop::num::u8::ANY, 0..500)) {
CredentialRequest::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_credential_response(bytes in vec(any::<u8>(), 0..500)) {
fn test_nocrash_credential_response(ref bytes in vec(prop::num::u8::ANY, 0..500)) {
CredentialResponse::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_credential_finalization(bytes in vec(any::<u8>(), 0..500)) {
fn test_nocrash_credential_finalization(ref bytes in vec(prop::num::u8::ANY, 0..500)) {
CredentialFinalization::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_client_registration(bytes in vec(any::<u8>(), 0..700)) {
fn test_nocrash_client_registration(ref bytes in vec(prop::num::u8::ANY, 0..700)) {
ClientRegistration::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_server_registration(bytes in vec(any::<u8>(), 0..700)) {
fn test_nocrash_server_registration(ref bytes in vec(prop::num::u8::ANY, 0..700)) {
ServerRegistration::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_client_login(bytes in vec(any::<u8>(), 0..700)) {
fn test_nocrash_client_login(ref bytes in vec(prop::num::u8::ANY, 0..700)) {
ClientLogin::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

#[test]
fn test_nocrash_server_login(bytes in vec(any::<u8>(), 0..700)) {
fn test_nocrash_server_login(ref bytes in vec(prop::num::u8::ANY, 0..700)) {
ServerLogin::<Default>::deserialize(&bytes[..]).map_or(true, |_| true);
}

Expand Down

0 comments on commit 1012439

Please sign in to comment.