Skip to content

Commit

Permalink
Use nitrokey::DEFAULT_{ADMIN,USER}_PIN constants
Browse files Browse the repository at this point in the history
Since version 0.4.0, nitrokey provides the default admin and user PIN as
constants. This patch removes the constants from nitrocli and uses
nitrokey's constant instead.
  • Loading branch information
robinkrahl authored and d-e-s-o committed Dec 17, 2019
1 parent cc4a29c commit a18066a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
4 changes: 1 addition & 3 deletions nitrocli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ use crate::error::Error;
use crate::pinentry;
use crate::Result;

const NITROKEY_DEFAULT_ADMIN_PIN: &str = "12345678";

/// Create an `error::Error` with an error message of the format `msg: err`.
fn get_error(msg: &'static str, err: nitrokey::Error) -> Error {
Error::NitrokeyError(Some(msg), err)
Expand Down Expand Up @@ -387,7 +385,7 @@ pub fn reset(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
// build_aes_key after a factory reset on Pro devices.
// https://github.com/Nitrokey/nitrokey-pro-firmware/issues/57
let _ = device.get_user_retry_count();
device.build_aes_key(NITROKEY_DEFAULT_ADMIN_PIN)
device.build_aes_key(nitrokey::DEFAULT_ADMIN_PIN)
})
})
}
Expand Down
13 changes: 4 additions & 9 deletions nitrocli/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ use std::fmt;

use nitrokey_test::test as test_device;

// TODO: Those defines should potentially be taken from the `nitrokey`
// crate, once exported.
const NITROKEY_DEFAULT_ADMIN_PIN: &str = "12345678";
const NITROKEY_DEFAULT_USER_PIN: &str = "123456";

mod config;
mod encrypted;
mod hidden;
Expand Down Expand Up @@ -94,8 +89,8 @@ impl Nitrocli {
pub fn new() -> Self {
Self {
model: None,
admin_pin: Some(NITROKEY_DEFAULT_ADMIN_PIN.into()),
user_pin: Some(NITROKEY_DEFAULT_USER_PIN.into()),
admin_pin: Some(nitrokey::DEFAULT_ADMIN_PIN.into()),
user_pin: Some(nitrokey::DEFAULT_USER_PIN.into()),
new_admin_pin: None,
new_user_pin: None,
password: None,
Expand All @@ -108,8 +103,8 @@ impl Nitrocli {
{
let result = Self {
model: Some(device.get_model()),
admin_pin: Some(NITROKEY_DEFAULT_ADMIN_PIN.into()),
user_pin: Some(NITROKEY_DEFAULT_USER_PIN.into()),
admin_pin: Some(nitrokey::DEFAULT_ADMIN_PIN.into()),
user_pin: Some(nitrokey::DEFAULT_USER_PIN.into()),
new_admin_pin: None,
new_user_pin: None,
password: Some("1234567".into()),
Expand Down
8 changes: 5 additions & 3 deletions nitrocli/src/tests/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn set_user(device: nitrokey::DeviceWrapper) -> crate::Result<()> {

let device = nitrokey::connect_model(ncli.model().unwrap())?;
let (device, err) = device
.authenticate_user(NITROKEY_DEFAULT_USER_PIN)
.authenticate_user(nitrokey::DEFAULT_USER_PIN)
.unwrap_err();

match err {
Expand All @@ -60,12 +60,14 @@ fn set_user(device: nitrokey::DeviceWrapper) -> crate::Result<()> {

// Revert to the default user PIN.
ncli.user_pin("new-pin");
ncli.new_user_pin(NITROKEY_DEFAULT_USER_PIN);
ncli.new_user_pin(nitrokey::DEFAULT_USER_PIN);

let out = ncli.handle(&["pin", "set", "user"])?;
assert!(out.is_empty());

let device = nitrokey::connect_model(ncli.model().unwrap())?;
let _ = device.authenticate_user(NITROKEY_DEFAULT_USER_PIN).unwrap();
let _ = device
.authenticate_user(nitrokey::DEFAULT_USER_PIN)
.unwrap();
Ok(())
}
4 changes: 2 additions & 2 deletions nitrocli/src/tests/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ fn reset(device: nitrokey::DeviceWrapper) -> crate::Result<()> {
// Check that the admin PIN has been reset.
let device = nitrokey::connect_model(ncli.model().unwrap())?;
let device = device
.authenticate_admin(NITROKEY_DEFAULT_ADMIN_PIN)
.authenticate_admin(nitrokey::DEFAULT_ADMIN_PIN)
.unwrap();

// Check that the password store works, i.e., the AES key has been
// built.
let _ = device.get_password_safe(NITROKEY_DEFAULT_USER_PIN)?;
let _ = device.get_password_safe(nitrokey::DEFAULT_USER_PIN)?;

Ok(())
}

0 comments on commit a18066a

Please sign in to comment.