Skip to content

Commit 9e2343c

Browse files
committed
Merge branch 'keystore-rust-is-unlocked'
2 parents fb1d7f4 + 05c21c6 commit 9e2343c

File tree

23 files changed

+573
-504
lines changed

23 files changed

+573
-504
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ mod tests {
329329
}]
330330
);
331331

332-
assert!(!bitbox02::keystore::is_locked());
332+
assert!(!crate::keystore::is_locked());
333333
assert!(bitbox02::memory::is_seeded());
334334
assert!(!bitbox02::memory::is_initialized());
335335

@@ -343,7 +343,7 @@ mod tests {
343343

344344
// Can reboot when seeded and locked. This happens when the user sets a password and then
345345
// reconnects the device.
346-
bitbox02::keystore::lock();
346+
crate::keystore::lock();
347347
let mut mock_hal = TestingHal::new();
348348
let reboot_called = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
349349
make_request(&mut mock_hal, reboot_request.encode_to_vec().as_ref()).unwrap();
@@ -372,7 +372,7 @@ mod tests {
372372

373373
let mut make_request = init_noise();
374374

375-
bitbox02::keystore::lock();
375+
crate::keystore::lock();
376376
let mut mock_hal = TestingHal::new();
377377
mock_hal.sd.inserted = Some(true);
378378
mock_hal
@@ -391,7 +391,7 @@ mod tests {
391391
.as_ref(),
392392
)
393393
.unwrap();
394-
assert!(!bitbox02::keystore::is_locked());
394+
assert!(!crate::keystore::is_locked());
395395
assert!(!bitbox02::memory::is_initialized());
396396
let mut mock_hal = TestingHal::new();
397397
mock_hal.sd.inserted = Some(true);
@@ -434,7 +434,7 @@ mod tests {
434434
};
435435

436436
// Can't reboot when initialized but locked.
437-
bitbox02::keystore::lock();
437+
crate::keystore::lock();
438438
let mut mock_hal = TestingHal::new();
439439
let response_encoded =
440440
make_request(&mut mock_hal, &reboot_request.encode_to_vec()).unwrap();
@@ -456,7 +456,7 @@ mod tests {
456456
block_on(_process_packet(&mut mock_hal, vec![OP_UNLOCK])),
457457
[OP_STATUS_SUCCESS].to_vec()
458458
);
459-
assert!(!bitbox02::keystore::is_locked());
459+
assert!(!crate::keystore::is_locked());
460460

461461
// Since in the previous request the msg was encrypted but not decrypted (query was
462462
// rejected), the noise states are out of sync and we need to make a new channel.
@@ -490,7 +490,7 @@ mod tests {
490490
&b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"[..],
491491
&b"aaaaaaaaaaaaaaaa"[..],
492492
] {
493-
bitbox02::keystore::lock();
493+
crate::keystore::lock();
494494
mock_memory();
495495

496496
bitbox02::memory::set_device_name("test device name").unwrap();
@@ -552,7 +552,7 @@ mod tests {
552552
]
553553
);
554554

555-
let seed = bitbox02::keystore::copy_seed().unwrap();
555+
let seed = crate::keystore::copy_seed().unwrap();
556556
assert_eq!(seed.len(), host_entropy.len());
557557
mock_hal.ui = crate::workflow::testing::TestingWorkflows::new();
558558
assert!(matches!(
@@ -718,7 +718,7 @@ mod tests {
718718
);
719719

720720
// Restored seed is the same as the seed that was backed up.
721-
assert_eq!(seed, bitbox02::keystore::copy_seed().unwrap());
721+
assert_eq!(seed, crate::keystore::copy_seed().unwrap());
722722
}
723723
}
724724
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn can_call(request: &Request) -> bool {
110110
InitializedAndUnlocked,
111111
}
112112
let state: State = if bitbox02::memory::is_initialized() {
113-
if bitbox02::keystore::is_locked() {
113+
if crate::keystore::is_locked() {
114114
State::InitializedAndLocked
115115
} else {
116116
State::InitializedAndUnlocked

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub async fn check(
3030
return Err(Error::InvalidInput);
3131
}
3232

33-
let seed = bitbox02::keystore::copy_seed()?;
33+
let seed = crate::keystore::copy_seed()?;
3434
let id = backup::id(&seed);
3535
let (backup_data, metadata) = backup::load(hal, &id).await?;
3636
if seed.as_slice() != backup_data.get_seed() {
@@ -102,7 +102,7 @@ pub async fn create(
102102
let seed = if is_initialized {
103103
unlock::unlock_keystore(hal, "Unlock device", unlock::CanCancel::Yes).await?
104104
} else {
105-
let seed = bitbox02::keystore::copy_seed()?;
105+
let seed = crate::keystore::copy_seed()?;
106106
// Yield now to give executor a chance to process USB/BLE communication, as copy_seed() causes
107107
// some delay.
108108
futures_lite::future::yield_now().await;
@@ -234,7 +234,7 @@ mod tests {
234234

235235
let seed = hex::decode("cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044")
236236
.unwrap();
237-
bitbox02::keystore::encrypt_and_store_seed(&seed, "password").unwrap();
237+
crate::keystore::encrypt_and_store_seed(&seed, "password").unwrap();
238238
bitbox02::memory::set_initialized().unwrap();
239239

240240
let mut password_entered: bool = false;

src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ mod tests {
589589
};
590590

591591
// Keystore locked.
592-
bitbox02::keystore::lock();
592+
crate::keystore::lock();
593593
assert!(validate(&multisig, keypath).is_err());
594594

595595
// Ok.

src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ use pb::btc_script_config::{Config, SimpleType};
2424

2525
use pb::btc_response::Response;
2626

27-
use bitbox02::keystore;
27+
use crate::keystore;
2828

2929
use crate::hal::Ui;
30-
use crate::secp256k1::SECP256K1;
3130
use crate::workflow::{confirm, verify_message};
3231

3332
const MAX_MESSAGE_SIZE: usize = 1024;
@@ -99,8 +98,7 @@ pub async fn process(
9998
// Engage in the anti-klepto protocol if the host sends a host nonce commitment.
10099
Some(pb::AntiKleptoHostNonceCommitment { ref commitment }) => {
101100
let signer_commitment = keystore::secp256k1_nonce_commit(
102-
SECP256K1,
103-
crate::keystore::secp256k1_get_private_key(keypath)?
101+
keystore::secp256k1_get_private_key(keypath)?
104102
.as_slice()
105103
.try_into()
106104
.unwrap(),
@@ -119,9 +117,8 @@ pub async fn process(
119117
None => [0; 32],
120118
};
121119

122-
let sign_result = bitbox02::keystore::secp256k1_sign(
123-
SECP256K1,
124-
crate::keystore::secp256k1_get_private_key(keypath)?
120+
let sign_result = keystore::secp256k1_sign(
121+
keystore::secp256k1_get_private_key(keypath)?
125122
.as_slice()
126123
.try_into()
127124
.unwrap(),

src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ async fn _process(
661661
hal: &mut impl crate::hal::Hal,
662662
request: &pb::BtcSignInitRequest,
663663
) -> Result<Response, Error> {
664-
if bitbox02::keystore::is_locked() {
664+
if crate::keystore::is_locked() {
665665
return Err(Error::InvalidState);
666666
}
667667
// Validate the coin.
@@ -1230,8 +1230,7 @@ async fn _process(
12301230
// Engage in the Anti-Klepto protocol if the host sends a host nonce commitment.
12311231
let host_nonce: [u8; 32] = match tx_input.host_nonce_commitment {
12321232
Some(pb::AntiKleptoHostNonceCommitment { ref commitment }) => {
1233-
let signer_commitment = bitbox02::keystore::secp256k1_nonce_commit(
1234-
SECP256K1,
1233+
let signer_commitment = crate::keystore::secp256k1_nonce_commit(
12351234
private_key.as_slice().try_into().unwrap(),
12361235
&sighash,
12371236
commitment
@@ -1255,8 +1254,7 @@ async fn _process(
12551254
None => [0; 32],
12561255
};
12571256

1258-
let sign_result = bitbox02::keystore::secp256k1_sign(
1259-
SECP256K1,
1257+
let sign_result = crate::keystore::secp256k1_sign(
12601258
private_key.as_slice().try_into().unwrap(),
12611259
&sighash,
12621260
&host_nonce,
@@ -1705,7 +1703,7 @@ mod tests {
17051703

17061704
{
17071705
// test keystore locked
1708-
bitbox02::keystore::lock();
1706+
crate::keystore::lock();
17091707
assert_eq!(
17101708
block_on(process(&mut TestingHal::new(), &init_req_valid,)),
17111709
Err(Error::InvalidState)

src/rust/bitbox02-rust/src/hww/api/cardano/address.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ mod tests {
488488

489489
#[test]
490490
fn test_pubkey_hash_at_keypath() {
491-
bitbox02::keystore::lock();
491+
crate::keystore::lock();
492492
assert!(
493493
pubkey_hash_at_keypath(&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0]).is_err()
494494
);
@@ -515,7 +515,7 @@ mod tests {
515515
);
516516

517517
// Keystore locked
518-
bitbox02::keystore::lock();
518+
crate::keystore::lock();
519519
assert_eq!(
520520
do_pkh_skh(
521521
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],

src/rust/bitbox02-rust/src/hww/api/cardano/xpubs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod tests {
4747

4848
#[test]
4949
fn test_process() {
50-
bitbox02::keystore::lock();
50+
crate::keystore::lock();
5151
assert_eq!(
5252
process(&pb::CardanoXpubsRequest { keypaths: vec![] }),
5353
Ok(Response::Xpubs(pb::CardanoXpubsResponse { xpubs: vec![] })),

src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mod tests {
138138
);
139139

140140
// xpub fetching/encoding failed.
141-
bitbox02::keystore::lock();
141+
keystore::lock();
142142
assert_eq!(
143143
block_on(process(&mut TestingHal::new(), &request)),
144144
Err(Error::InvalidInput)
@@ -231,7 +231,7 @@ mod tests {
231231
);
232232

233233
// Keystore locked.
234-
bitbox02::keystore::lock();
234+
keystore::lock();
235235
assert_eq!(
236236
block_on(process(
237237
&mut TestingHal::new(),

src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ use super::amount::{Amount, calculate_percentage};
1717
use super::params::Params;
1818
use super::pb;
1919

20-
use bitbox02::keystore;
20+
use crate::keystore;
2121

2222
use crate::hal::Ui;
23-
use crate::secp256k1::SECP256K1;
2423
use crate::workflow::{confirm, transaction};
2524

2625
use alloc::vec::Vec;
@@ -390,8 +389,7 @@ pub async fn _process(
390389
// Engage in the anti-klepto protocol if the host sends a host nonce commitment.
391390
Some(pb::AntiKleptoHostNonceCommitment { commitment }) => {
392391
let signer_commitment = keystore::secp256k1_nonce_commit(
393-
SECP256K1,
394-
&crate::keystore::secp256k1_get_private_key(request.keypath())?
392+
&keystore::secp256k1_get_private_key(request.keypath())?
395393
.as_slice()
396394
.try_into()
397395
.unwrap(),
@@ -410,8 +408,7 @@ pub async fn _process(
410408
None => [0; 32],
411409
};
412410
let sign_result = keystore::secp256k1_sign(
413-
SECP256K1,
414-
&crate::keystore::secp256k1_get_private_key(request.keypath())?
411+
&keystore::secp256k1_get_private_key(request.keypath())?
415412
.as_slice()
416413
.try_into()
417414
.unwrap(),

0 commit comments

Comments
 (0)