From 4da3eadcca6e7198074898f71b00f647823cef4f Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 14 Apr 2024 21:19:06 -0400 Subject: [PATCH] keyfork-shard: base64 encode content instead of base16 --- Cargo.lock | 9 ++++++++- crates/keyfork-shard/Cargo.toml | 1 + crates/keyfork-shard/src/lib.rs | 13 +++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a4320d..64f4d47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -341,6 +341,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "base64ct" version = "1.6.0" @@ -1834,6 +1840,7 @@ version = "0.2.0" dependencies = [ "aes-gcm", "anyhow", + "base64 0.22.0", "card-backend", "card-backend-pcsc", "hkdf", @@ -2886,7 +2893,7 @@ dependencies = [ "aes", "aes-gcm", "anyhow", - "base64", + "base64 0.21.7", "block-padding", "blowfish", "buffered-reader", diff --git a/crates/keyfork-shard/Cargo.toml b/crates/keyfork-shard/Cargo.toml index 8066277..4d0737f 100644 --- a/crates/keyfork-shard/Cargo.toml +++ b/crates/keyfork-shard/Cargo.toml @@ -37,3 +37,4 @@ card-backend-pcsc = { version = "0.5.0", optional = true } openpgp-card-sequoia = { version = "0.2.0", optional = true, default-features = false } openpgp-card = { version = "0.4.0", optional = true } sequoia-openpgp = { version = "1.17.0", optional = true, default-features = false } +base64 = "0.22.0" diff --git a/crates/keyfork-shard/src/lib.rs b/crates/keyfork-shard/src/lib.rs index e81c57a..cb5c669 100644 --- a/crates/keyfork-shard/src/lib.rs +++ b/crates/keyfork-shard/src/lib.rs @@ -23,6 +23,7 @@ use keyfork_prompt::{ use sha2::Sha256; use sharks::{Share, Sharks}; use x25519_dalek::{EphemeralSecret, PublicKey}; +use base64::prelude::{BASE64_STANDARD, Engine}; // 32-byte share, 1-byte index, 1-byte threshold, 1-byte version == 36 bytes // Encrypted, is 52 bytes @@ -208,10 +209,10 @@ pub trait Format { .lock() .expect(bug!(POISONED_MUTEX)) .prompt_message(PromptMessage::Text(QRCODE_PROMPT.to_string()))?; - if let Ok(Some(hex)) = + if let Ok(Some(qrcode_content)) = keyfork_qrcode::scan_camera(std::time::Duration::from_secs(30), 0) { - let decoded_data = smex::decode(hex)?; + let decoded_data = BASE64_STANDARD.decode(qrcode_content).unwrap(); pubkey_data = Some(decoded_data.try_into().map_err(|_| InvalidData)?) } else { prompt @@ -299,7 +300,7 @@ pub trait Format { use keyfork_qrcode::{qrencode, ErrorCorrection}; let mut qrcode_data = our_pubkey_mnemonic.to_bytes(); qrcode_data.extend(payload_mnemonic.as_bytes()); - if let Ok(qrcode) = qrencode(&smex::encode(&qrcode_data), ErrorCorrection::Highest) { + if let Ok(qrcode) = qrencode(&BASE64_STANDARD.encode(qrcode_data), ErrorCorrection::Highest) { prompt .lock() .expect(bug!(POISONED_MUTEX)) @@ -432,7 +433,7 @@ pub fn remote_decrypt(w: &mut impl Write) -> Result<(), Box Result<(), Box