From a0c6480aa6b1c6dad45b67e5bc7c29c5f0a4bb0e Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Tue, 28 Mar 2017 20:06:42 -0700 Subject: 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. --- nitrocli/src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'nitrocli/src/main.rs') 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(()); }); } -- cgit v1.2.1