1OPENSSL-REQ(1ossl) OpenSSL OPENSSL-REQ(1ossl)
2
3
4
6 openssl-req - PKCS#10 certificate request and certificate generating
7 command
8
10 openssl req [-help] [-inform DER|PEM] [-outform DER|PEM] [-in filename]
11 [-passin arg] [-out filename] [-passout arg] [-text] [-pubkey] [-noout]
12 [-verify] [-modulus] [-new] [-newkey arg] [-pkeyopt opt:value] [-noenc]
13 [-nodes] [-key filename|uri] [-keyform DER|PEM|P12|ENGINE] [-keyout
14 filename] [-keygen_engine id] [-digest] [-config filename] [-section
15 name] [-x509] [-CA filename|uri] [-CAkey filename|uri] [-days n]
16 [-set_serial n] [-newhdr] [-copy_extensions arg] [-addext ext]
17 [-extensions section] [-reqexts section] [-precert] [-utf8] [-reqopt]
18 [-subject] [-subj arg] [-multivalue-rdn] [-sigopt nm:v] [-vfyopt nm:v]
19 [-batch] [-verbose] [-nameopt option] [-rand files] [-writerand file]
20 [-engine id] [-provider name] [-provider-path path] [-propquery propq]
21
23 This command primarily creates and processes certificate requests
24 (CSRs) in PKCS#10 format. It can additionally create self-signed
25 certificates for use as root CAs for example.
26
28 -help
29 Print out a usage message.
30
31 -inform DER|PEM, -outform DER|PEM
32 The input and output formats; unspecified by default. See
33 openssl-format-options(1) for details.
34
35 The data is a PKCS#10 object.
36
37 -in filename
38 This specifies the input filename to read a request from. This
39 defaults to standard input unless -x509 or -CA is specified. A
40 request is only read if the creation options (-new or -newkey or
41 -precert) are not specified.
42
43 -sigopt nm:v
44 Pass options to the signature algorithm during sign operations.
45 Names and values of these options are algorithm-specific.
46
47 -vfyopt nm:v
48 Pass options to the signature algorithm during verify operations.
49 Names and values of these options are algorithm-specific.
50
51 -passin arg
52 The password source for private key and certificate input. For
53 more information about the format of arg see
54 openssl-passphrase-options(1).
55
56 -passout arg
57 The password source for the output file. For more information
58 about the format of arg see openssl-passphrase-options(1).
59
60 -out filename
61 This specifies the output filename to write to or standard output
62 by default.
63
64 -text
65 Prints out the certificate request in text form.
66
67 -subject
68 Prints out the certificate request subject (or certificate subject
69 if -x509 is in use).
70
71 -pubkey
72 Prints out the public key.
73
74 -noout
75 This option prevents output of the encoded version of the
76 certificate request.
77
78 -modulus
79 Prints out the value of the modulus of the public key contained in
80 the request.
81
82 -verify
83 Verifies the self-signature on the request.
84
85 -new
86 This option generates a new certificate request. It will prompt the
87 user for the relevant field values. The actual fields prompted for
88 and their maximum and minimum sizes are specified in the
89 configuration file and any requested extensions.
90
91 If the -key option is not given it will generate a new private key
92 using information specified in the configuration file or given with
93 the -newkey and -pkeyopt options, else by default an RSA key with
94 2048 bits length.
95
96 -newkey arg
97 This option is used to generate a new private key unless -key is
98 given. It is subsequently used as if it was given using the -key
99 option.
100
101 This option implies the -new flag to create a new certificate
102 request or a new certificate in case -x509 is given.
103
104 The argument takes one of several forms.
105
106 [rsa:]nbits generates an RSA key nbits in size. If nbits is
107 omitted, i.e., -newkey rsa is specified, the default key size
108 specified in the configuration file with the default_bits option is
109 used if present, else 2048.
110
111 All other algorithms support the -newkey algname:file form, where
112 file is an algorithm parameter file, created with "openssl genpkey
113 -genparam" or an X.509 certificate for a key with appropriate
114 algorithm.
115
116 param:file generates a key using the parameter file or certificate
117 file, the algorithm is determined by the parameters.
118
119 algname[:file] generates a key using the given algorithm algname.
120 If a parameter file file is given then the parameters specified
121 there are used, where the algorithm parameters must match algname.
122 If algorithm parameters are not given, any necessary parameters
123 should be specified via the -pkeyopt option.
124
125 dsa:filename generates a DSA key using the parameters in the file
126 filename. ec:filename generates EC key (usable both with ECDSA or
127 ECDH algorithms), gost2001:filename generates GOST R 34.10-2001 key
128 (requires gost engine configured in the configuration file). If
129 just gost2001 is specified a parameter set should be specified by
130 -pkeyopt paramset:X
131
132 -pkeyopt opt:value
133 Set the public key algorithm option opt to value. The precise set
134 of options supported depends on the public key algorithm used and
135 its implementation. See "KEY GENERATION OPTIONS" in
136 openssl-genpkey(1) for more details.
137
138 -key filename|uri
139 This option provides the private key for signing a new certificate
140 or certificate request. Unless -in is given, the corresponding
141 public key is placed in the new certificate or certificate request,
142 resulting in a self-signature.
143
144 For certificate signing this option is overridden by the -CA
145 option.
146
147 This option also accepts PKCS#8 format private keys for PEM format
148 files.
149
150 -keyform DER|PEM|P12|ENGINE
151 The format of the private key; unspecified by default. See
152 openssl-format-options(1) for details.
153
154 -keyout filename
155 This gives the filename to write any private key to that has been
156 newly created or read from -key. If neither the -keyout option nor
157 the -key option are given then the filename specified in the
158 configuration file with the default_keyfile option is used, if
159 present. Thus, if you want to write the private key and the -key
160 option is provided, you should provide the -keyout option
161 explicitly. If a new key is generated and no filename is specified
162 the key is written to standard output.
163
164 -noenc
165 If this option is specified then if a private key is created it
166 will not be encrypted.
167
168 -nodes
169 This option is deprecated since OpenSSL 3.0; use -noenc instead.
170
171 -digest
172 This specifies the message digest to sign the request. Any digest
173 supported by the OpenSSL dgst command can be used. This overrides
174 the digest algorithm specified in the configuration file.
175
176 Some public key algorithms may override this choice. For instance,
177 DSA signatures always use SHA1, GOST R 34.10 signatures always use
178 GOST R 34.11-94 (-md_gost94), Ed25519 and Ed448 never use any
179 digest.
180
181 -config filename
182 This allows an alternative configuration file to be specified.
183 Optional; for a description of the default value, see "COMMAND
184 SUMMARY" in openssl(1).
185
186 -section name
187 Specifies the name of the section to use; the default is req.
188
189 -subj arg
190 Sets subject name for new request or supersedes the subject name
191 when processing a certificate request.
192
193 The arg must be formatted as
194 "/type0=value0/type1=value1/type2=...". Special characters may be
195 escaped by "\" (backslash), whitespace is retained. Empty values
196 are permitted, but the corresponding type will not be included in
197 the request. Giving a single "/" will lead to an empty sequence of
198 RDNs (a NULL-DN). Multi-valued RDNs can be formed by placing a "+"
199 character instead of a "/" between the AttributeValueAssertions
200 (AVAs) that specify the members of the set. Example:
201
202 "/DC=org/DC=OpenSSL/DC=users/UID=123456+CN=John Doe"
203
204 -multivalue-rdn
205 This option has been deprecated and has no effect.
206
207 -x509
208 This option outputs a certificate instead of a certificate request.
209 This is typically used to generate test certificates. It is
210 implied by the -CA option.
211
212 This option implies the -new flag if -in is not given.
213
214 If an existing request is specified with the -in option, it is
215 converted to the a certificate; otherwise a request is created from
216 scratch.
217
218 Unless specified using the -set_serial option, a large random
219 number will be used for the serial number.
220
221 Unless the -copy_extensions option is used, X.509 extensions are
222 not copied from any provided request input file.
223
224 X.509 extensions to be added can be specified in the configuration
225 file or using the -addext option.
226
227 -CA filename|uri
228 Specifies the "CA" certificate to be used for signing a new
229 certificate and implies use of -x509. When present, this behaves
230 like a "micro CA" as follows: The subject name of the "CA"
231 certificate is placed as issuer name in the new certificate, which
232 is then signed using the "CA" key given as specified below.
233
234 -CAkey filename|uri
235 Sets the "CA" private key to sign a certificate with. The private
236 key must match the public key of the certificate given with -CA.
237 If this option is not provided then the key must be present in the
238 -CA input.
239
240 -days n
241 When -x509 is in use this specifies the number of days to certify
242 the certificate for, otherwise it is ignored. n should be a
243 positive integer. The default is 30 days.
244
245 -set_serial n
246 Serial number to use when outputting a self-signed certificate.
247 This may be specified as a decimal value or a hex value if preceded
248 by "0x". If not given, a large random number will be used.
249
250 -copy_extensions arg
251 Determines how X.509 extensions in certificate requests should be
252 handled when -x509 is in use. If arg is none or this option is not
253 present then extensions are ignored. If arg is copy or copyall
254 then all extensions in the request are copied to the certificate.
255
256 The main use of this option is to allow a certificate request to
257 supply values for certain extensions such as subjectAltName.
258
259 -addext ext
260 Add a specific extension to the certificate (if -x509 is in use) or
261 certificate request. The argument must have the form of a
262 key=value pair as it would appear in a config file.
263
264 This option can be given multiple times.
265
266 -extensions section
267 -reqexts section
268 These options specify alternative sections to include certificate
269 extensions (if -x509 is in use) or certificate request extensions.
270 This allows several different sections to be used in the same
271 configuration file to specify requests for a variety of purposes.
272
273 -precert
274 A poison extension will be added to the certificate, making it a
275 "pre-certificate" (see RFC6962). This can be submitted to
276 Certificate Transparency logs in order to obtain signed certificate
277 timestamps (SCTs). These SCTs can then be embedded into the pre-
278 certificate as an extension, before removing the poison and signing
279 the certificate.
280
281 This implies the -new flag.
282
283 -utf8
284 This option causes field values to be interpreted as UTF8 strings,
285 by default they are interpreted as ASCII. This means that the field
286 values, whether prompted from a terminal or obtained from a
287 configuration file, must be valid UTF8 strings.
288
289 -reqopt option
290 Customise the printing format used with -text. The option argument
291 can be a single option or multiple options separated by commas.
292
293 See discussion of the -certopt parameter in the openssl-x509(1)
294 command.
295
296 -newhdr
297 Adds the word NEW to the PEM file header and footer lines on the
298 outputted request. Some software (Netscape certificate server) and
299 some CAs need this.
300
301 -batch
302 Non-interactive mode.
303
304 -verbose
305 Print extra details about the operations being performed.
306
307 -keygen_engine id
308 Specifies an engine (by its unique id string) which would be used
309 for key generation operations.
310
311 -nameopt option
312 This specifies how the subject or issuer names are displayed. See
313 openssl-namedisplay-options(1) for details.
314
315 -rand files, -writerand file
316 See "Random State Options" in openssl(1) for details.
317
318 -engine id
319 See "Engine Options" in openssl(1). This option is deprecated.
320
321 -provider name
322 -provider-path path
323 -propquery propq
324 See "Provider Options" in openssl(1), provider(7), and property(7).
325
327 The configuration options are specified in the req section of the
328 configuration file. An alternate name be specified by using the
329 -section option. As with all configuration files, if no value is
330 specified in the specific section then the initial unnamed or default
331 section is searched too.
332
333 The options available are described in detail below.
334
335 input_password, output_password
336 The passwords for the input private key file (if present) and the
337 output private key file (if one will be created). The command line
338 options passin and passout override the configuration file values.
339
340 default_bits
341 Specifies the default key size in bits.
342
343 This option is used in conjunction with the -new option to generate
344 a new key. It can be overridden by specifying an explicit key size
345 in the -newkey option. The smallest accepted key size is 512 bits.
346 If no key size is specified then 2048 bits is used.
347
348 default_keyfile
349 This is the default filename to write a private key to. If not
350 specified the key is written to standard output. This can be
351 overridden by the -keyout option.
352
353 oid_file
354 This specifies a file containing additional OBJECT IDENTIFIERS.
355 Each line of the file should consist of the numerical form of the
356 object identifier followed by whitespace then the short name
357 followed by whitespace and finally the long name.
358
359 oid_section
360 This specifies a section in the configuration file containing extra
361 object identifiers. Each line should consist of the short name of
362 the object identifier followed by = and the numerical form. The
363 short and long names are the same when this option is used.
364
365 RANDFILE
366 At startup the specified file is loaded into the random number
367 generator, and at exit 256 bytes will be written to it. It is used
368 for private key generation.
369
370 encrypt_key
371 If this is set to no then if a private key is generated it is not
372 encrypted. This is equivalent to the -noenc command line option.
373 For compatibility encrypt_rsa_key is an equivalent option.
374
375 default_md
376 This option specifies the digest algorithm to use. Any digest
377 supported by the OpenSSL dgst command can be used. This option can
378 be overridden on the command line. Certain signing algorithms (i.e.
379 Ed25519 and Ed448) will ignore any digest that has been set.
380
381 string_mask
382 This option masks out the use of certain string types in certain
383 fields. Most users will not need to change this option.
384
385 It can be set to several values default which is also the default
386 option uses PrintableStrings, T61Strings and BMPStrings if the pkix
387 value is used then only PrintableStrings and BMPStrings will be
388 used. This follows the PKIX recommendation in RFC2459. If the
389 utf8only option is used then only UTF8Strings will be used: this is
390 the PKIX recommendation in RFC2459 after 2003. Finally the nombstr
391 option just uses PrintableStrings and T61Strings: certain software
392 has problems with BMPStrings and UTF8Strings: in particular
393 Netscape.
394
395 req_extensions
396 This specifies the configuration file section containing a list of
397 extensions to add to the certificate request. It can be overridden
398 by the -reqexts command line switch. See the x509v3_config(5)
399 manual page for details of the extension section format.
400
401 x509_extensions
402 This specifies the configuration file section containing a list of
403 extensions to add to certificate generated when -x509 is in use.
404 It can be overridden by the -extensions command line switch.
405
406 prompt
407 If set to the value no this disables prompting of certificate
408 fields and just takes values from the config file directly. It also
409 changes the expected format of the distinguished_name and
410 attributes sections.
411
412 utf8
413 If set to the value yes then field values to be interpreted as UTF8
414 strings, by default they are interpreted as ASCII. This means that
415 the field values, whether prompted from a terminal or obtained from
416 a configuration file, must be valid UTF8 strings.
417
418 attributes
419 This specifies the section containing any request attributes: its
420 format is the same as distinguished_name. Typically these may
421 contain the challengePassword or unstructuredName types. They are
422 currently ignored by OpenSSL's request signing utilities but some
423 CAs might want them.
424
425 distinguished_name
426 This specifies the section containing the distinguished name fields
427 to prompt for when generating a certificate or certificate request.
428 The format is described in the next section.
429
431 There are two separate formats for the distinguished name and attribute
432 sections. If the prompt option is set to no then these sections just
433 consist of field names and values: for example,
434
435 CN=My Name
436 OU=My Organization
437 emailAddress=someone@somewhere.org
438
439 This allows external programs (e.g. GUI based) to generate a template
440 file with all the field names and values and just pass it to this
441 command. An example of this kind of configuration file is contained in
442 the EXAMPLES section.
443
444 Alternatively if the prompt option is absent or not set to no then the
445 file contains field prompting information. It consists of lines of the
446 form:
447
448 fieldName="prompt"
449 fieldName_default="default field value"
450 fieldName_min= 2
451 fieldName_max= 4
452
453 "fieldName" is the field name being used, for example commonName (or
454 CN). The "prompt" string is used to ask the user to enter the relevant
455 details. If the user enters nothing then the default value is used if
456 no default value is present then the field is omitted. A field can
457 still be omitted if a default value is present if the user just enters
458 the '.' character.
459
460 The number of characters entered must be between the fieldName_min and
461 fieldName_max limits: there may be additional restrictions based on the
462 field being used (for example countryName can only ever be two
463 characters long and must fit in a PrintableString).
464
465 Some fields (such as organizationName) can be used more than once in a
466 DN. This presents a problem because configuration files will not
467 recognize the same name occurring twice. To avoid this problem if the
468 fieldName contains some characters followed by a full stop they will be
469 ignored. So for example a second organizationName can be input by
470 calling it "1.organizationName".
471
472 The actual permitted field names are any object identifier short or
473 long names. These are compiled into OpenSSL and include the usual
474 values such as commonName, countryName, localityName, organizationName,
475 organizationalUnitName, stateOrProvinceName. Additionally emailAddress
476 is included as well as name, surname, givenName, initials, and
477 dnQualifier.
478
479 Additional object identifiers can be defined with the oid_file or
480 oid_section options in the configuration file. Any additional fields
481 will be treated as though they were a DirectoryString.
482
484 Examine and verify certificate request:
485
486 openssl req -in req.pem -text -verify -noout
487
488 Create a private key and then generate a certificate request from it:
489
490 openssl genrsa -out key.pem 2048
491 openssl req -new -key key.pem -out req.pem
492
493 The same but just using req:
494
495 openssl req -newkey rsa:2048 -keyout key.pem -out req.pem
496
497 Generate a self-signed root certificate:
498
499 openssl req -x509 -newkey rsa:2048 -keyout key.pem -out req.pem
500
501 Create an SM2 private key and then generate a certificate request from
502 it:
503
504 openssl ecparam -genkey -name SM2 -out sm2.key
505 openssl req -new -key sm2.key -out sm2.csr -sm3 -sigopt "distid:1234567812345678"
506
507 Examine and verify an SM2 certificate request:
508
509 openssl req -verify -in sm2.csr -sm3 -vfyopt "distid:1234567812345678"
510
511 Example of a file pointed to by the oid_file option:
512
513 1.2.3.4 shortName A longer Name
514 1.2.3.6 otherName Other longer Name
515
516 Example of a section pointed to by oid_section making use of variable
517 expansion:
518
519 testoid1=1.2.3.5
520 testoid2=${testoid1}.6
521
522 Sample configuration file prompting for field values:
523
524 [ req ]
525 default_bits = 2048
526 default_keyfile = privkey.pem
527 distinguished_name = req_distinguished_name
528 attributes = req_attributes
529 req_extensions = v3_ca
530
531 dirstring_type = nobmp
532
533 [ req_distinguished_name ]
534 countryName = Country Name (2 letter code)
535 countryName_default = AU
536 countryName_min = 2
537 countryName_max = 2
538
539 localityName = Locality Name (eg, city)
540
541 organizationalUnitName = Organizational Unit Name (eg, section)
542
543 commonName = Common Name (eg, YOUR name)
544 commonName_max = 64
545
546 emailAddress = Email Address
547 emailAddress_max = 40
548
549 [ req_attributes ]
550 challengePassword = A challenge password
551 challengePassword_min = 4
552 challengePassword_max = 20
553
554 [ v3_ca ]
555
556 subjectKeyIdentifier=hash
557 authorityKeyIdentifier=keyid:always,issuer:always
558 basicConstraints = critical, CA:true
559
560 Sample configuration containing all field values:
561
562 [ req ]
563 default_bits = 2048
564 default_keyfile = keyfile.pem
565 distinguished_name = req_distinguished_name
566 attributes = req_attributes
567 prompt = no
568 output_password = mypass
569
570 [ req_distinguished_name ]
571 C = GB
572 ST = Test State or Province
573 L = Test Locality
574 O = Organization Name
575 OU = Organizational Unit Name
576 CN = Common Name
577 emailAddress = test@email.address
578
579 [ req_attributes ]
580 challengePassword = A challenge password
581
582 Example of giving the most common attributes (subject and extensions)
583 on the command line:
584
585 openssl req -new -subj "/C=GB/CN=foo" \
586 -addext "subjectAltName = DNS:foo.co.uk" \
587 -addext "certificatePolicies = 1.2.3.4" \
588 -newkey rsa:2048 -keyout key.pem -out req.pem
589
591 The certificate requests generated by Xenroll with MSIE have extensions
592 added. It includes the keyUsage extension which determines the type of
593 key (signature only or general purpose) and any additional OIDs entered
594 by the script in an extendedKeyUsage extension.
595
597 The following messages are frequently asked about:
598
599 Using configuration from /some/path/openssl.cnf
600 Unable to load config info
601
602 This is followed some time later by:
603
604 unable to find 'distinguished_name' in config
605 problems making Certificate Request
606
607 The first error message is the clue: it can't find the configuration
608 file! Certain operations (like examining a certificate request) don't
609 need a configuration file so its use isn't enforced. Generation of
610 certificates or requests however does need a configuration file. This
611 could be regarded as a bug.
612
613 Another puzzling message is this:
614
615 Attributes:
616 a0:00
617
618 this is displayed when no attributes are present and the request
619 includes the correct empty SET OF structure (the DER encoding of which
620 is 0xa0 0x00). If you just see:
621
622 Attributes:
623
624 then the SET OF is missing and the encoding is technically invalid (but
625 it is tolerated). See the description of the command line option
626 -asn1-kludge for more information.
627
629 OpenSSL's handling of T61Strings (aka TeletexStrings) is broken: it
630 effectively treats them as ISO-8859-1 (Latin 1), Netscape and MSIE have
631 similar behaviour. This can cause problems if you need characters that
632 aren't available in PrintableStrings and you don't want to or can't use
633 BMPStrings.
634
635 As a consequence of the T61String handling the only correct way to
636 represent accented characters in OpenSSL is to use a BMPString:
637 unfortunately Netscape currently chokes on these. If you have to use
638 accented characters with Netscape and MSIE then you currently need to
639 use the invalid T61String form.
640
641 The current prompting is not very friendly. It doesn't allow you to
642 confirm what you've just entered. Other things like extensions in
643 certificate requests are statically defined in the configuration file.
644 Some of these: like an email address in subjectAltName should be input
645 by the user.
646
648 openssl(1), openssl-x509(1), openssl-ca(1), openssl-genrsa(1),
649 openssl-gendsa(1), config(5), x509v3_config(5)
650
652 The -section option was added in OpenSSL 3.0.0.
653
654 The -multivalue-rdn option has become obsolete in OpenSSL 3.0.0 and has
655 no effect.
656
657 The -engine option was deprecated in OpenSSL 3.0. The <-nodes> option
658 was deprecated in OpenSSL 3.0, too; use -noenc instead.
659
661 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
662
663 Licensed under the Apache License 2.0 (the "License"). You may not use
664 this file except in compliance with the License. You can obtain a copy
665 in the file LICENSE in the source distribution or at
666 <https://www.openssl.org/source/license.html>.
667
668
669
6703.1.1 2023-08-31 OPENSSL-REQ(1ossl)