Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fill command to overwrite SD card #125

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Unreleased
- Added `--usb-path` option that restricts the USB path of the device to
connect to
- Bumped `structopt` dependency to `0.3.17`
- Added the `fill` command that fills the SD card of a Nitrokey Storage device
with random data
- Added the `crossterm` dependency in version `0.17.8`


0.3.4
Expand Down
171 changes: 171 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ version = "1.0"
[dependencies.base32]
version = "0.4.0"

[dependencies.crossterm]
version = "0.17.7"

[dependencies.envy]
version = "0.4.1"

Expand All @@ -53,6 +56,9 @@ version = "0.1"
[dependencies.nitrokey]
version = "0.7.1"

[dependencies.progressing]
version = "3.0.2"

[dependencies.serde]
version = "1.0"
features = ["derive"]
Expand Down
10 changes: 10 additions & 0 deletions doc/nitrocli.1
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ open.
.TP
\fBnitrocli hidden close
Close a hidden volume.
.TP
\fBnitrocli fill\fR
robinkrahl marked this conversation as resolved.
Show resolved Hide resolved
Fills the SD card with random data, overwriting all existing data.
This operation takes about one hour to finish for a 16 GB SD card.
It cannot be cancelled, even if the \fBnitrocli\fR process is terminated before
it finishes.

This command requires the admin PIN.
To avoid accidental calls of this command, the user has to enter the PIN even
if it has been cached.

.SS One-time passwords
The Nitrokey Pro and the Nitrokey Storage support the generation of one-time
Expand Down
Binary file modified doc/nitrocli.1.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Command! {
Config(ConfigArgs) => |ctx, args: ConfigArgs| args.subcmd.execute(ctx),
/// Interacts with the device's encrypted volume
Encrypted(EncryptedArgs) => |ctx, args: EncryptedArgs| args.subcmd.execute(ctx),
/// Fills the SD card with random data
Fill => crate::commands::fill,
/// Interacts with the device's hidden volume
Hidden(HiddenArgs) => |ctx, args: HiddenArgs| args.subcmd.execute(ctx),
/// Lists the attached Nitrokey devices
Expand Down
34 changes: 34 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use nitrokey::GetPasswordSafe;

use crate::args;
use crate::config;
use crate::output;
use crate::pinentry;
use crate::Context;

Expand Down Expand Up @@ -461,6 +462,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")?;
d-e-s-o marked this conversation as resolved.
Show resolved Hide resolved

try_with_pin(ctx, &pin_entry, |pin| {
device.fill_sd_card(&pin).context("Failed to fill SD card")
})?;

let mut progress_bar = output::ProgressBar::new();
progress_bar.draw(ctx)?;
while !progress_bar.is_finished() {
use nitrokey::OperationStatus;

thread::sleep(time::Duration::from_secs(1));
let status = device
.get_operation_status()
.context("Failed to query operation status")?;
match status {
OperationStatus::Ongoing(progress) => progress_bar.update(progress)?,
OperationStatus::Idle => progress_bar.finish(),
};
progress_bar.draw(ctx)?;
}

Ok(())
})
}

/// Perform a factory reset.
pub fn reset(ctx: &mut Context<'_>) -> anyhow::Result<()> {
with_device(ctx, |ctx, mut device| {
Expand Down
Loading