Skip to content

Commit

Permalink
Rename storage command to encrypted
Browse files Browse the repository at this point in the history
This change is the last step in the process of restructuring the storage
command. In particular, now that functionality pertaining hidden volumes
has been moved out into a dedicated top-level command, it renames said
command to encrypted, because dealing with the encrypted volume is the
only functionality it provides.
  • Loading branch information
d-e-s-o committed May 27, 2019
1 parent f40cbc0 commit 5b93c48
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions nitrocli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------
- Changed `storage hidden` subcommand to `hidden` top-level command
- Renamed `storage` command to `encrypted`
- Removed `storage status` subcommand
- Moved its output into `status` command

Expand Down
2 changes: 1 addition & 1 deletion nitrocli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following commands are currently supported:
- config: Access the Nitrokey's configuration
- get: Read the current configuration.
- set: Change the configuration.
- storage: Work with the Nitrokey Storage's storage.
- encrypted: Work with the Nitrokey Storage's encrypted volume.
- open: Open the encrypted volume. The user PIN needs to be entered.
- close: Close the encrypted volume.
- hidden: Work with the Nitrokey Storage's hidden volume.
Expand Down
4 changes: 2 additions & 2 deletions nitrocli/doc/nitrocli.1
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ this overlay (which is required to achieve plausible deniability of the
existence of hidden volumes), the burden of ensuring that data on the encrypted
volume does not overlap with data on one of the hidden volumes is on the user.
.TP
\fBnitrocli storage open
\fBnitrocli encrypted open
Open the encrypted volume on the Nitrokey Storage.
The user PIN that is required to open the volume is queried using
\fBpinentry\fR(1) and cached by \fBgpg\-agent\fR(1).
.TP
\fBnitrocli storage close
\fBnitrocli encrypted close
Close the encrypted volume on the Nitrokey Storage.
.TP
\fBnitrocli hidden create \fIslot\fR \fIstart\fR \fIend\fR
Expand Down
Binary file modified nitrocli/doc/nitrocli.1.pdf
Binary file not shown.
26 changes: 13 additions & 13 deletions nitrocli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ impl From<DeviceModel> for nitrokey::Model {
#[allow(unused_doc_comments)]
Enum! {Command, [
Config => ("config", config),
Encrypted => ("encrypted", encrypted),
Hidden => ("hidden", hidden),
Lock => ("lock", lock),
Otp => ("otp", otp),
Pin => ("pin", pin),
Pws => ("pws", pws),
Reset => ("reset", reset),
Status => ("status", status),
Storage => ("storage", storage),
]}

Enum! {ConfigCommand, [
Expand Down Expand Up @@ -247,18 +247,18 @@ fn reset(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
commands::reset(ctx)
}

Enum! {StorageCommand, [
Close => ("close", storage_close),
Open => ("open", storage_open),
Enum! {EncryptedCommand, [
Close => ("close", encrypted_close),
Open => ("open", encrypted_open),
]}

/// Execute a storage subcommand.
fn storage(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
let mut subcommand = StorageCommand::Open;
/// Execute an encrypted subcommand.
fn encrypted(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
let mut subcommand = EncryptedCommand::Open;
let help = cmd_help!(subcommand);
let mut subargs = vec![];
let mut parser = argparse::ArgumentParser::new();
parser.set_description("Interacts with the device's storage");
parser.set_description("Interacts with the device's encrypted volume");
let _ =
parser
.refer(&mut subcommand)
Expand All @@ -272,26 +272,26 @@ fn storage(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
parser.stop_on_first_argument(true);
parse(ctx, parser, args)?;

subargs.insert(0, format!("nitrocli {} {}", Command::Storage, subcommand));
subargs.insert(0, format!("nitrocli {}", subcommand));
subcommand.execute(ctx, subargs)
}

/// Open the encrypted volume on the nitrokey.
fn storage_open(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
fn encrypted_open(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
let mut parser = argparse::ArgumentParser::new();
parser.set_description("Opens the encrypted volume on a Nitrokey Storage");
parse(ctx, parser, args)?;

commands::storage_open(ctx)
commands::encrypted_open(ctx)
}

/// Close the previously opened encrypted volume.
fn storage_close(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
fn encrypted_close(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
let mut parser = argparse::ArgumentParser::new();
parser.set_description("Closes the encrypted volume on a Nitrokey Storage");
parse(ctx, parser, args)?;

commands::storage_close(ctx)
commands::encrypted_close(ctx)
}

Enum! {HiddenCommand, [
Expand Down
4 changes: 2 additions & 2 deletions nitrocli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ pub fn reset(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
}

/// Open the encrypted volume on the nitrokey.
pub fn storage_open(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
pub fn encrypted_open(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
let device = get_storage_device(ctx)?;
let pin_entry = pinentry::PinEntry::from(pinentry::PinType::User, &device)?;

Expand All @@ -376,7 +376,7 @@ pub fn storage_open(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
}

/// Close the previously opened encrypted volume.
pub fn storage_close(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
pub fn encrypted_close(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
// Flush all filesystem caches to disk. We are mostly interested in
// making sure that the encrypted volume on the nitrokey we are
// about to close is not closed while not all data was written to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// storage.rs
// encrypted.rs

// *************************************************************************
// * Copyright (C) 2019 Daniel Mueller ([email protected]) *
Expand Down Expand Up @@ -48,11 +48,11 @@ $"#,
let out = ncli.handle(&["status"])?;
assert!(make_re(None).is_match(&out), out);

let _ = ncli.handle(&["storage", "open"])?;
let _ = ncli.handle(&["encrypted", "open"])?;
let out = ncli.handle(&["status"])?;
assert!(make_re(Some(true)).is_match(&out), out);

let _ = ncli.handle(&["storage", "close"])?;
let _ = ncli.handle(&["encrypted", "close"])?;
let out = ncli.handle(&["status"])?;
assert!(make_re(Some(false)).is_match(&out), out);

Expand All @@ -62,15 +62,15 @@ $"#,
#[test_device]
fn encrypted_open_close(device: nitrokey::Storage) -> crate::Result<()> {
let mut ncli = Nitrocli::with_dev(device);
let out = ncli.handle(&["storage", "open"])?;
let out = ncli.handle(&["encrypted", "open"])?;
assert!(out.is_empty());

let device = nitrokey::Storage::connect()?;
assert!(device.get_status()?.encrypted_volume.active);
assert!(!device.get_status()?.hidden_volume.active);
drop(device);

let out = ncli.handle(&["storage", "close"])?;
let out = ncli.handle(&["encrypted", "close"])?;
assert!(out.is_empty());

let device = nitrokey::Storage::connect()?;
Expand Down
2 changes: 1 addition & 1 deletion nitrocli/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const NITROKEY_DEFAULT_USER_PIN: &str = "123456";
fn dummy() {}

mod config;
mod encrypted;
mod hidden;
mod lock;
mod otp;
Expand All @@ -45,7 +46,6 @@ mod pws;
mod reset;
mod run;
mod status;
mod storage;

/// A trait simplifying checking for expected errors.
pub trait UnwrapError {
Expand Down

0 comments on commit 5b93c48

Please sign in to comment.