fix asn1 parsing of dates

This commit is contained in:
iceman1001 2023-03-19 12:47:24 +01:00
commit 69e43b362e

View file

@ -123,12 +123,20 @@ static void asn1_tag_dump_str_time(const struct tlv *tlv, const struct asn1_tag
if (len > 4) { if (len > 4) {
PrintAndLogEx(NORMAL, " value: '" NOLF); PrintAndLogEx(NORMAL, " value: '" NOLF);
while (true) { while (true) {
// year // year
if (longyear == false) if (longyear == false) {
PrintAndLogEx(NORMAL, "20" NOLF); int short_year = (tlv->value[0] - '0') * 10 + (tlv->value[1] - '0');
if (short_year >= 0 && short_year <= 99) {
if (short_year > 50) {
PrintAndLogEx(NORMAL, "19" NOLF);
} else {
PrintAndLogEx(NORMAL, "20" NOLF);
}
}
}
PrintAndLogEx(NORMAL, "%.*s-" NOLF, startidx, tlv->value); PrintAndLogEx(NORMAL, "%.*s-" NOLF, startidx, tlv->value);
if (len < startidx + 2) if (len < startidx + 2)
break; break;
@ -154,11 +162,11 @@ static void asn1_tag_dump_str_time(const struct tlv *tlv, const struct asn1_tag
// sec // sec
PrintAndLogEx(NORMAL, "%.*s" NOLF, 2, tlv->value + startidx + 8); PrintAndLogEx(NORMAL, "%.*s" NOLF, 2, tlv->value + startidx + 8);
if (len < startidx + 11) if (len < startidx + 12)
break; break;
// time zone // time zone
PrintAndLogEx(NORMAL, " zone: %.*s" NOLF, len - 10 - (longyear ? 4 : 2), tlv->value + startidx + 10); PrintAndLogEx(NORMAL, " zone: %.*s" NOLF, len - startidx - 10, tlv->value + startidx + 10);
break; break;
} }
PrintAndLogEx(NORMAL, "'"); PrintAndLogEx(NORMAL, "'");