| 1 | % unber(1) ASN.1 BER Decoder |
| 2 | % Lev Walkin <[email protected]> |
| 3 | % 2016-01-23 |
| 4 | |
| 5 | # NAME |
| 6 | |
| 7 | unber -- the ASN.1 BER Decoder |
| 8 | |
| 9 | # SYNOPSIS |
| 10 | |
| 11 | unber [**-1**] [**-i***indent*] [**-m**] [**-p**] [**-s***skip*] [**-t***hex-string*] [**-**] [*input-filenames*...] |
| 12 | |
| 13 | # DESCRIPTION |
| 14 | |
| 15 | unber presents the internal structure of BER-encoded files as a human readable text. |
| 16 | A single dash denotes the standard input. |
| 17 | |
| 18 | (The DER and CER formats are subsets of the BER and are also supported.) |
| 19 | |
| 20 | # OPTIONS |
| 21 | |
| 22 | -1 |
| 23 | : Do *not* attempt to read the next BER structure after the first one. |
| 24 | This may be useful if the input contains garbage past the single BER sequence. |
| 25 | By default, unber continues decoding until the end of file (input stream). |
| 26 | |
| 27 | -i *indent* |
| 28 | : Use the specified number of spaces for output indentation. |
| 29 | Default is 4 spaces. |
| 30 | |
| 31 | -m |
| 32 | : Generate shorter output while still preserving BER encoding information. |
| 33 | |
| 34 | -p |
| 35 | : Do *not* attempt to pretty-print known ASN.1 types (`BOOLEAN`, `INTEGER`, `OBJECT IDENTIFIER`, etc). |
| 36 | By default, some ASN.1 types are converted into the text representation. |
| 37 | |
| 38 | This option is required if the `unber`(1) output is used as an input to `enber`(1). |
| 39 | |
| 40 | -s *skip* |
| 41 | : Ignore the first *skip* bytes in the input stream; |
| 42 | useful for stripping off lower level protocol framing data. |
| 43 | |
| 44 | -t *hex-string* |
| 45 | : Interpret the hex-string as a sequence of hexadecimal values representing |
| 46 | the start of BER TLV encoding. |
| 47 | Print the human readable explanation. |
| 48 | |
| 49 | # XML FORMAT |
| 50 | unber dumps the output in the regular XML format which preserves most of the |
| 51 | information from the underlying binary encoding. |
| 52 | |
| 53 | The XML opening tag format is as follows: |
| 54 | |
| 55 | <**tform** O="**off**" T="**tag**" TL="**t_len**" V="{Indefinite|**v_len**}" [A="**type**"] [**F**]> |
| 56 | |
| 57 | Where: |
| 58 | |
| 59 | **tform** |
| 60 | : Encoding form the value is in: primitive ("P") or constructed ("C") or constructed with indefinite length ("I") |
| 61 | |
| 62 | **off** |
| 63 | : Offset of the encoded element in the unber input stream. |
| 64 | |
| 65 | **tag** |
| 66 | : The tag class and value in human readable form. |
| 67 | |
| 68 | **t_len** |
| 69 | : The length of the TL (BER Tag and Length) encoding. |
| 70 | |
| 71 | **v_len** |
| 72 | : The length of the value (V, encoded by the L), may be "Indefinite". |
| 73 | |
| 74 | **type** |
| 75 | : Likely name of the underlying ASN.1 type (for UNIVERSAL tags). |
| 76 | |
| 77 | [**F**] |
| 78 | : Indicates that the value was reformatted (pretty-printed). |
| 79 | This will never appear in the output produced using the **-p** |
| 80 | command line option. |
| 81 | |
| 82 | ## Example XML output: |
| 83 | |
| 84 | | \<I O="0" T="[UNIVERSAL 16]" TL="2" V="Indefinite" A="SEQUENCE"> |
| 85 | | \<P O="2" T="[UNIVERSAL 19]" TL="2" V="2" A="PrintableString">US\</P> |
| 86 | | \<C O="6" T="[UNIVERSAL 16]" TL="2" V="6" A="SEQUENCE"> |
| 87 | | \<P O="8" T="[UNIVERSAL 2]" TL="2" V="4" A="INTEGER" F>832970823\</P> |
| 88 | | \</C O="14" T="[UNIVERSAL 16]" A="SEQUENCE" L="8"> |
| 89 | | \</I O="14" T="[UNIVERSAL 0]" TL="2" L="16"> |
| 90 | |
| 91 | # EXAMPLES |
| 92 | |
| 93 | Decode the given Tag/Length sequence specified in hexadecimal form: |
| 94 | |
| 95 | > unber\ **-t** "*bf 20*" |
| 96 | |
| 97 | Decode the DER file using two-spaces indentation: |
| 98 | |
| 99 | > unber\ **-i** *2*\ *filename.der* |
| 100 | |
| 101 | Decode the binary stream taken from the standard input: |
| 102 | |
| 103 | > cat *filename.der* | unber **-** |
| 104 | |
| 105 | Decode the binary stream and encode it back into an identical stream (see `enber`(1)): |
| 106 | |
| 107 | > cat *filename.der* | unber **-p** **-** | enber **-** > *filename.ber* |
| 108 | |
| 109 | # FOOTNOTES |
| 110 | The constructed XML output is not necessarily well-formed. |
| 111 | |
| 112 | When indefinite length encoding is being used, the BER sequence which is not |
| 113 | terminated with the end-of-content octets will cause the terminating **\</I>** |
| 114 | XML tag to disappear. |
| 115 | Thus, invalid BER framing directly causes invalid XML output. |
| 116 | |
| 117 | The `enber`(1) utility understands such XML correctly. |
| 118 | |
| 119 | # SEE ALSO |
| 120 | |
| 121 | `enber`(1), `asn1c`(1). |