6 req - PKCS#10 certificate and certificate generating utility.
26 [B<-[md5|sha1|md2|mdc2]>]
31 [B<-extensions section>]
36 The B<req> command primarily creates and processes certificate requests
37 in PKCS#10 format. It can additionally create self signed certificates
38 for use as root CAs for example.
40 =head1 COMMAND OPTIONS
44 =item B<-inform DER|PEM>
46 This specifies the input format. The B<DER> option uses an ASN1 DER encoded
47 form compatible with the PKCS#10. The B<PEM> form is the default format: it
48 consists of the B<DER> format base64 encoded with additional header and
51 =item B<-outform DER|PEM>
53 This specifies the output format, the options have the same meaning as the
58 This specifies the input filename to read a request from or standard input
59 if this option is not specified. A request is only read if the creation
60 options (B<-new> and B<-newkey>) are not specified.
62 =item B<-out filename>
64 This specifies the output filename to write to or standard output by
69 prints out the certificate request in text form.
73 this option prevents output of the encoded version of the request.
77 this option prints out the value of the modulus of the public key
78 contained in the request.
82 verifies the signature on the request.
86 this option generates a new certificate request. It will prompt
87 the user for the relevant field values. The actual fields
88 prompted for and their maximum and minimum sizes are specified
89 in the configuration file and any requested extensions.
91 If the B<-key> option is not used it will generate a new RSA private
92 key using information specified in the configuration file.
96 this option creates a new certificate request and a new private
97 key. The argument takes one of two forms. B<rsa:nbits>, where
98 B<nbits> is the number of bits, generates an RSA key B<nbits>
99 in size. B<dsa:filename> generates a DSA key using the parameters
100 in the file B<filename>.
102 =item B<-key filename>
104 This specifies the file to read the private key from. It also
105 accepts PKCS#8 format private keys for PEM format files.
107 =item B<-keyform PEM|DER>
109 the format of the private key file specified in the B<-key>
110 argument. PEM is the default.
112 =item B<-keyout filename>
114 this gives the filename to write the newly created private key to.
115 If this option is not specified then the filename present in the
116 configuration file is used.
120 if this option is specified then if a private key is created it
121 will not be encrypted.
123 =item B<-[md5|sha1|md2|mdc2]>
125 this specifies the message digest to sign the request with. This
126 overrides the digest algorithm specified in the configuration file.
127 This option is ignore for DSA requests: they always use SHA1.
129 =item B<-config filename>
131 this allows an alternative configuration file to be specified,
132 this overrides the compile time filename or any specified in
133 the B<OPENSSL_CONF> environment variable.
137 this option outputs a self signed certificate instead of a certificate
138 request. This is typically used to generate a test certificate or
139 a self signed root CA. The extensions added to the certificate
140 (if any) are specified in the configuration file.
144 when the B<-x509> option is being used this specifies the number of
145 days to certify the certificate for. The default is 30 days.
147 =item B<-extensions section>
148 =item B<-reqexts section>
150 these options specify alternative sections to include certificate
151 extensions (if the B<-x509> option is present) or certificate
152 request extensions. This allows several different sections to
153 be used in the same configuration file to specify requests for
154 a variety of purposes.
156 =item B<-asn1-kludge>
158 by default the B<req> command outputs certificate requests containing
159 no attributes in the correct PKCS#10 format. However certain CAs will only
160 accept requests containing no attributes in an invalid form: this
161 option produces this invalid format.
163 More precisely the B<Attributes> in a PKCS#10 certificate request
164 are defined as a B<SET OF Attribute>. They are B<not OPTIONAL> so
165 if no attributes are present then they should be encoded as an
166 empty B<SET OF>. The invalid form does not include the empty
167 B<SET OF> whereas the correct form does.
169 It should be noted that very few CAs still require the use of this option.
173 =head1 CONFIGURATION FILE FORMAT
175 The configuation options are specified in the B<req> section of
176 the configuration file. As with all configuration files if no
177 value is specified in the specific section (i.e. B<req>) then
178 the initial unnamed or B<default> section is searched too.
180 The options available are described in detail below.
184 =item B<default_bits>
186 This specifies the default key size in bits. If not specified then
187 512 is used. It is used if the B<-new> option is used. It can be
188 overriden by using the B<-newkey> option.
190 =item B<default_keyfile>
192 This is the default filename to write a private key to. If not
193 specified the key is written to standard output. This can be
194 overriden by the B<-keyout> option.
198 This specifies a file containing additional B<OBJECT IDENTIFIERS>.
199 Each line of the file should consist of the numerical form of the
200 object identifier followed by white space then the short name followed
201 by white space and finally the long name.
205 This specifies a section in the configuration file containing extra
206 object identifiers. Each line should consist of the short name of the
207 object identifier followed by B<=> and the numerical form. The short
208 and long names are the same when this option is used.
212 This specifies a filename in which random number seed information is
213 placed and read from. It is used for private key generation.
215 =item B<encrypt_rsa_key|encrypt_key>
217 If this is set to B<no> then if a private key is generated it is
218 B<not> encrypted. This is equivalent to the B<-nodes> command line
223 This option specifies the digest algorithm to use. Possible values
224 include B<md5 sha1 mdc2>. If not present then MD5 is used. This
225 option can be overridden on the command line.
227 =item B<dirstring_type>
229 This option specifies which string types are permissible in a
230 B<DirectoryString>. Most users will not need to change this option.
232 It can be set to several values B<default> which is also the default
233 option uses PrintableStrings, T61Strings and BMPStrings if the
234 B<pkix> value is used then only PrintableStrings and BMPStrings will
235 be used. This follows the PKIX recommendation in RFC2459. If the
236 B<utf8only> option is used then only UTF8Strings will be used: this
237 is the PKIX recommendation in RFC2459 after 2003. Finally the B<nobmp>
238 option just uses PrintableStrings and T61Strings: certain software has
239 problems with BMPStrings.
241 =item B<req_extensions>
243 this specifies the configuration file section containing a list of
244 extensions to add to the certificate request. It can be overridden
245 by the B<-reqexts> command line switch.
247 =item B<x509_extensions>
249 this specifies the configuration file section containing a list of
250 extensions to add to certificate generated when the B<-x509> switch
251 is used. It can be overridden by the B<-extensions> command line switch.
255 this specifies the section containing any request attributes: its format
256 is the same as B<distinguished_name> described below. Typically these
257 may contain the challengePassword or unstructuredName types. They are
258 currently ignored by OpenSSLs request signing utilities but some CAs might want
261 =item B<distinguished_name>
263 This specifies the section containing the distiguished name fields to
264 prompt for when generating a certificate or certificate request. This
265 consists of lines of the form:
268 fieldName_default="default field value"
272 "fieldName" is the field name being used, for example commonName.
273 The "prompt" string is used to ask the user to enter the relvant
274 details. If the user enters nothing then the default value is used if no
275 default value is present then the field is omitted. A field can
276 still be omitted if a default value is present if the user just
277 enters the '.' character.
279 The number of characters entered must be between the fieldName_min and
280 fieldName_max limits: there may be additional restrictions based
281 on the field being used (for example countryName can only ever be
282 two characters long and must fit in a PrintableString).
284 Some fields (such as organizationName) can be used more than once
285 in a DN. This presents a problem because configuration files will
286 not recognise the same name occurring twice. To avoid this problem
287 if the fieldName contains an some characters followed by a full stop
288 they will be ignored. So for example a second organizationName can
289 be input by calling it "1.organizationName".
291 The actual permitted field names are any object identifier short or
292 long names. These are compiled into OpenSSL and include the usual
293 values such as commonName, countryName, localityName, organizationName,
294 organizationUnitName, stateOrPrivinceName. Additionally emailAddress
295 is include as well as name, surname, givenName initials and dnQualifier
298 Additional object identifiers can be defined with the B<oid_file> or
299 B<oid_section> options in the configuration file. Any additional fields
300 will be treated as though they were a DirectoryString.
306 Examine and verify certificate request:
308 openssl req -in req.pem -text -verify -noout
310 Create a private key and then generate a certificate request from it:
312 openssl genrsa -out key.pem 1024
313 openssl req -new -key key.pem -out req.pem
315 The same but just using req:
317 openssl req -newkey rsa:1024 -keyout key.pem -out req.pem
319 Generate a self signed root certificate:
321 openssl req -x509 -newkey rsa:1024 -keyout key.pem -out req.pem
323 Example of a file pointed to by the B<oid_file> option:
325 1.2.3.4 shortName A longer Name
326 1.2.3.6 otherName Other longer Name
328 Example of a section pointed to by B<oid_section> making use of variable
332 testoid2=${testoid1}.6
334 Sample configuration file:
338 default_keyfile = privkey.pem
339 distinguished_name = req_distinguished_name
340 attributes = req_attributes
341 x509_extensions = v3_ca
343 dirstring_type = nobmp
345 [ req_distinguished_name ]
346 countryName = Country Name (2 letter code)
347 countryName_default = AU
351 localityName = Locality Name (eg, city)
353 organizationalUnitName = Organizational Unit Name (eg, section)
355 commonName = Common Name (eg, YOUR name)
358 emailAddress = Email Address
359 emailAddress_max = 40
362 challengePassword = A challenge password
363 challengePassword_min = 4
364 challengePassword_max = 20
368 subjectKeyIdentifier=hash
369 authorityKeyIdentifier=keyid:always,issuer:always
370 basicConstraints = CA:true
374 The header and footer lines in the B<PEM> format are respectively:
376 -----BEGIN CERTIFICATE REQUEST----
377 -----END CERTIFICATE REQUEST----
379 some software (some versions of Netscape certificate server) instead needs:
381 -----BEGIN NEW CERTIFICATE REQUEST----
382 -----END NEW CERTIFICATE REQUEST----
384 but is otherwise compatible. Either form is accepted on input.
386 The certificate requests generated by B<Xenroll> with MSIE have extensions
387 added. It includes the B<keyUsage> extension which determines the type of
388 key (signature only or general purpose) and any additional OIDs entered
389 by the script in an extendedKeyUsage extension.
393 The following messages are frequently asked about:
395 Using configuration from /some/path/openssl.cnf
396 Unable to load config info
398 This is followed some time later by...
400 unable to find 'distinguished_name' in config
401 problems making Certificate Request
403 The first error message is the clue: it can't find the configuration
404 file! Certain operations (like examining a certificate request) don't
405 need a configuration file so its use isn't enforced. Generation of
406 certficates or requests however does need a configuration file. This
407 could be regarded as a bug.
409 Another puzzling message is this:
414 this is displayed when no attributes are present and the request includes
415 the correct empty B<SET OF> structure (the DER encoding of which is 0xa0
416 0x00). If you just see:
420 then the B<SET OF> is missing and the encoding is technically invalid (but
421 it is tolerated). See the description of the command line option B<-asn1-kludge>
422 for more information.
424 =head1 ENVIRONMENT VARIABLES
426 The variable B<OPENSSL_CONF> if defined allows an alternative configuration
427 file location to be specified, it will be overridden by the B<-config> command
428 line switch if it is present. For compatability reasons the B<SSLEAY_CONF>
429 environment variable serves the same purpose but its use is discouraged.
433 OpenSSLs handling of T61Strings (aka TeletexStrings) is broken: it effectively
434 treats them as ISO-8859-1 (latin 1), Netscape and MSIE have similar behaviour.
435 This can cause problems if you need characters that aren't available in
436 PrintableStrings and you don't want to or can't use BMPStrings.
438 As a consequence of the T61String handling the only correct way to represent
439 accented characters in OpenSSL is to use a BMPString: unfortunately Netscape
440 currently chokes on these. If you have to use accented characters with Netscape
441 and MSIE then you currently need to use the invalid T61String form.
443 The current prompting is not very friendly. It exits if you get the strings
444 wrong and doesn't allow you to confirm what you've just entered. Other things
445 like extensions in certificate requests are statically defined in the configuration
446 file. Some of these: like an email address in subjectAltName should be input
449 There should be a way to have a friendly front end (e.g. perl script or GUI)
450 handle all user input and then just feed a "template" file into B<req> which
451 then silently creates the request or certificate. This would also shift the
452 responsibility for handling such problems as internationalisation of characters
453 onto the front end: the template could then just expect valid UTF8 character
458 x509(1), ca(1), genrsa(1), gendsa(1), config(5)