Skip to content

Commit 0eb2dc4

Browse files
committed
card-piv.c - fix history object
/* filename must be "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile> On branch piv-history-fix Changes to be committed: modified: card-piv.c
1 parent 24869e7 commit 0eb2dc4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libopensc/card-piv.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5084,6 +5084,10 @@ piv_process_history(sc_card_t *card)
50845084

50855085
url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
50865086
if (url) {
5087+
if (urllen > 118) {
5088+
r = SC_ERROR_INVALID_ASN1_OBJECT;
5089+
goto err;
5090+
}
50875091
priv->offCardCertURL = calloc(1,urllen+1);
50885092
if (priv->offCardCertURL == NULL)
50895093
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
@@ -5110,8 +5114,9 @@ piv_process_history(sc_card_t *card)
51105114
* the card. some of the certs may be on the card as well.
51115115
*
51125116
* Get file name from url. verify that the filename is valid
5113-
* The URL ends in a SHA1 string. We will use this as the filename
5117+
* The URL ends in a SHA-256 string. We will use this as the filename
51145118
* in the directory used for the PKCS15 cache
5119+
* "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
51155120
*/
51165121

51175122
r = 0;
@@ -5130,6 +5135,11 @@ piv_process_history(sc_card_t *card)
51305135
goto err;
51315136
}
51325137
fp++;
5138+
if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
5139+
r = SC_ERROR_INVALID_DATA;
5140+
goto err;
5141+
}
5142+
51335143

51345144
/* Use the same directory as used for other OpenSC cached items */
51355145
r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);

0 commit comments

Comments
 (0)