-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and fix response formatting
- Loading branch information
1 parent
4ce0c8b
commit 71cc9a8
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2022 Nitrokey GmbH | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
#![cfg(feature = "virtual")] | ||
|
||
use hex_literal::hex; | ||
|
||
#[test_log::test] | ||
fn command_response() { | ||
trussed::virt::with_ram_client("opcard", |client| { | ||
let mut card = opcard::Card::new(client, opcard::Options::default()); | ||
let reset_command: iso7816::Command<4> = | ||
iso7816::Command::try_from(&hex!("00 44 0000")).unwrap(); | ||
let mut rep: heapless::Vec<u8, 0> = heapless::Vec::new(); | ||
card.handle(&reset_command, &mut rep).unwrap(); | ||
rep.clear(); | ||
|
||
let admin_pin_cmd: iso7816::Command<32> = | ||
iso7816::Command::try_from(hex!("00200083 08 3132333435363738").as_slice()).unwrap(); | ||
card.handle(&admin_pin_cmd, &mut rep).unwrap(); | ||
rep.clear(); | ||
|
||
let user_pin_cmd: iso7816::Command<32> = | ||
iso7816::Command::try_from(hex!("00200082 06 313233343536").as_slice()).unwrap(); | ||
card.handle(&user_pin_cmd, &mut rep).unwrap(); | ||
|
||
let mut set_aes_key = Vec::from(hex!("0C DA 00D5 20 ")); | ||
set_aes_key.extend_from_slice(&[0; 32]); | ||
let import_cmd: iso7816::Command<32> = iso7816::Command::try_from(&set_aes_key).unwrap(); | ||
card.handle(&import_cmd, &mut rep).unwrap(); | ||
|
||
let encrypt_aes = Vec::from(hex!("00 2A 86 80 10 00112233445566778899AABBCCDDEEFF 00")); | ||
let encrypt_cmd: iso7816::Command<16> = iso7816::Command::try_from(&encrypt_aes).unwrap(); | ||
let mut rep: heapless::Vec<u8, 17> = heapless::Vec::new(); | ||
card.handle(&encrypt_cmd, &mut rep).unwrap(); | ||
assert_eq!(rep, hex!("02 1c060f4c9e7ea8d6ca961a2d64c05c18")); | ||
|
||
let mut decrypt_aes = Vec::from(hex!("00 2A 80 86 11")); | ||
decrypt_aes.extend_from_slice(&rep); | ||
decrypt_aes.push(0x00); | ||
|
||
let decrypt_cmd: iso7816::Command<17> = iso7816::Command::try_from(&decrypt_aes).unwrap(); | ||
let mut rep: heapless::Vec<u8, 16> = heapless::Vec::new(); | ||
card.handle(&decrypt_cmd, &mut rep).unwrap(); | ||
assert_eq!(rep, hex!("00112233445566778899AABBCCDDEEFF")); | ||
}) | ||
} |