diff --git a/tests/command_response.ron b/tests/command_response.ron index 6c39720..0ff97e9 100644 --- a/tests/command_response.ron +++ b/tests/command_response.ron @@ -182,5 +182,22 @@ output: Data("53 3b 3019d4e739d821086c1084210d8360d8210842108421804210c3f33410B0BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB30839393939313233313e00fe00"), ), ] - ) + ), + IoTest( + name: "Pin and Puk", + uuid_config: WithBoth("00112233445566778899AABBCCDDEEFF"), + cmd_resp: [ + ChangePin( + new: "01020304FFFFFFFF", + ), + ChangePuk( + new: "0102030405060708", + ), + VerifyApplicationPin(pin: "0102030405060708", expected_status: RemainingRetries(2)), + ChangePuk( + old: "0102030405060708", + new: "AABBCCDDEEFF0011", + ), + ] + ), ] diff --git a/tests/command_response.rs b/tests/command_response.rs index 45f7e70..9a88b0e 100644 --- a/tests/command_response.rs +++ b/tests/command_response.rs @@ -255,6 +255,10 @@ fn default_app_pin() -> String { "313233343536FFFF".into() } +fn default_puk() -> String { + "3132333435363738".into() +} + #[derive(Deserialize, Debug)] #[serde(deny_unknown_fields)] enum IoCmd { @@ -303,6 +307,20 @@ enum IoCmd { #[serde(default)] expected_status_response: Status, }, + ChangePin { + #[serde(default = "default_app_pin")] + old: String, + new: String, + #[serde(default)] + expected_status: Status, + }, + ChangePuk { + #[serde(default = "default_puk")] + old: String, + new: String, + #[serde(default)] + expected_status: Status, + }, Select, Reset { #[serde(default)] @@ -315,6 +333,7 @@ const MATCH_ANY: OutputMatcher = OutputMatcher::All(Cow::Borrowed(&[]), ()); impl IoCmd { fn run(&self, card: &mut setup::Piv) { + println!("Running {self:?}"); match self { Self::IoData { input, @@ -354,6 +373,16 @@ impl IoCmd { key, expected_status, } => Self::run_set_administration_key(key.algorithm, &key.key, *expected_status, card), + Self::ChangePin { + old, + new, + expected_status, + } => Self::run_change_pin(old, new, *expected_status, card), + Self::ChangePuk { + old, + new, + expected_status, + } => Self::run_change_puk(old, new, *expected_status, card), Self::Select => Self::run_select(card), Self::Reset { expected_status } => Self::run_reset(*expected_status, card), } @@ -405,7 +434,7 @@ impl IoCmd { panic!("Bad output. Expected {output:02x?}"); } if status != expected_status { - panic!("Bad status. Expected {expected_status:?}"); + panic!("Bad status. Expected {expected_status:?}, got {status:?}"); } rep } @@ -534,6 +563,25 @@ impl IoCmd { fn run_reset(expected_status: Status, card: &mut setup::Piv) { Self::run_bytes(&hex!("00 FB 00 00"), &MATCH_EMPTY, expected_status, card); } + + fn run_change_pin(old: &str, new: &str, status: Status, card: &mut setup::Piv) { + let command = parse_hex(&format!("{old}{new}")); + Self::run_bytes( + &build_command(0, 0x24, 0x00, 0x80, &command, 0x00), + &MATCH_EMPTY, + status, + card, + ); + } + fn run_change_puk(old: &str, new: &str, status: Status, card: &mut setup::Piv) { + let command = parse_hex(&format!("{old}{new}")); + Self::run_bytes( + &build_command(0, 0x24, 0x00, 0x81, &command, 0x00), + &MATCH_EMPTY, + status, + card, + ); + } } #[derive(Deserialize, Debug, PartialEq, Clone)]