Skip to content

Commit

Permalink
Require PIN for registering an hotp credential
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Apr 24, 2024
1 parent 6eff6f9 commit 674b981
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::command::CredentialData::HmacData;
use crate::command::{Credential, EncryptionKeyType, ListCredentials, VerifyCode, YkGetHmac};
use crate::credential::CredentialFlat;

use crate::oath::Kind;
use crate::{
command, ensure, oath,
state::{CommandState, State},
Expand Down Expand Up @@ -626,6 +627,12 @@ where
// 2. Generate a filename for the credential
let filename = self.filename_for_label(&credential.label);

// 2.5 Require PIN to have been verified before creating an ReverseHOTP credential
if credential.kind == Kind::HotpReverse && !self.state.runtime.client_authorized {
warn_now!("Attempt to create ReverseHOTP credential without authentication");
return Err(Status::SecurityStatusNotSatisfied);
}

// 3. Serialize the credential (implicitly) and store it
let write_res = self.state.try_write_file(
&mut self.trussed,
Expand Down
6 changes: 6 additions & 0 deletions src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ impl CredentialFlat {

/// Update credential fields with new values, and save
pub fn update_from(&mut self, update_req: UpdateCredential) -> Result<(), Status> {
// Updating ReverseHOTP is disabled without PIN
if matches!(self.kind, Kind::HotpReverse) {
warn_now!("Attempt to update ReverseHOTP credential");
return Err(Status::ConditionsOfUseNotSatisfied);
}

if let Some(new_label) = update_req.new_label {
self.label = ShortData::from_slice(new_label).map_err(|_| Status::NotEnoughMemory)?;
}
Expand Down

0 comments on commit 674b981

Please sign in to comment.