Skip to content

Commit

Permalink
fix policy parsing in PIV
Browse files Browse the repository at this point in the history
  • Loading branch information
z4yx committed Oct 13, 2023
1 parent 3c2110b commit ef165a0
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions src/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,38 @@ int ck_encode_public_key(const ck_key_t *key, uint8_t *buf, bool include_length)
int ck_parse_piv_policies(ck_key_t *key, const uint8_t *buf, size_t buf_len) {
const uint8_t *end = buf + buf_len;

if (buf < end) {
DBG_MSG("May have pin policy\n");
if (buf < end && *buf++ != 0xAA) {
DBG_MSG("Wrong tag for pin policy\n");
return KEY_ERR_DATA;
}
if (buf < end && *buf++ != 0x01) {
DBG_MSG("Wrong length for pin policy\n");
return KEY_ERR_LENGTH;
}
if (buf < end && (*buf > PIN_POLICY_ALWAYS || *buf < PIN_POLICY_NEVER)) {
DBG_MSG("Wrong data for pin policy\n");
return KEY_ERR_DATA;
}
key->meta.pin_policy = *buf++;
}

if (buf < end) {
DBG_MSG("May have touch policy\n");
if (buf < end && *buf++ != 0xAB) {
DBG_MSG("Wrong tag for touch policy\n");
return KEY_ERR_DATA;
}
if (buf < end && *buf++ != 0x01) {
DBG_MSG("Wrong length for touch policy\n");
return KEY_ERR_LENGTH;
}
if (buf < end && (*buf > TOUCH_POLICY_CACHED || *buf < TOUCH_POLICY_NEVER)) {
DBG_MSG("Wrong data for touch policy\n");
return KEY_ERR_DATA;
while (buf < end) {
switch (*buf++) {
case 0xAA:
DBG_MSG("May have pin policy\n");
if (buf < end && *buf++ != 0x01) {
DBG_MSG("Wrong length for pin policy\n");
return KEY_ERR_LENGTH;
}
if (buf < end && (*buf > PIN_POLICY_ALWAYS || *buf < PIN_POLICY_NEVER)) {
DBG_MSG("Wrong data for pin policy\n");
return KEY_ERR_DATA;
}
key->meta.pin_policy = *buf++;
break;

case 0xAB:
DBG_MSG("May have touch policy\n");
if (buf < end && *buf++ != 0x01) {
DBG_MSG("Wrong length for touch policy\n");
return KEY_ERR_LENGTH;
}
if (buf < end && (*buf > TOUCH_POLICY_CACHED || *buf < TOUCH_POLICY_NEVER)) {
DBG_MSG("Wrong data for touch policy\n");
return KEY_ERR_DATA;
}
key->meta.touch_policy = *buf++;
break;

default:
buf = end;
break;
}
key->meta.touch_policy = *buf++;
}

return 0;
Expand Down

0 comments on commit ef165a0

Please sign in to comment.