Skip to content

Commit

Permalink
Return 6285 for SELECT in termination state
Browse files Browse the repository at this point in the history
This patch changes the status code for SELECT APDUs to 6285 if the card
is in termination/initialization state.

Fixes: #154
  • Loading branch information
robin-nitrokey committed May 2, 2023
1 parent e4ae7a5 commit a68340d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ SPDX-License-Identifier: CC0-1.0

## Unreleased

### Bugfixes

- Return status 6285 if SELECT is called in termination state ([#154][])

[#154]: https://github.com/Nitrokey/opcard-rs/issues/154

## [v1.0.0][] (2023-04-27)

- Add support for larger storage for certificates and private use data objects ([#150][])
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ log-warn = []
log-error = []

[patch.crates-io]
iso7816 = { git = "https://github.com/Nitrokey/iso7816.git", rev = "refs/pull/1/head" }
p256-cortex-m4 = { git = "https://github.com/Nitrokey/p256-cortex-m4", tag = "v0.1.0-alpha.6-nitrokey-1" }
trussed = { git = "https://github.com/trussed-dev/trussed" , rev = "55ea391367fce4bf5093ff2d3c79041d7aef0485" }
trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth.git", tag = "v0.2.2"}
Expand Down
14 changes: 8 additions & 6 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,16 @@ impl Command {
&self,
mut ctx: Context<'_, R, T>,
) -> Result<(), Status> {
if !self.can_lifecycle_run(State::lifecycle(
ctx.backend.client_mut(),
ctx.options.storage,
)) {
let lifecycle = State::lifecycle(ctx.backend.client_mut(), ctx.options.storage);
if !self.can_lifecycle_run(lifecycle) {
warn!(
"Command {self:?} called in lifecycle {:?}",
State::lifecycle(ctx.backend.client_mut(), ctx.options.storage)
);
return Err(Status::ConditionsOfUseNotSatisfied);
}
match self {
Self::Select => select(ctx),
Self::Select => select(ctx, lifecycle),
Self::GetData(mode, tag) => data::get_data(ctx, *mode, *tag),
Self::GetNextData(tag) => data::get_next_data(ctx, *tag),
Self::PutData(mode, tag) => data::put_data(ctx, *mode, *tag),
Expand Down Expand Up @@ -338,11 +336,15 @@ impl TryFrom<u8> for ManageSecurityEnvironmentMode {
// § 7.2.1
fn select<const R: usize, T: crate::card::Client>(
context: Context<'_, R, T>,
lifecycle: LifeCycle,
) -> Result<(), Status> {
if context.data.starts_with(&RID) {
context.state.volatile.cur_do = None;
context.state.volatile.keyrefs = Default::default();
Ok(())
match lifecycle {
LifeCycle::Operational => Ok(()),
LifeCycle::Initialization => Err(Status::SelectedFileInTerminationState),
}
} else {
info!("Selected application {:x?} not found", context.data);
Err(Status::NotFound)
Expand Down

0 comments on commit a68340d

Please sign in to comment.