BER-TLV open source library for Objective-C

objective-c, smartcard, tlv

Solution

Here is a project decode the ASN.1 BER format. https://github.com/chrisridd/asn1-dump/

main logic located in this file: https://github.com/chrisridd/asn1-dump/blob/master/berd.m

And if have enough time, it's not hard to write you own decoder after you read the standard: http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf http://luca.ntop.org/Teaching/Appunti/asn1.html

decode flow is like this: read in Tag, Length, Value sequence.

From Tag you will get

- Data Class, usually be Universal(predefined type in standard like "Boolean","Sequence"...) and context-specific (to distinguish different field with same type).

- Primitive (like boolean and integer) or Constructed (usually is sequence). because constructed type can contains Primitive or Constructed type. maybe need recursive decoding.

- Tag Number, determine data types (boolean? integer? bitstring?)

Length:

- determine length of the contents to decode into (maybe need recursively decoding).

- length has two form (short and long). you'd better support both.

Value: the real value to read in current TLV level. if this is a constructed data(like sequence), the Value will contains internal level of TLV.

In the end of standard (http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf) there is an image shows multiple level TLV, maybe can better help you to understand BER.

After you read the standards, the best way is: 1) find some GUI viewer to look some BER Certificate file, to get familar with it. google "ASN.1 viewer" to find. 2) start to look the code https://github.com/chrisridd/asn1-dump/blob/master/berd.m

Problem

I intend to parse BER-TLV format from smart card response to interpret the data. it similar like JACCAL, but in Objective-C or C++ Can anyone give reference any open source project or any reference to do this?

Original source