Skip to content

Commit

Permalink
fix: Force extended length apdu for export object
Browse files Browse the repository at this point in the history
Basically the SE050 will never respond with more than 256 bytes when responding to a short apdu
This was not an issue previously since we only ever exported keys that were smaller than that.
  • Loading branch information
sosthene-nitrokey committed Aug 9, 2024
1 parent 2e1adc4 commit e0ebd7e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions generate_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def flatten(items):
p2 = v["p2"]
p2_val = p2
le = v.get("le", 0)
force_extended = v.get("force_extended", False)

payload_has_lifetime = False
for _, a in flatten(v["payload"].items()):
Expand Down Expand Up @@ -203,6 +204,8 @@ def flatten(items):
slice_val = "&[" + slice_val_inner + "]"

command_builder = f'CommandBuilder::new({cla}, {ins}, {p1_val}, {p2_val}, __data, {le})'
if force_extended:
command_builder = f'{command_builder}.force_extended()'

outfile.write(f'impl{payload_lifetime} DataSource for {name}{payload_lifetime} {{\n')
outfile.write(' fn len(&self) -> usize {\n')
Expand Down
6 changes: 4 additions & 2 deletions src/se05x/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,8 @@ impl DataSource for ExportObject {
let object_id = &Tlv::new(TAG_1, self.object_id);
let rsa_key_component = &Tlv::new(TAG_2, self.rsa_key_component);
let __data: &[&dyn DataSource] = &[object_id, rsa_key_component];
let command = CommandBuilder::new(NO_SM_CLA, INS_READ, P1_DEFAULT, P2_EXPORT, __data, 256);
let command = CommandBuilder::new(NO_SM_CLA, INS_READ, P1_DEFAULT, P2_EXPORT, __data, 256)
.force_extended();
command.len()
}
fn is_empty(&self) -> bool {
Expand All @@ -1636,7 +1637,8 @@ impl<W: Writer> DataStream<W> for ExportObject {
let object_id = &Tlv::new(TAG_1, self.object_id);
let rsa_key_component = &Tlv::new(TAG_2, self.rsa_key_component);
let __data: &[&dyn DataStream<W>] = &[object_id, rsa_key_component];
let command = CommandBuilder::new(NO_SM_CLA, INS_READ, P1_DEFAULT, P2_EXPORT, __data, 256);
let command = CommandBuilder::new(NO_SM_CLA, INS_READ, P1_DEFAULT, P2_EXPORT, __data, 256)
.force_extended();
command.to_writer(writer)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/se05x/commands.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ ins = "INS_READ"
p1 = "P1_DEFAULT"
p2 = "P2_EXPORT"
le = "256"
force_extended = true

[export_object.payload]
TAG_1 = { name = "object_id", type = "ObjectId" }
Expand Down

0 comments on commit e0ebd7e

Please sign in to comment.