1 .\" $OpenBSD: ASN1_generate_nconf.3,v 1.9 2016/12/25 22:15:10 schwarze Exp $
2 .\" OpenSSL 05ea606a Fri May 20 20:52:46 2016 -0400
4 .\" This file was written by Dr. Stephen Henson.
5 .\" Copyright (c) 2002, 2003, 2006-2009, 2013-2015 The OpenSSL Project.
6 .\" All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in
17 .\" the documentation and/or other materials provided with the
20 .\" 3. All advertising materials mentioning features or use of this
21 .\" software must display the following acknowledgment:
22 .\" "This product includes software developed by the OpenSSL Project
23 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 .\" endorse or promote products derived from this software without
27 .\" prior written permission. For written permission, please contact
28 .\" openssl-core@openssl.org.
30 .\" 5. Products derived from this software may not be called "OpenSSL"
31 .\" nor may "OpenSSL" appear in their names without prior written
32 .\" permission of the OpenSSL Project.
34 .\" 6. Redistributions of any form whatsoever must retain the following
36 .\" "This product includes software developed by the OpenSSL Project
37 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
52 .Dd $Mdocdate: December 25 2016 $
53 .Dt ASN1_GENERATE_NCONF 3
56 .Nm ASN1_generate_nconf ,
58 .Nd ASN.1 generation functions
62 .Fo ASN1_generate_nconf
72 These functions generate the ASN.1 encoding of a string in an
77 contains the string to encode
81 contains the optional configuration information
82 where additional strings will be read from.
84 will typically come from a config file whereas
88 structure which will typically be used
89 by X509 v3 certificate extension functions.
95 if no additional configuration will be used.
96 .Sh GENERATION STRING FORMAT
97 The actual data encoded is determined by the string
99 and the configuration information.
100 The general format of the string is:
102 .D1 Oo Ar modifier , Oc Ns Ar type Ns Op : Ns Ar value
104 That is zero or more comma separated modifiers followed by a type
105 followed by an optional colon and a value.
113 The supported types are listed below.
114 Unless otherwise specified, only the
116 format is permissible.
118 .It Cm BOOLEAN , BOOL
119 This encodes a boolean type.
122 string is mandatory and should be
140 Encode the NULL type.
143 string must not be present.
145 Encodes an ASN.1 INTEGER type.
148 string represents the value of the integer.
149 It can be prefaced by a minus sign
150 and is normally interpreted as a decimal value unless the prefix
153 .It Cm ENUMERATED , ENUM
154 Encodes the ASN.1 ENUMERATED type.
155 It is otherwise identical to
158 Encodes an ASN.1 OBJECT IDENTIFIER.
161 string can be a short name, a long name, or numerical format.
163 Encodes an ASN.1 UTCTime structure.
164 The value should be in the format
166 .It Cm GENERALIZEDTIME , GENTIME
167 Encodes an ASN.1 GeneralizedTime structure.
168 The value should be in the format
169 .Ar YYYYMMDDHHMMSSZ .
170 .It Cm OCTETSTRING , OCT
171 Encodes an ASN.1 OCTET STRING.
173 represents the contents of this structure.
178 can be used to specify the format of
180 .It Cm BITSTRING , BITSTR
181 Encodes an ASN.1 BIT STRING.
183 represents the contents of this structure.
189 can be used to specify the format of
192 If the format is anything other than
194 the number of unused bits is set to zero.
196 .Cm BMPSTRING , BMP ,
198 .Cm IA5STRING , IA5 ,
199 .Cm NUMERICSTRING , NUMERIC ,
200 .Cm PRINTABLESTRING , PRINTABLE ,
201 .Cm T61STRING , T61 ,
203 .Cm UNIVERSALSTRING , UNIV ,
204 .Cm UTF8String , UTF8 ,
205 .Cm VISIBLESTRING , VISIBLE
207 These encode the corresponding string types.
209 represents the contents of this structure.
214 .It Cm SEQUENCE , SEQ , SET
215 Formats the result as an ASN.1 SEQUENCE or SET type.
217 should be a section name which will contain the contents.
218 The field names in the section are ignored
219 and the values are in the generated string format.
222 is absent, then an empty SEQUENCE will be encoded.
225 Modifiers affect the following structure.
226 They can be used to add EXPLICIT or IMPLICIT tagging, add wrappers,
227 or to change the string format of the final type and value.
228 The supported formats are:
230 .It Cm EXPLICIT , EXP
231 Add an explicit tag to the following structure.
232 This string should be followed by a colon
233 and the tag value to use as a decimal value.
235 By following the number with
241 UNIVERSAL, APPLICATION, PRIVATE or CONTEXT SPECIFIC tagging can be used.
242 The default is CONTEXT SPECIFIC.
243 .It Cm IMPLICIT , IMP
246 except IMPLICIT tagging is used instead.
247 .It Cm OCTWRAP , SEQWRAP , SETWRAP , BITWRAP
248 The following structure is surrounded by
249 an OCTET STRING, a SEQUENCE, a SET, or a BIT STRING, respectively.
250 For a BIT STRING the number of unused bits is set to zero.
252 This specifies the format of the ultimate value.
253 It should be followed by a colon and one of the strings
260 If no format specifier is included, then
265 is specified, then the
267 string must be a valid UTF-8 string.
270 the output must be a set of hex digits.
272 (which is only valid for a BIT STRING) is a comma separated list
273 of the indices of the set bits, all other bits are zero.
276 .Fn ASN1_generate_nconf
279 return the encoded data as an
283 if an error occurred.
285 The error codes can be obtained by
286 .Xr ERR_get_error 3 .
291 .Dl IA5STRING:Hello World
297 .Dl EXPLICIT:0,IA5STRING:Hello World
301 explicitly tagged using APPLICATION tagging:
303 .Dl EXPLICIT:0A,IA5STRING:Hello World
305 A BITSTRING with bits 1 and 5 set and all others zero:
307 .Dl FORMAT:BITLIST,BITSTRING:1,5
309 A more complex example using a config file to produce a
310 SEQUENCE consisting of a BOOL an OID and a
312 .Bd -literal -offset indent
313 asn1 = SEQUENCE:seq_section
317 field1 = BOOLEAN:TRUE
318 field2 = OID:commonName
319 field3 = UTF8:Third field
322 This example produces an
325 This is the key contained in the file
327 in all OpenSSL distributions.
328 Note that the field names such as
330 are ignored and are present just for clarity.
331 .Bd -literal -offset 2n
332 asn1=SEQUENCE:private_key
336 n=INTEGER:0xBB6FE79432CC6EA2D8F970675A5A87BFBE1AFF0BE63E879F2AFFB93644\e
337 D4D2C6D000430DEC66ABF47829E74B8C5108623A1C0EE8BE217B3AD8D36D5EB4FCA1D9
341 d=INTEGER:0x6F05EAD2F27FFAEC84BEC360C4B928FD5F3A9865D0FCAAD291E2A52F4A\e
342 F810DC6373278C006A0ABBA27DC8C63BF97F7E666E27C5284D7D3B1FFFE16B7A87B51D
344 p=INTEGER:0xF3929B9435608F8A22C208D86795271D54EBDFB09DDEF539AB083DA912\e
347 q=INTEGER:0xC50016F89DFF2561347ED1186A46E150E28BF2D0F539A1594BBD7FE467\e
350 exp1=INTEGER:0x9E7D4326C924AFC1DEA40B45650134966D6F9DFA3A7F9D698CD4ABEA\e
353 exp2=INTEGER:0xBA84003BB95355AFB7C50DF140C60513D0BA51D637272E355E397779\e
356 coeff=INTEGER:0x30B9E4F2AFA5AC679F920FC83F1F2DF1BAF1779CF989447FABC2F5\e
360 This example is the corresponding public key in an ASN.1
361 .Vt SubjectPublicKeyInfo
363 .Bd -literal -offset 2n
364 # Start with a SEQUENCE
365 asn1=SEQUENCE:pubkeyinfo
367 # pubkeyinfo contains an algorithm identifier and the public key
368 # wrapped in a BIT STRING
370 algorithm=SEQUENCE:rsa_alg
371 pubkey=BITWRAP,SEQUENCE:rsapubkey
373 # algorithm ID for RSA is just an OID and a NULL
375 algorithm=OID:rsaEncryption
378 # Actual public key: modulus and exponent
380 n=INTEGER:0xBB6FE79432CC6EA2D8F970675A5A87BFBE1AFF0BE63E879F2AFFB93644\e
381 D4D2C6D000430DEC66ABF47829E74B8C5108623A1C0EE8BE217B3AD8D36D5EB4FCA1D9
386 .Xr ERR_get_error 3 ,
389 .Fn ASN1_generate_nconf
392 were added to OpenSSL 0.9.8.