
#use wml::openssl-macros area=docs page=ASN1_generate_nconf

<title>Documents, ASN1_generate_nconf(3)</title>

<h1>ASN1_generate_nconf(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#GENERATION_STRING_FORMAT">GENERATION STRING FORMAT</A>
	<UL>

		<LI><A HREF="#SUPPORTED_TYPES">SUPPORTED TYPES</A>
		<LI><A HREF="#MODIFIERS">MODIFIERS</A>
	</UL>

	<LI><A HREF="#EXAMPLES">EXAMPLES</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
ASN1_generate_nconf, ASN1_generate_v3 - ASN1 generation functions

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/asn1.h&gt;
</PRE>
<PRE> ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
 ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
These functions generate the ASN1 encoding of a string in an <STRONG>ASN1_TYPE</STRONG> structure.

</P>
<P>
<STRONG>str</STRONG> contains the string to encode <STRONG>nconf</STRONG> or <STRONG>cnf</STRONG> contains the optional configuration information where additional strings
will be read from. <STRONG>nconf</STRONG> will typically come from a config file wherease <STRONG>cnf</STRONG> is obtained from an <STRONG>X509V3_CTX</STRONG> structure which will typically be used by X509 v3 certificate extension
functions. <STRONG>cnf</STRONG> or <STRONG>nconf</STRONG> can be set to <STRONG>NULL</STRONG> if no additional configuration will be used.

</P>
<P>
<HR>
<H1><A NAME="GENERATION_STRING_FORMAT">GENERATION STRING FORMAT</A></H1>
<P>
The actual data encoded is determined by the string <STRONG>str</STRONG> and the configuration information. The general format of the string is:

</P>
<DL>
<DT><STRONG><A NAME="item__modifier_type_value_"><STRONG>[modifier,]type[:value]</STRONG></A></STRONG><DD>
</DL>
<P>
That is zero or more comma separated modifiers followed by a type followed
by an optional colon and a value. The formats of <STRONG>type</STRONG>,
<STRONG>value</STRONG> and <STRONG>modifier</STRONG> are explained below.

</P>
<P>
<HR>
<H2><A NAME="SUPPORTED_TYPES">SUPPORTED TYPES</A></H2>
<P>
The supported types are listed below. Unless otherwise specified only the <STRONG>ASCII</STRONG> format is permissible.

</P>
<DL>
<DT><STRONG><A NAME="item_BOOLEAN"><STRONG>BOOLEAN</STRONG>, <STRONG>BOOL</STRONG></A></STRONG><DD>
<P>
This encodes a boolean type. The <STRONG>value</STRONG> string is mandatory and should be <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>. Additionally <STRONG>TRUE</STRONG>, <STRONG>true</STRONG>, <STRONG>Y</STRONG>,
<STRONG>y</STRONG>, <STRONG>YES</STRONG>, <STRONG>yes</STRONG>, <STRONG>FALSE</STRONG>, <STRONG>false</STRONG>, <STRONG>N</STRONG>, <STRONG>n</STRONG>, <STRONG>NO</STRONG> and <STRONG>no</STRONG>
are acceptable. 

</P>
<DT><STRONG><A NAME="item_NULL"><STRONG>NULL</STRONG></A></STRONG><DD>
<P>
Encode the <STRONG>NULL</STRONG> type, the <STRONG>value</STRONG> string must not be present.

</P>
<DT><STRONG><A NAME="item_INTEGER"><STRONG>INTEGER</STRONG>, <STRONG>INT</STRONG></A></STRONG><DD>
<P>
Encodes an ASN1 <STRONG>INTEGER</STRONG> type. The <STRONG>value</STRONG> string represents the value of the integer, it can be preceeded by a minus
sign and is normally interpreted as a decimal value unless the prefix <STRONG>0x</STRONG>
is included.

</P>
<DT><STRONG><A NAME="item_ENUMERATED"><STRONG>ENUMERATED</STRONG>, <STRONG>ENUM</STRONG></A></STRONG><DD>
<P>
Encodes the ASN1 <STRONG>ENUMERATED</STRONG> type, it is otherwise identical to
<STRONG>INTEGER</STRONG>.

</P>
<DT><STRONG><A NAME="item_OBJECT"><STRONG>OBJECT</STRONG>, <STRONG>OID</STRONG></A></STRONG><DD>
<P>
Encodes an ASN1 <STRONG>OBJECT IDENTIFIER</STRONG>, the <STRONG>value</STRONG> string can be a short name, a long name or numerical format.

</P>
<DT><STRONG><A NAME="item_UTCTIME"><STRONG>UTCTIME</STRONG>, <STRONG>UTC</STRONG></A></STRONG><DD>
<P>
Encodes an ASN1 <STRONG>UTCTime</STRONG> structure, the value should be in the format <STRONG>YYMMDDHHMMSSZ</STRONG>. 

</P>
<DT><STRONG><A NAME="item_GENERALIZEDTIME"><STRONG>GENERALIZEDTIME</STRONG>, <STRONG>GENTIME</STRONG></A></STRONG><DD>
<P>
Encodes an ASN1 <STRONG>GeneralizedTime</STRONG> structure, the value should be in the format <STRONG>YYYYMMDDHHMMSSZ</STRONG>. 

</P>
<DT><STRONG><A NAME="item_OCTETSTRING"><STRONG>OCTETSTRING</STRONG>, <STRONG>OCT</STRONG></A></STRONG><DD>
<P>
Encodes an ASN1 <STRONG>OCTET STRING</STRONG>. <STRONG>value</STRONG> represents the contents of this structure, the format strings <STRONG>ASCII</STRONG> and <STRONG>HEX</STRONG> can be used to specify the format of <STRONG>value</STRONG>.

</P>
<DT><STRONG><A NAME="item_BITSTRING"><STRONG>BITSTRING</STRONG>, <STRONG>BITSTR</STRONG></A></STRONG><DD>
<P>
Encodes an ASN1 <STRONG>BIT STRING</STRONG>. <STRONG>value</STRONG> represents the contents of this structure, the format strings <STRONG>ASCII</STRONG>, <STRONG>HEX</STRONG> and <STRONG>BITLIST</STRONG>
can be used to specify the format of <STRONG>value</STRONG>.

</P>
<P>
If the format is anything other than <STRONG>BITLIST</STRONG> the number of unused bits is set to zero.

</P>
<DT><STRONG><A NAME="item_UNIVERSALSTRING"><STRONG>UNIVERSALSTRING</STRONG>, <STRONG>UNIV</STRONG>, <STRONG>IA5</STRONG>, <STRONG>IA5STRING</STRONG>, <STRONG>UTF8</STRONG>,
<STRONG>UTF8String</STRONG>, <STRONG>BMP</STRONG>, <STRONG>BMPSTRING</STRONG>, <STRONG>VISIBLESTRING</STRONG>,
<STRONG>VISIBLE</STRONG>, <STRONG>PRINTABLESTRING</STRONG>, <STRONG>PRINTABLE</STRONG>, <STRONG>T61</STRONG>,
<STRONG>T61STRING</STRONG>, <STRONG>TELETEXSTRING</STRONG>, <STRONG>GeneralString</STRONG>, <STRONG>NUMERICSTRING</STRONG>,
<STRONG>NUMERIC</STRONG></A></STRONG><DD>
<P>
These encode the corresponding string types. <STRONG>value</STRONG> represents the contents of this structure. The format can be <STRONG>ASCII</STRONG> or <STRONG>UTF8</STRONG>.

</P>
<DT><STRONG><A NAME="item_SEQUENCE"><STRONG>SEQUENCE</STRONG>, <STRONG>SEQ</STRONG>, <STRONG>SET</STRONG></A></STRONG><DD>
<P>
Formats the result as an ASN1 <STRONG>SEQUENCE</STRONG> or <STRONG>SET</STRONG> type. <STRONG>value</STRONG>
should be a section name which will contain the contents. The field names
in the section are ignored and the values are in the generated string
format. If <STRONG>value</STRONG> is absent then an empty SEQUENCE will be encoded.

</P>
</DL>
<P>
<HR>
<H2><A NAME="MODIFIERS">MODIFIERS</A></H2>
<P>
Modifiers affect the following structure, they can be used to add EXPLICIT
or IMPLICIT tagging, add wrappers or to change the string format of the
final type and value. The supported formats are documented below.

</P>
<DL>
<DT><STRONG><A NAME="item_EXPLICIT"><STRONG>EXPLICIT</STRONG>, <STRONG>EXP</STRONG></A></STRONG><DD>
<P>
Add an explicit tag to the following structure. This string should be
followed by a colon and the tag value to use as a decimal value.

</P>
<P>
By following the number with <STRONG>U</STRONG>, <STRONG>A</STRONG>, <STRONG>P</STRONG> or <STRONG>C</STRONG> UNIVERSAL, APPLICATION, PRIVATE or CONTEXT SPECIFIC tagging can be used,
the default is CONTEXT SPECIFIC.

</P>
<DT><STRONG><A NAME="item_IMPLICIT"><STRONG>IMPLICIT</STRONG>, <STRONG>IMP</STRONG></A></STRONG><DD>
<P>
This is the same as <STRONG>EXPLICIT</STRONG> except IMPLICIT tagging is used instead.

</P>
<DT><STRONG><A NAME="item_OCTWRAP"><STRONG>OCTWRAP</STRONG>, <STRONG>SEQWRAP</STRONG>, <STRONG>SETWRAP</STRONG>, <STRONG>BITWRAP</STRONG></A></STRONG><DD>
<P>
The following structure is surrounded by an OCTET STRING, a SEQUENCE, a SET
or a BIT STRING respectively. For a BIT STRING the number of unused bits is
set to zero.

</P>
<DT><STRONG><A NAME="item_FORMAT"><STRONG>FORMAT</STRONG></A></STRONG><DD>
<P>
This specifies the format of the ultimate value. It should be followed by a
colon and one of the strings <STRONG>ASCII</STRONG>, <STRONG>UTF8</STRONG>, <STRONG>HEX</STRONG> or <STRONG>BITLIST</STRONG>.

</P>
<P>
If no format specifier is included then <STRONG>ASCII</STRONG> is used. If <STRONG>UTF8</STRONG> is specified then the value string must be a valid <STRONG>UTF8</STRONG> string. For <STRONG>HEX</STRONG> the output must be a set of hex digits. <STRONG>BITLIST</STRONG> (which is only valid for a BIT STRING) is a comma separated list of the
indices of the set bits, all other bits are zero.

</P>
</DL>
<P>
<HR>
<H1><A NAME="EXAMPLES">EXAMPLES</A></H1>
<P>
A simple IA5String:

</P>
<PRE> IA5STRING:Hello World
</PRE>
<P>
An IA5String explicitly tagged:

</P>
<PRE> EXPLICIT:0,IA5STRING:Hello World
</PRE>
<P>
An IA5String explicitly tagged using APPLICATION tagging:

</P>
<PRE> EXPLICIT:0A,IA5STRING:Hello World
</PRE>
<P>
A BITSTRING with bits 1 and 5 set and all others zero:

</P>
<PRE> FORMAT:BITLIST,BITSTRING:1,5
</PRE>
<P>
A more complex example using a config file to produce a SEQUENCE consiting
of a BOOL an OID and a UTF8String:

</P>
<PRE> asn1 = SEQUENCE:seq_section
</PRE>
<PRE> [seq_section]
</PRE>
<PRE> field1 = BOOLEAN:TRUE
 field2 = OID:commonName
 field3 = UTF8:Third field
</PRE>
<P>
This example produces an RSAPrivateKey structure, this is the key contained
in the file client.pem in all OpenSSL distributions (note: the field names
such as 'coeff' are ignored and are present just for clarity):

</P>
<PRE> asn1=SEQUENCE:private_key
 [private_key]
 version=INTEGER:0
</PRE>
<PRE> n=INTEGER:0xBB6FE79432CC6EA2D8F970675A5A87BFBE1AFF0BE63E879F2AFFB93644\\
 D4D2C6D000430DEC66ABF47829E74B8C5108623A1C0EE8BE217B3AD8D36D5EB4FCA1D9
</PRE>
<PRE> e=INTEGER:0x010001
</PRE>
<PRE> d=INTEGER:0x6F05EAD2F27FFAEC84BEC360C4B928FD5F3A9865D0FCAAD291E2A52F4A\\
 F810DC6373278C006A0ABBA27DC8C63BF97F7E666E27C5284D7D3B1FFFE16B7A87B51D
</PRE>
<PRE> p=INTEGER:0xF3929B9435608F8A22C208D86795271D54EBDFB09DDEF539AB083DA912\\
 D4BD57
</PRE>
<PRE> q=INTEGER:0xC50016F89DFF2561347ED1186A46E150E28BF2D0F539A1594BBD7FE467\\
 46EC4F
</PRE>
<PRE> exp1=INTEGER:0x9E7D4326C924AFC1DEA40B45650134966D6F9DFA3A7F9D698CD4ABEA\\
 9C0A39B9
</PRE>
<PRE> exp2=INTEGER:0xBA84003BB95355AFB7C50DF140C60513D0BA51D637272E355E397779\\
 E7B2458F
</PRE>
<PRE> coeff=INTEGER:0x30B9E4F2AFA5AC679F920FC83F1F2DF1BAF1779CF989447FABC2F5\\
 628657053A
</PRE>
<P>
This example is the corresponding public key in a SubjectPublicKeyInfo
structure:

</P>
<PRE> # Start with a SEQUENCE
 asn1=SEQUENCE:pubkeyinfo
</PRE>
<PRE> # pubkeyinfo contains an algorithm identifier and the public key wrapped
 \# in a BIT STRING
 [pubkeyinfo]
 algorithm=SEQUENCE:rsa_alg
 pubkey=BITWRAP,SEQUENCE:rsapubkey
</PRE>
<PRE> # algorithm ID for RSA is just an OID and a NULL
 [rsa_alg]
 algorithm=OID:rsaEncryption
 parameter=NULL
</PRE>
<PRE> # Actual public key: modulus and exponent
 [rsapubkey]
 n=INTEGER:0xBB6FE79432CC6EA2D8F970675A5A87BFBE1AFF0BE63E879F2AFFB93644\\
 D4D2C6D000430DEC66ABF47829E74B8C5108623A1C0EE8BE217B3AD8D36D5EB4FCA1D9
</PRE>
<PRE> e=INTEGER:0x010001
</PRE>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>ASN1_generate_nconf()</CODE> and <CODE>ASN1_generate_v3()</CODE>
return the encoded data as an <STRONG>ASN1_TYPE</STRONG> structure or <STRONG>NULL</STRONG> if an error occurred.

</P>
<P>
The error codes that can be obtained by <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>ASN1_generate_nconf()</CODE> and <CODE>ASN1_generate_v3()</CODE> were
added to OpenSSL 0.9.8

</P>
:}

