xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/doc/man1/asn1parse.pod (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos=pod
2*4724848cSchristos
3*4724848cSchristos=head1 NAME
4*4724848cSchristos
5*4724848cSchristosopenssl-asn1parse,
6*4724848cSchristosasn1parse - ASN.1 parsing tool
7*4724848cSchristos
8*4724848cSchristos=head1 SYNOPSIS
9*4724848cSchristos
10*4724848cSchristosB<openssl> B<asn1parse>
11*4724848cSchristos[B<-help>]
12*4724848cSchristos[B<-inform PEM|DER>]
13*4724848cSchristos[B<-in filename>]
14*4724848cSchristos[B<-out filename>]
15*4724848cSchristos[B<-noout>]
16*4724848cSchristos[B<-offset number>]
17*4724848cSchristos[B<-length number>]
18*4724848cSchristos[B<-i>]
19*4724848cSchristos[B<-oid filename>]
20*4724848cSchristos[B<-dump>]
21*4724848cSchristos[B<-dlimit num>]
22*4724848cSchristos[B<-strparse offset>]
23*4724848cSchristos[B<-genstr string>]
24*4724848cSchristos[B<-genconf file>]
25*4724848cSchristos[B<-strictpem>]
26*4724848cSchristos[B<-item name>]
27*4724848cSchristos
28*4724848cSchristos=head1 DESCRIPTION
29*4724848cSchristos
30*4724848cSchristosThe B<asn1parse> command is a diagnostic utility that can parse ASN.1
31*4724848cSchristosstructures. It can also be used to extract data from ASN.1 formatted data.
32*4724848cSchristos
33*4724848cSchristos=head1 OPTIONS
34*4724848cSchristos
35*4724848cSchristos=over 4
36*4724848cSchristos
37*4724848cSchristos=item B<-help>
38*4724848cSchristos
39*4724848cSchristosPrint out a usage message.
40*4724848cSchristos
41*4724848cSchristos=item B<-inform> B<DER|PEM>
42*4724848cSchristos
43*4724848cSchristosThe input format. B<DER> is binary format and B<PEM> (the default) is base64
44*4724848cSchristosencoded.
45*4724848cSchristos
46*4724848cSchristos=item B<-in filename>
47*4724848cSchristos
48*4724848cSchristosThe input file, default is standard input.
49*4724848cSchristos
50*4724848cSchristos=item B<-out filename>
51*4724848cSchristos
52*4724848cSchristosOutput file to place the DER encoded data into. If this
53*4724848cSchristosoption is not present then no data will be output. This is most useful when
54*4724848cSchristoscombined with the B<-strparse> option.
55*4724848cSchristos
56*4724848cSchristos=item B<-noout>
57*4724848cSchristos
58*4724848cSchristosDon't output the parsed version of the input file.
59*4724848cSchristos
60*4724848cSchristos=item B<-offset number>
61*4724848cSchristos
62*4724848cSchristosStarting offset to begin parsing, default is start of file.
63*4724848cSchristos
64*4724848cSchristos=item B<-length number>
65*4724848cSchristos
66*4724848cSchristosNumber of bytes to parse, default is until end of file.
67*4724848cSchristos
68*4724848cSchristos=item B<-i>
69*4724848cSchristos
70*4724848cSchristosIndents the output according to the "depth" of the structures.
71*4724848cSchristos
72*4724848cSchristos=item B<-oid filename>
73*4724848cSchristos
74*4724848cSchristosA file containing additional OBJECT IDENTIFIERs (OIDs). The format of this
75*4724848cSchristosfile is described in the NOTES section below.
76*4724848cSchristos
77*4724848cSchristos=item B<-dump>
78*4724848cSchristos
79*4724848cSchristosDump unknown data in hex format.
80*4724848cSchristos
81*4724848cSchristos=item B<-dlimit num>
82*4724848cSchristos
83*4724848cSchristosLike B<-dump>, but only the first B<num> bytes are output.
84*4724848cSchristos
85*4724848cSchristos=item B<-strparse offset>
86*4724848cSchristos
87*4724848cSchristosParse the contents octets of the ASN.1 object starting at B<offset>. This
88*4724848cSchristosoption can be used multiple times to "drill down" into a nested structure.
89*4724848cSchristos
90*4724848cSchristos=item B<-genstr string>, B<-genconf file>
91*4724848cSchristos
92*4724848cSchristosGenerate encoded data based on B<string>, B<file> or both using
93*4724848cSchristosL<ASN1_generate_nconf(3)> format. If B<file> only is
94*4724848cSchristospresent then the string is obtained from the default section using the name
95*4724848cSchristosB<asn1>. The encoded data is passed through the ASN1 parser and printed out as
96*4724848cSchristosthough it came from a file, the contents can thus be examined and written to a
97*4724848cSchristosfile using the B<out> option.
98*4724848cSchristos
99*4724848cSchristos=item B<-strictpem>
100*4724848cSchristos
101*4724848cSchristosIf this option is used then B<-inform> will be ignored. Without this option any
102*4724848cSchristosdata in a PEM format input file will be treated as being base64 encoded and
103*4724848cSchristosprocessed whether it has the normal PEM BEGIN and END markers or not. This
104*4724848cSchristosoption will ignore any data prior to the start of the BEGIN marker, or after an
105*4724848cSchristosEND marker in a PEM file.
106*4724848cSchristos
107*4724848cSchristos=item B<-item name>
108*4724848cSchristos
109*4724848cSchristosAttempt to decode and print the data as B<ASN1_ITEM name>. This can be used to
110*4724848cSchristosprint out the fields of any supported ASN.1 structure if the type is known.
111*4724848cSchristos
112*4724848cSchristos=back
113*4724848cSchristos
114*4724848cSchristos=head2 Output
115*4724848cSchristos
116*4724848cSchristosThe output will typically contain lines like this:
117*4724848cSchristos
118*4724848cSchristos  0:d=0  hl=4 l= 681 cons: SEQUENCE
119*4724848cSchristos
120*4724848cSchristos.....
121*4724848cSchristos
122*4724848cSchristos  229:d=3  hl=3 l= 141 prim: BIT STRING
123*4724848cSchristos  373:d=2  hl=3 l= 162 cons: cont [ 3 ]
124*4724848cSchristos  376:d=3  hl=3 l= 159 cons: SEQUENCE
125*4724848cSchristos  379:d=4  hl=2 l=  29 cons: SEQUENCE
126*4724848cSchristos  381:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Subject Key Identifier
127*4724848cSchristos  386:d=5  hl=2 l=  22 prim: OCTET STRING
128*4724848cSchristos  410:d=4  hl=2 l= 112 cons: SEQUENCE
129*4724848cSchristos  412:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Authority Key Identifier
130*4724848cSchristos  417:d=5  hl=2 l= 105 prim: OCTET STRING
131*4724848cSchristos  524:d=4  hl=2 l=  12 cons: SEQUENCE
132*4724848cSchristos
133*4724848cSchristos.....
134*4724848cSchristos
135*4724848cSchristosThis example is part of a self-signed certificate. Each line starts with the
136*4724848cSchristosoffset in decimal. B<d=XX> specifies the current depth. The depth is increased
137*4724848cSchristoswithin the scope of any SET or SEQUENCE. B<hl=XX> gives the header length
138*4724848cSchristos(tag and length octets) of the current type. B<l=XX> gives the length of
139*4724848cSchristosthe contents octets.
140*4724848cSchristos
141*4724848cSchristosThe B<-i> option can be used to make the output more readable.
142*4724848cSchristos
143*4724848cSchristosSome knowledge of the ASN.1 structure is needed to interpret the output.
144*4724848cSchristos
145*4724848cSchristosIn this example the BIT STRING at offset 229 is the certificate public key.
146*4724848cSchristosThe contents octets of this will contain the public key information. This can
147*4724848cSchristosbe examined using the option B<-strparse 229> to yield:
148*4724848cSchristos
149*4724848cSchristos    0:d=0  hl=3 l= 137 cons: SEQUENCE
150*4724848cSchristos    3:d=1  hl=3 l= 129 prim: INTEGER           :E5D21E1F5C8D208EA7A2166C7FAF9F6BDF2059669C60876DDB70840F1A5AAFA59699FE471F379F1DD6A487E7D5409AB6A88D4A9746E24B91D8CF55DB3521015460C8EDE44EE8A4189F7A7BE77D6CD3A9AF2696F486855CF58BF0EDF2B4068058C7A947F52548DDF7E15E96B385F86422BEA9064A3EE9E1158A56E4A6F47E5897
151*4724848cSchristos  135:d=1  hl=2 l=   3 prim: INTEGER           :010001
152*4724848cSchristos
153*4724848cSchristos=head1 NOTES
154*4724848cSchristos
155*4724848cSchristosIf an OID is not part of OpenSSL's internal table it will be represented in
156*4724848cSchristosnumerical form (for example 1.2.3.4). The file passed to the B<-oid> option
157*4724848cSchristosallows additional OIDs to be included. Each line consists of three columns,
158*4724848cSchristosthe first column is the OID in numerical format and should be followed by white
159*4724848cSchristosspace. The second column is the "short name" which is a single word followed
160*4724848cSchristosby white space. The final column is the rest of the line and is the
161*4724848cSchristos"long name". B<asn1parse> displays the long name. Example:
162*4724848cSchristos
163*4724848cSchristosC<1.2.3.4       shortName       A long name>
164*4724848cSchristos
165*4724848cSchristos=head1 EXAMPLES
166*4724848cSchristos
167*4724848cSchristosParse a file:
168*4724848cSchristos
169*4724848cSchristos openssl asn1parse -in file.pem
170*4724848cSchristos
171*4724848cSchristosParse a DER file:
172*4724848cSchristos
173*4724848cSchristos openssl asn1parse -inform DER -in file.der
174*4724848cSchristos
175*4724848cSchristosGenerate a simple UTF8String:
176*4724848cSchristos
177*4724848cSchristos openssl asn1parse -genstr 'UTF8:Hello World'
178*4724848cSchristos
179*4724848cSchristosGenerate and write out a UTF8String, don't print parsed output:
180*4724848cSchristos
181*4724848cSchristos openssl asn1parse -genstr 'UTF8:Hello World' -noout -out utf8.der
182*4724848cSchristos
183*4724848cSchristosGenerate using a config file:
184*4724848cSchristos
185*4724848cSchristos openssl asn1parse -genconf asn1.cnf -noout -out asn1.der
186*4724848cSchristos
187*4724848cSchristosExample config file:
188*4724848cSchristos
189*4724848cSchristos asn1=SEQUENCE:seq_sect
190*4724848cSchristos
191*4724848cSchristos [seq_sect]
192*4724848cSchristos
193*4724848cSchristos field1=BOOL:TRUE
194*4724848cSchristos field2=EXP:0, UTF8:some random string
195*4724848cSchristos
196*4724848cSchristos
197*4724848cSchristos=head1 BUGS
198*4724848cSchristos
199*4724848cSchristosThere should be options to change the format of output lines. The output of some
200*4724848cSchristosASN.1 types is not well handled (if at all).
201*4724848cSchristos
202*4724848cSchristos=head1 SEE ALSO
203*4724848cSchristos
204*4724848cSchristosL<ASN1_generate_nconf(3)>
205*4724848cSchristos
206*4724848cSchristos=head1 COPYRIGHT
207*4724848cSchristos
208*4724848cSchristosCopyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
209*4724848cSchristos
210*4724848cSchristosLicensed under the OpenSSL license (the "License").  You may not use
211*4724848cSchristosthis file except in compliance with the License.  You can obtain a copy
212*4724848cSchristosin the file LICENSE in the source distribution or at
213*4724848cSchristosL<https://www.openssl.org/source/license.html>.
214*4724848cSchristos
215*4724848cSchristos=cut
216