Minor cleanups

This commit is contained in:
Jack Grigg
2019-12-02 02:31:33 +00:00
parent ada3454d26
commit 76c093e68e
2 changed files with 6 additions and 5 deletions
+2 -3
View File
@@ -422,7 +422,6 @@ pub fn generate(
pin_policy: PinPolicy, pin_policy: PinPolicy,
touch_policy: TouchPolicy, touch_policy: TouchPolicy,
) -> Result<GeneratedKey, Error> { ) -> Result<GeneratedKey, Error> {
let mut templ = [0, Ins::GenerateAsymmetric.code(), 0, 0];
let setting_roca: settings::BoolValue; let setting_roca: settings::BoolValue;
match algorithm { match algorithm {
@@ -470,7 +469,7 @@ pub fn generate(
let txn = yubikey.begin_transaction()?; let txn = yubikey.begin_transaction()?;
templ[3] = slot.into(); let templ = [0, Ins::GenerateAsymmetric.code(), 0, slot.into()];
let mut in_data = [0u8; 11]; let mut in_data = [0u8; 11];
in_data[0] = 0xac; in_data[0] = 0xac;
@@ -512,7 +511,7 @@ pub fn generate(
return Err(Error::AuthenticationError); return Err(Error::AuthenticationError);
} }
other => { other => {
error!("{} (error {:x})", err_msg, other.code()); error!("{} (error {:?})", err_msg, other);
return Err(Error::GenericError); return Err(Error::GenericError);
} }
} }
+4 -2
View File
@@ -227,10 +227,12 @@ impl YubiKey {
pub fn authenticate(&mut self, mgm_key: MgmKey) -> Result<(), Error> { pub fn authenticate(&mut self, mgm_key: MgmKey) -> Result<(), Error> {
let txn = self.begin_transaction()?; let txn = self.begin_transaction()?;
const TAG_DYN_AUTH: u8 = 0x7c;
// get a challenge from the card // get a challenge from the card
let challenge = APDU::new(Ins::Authenticate) let challenge = APDU::new(Ins::Authenticate)
.params(YKPIV_ALGO_3DES, YKPIV_KEY_CARDMGM) .params(YKPIV_ALGO_3DES, YKPIV_KEY_CARDMGM)
.data(&[0x7c, 0x02, 0x80, 0x00]) .data(&[TAG_DYN_AUTH, 0x02, 0x80, 0x00])
.transmit(&txn, 261)?; .transmit(&txn, 261)?;
if !challenge.is_success() || challenge.data().len() < 12 { if !challenge.is_success() || challenge.data().len() < 12 {
@@ -241,7 +243,7 @@ impl YubiKey {
let response = mgm_key.decrypt(challenge.data()[4..12].try_into().unwrap()); let response = mgm_key.decrypt(challenge.data()[4..12].try_into().unwrap());
let mut data = [0u8; 22]; let mut data = [0u8; 22];
data[0] = 0x7c; data[0] = TAG_DYN_AUTH;
data[1] = 20; // 2 + 8 + 2 +8 data[1] = 20; // 2 + 8 + 2 +8
data[2] = 0x80; data[2] = 0x80;
data[3] = 8; data[3] = 8;