Skip to content

Commit b5beeee

Browse files
msirringhausjschanck
authored andcommitted
Use workaround for broken generic array 0.14.9 by using the new version in compat-mode
1 parent 847c7bd commit b5beeee

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ assert_matches = "1.2"
8383
rpassword = "5.0"
8484
flate3 = "1"
8585
aes-gcm = "0.10"
86+
# Workaround for 'broken' generic-array 0.14.9, see ctap2_discoverable_creds.rs for details
87+
generic-array = { version = "1.3", features = ["compat-0_14"] }
8688

8789
[lints.rust]
8890
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }

examples/ctap2_discoverable_creds.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use aes_gcm::{
66
aead::{Aead, AeadCore, KeyInit, OsRng, Payload},
7-
Aes256Gcm, Key,
7+
Aes256Gcm,
88
};
99
use authenticator::{
1010
authenticatorservice::{AuthenticatorService, RegisterArgs, SignArgs},
@@ -21,6 +21,7 @@ use authenticator::{
2121
statecallback::StateCallback,
2222
Pin, StatusPinUv, StatusUpdate,
2323
};
24+
use generic_array::GenericArray;
2425
use getopts::{Matches, Options};
2526
use sha2::{Digest, Sha256};
2627
use std::sync::mpsc::{channel, RecvError};
@@ -157,8 +158,14 @@ fn register_user(
157158
// Let nonce be a fresh, random, 12-byte value.
158159
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
159160
// Let ciphertext be the AEAD_AES_256_GCM authenticated encryption of plaintext using key, nonce, and the associated data as specified above.
160-
let gcm_key = Key::<Aes256Gcm>::from_slice(&key);
161-
let cipher = Aes256Gcm::new(gcm_key);
161+
//
162+
// Note: Because of bug https://github.com/RustCrypto/traits/issues/2036 and/or https://github.com/fizyk20/generic-array/issues/158 we can't use the
163+
// simple version below, but have to request the new generic-array 1.x in
164+
// our Cargo.toml and use it directly here, as aes_gcm uses the old version
165+
// that got 'broken' by a dot-release
166+
// let gcm_key = Key::<Aes256Gcm>::from_slice(&key);
167+
// let cipher = Aes256Gcm::new(gcm_key);
168+
let cipher = Aes256Gcm::new(GenericArray::from_slice(&key).as_ref());
162169
let mut payload = Payload::from(plaintext.as_ref());
163170
// Associated data: The value 0x626c6f62 ("blob") || uint64LittleEndian(origSize).
164171
let mut aad = b"blob".to_vec();
@@ -259,8 +266,13 @@ fn extract_associated_large_blobs(key: Vec<u8>, array: Vec<LargeBlobArrayElement
259266
let valid_elements = array
260267
.iter()
261268
.filter_map(|e| {
262-
let gcm_key = Key::<Aes256Gcm>::from_slice(&key);
263-
let cipher = Aes256Gcm::new(gcm_key);
269+
// Note: Because of bug https://github.com/RustCrypto/traits/issues/2036 and/or https://github.com/fizyk20/generic-array/issues/158 we can't use the
270+
// simple version below, but have to request the new generic-array 1.x in
271+
// our Cargo.toml and use it directly here, as aes_gcm uses the old version
272+
// that got 'broken' by a dot-release
273+
// let gcm_key = Key::<Aes256Gcm>::from_slice(&key);
274+
// let cipher = Aes256Gcm::new(gcm_key);
275+
let cipher = Aes256Gcm::new(GenericArray::from_slice(&key).as_ref());
264276
let mut payload = Payload::from(e.ciphertext.as_slice());
265277
// Associated data: The value 0x626c6f62 ("blob") || uint64LittleEndian(origSize).
266278
let mut aad = b"blob".to_vec();

0 commit comments

Comments
 (0)