一、简介

asn1parse命令是一种用来诊断ASN.1结构的工具,也能用于从ASN1.1数据中提取数据

 

二、语法

openssl asn1parse [-inform PEM|DER] [-in filename] [-out filename] [-noout] [-offset number] [-length number] [-i] [- structure filename] [-strparse offset]

选项

-inform arg   input format - one of DER PEM
 -in arg       input file
 -out arg      output file (output format is always DER
 -noout arg    don't produce any output
 -offset arg   offset into file
 -length arg   length of section in file
 -i            indent entries
 -dump         dump unknown data in hex form
 -dlimit arg   dump the first arg bytes of unknown data in hex form
 -oid file     file of extra oid definitions
 -strparse offset
               a series of these can be used to 'dig' into multiple
               ASN1 blob wrappings
 -genstr str   string to generate ASN1 structure from
 -genconf file file to generate ASN1 structure from

 

三、ASN.1结构

0:d=0  hl=4 l= 710 cons: SEQUENCE
0 表示节点在整个文件中的偏移长度

d=0 表示节点深度

hl=4 表示节点头字节长度

l=710 表示节点数据字节长度

cons 表示该节点为结构节点,表示包含子节点或者子结构数据

prim 表示该节点为原始节点,包含数据

SEQUENCE、OCTETSTRING等都是ASN.1中定义的数据类型,具体可以参考ASN.1格式说明。

最后一个节点OCTET STRING      [HEX DUMP],就是加密后的私钥数据。

 

四、实例

1)分析一个文件

openssl asn1parse -in ec_pubkey.pem

image

2)分析一个DER文件

openssl asn1parse -inform DER -in file.der

3)解析公钥文件

openssl x509 -in cert.pem -pubkey -noout > pubkey.key

移除pem头尾后进行base64解码: openssl base64 x -in pubkey.key -out pubkey.bin

openssl asn1parse -in pubkey.key

    0:d=0  hl=3 l= 159 cons: SEQUENCE          

    3:d=1  hl=2 l=  13 cons: SEQUENCE          

    5:d=2  hl=2 l=   9 prim: OBJECT            :rsaEncryption

   16:d=2  hl=2 l=   0 prim: NULL              

   18:d=1  hl=3 l= 141 prim: BIT STRING 

openssl asn1parse -strparse 18 -in pubkey.key

    0:d=0  hl=3 l= 137 cons: SEQUENCE          

    3:d=1  hl=3 l= 129 prim: INTEGER           :BD08016AC47043B12704EF63B82AA311204A627C550CB5E0B44FBF70731F5A19C3E1FAA36F8E52F6C8A673F3704B0A3F1888F665EBFB257D5689F36F805F2C7442A0E0F90B1E3542A08C5E347FA21

DE6CE84A572BAAC892DE8AF611B5B2F81E8DA3EEA6E6C92A488876DF0B9DD9CEECC2A22D0C985904F40740FFF49836DE2B7

  135:d=1  hl=2 l=   3 prim: INTEGER           :010001

4)解析私钥文件

移除pem头尾后进行base64解码: openssl base64 -d -in cert.key -out prikey.key
openssl asn1parse -in prikey.key
    0:d=0  hl=4 l= 606 cons: SEQUENCE          
    4:d=1  hl=2 l=   1 prim: INTEGER           :00
    7:d=1  hl=3 l= 129 prim: INTEGER           :BD08016AC47043B12704EF63B82AA311204A627C550CB5E0B44FBF70731F5A19C3E1FAA36F8E52F6C8A673F3704B0A3F1888F665EBFB257D5689F36F805F2C7442A0E0F90B1E3542A08C5E347FA21
DE6CE84A572BAAC892DE8AF611B5B2F81E8DA3EEA6E6C92A488876DF0B9DD9CEECC2A22D0C985904F40740FFF49836DE2B7
  139:d=1  hl=2 l=   3 prim: INTEGER           :010001
  144:d=1  hl=3 l= 129 prim: INTEGER          :XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  276:d=1  hl=2 l=  65 prim: INTEGER           :XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  343:d=1  hl=2 l=  65 prim: INTEGER           :XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  410:d=1  hl=2 l=  64 prim: INTEGER           :XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  476:d=1  hl=2 l=  65 prim: INTEGER           :XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  543:d=1  hl=2 l=  65 prim: INTEGER           :XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

posted on 2017-10-30 23:45  红孩儿你好  阅读(1777)  评论(0编辑  收藏  举报