From e6d89a69521db96e27d65d8284acfa81f0ff4b2d Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Mon, 27 May 2019 09:30:46 -0700 Subject: Rename storage command to encrypted 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. --- nitrocli/CHANGELOG.md | 1 + nitrocli/README.md | 2 +- nitrocli/doc/nitrocli.1 | 4 +- nitrocli/doc/nitrocli.1.pdf | Bin 18095 -> 18095 bytes nitrocli/src/args.rs | 26 ++++++------ nitrocli/src/commands.rs | 4 +- nitrocli/src/tests/encrypted.rs | 90 ++++++++++++++++++++++++++++++++++++++++ nitrocli/src/tests/lock.rs | 2 +- nitrocli/src/tests/mod.rs | 2 +- nitrocli/src/tests/storage.rs | 90 ---------------------------------------- 10 files changed, 111 insertions(+), 110 deletions(-) create mode 100644 nitrocli/src/tests/encrypted.rs delete mode 100644 nitrocli/src/tests/storage.rs diff --git a/nitrocli/CHANGELOG.md b/nitrocli/CHANGELOG.md index 2840f29..716ebc6 100644 --- a/nitrocli/CHANGELOG.md +++ b/nitrocli/CHANGELOG.md @@ -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 diff --git a/nitrocli/README.md b/nitrocli/README.md index b93119a..0a30696 100644 --- a/nitrocli/README.md +++ b/nitrocli/README.md @@ -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. diff --git a/nitrocli/doc/nitrocli.1 b/nitrocli/doc/nitrocli.1 index 3c5406d..3c1e1e4 100644 --- a/nitrocli/doc/nitrocli.1 +++ b/nitrocli/doc/nitrocli.1 @@ -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 diff --git a/nitrocli/doc/nitrocli.1.pdf b/nitrocli/doc/nitrocli.1.pdf index 81abc31..0384072 100644 Binary files a/nitrocli/doc/nitrocli.1.pdf and b/nitrocli/doc/nitrocli.1.pdf differ diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs index c37e5d2..c043938 100644 --- a/nitrocli/src/args.rs +++ b/nitrocli/src/args.rs @@ -121,6 +121,7 @@ impl From for nitrokey::Model { #[allow(unused_doc_comments)] Enum! {Command, [ Config => ("config", config), + Encrypted => ("encrypted", encrypted), Hidden => ("hidden", hidden), Lock => ("lock", lock), Otp => ("otp", otp), @@ -128,7 +129,6 @@ Enum! {Command, [ Pws => ("pws", pws), Reset => ("reset", reset), Status => ("status", status), - Storage => ("storage", storage), ]} Enum! {ConfigCommand, [ @@ -247,18 +247,18 @@ fn reset(ctx: &mut ExecCtx<'_>, args: Vec) -> 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) -> Result<()> { - let mut subcommand = StorageCommand::Open; +/// Execute an encrypted subcommand. +fn encrypted(ctx: &mut ExecCtx<'_>, args: Vec) -> 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) @@ -272,26 +272,26 @@ fn storage(ctx: &mut ExecCtx<'_>, args: Vec) -> 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) -> Result<()> { +fn encrypted_open(ctx: &mut ExecCtx<'_>, args: Vec) -> 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) -> Result<()> { +fn encrypted_close(ctx: &mut ExecCtx<'_>, args: Vec) -> 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, [ diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index 6374611..0d30bca 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -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)?; @@ -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 diff --git a/nitrocli/src/tests/encrypted.rs b/nitrocli/src/tests/encrypted.rs new file mode 100644 index 0000000..8aef864 --- /dev/null +++ b/nitrocli/src/tests/encrypted.rs @@ -0,0 +1,90 @@ +// encrypted.rs + +// ************************************************************************* +// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) * +// * * +// * This program is free software: you can redistribute it and/or modify * +// * it under the terms of the GNU General Public License as published by * +// * the Free Software Foundation, either version 3 of the License, or * +// * (at your option) any later version. * +// * * +// * This program is distributed in the hope that it will be useful, * +// * but WITHOUT ANY WARRANTY; without even the implied warranty of * +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +// * GNU General Public License for more details. * +// * * +// * You should have received a copy of the GNU General Public License * +// * along with this program. If not, see . * +// ************************************************************************* + +use super::*; + +#[test_device] +fn status_open_close(device: nitrokey::Storage) -> crate::Result<()> { + fn make_re(open: Option) -> regex::Regex { + let encrypted = match open { + Some(open) => { + if open { + "active" + } else { + "(read-only|inactive)" + } + } + None => "(read-only|active|inactive)", + }; + let re = format!( + r#" + volumes: + unencrypted: (read-only|active|inactive) + encrypted: {} + hidden: (read-only|active|inactive) +$"#, + encrypted + ); + regex::Regex::new(&re).unwrap() + } + + let mut ncli = Nitrocli::with_dev(device); + let out = ncli.handle(&["status"])?; + assert!(make_re(None).is_match(&out), out); + + let _ = ncli.handle(&["encrypted", "open"])?; + let out = ncli.handle(&["status"])?; + assert!(make_re(Some(true)).is_match(&out), out); + + let _ = ncli.handle(&["encrypted", "close"])?; + let out = ncli.handle(&["status"])?; + assert!(make_re(Some(false)).is_match(&out), out); + + Ok(()) +} + +#[test_device] +fn encrypted_open_on_pro(device: nitrokey::Pro) { + let res = Nitrocli::with_dev(device).handle(&["encrypted", "open"]); + assert_eq!( + res.unwrap_str_err(), + "This command is only available on the Nitrokey Storage", + ); +} + +#[test_device] +fn encrypted_open_close(device: nitrokey::Storage) -> crate::Result<()> { + let mut ncli = Nitrocli::with_dev(device); + 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(&["encrypted", "close"])?; + assert!(out.is_empty()); + + let device = nitrokey::Storage::connect()?; + assert!(!device.get_status()?.encrypted_volume.active); + assert!(!device.get_status()?.hidden_volume.active); + + Ok(()) +} diff --git a/nitrocli/src/tests/lock.rs b/nitrocli/src/tests/lock.rs index 1993350..d23d2ae 100644 --- a/nitrocli/src/tests/lock.rs +++ b/nitrocli/src/tests/lock.rs @@ -31,7 +31,7 @@ fn lock_pro(device: nitrokey::Pro) -> crate::Result<()> { #[test_device] fn lock_storage(device: nitrokey::Storage) -> crate::Result<()> { let mut ncli = Nitrocli::with_dev(device); - let _ = ncli.handle(&["storage", "open"])?; + let _ = ncli.handle(&["encrypted", "open"])?; let out = ncli.handle(&["lock"])?; assert!(out.is_empty()); diff --git a/nitrocli/src/tests/mod.rs b/nitrocli/src/tests/mod.rs index 2d6f93c..70a3d20 100644 --- a/nitrocli/src/tests/mod.rs +++ b/nitrocli/src/tests/mod.rs @@ -37,6 +37,7 @@ const NITROKEY_DEFAULT_USER_PIN: &str = "123456"; fn dummy() {} mod config; +mod encrypted; mod hidden; mod lock; mod otp; @@ -45,7 +46,6 @@ mod pws; mod reset; mod run; mod status; -mod storage; /// A trait simplifying checking for expected errors. pub trait UnwrapError { diff --git a/nitrocli/src/tests/storage.rs b/nitrocli/src/tests/storage.rs deleted file mode 100644 index a1c6ecf..0000000 --- a/nitrocli/src/tests/storage.rs +++ /dev/null @@ -1,90 +0,0 @@ -// storage.rs - -// ************************************************************************* -// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) * -// * * -// * This program is free software: you can redistribute it and/or modify * -// * it under the terms of the GNU General Public License as published by * -// * the Free Software Foundation, either version 3 of the License, or * -// * (at your option) any later version. * -// * * -// * This program is distributed in the hope that it will be useful, * -// * but WITHOUT ANY WARRANTY; without even the implied warranty of * -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -// * GNU General Public License for more details. * -// * * -// * You should have received a copy of the GNU General Public License * -// * along with this program. If not, see . * -// ************************************************************************* - -use super::*; - -#[test_device] -fn status_open_close(device: nitrokey::Storage) -> crate::Result<()> { - fn make_re(open: Option) -> regex::Regex { - let encrypted = match open { - Some(open) => { - if open { - "active" - } else { - "(read-only|inactive)" - } - } - None => "(read-only|active|inactive)", - }; - let re = format!( - r#" - volumes: - unencrypted: (read-only|active|inactive) - encrypted: {} - hidden: (read-only|active|inactive) -$"#, - encrypted - ); - regex::Regex::new(&re).unwrap() - } - - let mut ncli = Nitrocli::with_dev(device); - let out = ncli.handle(&["status"])?; - assert!(make_re(None).is_match(&out), out); - - let _ = ncli.handle(&["storage", "open"])?; - let out = ncli.handle(&["status"])?; - assert!(make_re(Some(true)).is_match(&out), out); - - let _ = ncli.handle(&["storage", "close"])?; - let out = ncli.handle(&["status"])?; - assert!(make_re(Some(false)).is_match(&out), out); - - Ok(()) -} - -#[test_device] -fn encrypted_open_on_pro(device: nitrokey::Pro) { - let res = Nitrocli::with_dev(device).handle(&["storage", "open"]); - assert_eq!( - res.unwrap_str_err(), - "This command is only available on the Nitrokey Storage", - ); -} - -#[test_device] -fn encrypted_open_close(device: nitrokey::Storage) -> crate::Result<()> { - let mut ncli = Nitrocli::with_dev(device); - let out = ncli.handle(&["storage", "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"])?; - assert!(out.is_empty()); - - let device = nitrokey::Storage::connect()?; - assert!(!device.get_status()?.encrypted_volume.active); - assert!(!device.get_status()?.hidden_volume.active); - - Ok(()) -} -- cgit v1.2.3