[go: up one dir, main page]

Skip to content

Commit

Permalink
idprime: fallback to 2 byte key_id
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrd2 committed May 17, 2021
1 parent c43c83a commit 55f3c4d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/libopensc/card-idprime.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef struct idprime_object {
unsigned short length;
u8 key_id[8];
u8 key_label[64];
u8 key_len;
} idprime_object_t;

/*
Expand Down Expand Up @@ -262,6 +263,7 @@ static int idprime_pubfile_extract(sc_card_t *card, idprime_object_t *obj, uint8
return -1;
/* copy key id - first byte is length: 8 bytes */
memcpy(obj->key_id, buf + 1, 8);
obj->key_len = 8;
return 0;
}
}
Expand Down Expand Up @@ -387,6 +389,7 @@ static int idprime_process_index(sc_card_t *card, idprime_private_data_t *priv,
static u8 pub[] = "pubxxxNNp11";
memcpy(&pub[3], &start[4], 5);
*new_object.key_id = 0;
new_object.key_len = 0;

for (int pki = 0; pki < num_entries; pki++) {
u8 *pub_start = &buf[pki * 21 + 1];
Expand All @@ -395,10 +398,10 @@ static int idprime_process_index(sc_card_t *card, idprime_private_data_t *priv,
break;
}
}
if (new_object.key_id[0] == 0) {
memset(new_object.key_id, 0, 6);
new_object.key_id[6] = (new_object.fd >> 8) & 0xff;
new_object.key_id[7] = new_object.fd & 0xff;
if (new_object.key_len == 0) {
new_object.key_id[0] = (new_object.fd >> 8) & 0xff;
new_object.key_id[1] = new_object.fd & 0xff;
new_object.key_len = 2;
}

idprime_add_object_to_list(&priv->pki_list, &new_object);
Expand Down Expand Up @@ -570,7 +573,7 @@ static int idprime_fill_prkey_info(list_t *list, idprime_object_t **entry, sc_pk
prkey_info->path.count = -1;

memcpy(prkey_info->id.value, (*entry)->key_id, 8);
prkey_info->id.len = 8;
prkey_info->id.len = (*entry)->key_len;
prkey_info->key_reference = (*entry)->key_reference;

/* TODO: this is ugly - pkcs15-idprime will set it to NULL */
Expand Down

0 comments on commit 55f3c4d

Please sign in to comment.