Implement get_private() and set_private().

This commit is contained in:
Heiko Schaefer 2021-08-22 18:59:54 +02:00
parent cb8f3c7cb1
commit 013af97c23
4 changed files with 73 additions and 5 deletions

View file

@ -40,9 +40,13 @@ fn main() -> Result<()> {
// let verify_out = run_test(&mut card, test_verify, &[])?;
// println!(" {:x?}", verify_out);
print!("PW Status bytes");
let pw_out = run_test(&mut card, test_pw_status, &[])?;
println!(" {:x?}", pw_out);
// print!("PW Status bytes");
// let pw_out = run_test(&mut card, test_pw_status, &[])?;
// println!(" {:x?}", pw_out);
print!("Private data");
let priv_out = run_test(&mut card, test_private_data, &[])?;
println!(" {:x?}", priv_out);
println!();
}

View file

@ -352,6 +352,39 @@ pub fn test_set_user_data(
Ok(vec![])
}
pub fn test_private_data(
ca: &mut CardApp,
_param: &[&str],
) -> Result<TestOutput, TestError> {
let mut out = vec![];
println!();
let d = ca.get_private(1)?;
println!("data 1 {:?}", d);
ca.verify_pw1("123456")?;
ca.set_private(1, "Foo bar1!".as_bytes().to_vec())?;
ca.set_private(3, "Foo bar3!".as_bytes().to_vec())?;
ca.verify_pw3("12345678")?;
ca.set_private(2, "Foo bar2!".as_bytes().to_vec())?;
ca.set_private(4, "Foo bar4!".as_bytes().to_vec())?;
let d = ca.get_private(1)?;
println!("data 1 {:?}", d);
let d = ca.get_private(2)?;
println!("data 2 {:?}", d);
let d = ca.get_private(3)?;
println!("data 3 {:?}", d);
let d = ca.get_private(4)?;
println!("data 4 {:?}", d);
Ok(out)
}
pub fn test_pw_status(
ca: &mut CardApp,
_param: &[&str],

View file

@ -35,6 +35,11 @@ pub(crate) fn get_application_data() -> Command {
get_data(&[0x6E])
}
/// Get DO "private use"
pub(crate) fn get_private_do(num: u8) -> Command {
get_data(&[0x01, num])
}
/// Get DO "Uniform resource locator"
pub(crate) fn get_url() -> Command {
get_data(&[0x5F, 0x50])
@ -98,6 +103,11 @@ pub(crate) fn put_data(tag: &[u8], data: Vec<u8>) -> Command {
Command::new(0x00, 0xda, p1, p2, data)
}
/// Put DO "private use"
pub(crate) fn put_private_do(num: u8, data: Vec<u8>) -> Command {
put_data(&[0x01, num], data)
}
/// PUT DO Name
pub(crate) fn put_name(name: Vec<u8>) -> Command {
put_data(&[0x5b], name)

View file

@ -93,7 +93,7 @@ impl CardApp {
.try_into()
}
// --- application data ---
// --- get data ---
/// Load "application related data".
///
@ -110,7 +110,15 @@ impl CardApp {
Ok(ApplicationRelatedData(Tlv(Tag::from([0x6E]), entry)))
}
// ---
/// Get data from "private use" DO, `num` must be between 1 and 4.
pub fn get_private(&mut self, num: u8) -> Result<Vec<u8>> {
assert!(num >= 1 && num <= 4);
let cmd = commands::get_private_do(num);
let resp = apdu::send_command(&mut self.card_client, cmd, true)?;
Ok(resp.data()?.to_vec())
}
pub fn get_ca_fingerprints() {
unimplemented!()
@ -385,6 +393,19 @@ impl CardApp {
// --- admin ---
/// Set data of "private use" DO, `num` must be between 1 and 4.
/// Access condition:
/// - 1/3 need PW1 (82)
/// - 2/4 need PW3
pub fn set_private(&mut self, num: u8, data: Vec<u8>) -> Result<Vec<u8>> {
assert!(num >= 1 && num <= 4);
let cmd = commands::put_private_do(num, data);
let resp = apdu::send_command(&mut self.card_client, cmd, true)?;
Ok(resp.data()?.to_vec())
}
pub fn set_name(
&mut self,
name: &str,