PKCS#15: prevent use of empty serial number in TokenInfo
... and initialize the serial number with the card's serial number if nothing useful is in EF.TokenInfo
This commit is contained in:
parent
e8e8153cda
commit
b403934718
|
@ -207,7 +207,7 @@ int sc_pkcs15_parse_tokeninfo(sc_context_t *ctx,
|
|||
r = sc_asn1_decode(ctx, asn1_tokeninfo, buf, blen, NULL, NULL);
|
||||
LOG_TEST_RET(ctx, r, "ASN.1 parsing of EF(TokenInfo) failed");
|
||||
|
||||
if (asn1_toki_attrs[1].flags & SC_ASN1_PRESENT) {
|
||||
if (asn1_toki_attrs[1].flags & SC_ASN1_PRESENT && serial_len > 0) {
|
||||
ti->serial_number = malloc(serial_len * 2 + 1);
|
||||
if (ti->serial_number == NULL)
|
||||
return SC_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -1188,6 +1188,10 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
|
|||
|
||||
*(p15card->tokeninfo) = tokeninfo;
|
||||
|
||||
if (!p15card->tokeninfo->serial_number && 0 == card->serialnr.len) {
|
||||
sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &card->serialnr);
|
||||
}
|
||||
|
||||
if (!p15card->tokeninfo->serial_number && card->serialnr.len) {
|
||||
char *serial = calloc(1, card->serialnr.len*2 + 1);
|
||||
size_t ii;
|
||||
|
|
Loading…
Reference in New Issue