Files
spacedrive/apps/cli/src/main.rs
jake e5b45d8f49 [ENG-355] Keychain integration (and some typesafety) (#558)
* update crypto MSRV

* rename `keychain` to `keyring`

* make a start on the keymanager unlock refactor/keychain integration

* update routes

* update bindings

* add const identifiers

* add UI/front-end support for unlocking KM with OS keychains

* remove SK from lib creation dialog

* update query name

* add keyring functions

* attempt to update `change_master_password()` to use the keychain

* cleanup, fix master password change ui, better secret key in keyring detection

* cleanup TS a little

* add route for getting secret key from keyring

* update bindings

* update var names + show secret key in keys settings

* add `react-qr-code` and option to view the secret key (if it's in the OS keyring)

* allow copying SK to clipboard

* add `key_type` so we're not reliant on specific UUIDs for root/verification key handling

* clippy

* fix mobile typecheck

* fix typecheck, fix typo and tweak balloon hash parameters

* minor cleanup + typo fix

* use newtype structs

* WIP type refactoring (major readability boost!)

* update `use`

* add tokio `sync` feature

* too many structs? idk

* more cleanup

* add `generate` and `Nonce`

* `Nonce` and `Key` typesafety (beautiful)

* clippy + cleanup

* update code & examples

* fix bug & remove `ProtectedVec` as it looked out of place

* use `Key`

* add a query invalidation to make the UI extremely responsive

* ci pls work

* remove `keyringHasSk` route
2023-02-07 12:03:12 +00:00

86 lines
2.1 KiB
Rust

use anyhow::{Context, Result};
use clap::Parser;
use indoc::printdoc;
use sd_crypto::header::file::FileHeader;
use std::path::PathBuf;
use tokio::fs::File;
#[derive(Parser)]
struct Args {
#[arg(help = "the file path to get details for")]
path: PathBuf,
}
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
let mut reader = File::open(args.path).await.context("unable to open file")?;
let (header, aad) = FileHeader::from_reader(&mut reader).await?;
print_crypto_details(&header, &aad);
Ok(())
}
fn print_crypto_details(header: &FileHeader, aad: &[u8]) {
printdoc! {"
Header version: {version}
Encryption algorithm: {algorithm}
AAD (hex): {hex}
",
version = header.version,
algorithm = header.algorithm,
hex = hex::encode(aad)
};
header.keyslots.iter().enumerate().for_each(|(i, k)| {
printdoc! {"
Keyslot {index}:
Version: {version}
Algorithm: {algorithm}
Hashing algorithm: {hashing_algorithm}
Salt (hex): {salt}
Master Key (hex, encrypted): {master}
Master key nonce (hex): {nonce}
",
index = i + i,
version = k.version,
algorithm = k.algorithm,
hashing_algorithm = k.hashing_algorithm,
salt = hex::encode(&*k.salt),
master = hex::encode(&*k.master_key),
nonce = hex::encode(k.nonce)
};
});
header.metadata.iter().for_each(|m| {
printdoc! {"
Metadata:
Version: {version}
Algorithm: {algorithm}
Encrypted size: {size}
Nonce (hex): {nonce}
",
version = m.version,
algorithm = m.algorithm,
size = m.metadata.len(),
nonce = hex::encode(m.metadata_nonce)
}
});
header.preview_media.iter().for_each(|p| {
printdoc! {"
Preview Media:
Version: {version}
Algorithm: {algorithm}
Encrypted size: {size}
Nonce (hex): {nonce}
",
version = p.version,
algorithm = p.algorithm,
size = p.media.len(),
nonce = hex::encode(p.media_nonce)
};
});
}