Skip to content

Commit 3ba8248

Browse files
committed
HAL: use SecureChip event counter
Proactivly replace calls wherever we have a HAL instance, so these tests will not fail later when the code starts using the SecureChip HAL.
1 parent df4c0a9 commit 3ba8248

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/rust/bitbox02-rust/src/hww/api/backup.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ mod tests {
187187

188188
let mut mock_hal = TestingHal::new();
189189
mock_hal.sd.inserted = Some(true);
190-
bitbox02::securechip::fake_event_counter_reset();
190+
mock_hal.securechip.event_counter_reset();
191191
assert_eq!(
192192
block_on(create(
193193
&mut mock_hal,
@@ -198,7 +198,7 @@ mod tests {
198198
)),
199199
Ok(Response::Success(pb::Success {}))
200200
);
201-
assert_eq!(bitbox02::securechip::fake_event_counter(), 1);
201+
assert_eq!(mock_hal.securechip.get_event_counter(), 1);
202202
assert_eq!(EXPECTED_TIMESTMAP, bitbox02::memory::get_seed_birthdate());
203203
assert_eq!(
204204
mock_hal.ui.screens,
@@ -246,7 +246,7 @@ mod tests {
246246
password_entered = true;
247247
Ok("password".into())
248248
}));
249-
bitbox02::securechip::fake_event_counter_reset();
249+
mock_hal.securechip.event_counter_reset();
250250
assert_eq!(
251251
block_on(create(
252252
&mut mock_hal,
@@ -257,7 +257,7 @@ mod tests {
257257
)),
258258
Ok(Response::Success(pb::Success {}))
259259
);
260-
assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
260+
assert_eq!(mock_hal.securechip.get_event_counter(), 5);
261261
assert_eq!(
262262
mock_hal.ui.screens,
263263
vec![

src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ mod tests {
9797
panic!("unexpected call to enter password")
9898
}));
9999

100-
bitbox02::securechip::fake_event_counter_reset();
100+
mock_hal.securechip.event_counter_reset();
101101
assert_eq!(
102102
block_on(process(&mut mock_hal)),
103103
Ok(Response::Success(pb::Success {}))
104104
);
105105
// 1 operation for one copy_seed() to get the seed to display it.
106-
assert_eq!(bitbox02::securechip::fake_event_counter(), 1);
106+
assert_eq!(mock_hal.securechip.get_event_counter(), 1);
107107

108108
assert_eq!(
109109
mock_hal.ui.screens,
@@ -151,12 +151,12 @@ mod tests {
151151
Ok("password".into())
152152
}));
153153

154-
bitbox02::securechip::fake_event_counter_reset();
154+
mock_hal.securechip.event_counter_reset();
155155
assert_eq!(
156156
block_on(process(&mut mock_hal)),
157157
Ok(Response::Success(pb::Success {}))
158158
);
159-
assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
159+
assert_eq!(mock_hal.securechip.get_event_counter(), 5);
160160

161161
assert_eq!(
162162
mock_hal.ui.screens,
@@ -206,9 +206,9 @@ mod tests {
206206
.ui
207207
.set_enter_string(Box::new(|_params| Ok("wrong password".into())));
208208

209-
bitbox02::securechip::fake_event_counter_reset();
209+
mock_hal.securechip.event_counter_reset();
210210
assert_eq!(block_on(process(&mut mock_hal)), Err(Error::Generic));
211-
assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
211+
assert_eq!(mock_hal.securechip.get_event_counter(), 5);
212212

213213
assert_eq!(
214214
mock_hal.ui.screens,

src/rust/bitbox02-rust/src/keystore.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,17 +892,17 @@ mod tests {
892892
));
893893

894894
// First call: unlock. The first one does a seed rentention (1 securechip event).
895-
bitbox02::securechip::fake_event_counter_reset();
895+
mock_hal.securechip.event_counter_reset();
896896
assert_eq!(unlock(&mut mock_hal, "password").unwrap().as_slice(), seed);
897-
assert_eq!(bitbox02::securechip::fake_event_counter(), 6);
897+
assert_eq!(mock_hal.securechip.get_event_counter(), 6);
898898

899899
// Loop to check that unlocking works while unlocked.
900900
for _ in 0..2 {
901901
// Further calls perform a password check.The password check does not do the retention
902902
// so it ends up needing one secure chip operation less.
903-
bitbox02::securechip::fake_event_counter_reset();
903+
mock_hal.securechip.event_counter_reset();
904904
assert_eq!(unlock(&mut mock_hal, "password").unwrap().as_slice(), seed);
905-
assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
905+
assert_eq!(mock_hal.securechip.get_event_counter(), 5);
906906
}
907907

908908
// Also check that the retained seed was encrypted with the expected encryption key.

src/rust/bitbox02-rust/src/workflow/unlock.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ mod tests {
218218
password_entered = true;
219219
Ok("password".into())
220220
}));
221-
bitbox02::securechip::fake_event_counter_reset();
221+
mock_hal.securechip.event_counter_reset();
222222
assert_eq!(block_on(unlock(&mut mock_hal)), Ok(()));
223223
// 6 for keystore unlock, 1 for keystore bip39 unlock.
224-
assert_eq!(bitbox02::securechip::fake_event_counter(), 7);
224+
assert_eq!(mock_hal.securechip.get_event_counter(), 7);
225225

226226
assert!(!crate::keystore::is_locked());
227227

@@ -261,7 +261,7 @@ mod tests {
261261
Ok("wrong password".into())
262262
}));
263263

264-
bitbox02::securechip::fake_event_counter_reset();
264+
mock_hal.securechip.event_counter_reset();
265265
assert!(matches!(
266266
block_on(unlock_keystore(
267267
&mut mock_hal,
@@ -270,7 +270,7 @@ mod tests {
270270
)),
271271
Err(UnlockError::IncorrectPassword),
272272
));
273-
assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
273+
assert_eq!(mock_hal.securechip.get_event_counter(), 5);
274274

275275
// Checks that the device is locked.
276276
assert!(crate::keystore::copy_seed().is_err());

0 commit comments

Comments
 (0)