aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/main.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2017-03-28 20:06:42 -0700
committerDaniel Mueller <deso@posteo.net>2017-03-28 20:06:42 -0700
commita0c6480aa6b1c6dad45b67e5bc7c29c5f0a4bb0e (patch)
treeb8698743b3d77b23147a49fd15a8d313340c1a8b /nitrocli/src/main.rs
parentfdd34d1ac10e37b3e0683a3c716665f50684596b (diff)
downloadnitrocli-a0c6480aa6b1c6dad45b67e5bc7c29c5f0a4bb0e.tar.gz
nitrocli-a0c6480aa6b1c6dad45b67e5bc7c29c5f0a4bb0e.tar.bz2
Send HID feature report to open/close the encrypted volume
With this change we assemble a HID feature report and send it to the nitrokey device. Feature reports are the objects used for sending commands to the nitrokey. We create two different reports for opening and closing of the encrypted volume.
Diffstat (limited to 'nitrocli/src/main.rs')
-rw-r--r--nitrocli/src/main.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/nitrocli/src/main.rs b/nitrocli/src/main.rs
index bdbfe37..700204d 100644
--- a/nitrocli/src/main.rs
+++ b/nitrocli/src/main.rs
@@ -26,8 +26,10 @@
extern crate hid as libhid;
+mod crc32;
mod error;
mod nitrokey;
+mod pinentry;
use error::Error;
use std::process;
@@ -54,7 +56,11 @@ fn nitrokey_do(function: &NitroFunc) -> Result<()> {
/// Open the encrypted volume on the nitrokey.
fn open() -> Result<()> {
return nitrokey_do(&|handle| {
- println!("Found nitrokey. Opening encrypted volume...");
+ let passphrase = pinentry::inquire_passphrase()?;
+ let payload = nitrokey::EnableEncryptedVolumeCommand::new(&passphrase);
+ let report = nitrokey::Report::from(payload);
+
+ handle.feature().send_to(0, report.as_ref())?;
return Ok(());
});
}
@@ -63,7 +69,10 @@ fn open() -> Result<()> {
/// Close the previously opened encrypted volume.
fn close() -> Result<()> {
return nitrokey_do(&|handle| {
- println!("Found nitrokey. Closing encrypted volume...");
+ let payload = nitrokey::DisableEncryptedVolumeCommand::new();
+ let report = nitrokey::Report::from(payload);
+
+ handle.feature().send_to(0, report.as_ref())?;
return Ok(());
});
}