OpenSSL "ans1parse -genconf" - Nested SEQUENCE ASN.1 Structure

Q

How to how generate a DER with a nested SEQUENCE ASN.1 structure using the OpenSSL "ans1parse" command?

✍: FYIcenter.com

A

You can define a nested SEQUENCE ASN.1 structure in an OpenSSL configuration file and use the "ans1parse -genconf" command to generate a DER with the structure as shown in the test below:

C:\Users\fyicenter>type asn1_question.cnf
default_md = md5
asn1 = SEQUENCE:questionSection

[questionSection]
trackingNumber = INTEGER:5
questionText   = IA5STRING:"In asymmetric encryption, which key can be given out?"
answerOption   = SEQUENCE:optionSection
   
[optionSection]
optionA = IA5STRING:"A) Private key"
optionB = IA5STRING:"B) Public key"
optionC = IA5STRING:"C) Both keys"

C:\Users\fyicenter>\local\openssl\openssl.exe

OpenSSL> asn1parse -genconf asn1_question.cnf -noout -out asn1_question.der

OpenSSL> asn1parse -inform DER -in asn1_question.der -i
    0:d=0  hl=2 l= 105 cons: SEQUENCE
    2:d=1  hl=2 l=   1 prim:  INTEGER           :05
    5:d=1  hl=2 l=  53 prim:  IA5STRING         :In asymmetric encryption, 
                                                 which key can be given out?
   60:d=1  hl=2 l=  45 cons:  SEQUENCE
   62:d=2  hl=2 l=  14 prim:   IA5STRING         :A) Private key
   78:d=2  hl=2 l=  13 prim:   IA5STRING         :B) Public key
   93:d=2  hl=2 l=  12 prim:   IA5STRING         :C) Both keys

Note about the test:

  • "-genconf asn1_question.cnf" option tells OpenSSL to read the ASN.1 structure from the given configuration file.
  • "-noout" option tells OpenSSL to not display parsed output on the screen.
  • "-out asn1_question.der" option tells OpenSSL to save the ASN.1 structure to the given file in DER format.
  • "-in asn1_question.der" option tells OpenSSL to read the ASN.1 structure from the given file.
  • "-inform DER" option tells OpenSSL to read the input in DER format.
  • "-i" option tells OpenSSL to indent child fields in parsed output.
  • "...cons..." column in the parsed output indicates a Constructed field, like SEQUENCE.

 

OpenSSL "ans1parse -strparse" - Extract ASN.1 Sub Structure

OpenSSL "ans1parse -genconf" - Configuration File

OpenSSL "ans1parse" Command

⇑⇑ OpenSSL Tutorials

2016-10-15, 9161🔥, 0💬