aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-06-25 07:14:26 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-06-25 07:14:26 +0200
commita1bf5c43e7d5faf9a1650ba1e7fd25ef46736b84 (patch)
treee3a9fa34a52f0af8afd5655dd425e0d4069330b5
parent4807dd9b21bf48b8a203abe53c5c36b9ecc8c038 (diff)
Fix BER decoding for the long form
The below ASN1 was parsed as "long form" even if it is not the long form. The highest bit indicates if it is the long form or the indefinite form. The below was going through the long form path but there is no long form in it. Change the long form code but don't verify it. It might still be broken. [98, 87, 130, 2, 120, 33, 131, 2, 127, 255, 132, 16, 160, 0, 0, 0, 135, 16, 2, 255, 255, 255, 255, 137, 7, 9, 0, 0, 165, 22, 131, 2, 127, 255, 203, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 202, 1, 128, 138, 1, 5, 171, 21, 128, 1, 1, 164, 6, 131, 1, 10, 149, 1, 8, 128, 1, 64, 151, 0, 128, 1, 6, 144, 0, 198, 9, 144, 1, 64, 131, 1, 1, 131, 1, 129]
-rw-r--r--card/utils.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/card/utils.py b/card/utils.py
index 05e7a9e..3c1b1f1 100644
--- a/card/utils.py
+++ b/card/utils.py
@@ -163,8 +163,8 @@ def first_BERTLV_parser(bytelist):
Tag_num += Tag_bits[len(Tag_bits)-j-1] * pow(2, j)
# Length coded with more than 1 byte
- if bytelist[i+1] > 0x50:
- Len_num = bytelist[i+1] - 0x50
+ if bytelist[i+1] & 0x80 > 0:
+ Len_num = bytelist[i+1] - 0x80
Len_bytes = bytelist[i+2:i+1+Len_num]
Len = 0
for j in range(len(Len_bytes)):