lapo-luchini / asn1js

JavaScript generic ASN.1 parser
ISC License
586 stars 161 forks source link

fix: don't throw exception on invalid BitString and Utf8String #70

Closed dishmaker closed 6 months ago

dishmaker commented 1 year ago

So there is an ISO/RFC example with 2 invalid ASN.1 values: BIT STRING and UTF8String All the other tags are valid.

With throw new Error(...) the ASN.1 JS Decoder wouldn't show anything. And yes, they really put an invalid example in kinda-new ISO/IEC from 2016.

Thanks for the awesome project.

Here's how it looks like parsed now:

obraz

lapo-luchini commented 8 months ago

Hi! I'm very sorry, I didn't properly read your PR until today. 😢 Things have changed re: this behavior in 8f048accac80bc166a24325d53b49a504144e7af. Can you provide the "broken" RFC example so that I can test it myself, too?

dishmaker commented 6 months ago

Can you provide the "broken" RFC example so that I can test it myself, too?

ISO/IEC 7816-15

A0 82 01 1A 30 50 30 26  0C 0F 47 6C 6F 62 61 6C
20 50 61 73 73 77 6F 72  64 03 01 00 04 01 03 30
0D 30 0B 03 01 00 30 06  03 01 80 02 01 02 30 09
04 01 01 02 01 01 80 01  02 A1 1B 30 19 03 01 00
0A 01 00 02 01 04 02 01  00 02 01 08 80 01 01 04
01 00 30 02 04 00 30 5A  30 29 0C 12 53 69 67 6E
61 74 75 72 65 20 50 61  73 73 77 6F 72 64 03 01
00 04 01 00 30 0D 30 0B  03 01 00 30 06 03 01 80
02 01 02 30 0A 04 01 02  02 02 00 81 80 01 02 A1
21 30 1F 03 02 06 40 0A  01 00 02 01 06 02 01 00
02 01 08 80 02 00 81 04  01 00 30 06 04 04 3F 00
3F 01 30 6A 30 3D 0C 26  52 65 73 65 74 74 69 6E
67 20 43 6F 64 65 20 66  6F 72 20 74 68 65 20 47
6C 6F 62 61 6C 20 50 61  73 73 77 6F 72 64 03 01
00 04 01 03 30 0D 30 0B  03 01 00 30 06 03 01 80
02 01 02 30 0A 04 01 03  02 02 00 81 80 01 02 A1
1D 30 1B 03 02 06 40 0A  01 00 02 01 08 02 01 00
02 01 08 80 02 00 81 04  01 00 30 02 04 00 
A0 62 A0 60 30 44 0C 0F  44 69 73 70 6C 61 79 20
4D 65 73 73 61 67 65 03  01 80 30 2E 30 1F 03 01
00 A2 1A A1 0B 04 01 01  30 06 03 01 00 02 01 01
A1 0B 04 01 01 30 06 03  01 80 02 01 02 30 0B 03
01 80 30 06 03 01 80 02  01 02 30 0C 0C 0A A0 00
00 01 67 45 53 49 47 4E  A1 0A 30 08 04 06 3F 00
3F 01 D0 00