From 4ebb29ce4df6dd5d273425757a75a233e57565cc Mon Sep 17 00:00:00 2001 From: Doug Engert Date: Tue, 12 May 2020 16:20:39 -0500 Subject: [PATCH] card-piv.c error in using sc_asn1-put-tag In piv_general_mutual_authenticate sc_asn1_put_tag is not used correctly. On branch piv-sc_asn1_put_tag-error Changes to be committed: modified: card-piv.c --- src/libopensc/card-piv.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libopensc/card-piv.c b/src/libopensc/card-piv.c index 4c885a78..84736263 100644 --- a/src/libopensc/card-piv.c +++ b/src/libopensc/card-piv.c @@ -1670,28 +1670,30 @@ static int piv_general_mutual_authenticate(sc_card_t *card, } /* nonce for challenge */ - tmplen = sc_asn1_put_tag(0x81, NULL, witness_len, NULL, 0, NULL); - if (tmplen <= 0) { + r = sc_asn1_put_tag(0x81, NULL, witness_len, NULL, 0, NULL); + if (r <= 0) { r = SC_ERROR_INTERNAL; goto err; } + tmplen = r; /* plain text witness keep a length separate for the 0x7C tag */ - tmplen2 = sc_asn1_put_tag(0x80, NULL, witness_len, NULL, 0, NULL); - if (tmplen2 <= 0) { + r = sc_asn1_put_tag(0x80, NULL, witness_len, NULL, 0, NULL); + if (r <= 0) { r = SC_ERROR_INTERNAL; goto err; } - tmplen2 += tmplen; + tmplen += r; + tmplen2 = tmplen; /* outside 7C tag with 81:80 as innards */ - tmplen = sc_asn1_put_tag(0x7C, NULL, tmplen, NULL, 0, NULL); - if (tmplen <= 0) { + r = sc_asn1_put_tag(0x7C, NULL, tmplen, NULL, 0, NULL); + if (r <= 0) { r = SC_ERROR_INTERNAL; goto err; } - built_len = tmplen; + built_len = r; /* Build the response buffer */ p = built = malloc(built_len);