parsing DER format data using SecAsn1Decode

Hi,


I'm working on the output of method `distinguishedNames` that available under challenge.protectionSpace when my application receieve callback from the server (didReceieveChallenge) of type NSURLAuthenticationMethodClientCertificate. In this case the server ask for certificate from the client that was signed by issuer from the issuersList provided by the server.


The method challenge.protectionSpace.distinguishedNames returns as a DER encoded data, and I wish to decode it and get the issuer distiguished name.


Since openssl is no longer native mac code, i turned to SecAsn1Decode and realized that it also expect to have a template of the DER format (SecAsn1Template).. so I pretty much need to have the formatted layout before I want to decode an instance formatted in this way.


Conceptually, I'm not sure I understand why this template is really needed, because the DER format explain the format by itself.


I've tested my assumption by copying the output of distinguishedNames and using asn.1 online converter to human readble text, and it revealed the format by itself.


here's the input :


30 81 8E 31 0B 30 09 06 03 55 04 06 13 02 49 49

31 0F 30 0D 06 03 55 04 08 0C 06 62 62 62 62 62

6C 31 0C 30 0A 06 03 55 04 07 0C 03 54 4C 56 31

0B 30 09 06 03 55 04 0A 0C 02 54 53 31 1E 30 1C

06 03 55 04 0B 0C 15 43 41 5F 63 65 72 74 69 66

69 63 61 74 65 5F 73 65 72 76 65 72 31 1B 30 19

06 03 55 04 03 0C 12 62 62 62 62 62 73 5F 4D 61

63 42 6F 6F 6B 5F 50 72 6F 31 16 30 14 06 09 2A

86 48 86 F7 0D 01 09 01 16 07 7A 40 7A 2E 63 6F

6D


and the output :


SEQUENCE (7 elem)

SET (1 elem)
SEQUENCE (2 elem)

OBJECT IDENTIFIER 2.5.4.6 countryName (X.520 DN component)

PrintableString II

SET (1 elem)
SEQUENCE (2 elem)

OBJECT IDENTIFIER 2.5.4.8 stateOrProvinceName (X.520 DN component)

UTF8String bbbbbl

SET (1 elem)
SEQUENCE (2 elem)

OBJECT IDENTIFIER 2.5.4.7 localityName (X.520 DN component)

UTF8String TLV

SET (1 elem)
SEQUENCE (2 elem)

OBJECT IDENTIFIER 2.5.4.10 organizationName (X.520 DN component)

UTF8String TS

SET (1 elem)
SEQUENCE (2 elem)

OBJECT IDENTIFIER 2.5.4.11 organizationalUnitName (X.520 DN component)

UTF8String CA_certificate_server

SET (1 elem)
SEQUENCE (2 elem)

OBJECT IDENTIFIER 2.5.4.3 commonName (X.520 DN component)

UTF8String bbbbbs_MacBook_Pro

SET (1 elem)
SEQUENCE (2 elem)

OBJECT IDENTIFIER 1.2.840.113549.1.9.1 emailAddress (PKCS #9. Deprecated, use an altName extension instead)

IA5String z@z.com




So perhaps anyone can thing of a good reason why is the template is needed ? and if so, how do i generate it for my specific example.


Thanks !

Most folks are not parsing ASN.1 in a vacuum. They are parsing ASN.1 in order to extract some meaningful data from that ASN.1. For example, in your case, you’re parsing the

distinguishedNames
value is order to choose an appropriate client digital identity.
SecAsn1Decode
is based on that idea. The template provides the outline of the ASN.1 for the parser to check and a way to specify what data needs to be extracted and where to store it.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

ps DTS is closed 21 Dec through 1 Jan.

And how do you do that natively in Swift on iOS? Thanks in advance.

And how do you do that natively in Swift on iOS?

You don’t. The <Security/SecAsn1Coder.h> API is not available on iOS. If you need to perform general-purpose ASN.1 parsing on iOS, you’ll have to write or acquire a library for that.

Also, see my answer to your other post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

parsing DER format data using SecAsn1Decode
 
 
Q