~spacekookie/public-inbox

keybob: Switch from miscreant to aes-siv in tests v1 PROPOSED

Alyssa Ross: 7
 Switch from miscreant to aes-siv in tests
 Update RustCrypto crates
 Update rand to 0.7
 Update base64 to 0.12
 Update serde_cbor to 0.11
 Update to Rust 2018 edition
 Remove explicit static lifetimes

 10 files changed, 25 insertions(+), 24 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~spacekookie/public-inbox/patches/20664/mbox | git am -3
Learn more about email & git

[PATCH keybob 1/7] Switch from miscreant to aes-siv in tests Export this patch

miscreant is deprecated in favour of aes-siv (according to the author --
this doesn't seem to be publicly documented yet).  Additionally,
with the version of miscreant we were using it wasn't even possible to
resolve the development dependencies, because it depended on sutble
0.3.0, which has been yanked.

One thing to note is that aes-siv enforces the nonce length (to 96
bits in our case).  Before we were passing in a whole 512-bit key,
which AFAICT miscreant happily accepted.
---

This supersedes my previous patch[1], which just upgraded miscreant to
a more recent version.

[1]: https://lists.sr.ht/~spacekookie/public-inbox/%3C20210227212926.22380-1-hi%40alyssa.is%3E

 Cargo.toml     |  4 ++--
 tests/basic.rs | 21 +++++++++++----------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 3a1cfd4..83fd80c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,8 +20,8 @@ serde_derive = "1.0"

[dev-dependencies]
serde_json = "1.0"
miscreant = { version = "0.4.0-beta", features = ["aes-soft"] }
aes-siv = "0.5"
rmp-serde = "0.13.7"
bincode = "1.0"
serde_cbor = "0.8"
toml = "0.4"
\ No newline at end of file
toml = "0.4"
diff --git a/tests/basic.rs b/tests/basic.rs
index 19a7b54..b286b80 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -38,24 +38,25 @@ mod derivation {

mod workflow {
    use keybob::{Key, KeyType};
    extern crate miscreant;
    extern crate aes_siv;

    #[test]
    fn miscreant() {
        use workflow::miscreant::aead::{Aes256Siv, Algorithm};
        use workflow::aes_siv::aead::generic_array::GenericArray;
        use workflow::aes_siv::aead::{Aead, NewAead};
        use workflow::aes_siv::Aes256SivAead;

        let key = Key::new(KeyType::Aes256);
        let mut aes: Aes256Siv = Aes256Siv::new(key.as_slice());
        let aes = Aes256SivAead::new_varkey(key.as_slice()).expect("incorrect key length");

        /* Technically just random data, you can also use a "key" as iv and nonce */
        let iv = Key::new(KeyType::Aes256);
        let nonce = Key::new(KeyType::Aes256);
        /* Technically just random data, you can also use a "key" as nonce */
        let nonce = GenericArray::clone_from_slice(&Key::new(KeyType::Aes256).as_slice()[..16]);
        let data_in = "This is a message!";

        let encrypted = aes.seal(nonce.as_slice(), iv.as_slice(), data_in.as_bytes());
        let decrypted = aes
            .open(nonce.as_slice(), iv.as_slice(), encrypted.as_slice())
            .unwrap();
        let encrypted = aes
            .encrypt(&nonce, data_in.as_bytes())
            .expect("encryption failed");
        let decrypted = aes.decrypt(&nonce, encrypted.as_slice()).unwrap();
        let data_out = ::std::str::from_utf8(&decrypted.as_slice()).unwrap();

        assert_eq!(data_in, data_out);
-- 
2.30.0

[PATCH keybob 2/7] Update RustCrypto crates Export this patch

blake2 0.8.1 fixed an issue where HMAC-BLAKE2 results were just
completely wrong.  Naturally we have to update our tests, because we
were testing we got an incorrect value!

This upgrades to the latest version of blake2.  There are more recent
versions of pbkdf2 and hmac, but here I've chosen to go to the latest
versions that are compatible with the latest version of crypto-mac
supported by blake2.

Fixes: CVE-2019-16143
---
 Cargo.toml     | 6 +++---
 tests/basic.rs | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 83fd80c..ea3da29 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,9 +10,9 @@ authors = ["Katharina Fey <kookie@spacekookie.de>"]

[dependencies]
rand = "0.5"
pbkdf2 = "0.2"
blake2 = "0.7"
hmac = "0.6"
pbkdf2 = "0.4"
blake2 = "0.9"
hmac = "0.8"
base64 = "0.9"

serde = "1.0"
diff --git a/tests/basic.rs b/tests/basic.rs
index b286b80..54f76ff 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -65,6 +65,6 @@ mod workflow {
    #[test]
    fn printers() {
        let k1 = Key::from_pw(KeyType::Aes128, "192837465", "jane");
        assert_eq!(&format!("{:?}", k1), "Key: type: Aes128 – \"Mvd0jg==\"");
        assert_eq!(&format!("{:?}", k1), "Key: type: Aes128 – \"4HaDrA==\"");
    }
}
-- 
2.30.0

[PATCH keybob 3/7] Update rand to 0.7 Export this patch

This is the same version of rand as used by pbkdf2.
---
 Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml
index ea3da29..f0d484a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,7 @@ license = "MIT/X11 OR Apache-2.0"
authors = ["Katharina Fey <kookie@spacekookie.de>"]

[dependencies]
rand = "0.5"
rand = "0.7"
pbkdf2 = "0.4"
blake2 = "0.9"
hmac = "0.8"
-- 
2.30.0

[PATCH keybob 4/7] Update base64 to 0.12 Export this patch

This is the same version of base64 as used by pbkdf2.
---
 Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml
index f0d484a..c52e93e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@ rand = "0.7"
pbkdf2 = "0.4"
blake2 = "0.9"
hmac = "0.8"
base64 = "0.9"
base64 = "0.12"

serde = "1.0"
serde_derive = "1.0"
-- 
2.30.0

[PATCH keybob 5/7] Update serde_cbor to 0.11 Export this patch

(CVE is about stack consumption -- probably not relevant to our use in
tests.)

Fixes: CVE-2019-25001
---
 Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml
index c52e93e..520efe0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,5 +23,5 @@ serde_json = "1.0"
aes-siv = "0.5"
rmp-serde = "0.13.7"
bincode = "1.0"
serde_cbor = "0.8"
serde_cbor = "0.11"
toml = "0.4"
-- 
2.30.0

[PATCH keybob 6/7] Update to Rust 2018 edition Export this patch

---
 Cargo.toml     | 1 +
 tests/basic.rs | 7 +++----
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 520efe0..f8e74f9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ repository = "https://github.com/spacekookie/keybob"
readme = "README.md"
license = "MIT/X11 OR Apache-2.0"
authors = ["Katharina Fey <kookie@spacekookie.de>"]
edition = "2018"

[dependencies]
rand = "0.7"
diff --git a/tests/basic.rs b/tests/basic.rs
index 54f76ff..b579289 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -38,13 +38,12 @@ mod derivation {

mod workflow {
    use keybob::{Key, KeyType};
    extern crate aes_siv;

    #[test]
    fn miscreant() {
        use workflow::aes_siv::aead::generic_array::GenericArray;
        use workflow::aes_siv::aead::{Aead, NewAead};
        use workflow::aes_siv::Aes256SivAead;
        use aes_siv::aead::generic_array::GenericArray;
        use aes_siv::aead::{Aead, NewAead};
        use aes_siv::Aes256SivAead;

        let key = Key::new(KeyType::Aes256);
        let aes = Aes256SivAead::new_varkey(key.as_slice()).expect("incorrect key length");
-- 
2.30.0

[PATCH keybob 7/7] Remove explicit static lifetimes Export this patch

---
 src/serial.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/serial.rs b/src/serial.rs
index 7bae46e..624e272 100644
--- a/src/serial.rs
+++ b/src/serial.rs
@@ -127,7 +127,7 @@ impl<'de> Deserialize<'de> for Key {
			}
		}

		const FIELDS: &'static [&'static str] = &["tt", "key"];
		const FIELDS: &[&str] = &["tt", "key"];
		deserializer.deserialize_struct("Key", FIELDS, KeyVisitor)
	}
}
-- 
2.30.0