allow pazzle_length of zero, sore its value in wallet

pull/19/head
Niko 1 year ago
parent 8cc441cb87
commit f1642dedfc
  1. 51
      ng-wallet/src/lib.rs
  2. 9
      ng-wallet/src/types.rs

@ -324,7 +324,11 @@ pub async fn create_wallet_v0(
let creating_pazzle = Instant::now(); let creating_pazzle = Instant::now();
// pazzle_length can only be 9, 12, or 15 // pazzle_length can only be 9, 12, or 15
if (params.pazzle_length != 9 && params.pazzle_length != 12 && params.pazzle_length != 15) { if (params.pazzle_length != 9
&& params.pazzle_length != 12
&& params.pazzle_length != 15
&& params.pazzle_length != 0)
{
return Err(NgWalletError::InvalidPazzleLength); return Err(NgWalletError::InvalidPazzleLength);
} }
@ -439,8 +443,22 @@ pub async fn create_wallet_v0(
sites: vec![site], sites: vec![site],
}; };
let mut master_key = [0u8; 32];
getrandom::getrandom(&mut master_key).map_err(|e| NgWalletError::InternalError)?;
let mut salt_pazzle = [0u8; 16]; let mut salt_pazzle = [0u8; 16];
getrandom::getrandom(&mut salt_pazzle).map_err(|e| NgWalletError::InternalError)?; let mut enc_master_key_pazzle = [0u8; 48];
if params.pazzle_length > 0 {
getrandom::getrandom(&mut salt_pazzle).map_err(|e| NgWalletError::InternalError)?;
let pazzle_key = derive_key_from_pass(
[pazzle.clone(), params.pin.to_vec()].concat(),
salt_pazzle,
wallet_id,
);
enc_master_key_pazzle = enc_master_key(master_key, pazzle_key, 0, wallet_id)?;
}
let mut salt_mnemonic = [0u8; 16]; let mut salt_mnemonic = [0u8; 16];
getrandom::getrandom(&mut salt_mnemonic).map_err(|e| NgWalletError::InternalError)?; getrandom::getrandom(&mut salt_mnemonic).map_err(|e| NgWalletError::InternalError)?;
@ -448,23 +466,12 @@ pub async fn create_wallet_v0(
//println!("salt_pazzle {:?}", salt_pazzle); //println!("salt_pazzle {:?}", salt_pazzle);
//println!("salt_mnemonic {:?}", salt_mnemonic); //println!("salt_mnemonic {:?}", salt_mnemonic);
let pazzle_key = derive_key_from_pass(
[pazzle.clone(), params.pin.to_vec()].concat(),
salt_pazzle,
wallet_id,
);
let mnemonic_key = derive_key_from_pass( let mnemonic_key = derive_key_from_pass(
[transmute_to_bytes(&mnemonic), &params.pin].concat(), [transmute_to_bytes(&mnemonic), &params.pin].concat(),
salt_mnemonic, salt_mnemonic,
wallet_id, wallet_id,
); );
let mut master_key = [0u8; 32];
getrandom::getrandom(&mut master_key).map_err(|e| NgWalletError::InternalError)?;
let enc_master_key_pazzle = enc_master_key(master_key, pazzle_key, 0, wallet_id)?;
let enc_master_key_mnemonic = enc_master_key(master_key, mnemonic_key, 0, wallet_id)?; let enc_master_key_mnemonic = enc_master_key(master_key, mnemonic_key, 0, wallet_id)?;
let timestamp = now_timestamp(); let timestamp = now_timestamp();
@ -481,6 +488,7 @@ pub async fn create_wallet_v0(
let wallet_content = WalletContentV0 { let wallet_content = WalletContentV0 {
security_img: cursor.into_inner(), security_img: cursor.into_inner(),
security_txt: new_string, security_txt: new_string,
pazzle_length: params.pazzle_length,
salt_pazzle, salt_pazzle,
salt_mnemonic, salt_mnemonic,
enc_master_key_pazzle, enc_master_key_pazzle,
@ -630,16 +638,17 @@ mod tests {
"opening of wallet with mnemonic took: {} ms", "opening of wallet with mnemonic took: {} ms",
opening_mnemonic.elapsed().as_millis() opening_mnemonic.elapsed().as_millis()
); );
let opening_pazzle = Instant::now();
let w = open_wallet_with_pazzle(Wallet::V0(v0.clone()), res.pazzle, pin) if v0.content.pazzle_length > 0 {
.expect("open with pazzle"); let opening_pazzle = Instant::now();
let w = open_wallet_with_pazzle(Wallet::V0(v0.clone()), res.pazzle, pin)
.expect("open with pazzle");
log!(
"opening of wallet with pazzle took: {} ms",
opening_pazzle.elapsed().as_millis()
);
}
//println!("encrypted part {:?}", w); //println!("encrypted part {:?}", w);
log!(
"opening of wallet with pazzle took: {} ms",
opening_pazzle.elapsed().as_millis()
);
} }
} }
} }

@ -113,6 +113,9 @@ pub struct WalletContentV0 {
pub security_txt: String, pub security_txt: String,
/// can be 9, 12 or 15 (or 0, in this case salt_pazzle and enc_master_key_pazzle are filled with zeros and should not be used)
pub pazzle_length: u8,
pub salt_pazzle: [u8; 16], pub salt_pazzle: [u8; 16],
pub salt_mnemonic: [u8; 16], pub salt_mnemonic: [u8; 16],
@ -175,6 +178,11 @@ impl Wallet {
Wallet::V0(v0) => v0.sig, Wallet::V0(v0) => v0.sig,
} }
} }
pub fn pazzle_length(&self) -> u8 {
match self {
Wallet::V0(v0) => v0.content.pazzle_length,
}
}
} }
/// Add Wallet Version 0 /// Add Wallet Version 0
@ -216,7 +224,6 @@ impl AddWallet {
pub struct CreateWalletV0 { pub struct CreateWalletV0 {
#[serde(with = "serde_bytes")] #[serde(with = "serde_bytes")]
pub security_img: Vec<u8>, pub security_img: Vec<u8>,
pub security_txt: String, pub security_txt: String,
pub pin: [u8; 4], pub pin: [u8; 4],
pub pazzle_length: u8, pub pazzle_length: u8,

Loading…
Cancel
Save