aboutsummaryrefslogtreecommitdiff
path: root/src/commands.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-10 12:20:13 +0200
committerDaniel Mueller <deso@posteo.net>2021-01-10 21:05:19 -0800
commitb23296e1cc47cf5350835d8a8cca6eb6f5d7d270 (patch)
tree61db1288e6076fd03bc8d9603817df8778c946ce /src/commands.rs
parent23dee1867bba7d899bd806b4ed41d29a2800db89 (diff)
downloadnitrocli-b23296e1cc47cf5350835d8a8cca6eb6f5d7d270.tar.gz
nitrocli-b23296e1cc47cf5350835d8a8cca6eb6f5d7d270.tar.bz2
Add fill command to overwrite SD card
This patch adds the fill command that overwrites the SD card with random data. Similar to the reset command, we always require the user to enter the admin PIN even if is cached.
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/commands.rs b/src/commands.rs
index d81e095..cf3b94f 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -469,6 +469,39 @@ pub fn list(ctx: &mut Context<'_>, no_connect: bool) -> anyhow::Result<()> {
Ok(())
}
+/// Fill the SD card with random data
+pub fn fill(ctx: &mut Context<'_>) -> anyhow::Result<()> {
+ with_storage_device(ctx, |ctx, mut device| {
+ let pin_entry = pinentry::PinEntry::from(args::PinType::Admin, &device)?;
+
+ // Similar to reset, we want the user to re-enter the admin PIN even if is cached to avoid
+ // accidental data loss.
+ pinentry::clear(&pin_entry).context("Failed to clear cached secret")?;
+
+ try_with_pin(ctx, &pin_entry, |pin| {
+ device.fill_sd_card(&pin).context("Failed to fill SD card")
+ })?;
+
+ let mut last_progress = 0;
+ loop {
+ let status = device
+ .get_operation_status()
+ .context("Failed to query operation status")?;
+ match status {
+ nitrokey::OperationStatus::Ongoing(progress) => {
+ if last_progress != progress {
+ println!(ctx, "{}/100", progress)?;
+ }
+ last_progress = progress;
+ }
+ nitrokey::OperationStatus::Idle => break,
+ };
+ }
+
+ Ok(())
+ })
+}
+
/// Perform a factory reset.
pub fn reset(ctx: &mut Context<'_>) -> anyhow::Result<()> {
with_device(ctx, |ctx, mut device| {