Skip to content

Commit

Permalink
Remove obsolete now RenameCredential
Browse files Browse the repository at this point in the history
  • Loading branch information
szszszsz committed Aug 16, 2023
1 parent 880a418 commit 0a5ecb7
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 64 deletions.
58 changes: 1 addition & 57 deletions src/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use core::time::Duration;
use flexiber::EncodableHeapless;
use heapless_bytes::Bytes;
use iso7816::{Data, Status};
use trussed::types::Location;
use trussed::types::{KeyId, Message};
use trussed::types::{Location, ShortData};
use trussed::{self, client, syscall, try_syscall};

use crate::calculate::hmac_challenge;
Expand Down Expand Up @@ -316,7 +316,6 @@ where
Command::Register(register) => self.register(register),
Command::Calculate(calculate) => self.calculate(calculate, reply),
Command::GetCredential(get) => self.get_credential(get, reply),
Command::RenameCredential(rename) => self.rename_credential(rename, reply),
Command::UpdateCredential(update) => self.update_credential(update, reply),
#[cfg(feature = "calculate-all")]
Command::CalculateAll(calculate_all) => self.calculate_all(calculate_all, reply),
Expand Down Expand Up @@ -863,61 +862,6 @@ where
Ok(())
}

/// Rename credential
///
/// Realized by loading FlatCredential object, changing its label,
/// writing under the new name and removing the previous file.
///
/// Requires button confirmation before starting.
///
/// returns: no data, except for the result code
/// Errors:
/// - OperationBlocked if the new name is occupied already (checked by name hash)
/// - NotFound, if the current credential can't be open (e.g. due to key not available) or deserialized
/// - UnspecifiedNonpersistentExecutionError, if the old file cannot be removed, or serialization error
/// - NotEnoughMemory, if new file cannot be written
/// - SecurityStatusNotSatisfied, if the encryption key cannot be fetched
fn rename_credential<const R: usize>(
&mut self,
rename_req: command::RenameCredential<'_>,
_reply: &mut Data<R>,
) -> Result {
// DESIGN Get operation confirmation from user before proceeding
self.user_present()?;

// DESIGN check if the target name is occupied already
self.err_if_credential_with_label_exists(rename_req.new_label)?;
if !self.credential_with_label_exists(rename_req.label)? {
return Err(Status::NotFound);
}

let credential = {
let mut c = self
.load_credential(rename_req.label)
.ok_or(Status::NotFound)?;
c.label =
ShortData::from_slice(rename_req.new_label).map_err(|_| Status::NotEnoughMemory)?;
c
};

// Serialize the credential (implicitly) and store it
let filename = self.filename_for_label(rename_req.new_label);
self.state.try_write_file(
&mut self.trussed,
filename,
&credential,
credential.encryption_key_type,
)?;

// Remove old file name
let filename_old = self.filename_for_label(rename_req.label);
try_syscall!(self
.trussed
.remove_file(self.options.location, filename_old))
.map_err(|_| Status::UnspecifiedNonpersistentExecutionError)?;
Ok(())
}

fn get_credential<const R: usize>(
&mut self,
get_credential_req: command::GetCredential<'_>,
Expand Down
5 changes: 0 additions & 5 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ pub enum Command<'l> {
SendRemaining,
/// Get Credential data
GetCredential(GetCredential<'l>),
/// Rename Credential
RenameCredential(RenameCredential<'l>),
/// Update Credential
UpdateCredential(CredentialUpdate<'l>),
/// Return serial number of the device. Yubikey-compatible command. Used in KeepassXC.
Expand Down Expand Up @@ -971,9 +969,6 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
(0x00, oath::Instruction::GetCredential, 0x00, 0x00) => {
Self::GetCredential(GetCredential::try_from(data)?)
}
(0x00, oath::Instruction::RenameCredential, 0x00, 0x00) => {
Self::RenameCredential(RenameCredential::try_from(data)?)
}
(0x00, oath::Instruction::CredentialUpdate, 0x00, 0x00) => {
Self::UpdateCredential(CredentialUpdate::try_from(data)?)
}
Expand Down
2 changes: 0 additions & 2 deletions src/oath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ pub enum Instruction {
ChangePIN = 0xb3,
SetPIN = 0xb4,
GetCredential = 0xb5,
RenameCredential = 0xb6,
CredentialUpdate = 0xb7,
}

Expand All @@ -225,7 +224,6 @@ impl TryFrom<u8> for Instruction {
0xb3 => ChangePIN,
0xb4 => SetPIN,
0xb5 => GetCredential,
0xb6 => RenameCredential,
0xb7 => CredentialUpdate,
_ => return Err(Self::Error::InstructionNotSupportedOrInvalid),
})
Expand Down

0 comments on commit 0a5ecb7

Please sign in to comment.