When the card doesn't support command chaining, throw CommandTooLong error if the command is too long.

(This currently happens with the scdc backend when uploading rsa4096 keys, because scdc additionally limits command size)
This commit is contained in:
Heiko Schaefer 2021-07-29 18:09:46 +02:00
parent dbf2e9e3fb
commit 56f4459932
2 changed files with 11 additions and 0 deletions

View file

@ -183,6 +183,14 @@ fn send_command_low_level(
} else { } else {
let serialized = cmd.serialize(ext)?; let serialized = cmd.serialize(ext)?;
// Can't send this command to the card, because it is too long and
// the card doesn't support command chaining.
if serialized.len() > max_cmd_bytes {
return Err(OpenpgpCardError::CommandTooLong(serialized.len()));
}
log::debug!(" -> APDU command: {:x?}", &serialized);
let resp = card_client.transmit(&serialized, buf_size)?; let resp = card_client.transmit(&serialized, buf_size)?;
log::debug!(" <- APDU response: {:x?}", resp); log::debug!(" <- APDU response: {:x?}", resp);

View file

@ -11,6 +11,9 @@ pub enum OpenpgpCardError {
#[error("OpenPGP card error status {0}")] #[error("OpenPGP card error status {0}")]
OcStatus(OcErrorStatus), OcStatus(OcErrorStatus),
#[error("Command too long ({0} bytes)")]
CommandTooLong(usize),
#[error("Internal error {0}")] #[error("Internal error {0}")]
InternalError(anyhow::Error), InternalError(anyhow::Error),
} }