openssl-asn1parse.1ossl 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "OPENSSL-ASN1PARSE 1ossl"
  58. .TH OPENSSL-ASN1PARSE 1ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. openssl\-asn1parse \- ASN.1 parsing command
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. \&\fBopenssl\fR \fBasn1parse\fR
  68. [\fB\-help\fR]
  69. [\fB\-inform\fR \fBDER\fR|\fBPEM\fR|\fBB64\fR]
  70. [\fB\-in\fR \fIfilename\fR]
  71. [\fB\-out\fR \fIfilename\fR]
  72. [\fB\-noout\fR]
  73. [\fB\-offset\fR \fInumber\fR]
  74. [\fB\-length\fR \fInumber\fR]
  75. [\fB\-i\fR]
  76. [\fB\-oid\fR \fIfilename\fR]
  77. [\fB\-dump\fR]
  78. [\fB\-dlimit\fR \fInum\fR]
  79. [\fB\-strparse\fR \fIoffset\fR]
  80. [\fB\-genstr\fR \fIstring\fR]
  81. [\fB\-genconf\fR \fIfile\fR]
  82. [\fB\-strictpem\fR]
  83. [\fB\-item\fR \fIname\fR]
  84. .SH DESCRIPTION
  85. .IX Header "DESCRIPTION"
  86. This command is a diagnostic utility that can parse ASN.1 structures.
  87. It can also be used to extract data from ASN.1 formatted data.
  88. .SH OPTIONS
  89. .IX Header "OPTIONS"
  90. .IP \fB\-help\fR 4
  91. .IX Item "-help"
  92. Print out a usage message.
  93. .IP "\fB\-inform\fR \fBDER\fR|\fBPEM\fR|\fBB64\fR" 4
  94. .IX Item "-inform DER|PEM|B64"
  95. The input format; the default is \fBPEM\fR.
  96. See \fBopenssl\-format\-options\fR\|(1) for details.
  97. .IP "\fB\-in\fR \fIfilename\fR" 4
  98. .IX Item "-in filename"
  99. The input file, default is standard input.
  100. .IP "\fB\-out\fR \fIfilename\fR" 4
  101. .IX Item "-out filename"
  102. Output file to place the DER encoded data into. If this
  103. option is not present then no data will be output. This is most useful when
  104. combined with the \fB\-strparse\fR option.
  105. .IP \fB\-noout\fR 4
  106. .IX Item "-noout"
  107. Don't output the parsed version of the input file.
  108. .IP "\fB\-offset\fR \fInumber\fR" 4
  109. .IX Item "-offset number"
  110. Starting offset to begin parsing, default is start of file.
  111. .IP "\fB\-length\fR \fInumber\fR" 4
  112. .IX Item "-length number"
  113. Number of bytes to parse, default is until end of file.
  114. .IP \fB\-i\fR 4
  115. .IX Item "-i"
  116. Indents the output according to the "depth" of the structures.
  117. .IP "\fB\-oid\fR \fIfilename\fR" 4
  118. .IX Item "-oid filename"
  119. A file containing additional OBJECT IDENTIFIERs (OIDs). The format of this
  120. file is described in the NOTES section below.
  121. .IP \fB\-dump\fR 4
  122. .IX Item "-dump"
  123. Dump unknown data in hex format.
  124. .IP "\fB\-dlimit\fR \fInum\fR" 4
  125. .IX Item "-dlimit num"
  126. Like \fB\-dump\fR, but only the first \fBnum\fR bytes are output.
  127. .IP "\fB\-strparse\fR \fIoffset\fR" 4
  128. .IX Item "-strparse offset"
  129. Parse the contents octets of the ASN.1 object starting at \fBoffset\fR. This
  130. option can be used multiple times to "drill down" into a nested structure.
  131. .IP "\fB\-genstr\fR \fIstring\fR, \fB\-genconf\fR \fIfile\fR" 4
  132. .IX Item "-genstr string, -genconf file"
  133. Generate encoded data based on \fIstring\fR, \fIfile\fR or both using
  134. \&\fBASN1_generate_nconf\fR\|(3) format. If \fIfile\fR only is
  135. present then the string is obtained from the default section using the name
  136. \&\fBasn1\fR. The encoded data is passed through the ASN1 parser and printed out as
  137. though it came from a file, the contents can thus be examined and written to a
  138. file using the \fB\-out\fR option.
  139. .IP \fB\-strictpem\fR 4
  140. .IX Item "-strictpem"
  141. If this option is used then \fB\-inform\fR will be ignored. Without this option any
  142. data in a PEM format input file will be treated as being base64 encoded and
  143. processed whether it has the normal PEM BEGIN and END markers or not. This
  144. option will ignore any data prior to the start of the BEGIN marker, or after an
  145. END marker in a PEM file.
  146. .IP "\fB\-item\fR \fIname\fR" 4
  147. .IX Item "-item name"
  148. Attempt to decode and print the data as an \fBASN1_ITEM\fR \fIname\fR. This can be
  149. used to print out the fields of any supported ASN.1 structure if the type is
  150. known.
  151. .SS Output
  152. .IX Subsection "Output"
  153. The output will typically contain lines like this:
  154. .PP
  155. .Vb 1
  156. \& 0:d=0 hl=4 l= 681 cons: SEQUENCE
  157. .Ve
  158. .PP
  159. \&.....
  160. .PP
  161. .Vb 10
  162. \& 229:d=3 hl=3 l= 141 prim: BIT STRING
  163. \& 373:d=2 hl=3 l= 162 cons: cont [ 3 ]
  164. \& 376:d=3 hl=3 l= 159 cons: SEQUENCE
  165. \& 379:d=4 hl=2 l= 29 cons: SEQUENCE
  166. \& 381:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Subject Key Identifier
  167. \& 386:d=5 hl=2 l= 22 prim: OCTET STRING
  168. \& 410:d=4 hl=2 l= 112 cons: SEQUENCE
  169. \& 412:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Authority Key Identifier
  170. \& 417:d=5 hl=2 l= 105 prim: OCTET STRING
  171. \& 524:d=4 hl=2 l= 12 cons: SEQUENCE
  172. .Ve
  173. .PP
  174. \&.....
  175. .PP
  176. This example is part of a self-signed certificate. Each line starts with the
  177. offset in decimal. \f(CW\*(C`d=XX\*(C'\fR specifies the current depth. The depth is increased
  178. within the scope of any SET or SEQUENCE. \f(CW\*(C`hl=XX\*(C'\fR gives the header length
  179. (tag and length octets) of the current type. \f(CW\*(C`l=XX\*(C'\fR gives the length of
  180. the contents octets.
  181. .PP
  182. The \fB\-i\fR option can be used to make the output more readable.
  183. .PP
  184. Some knowledge of the ASN.1 structure is needed to interpret the output.
  185. .PP
  186. In this example the BIT STRING at offset 229 is the certificate public key.
  187. The contents octets of this will contain the public key information. This can
  188. be examined using the option \f(CW\*(C`\-strparse 229\*(C'\fR to yield:
  189. .PP
  190. .Vb 3
  191. \& 0:d=0 hl=3 l= 137 cons: SEQUENCE
  192. \& 3:d=1 hl=3 l= 129 prim: INTEGER :E5D21E1F5C8D208EA7A2166C7FAF9F6BDF2059669C60876DDB70840F1A5AAFA59699FE471F379F1DD6A487E7D5409AB6A88D4A9746E24B91D8CF55DB3521015460C8EDE44EE8A4189F7A7BE77D6CD3A9AF2696F486855CF58BF0EDF2B4068058C7A947F52548DDF7E15E96B385F86422BEA9064A3EE9E1158A56E4A6F47E5897
  193. \& 135:d=1 hl=2 l= 3 prim: INTEGER :010001
  194. .Ve
  195. .SH NOTES
  196. .IX Header "NOTES"
  197. If an OID is not part of OpenSSL's internal table it will be represented in
  198. numerical form (for example 1.2.3.4). The file passed to the \fB\-oid\fR option
  199. allows additional OIDs to be included. Each line consists of three columns,
  200. the first column is the OID in numerical format and should be followed by white
  201. space. The second column is the "short name" which is a single word followed
  202. by whitespace. The final column is the rest of the line and is the
  203. "long name". Example:
  204. .PP
  205. \&\f(CW\*(C`1.2.3.4 shortName A long name\*(C'\fR
  206. .PP
  207. For any OID with an associated short and long name, this command will display
  208. the long name.
  209. .SH EXAMPLES
  210. .IX Header "EXAMPLES"
  211. Parse a file:
  212. .PP
  213. .Vb 1
  214. \& openssl asn1parse \-in file.pem
  215. .Ve
  216. .PP
  217. Parse a DER file:
  218. .PP
  219. .Vb 1
  220. \& openssl asn1parse \-inform DER \-in file.der
  221. .Ve
  222. .PP
  223. Generate a simple UTF8String:
  224. .PP
  225. .Vb 1
  226. \& openssl asn1parse \-genstr \*(AqUTF8:Hello World\*(Aq
  227. .Ve
  228. .PP
  229. Generate and write out a UTF8String, don't print parsed output:
  230. .PP
  231. .Vb 1
  232. \& openssl asn1parse \-genstr \*(AqUTF8:Hello World\*(Aq \-noout \-out utf8.der
  233. .Ve
  234. .PP
  235. Generate using a config file:
  236. .PP
  237. .Vb 1
  238. \& openssl asn1parse \-genconf asn1.cnf \-noout \-out asn1.der
  239. .Ve
  240. .PP
  241. Example config file:
  242. .PP
  243. .Vb 1
  244. \& asn1=SEQUENCE:seq_sect
  245. \&
  246. \& [seq_sect]
  247. \&
  248. \& field1=BOOL:TRUE
  249. \& field2=EXP:0, UTF8:some random string
  250. .Ve
  251. .SH BUGS
  252. .IX Header "BUGS"
  253. There should be options to change the format of output lines. The output of some
  254. ASN.1 types is not well handled (if at all).
  255. .SH "SEE ALSO"
  256. .IX Header "SEE ALSO"
  257. \&\fBopenssl\fR\|(1),
  258. \&\fBASN1_generate_nconf\fR\|(3)
  259. .SH COPYRIGHT
  260. .IX Header "COPYRIGHT"
  261. Copyright 2000\-2023 The OpenSSL Project Authors. All Rights Reserved.
  262. .PP
  263. Licensed under the Apache License 2.0 (the "License"). You may not use
  264. this file except in compliance with the License. You can obtain a copy
  265. in the file LICENSE in the source distribution or at
  266. <https://www.openssl.org/source/license.html>.