Update copyright year
[oweals/openssl.git] / doc / apps / ca.pod
1 =pod
2
3 =head1 NAME
4
5 openssl-ca,
6 ca - sample minimal CA application
7
8 =head1 SYNOPSIS
9
10 B<openssl> B<ca>
11 [B<-help>]
12 [B<-verbose>]
13 [B<-config filename>]
14 [B<-name section>]
15 [B<-gencrl>]
16 [B<-revoke file>]
17 [B<-valid file>]
18 [B<-status serial>]
19 [B<-updatedb>]
20 [B<-crl_reason reason>]
21 [B<-crl_hold instruction>]
22 [B<-crl_compromise time>]
23 [B<-crl_CA_compromise time>]
24 [B<-crldays days>]
25 [B<-crlhours hours>]
26 [B<-crlexts section>]
27 [B<-startdate date>]
28 [B<-enddate date>]
29 [B<-days arg>]
30 [B<-md arg>]
31 [B<-policy arg>]
32 [B<-keyfile arg>]
33 [B<-keyform PEM|DER>]
34 [B<-key arg>]
35 [B<-passin arg>]
36 [B<-cert file>]
37 [B<-selfsign>]
38 [B<-in file>]
39 [B<-out file>]
40 [B<-notext>]
41 [B<-outdir dir>]
42 [B<-infiles>]
43 [B<-spkac file>]
44 [B<-ss_cert file>]
45 [B<-preserveDN>]
46 [B<-noemailDN>]
47 [B<-batch>]
48 [B<-msie_hack>]
49 [B<-extensions section>]
50 [B<-extfile section>]
51 [B<-engine id>]
52 [B<-subj arg>]
53 [B<-utf8>]
54 [B<-create_serial>]
55 [B<-multivalue-rdn>]
56
57 =head1 DESCRIPTION
58
59 The B<ca> command is a minimal CA application. It can be used
60 to sign certificate requests in a variety of forms and generate
61 CRLs it also maintains a text database of issued certificates
62 and their status.
63
64 The options descriptions will be divided into each purpose.
65
66 =head1 OPTIONS
67
68 =over 4
69
70 =item B<-help>
71
72 Print out a usage message.
73
74 =item B<-verbose>
75
76 this prints extra details about the operations being performed.
77
78 =item B<-config filename>
79
80 specifies the configuration file to use.
81 Optional; for a description of the default value,
82 see L<openssl(1)/COMMAND SUMMARY>.
83
84 =item B<-name section>
85
86 specifies the configuration file section to use (overrides
87 B<default_ca> in the B<ca> section).
88
89 =item B<-in filename>
90
91 an input filename containing a single certificate request to be
92 signed by the CA.
93
94 =item B<-ss_cert filename>
95
96 a single self-signed certificate to be signed by the CA.
97
98 =item B<-spkac filename>
99
100 a file containing a single Netscape signed public key and challenge
101 and additional field values to be signed by the CA. See the B<SPKAC FORMAT>
102 section for information on the required input and output format.
103
104 =item B<-infiles>
105
106 if present this should be the last option, all subsequent arguments
107 are taken as the names of files containing certificate requests.
108
109 =item B<-out filename>
110
111 the output file to output certificates to. The default is standard
112 output. The certificate details will also be printed out to this
113 file in PEM format (except that B<-spkac> outputs DER format).
114
115 =item B<-outdir directory>
116
117 the directory to output certificates to. The certificate will be
118 written to a filename consisting of the serial number in hex with
119 ".pem" appended.
120
121 =item B<-cert>
122
123 the CA certificate file.
124
125 =item B<-keyfile filename>
126
127 the private key to sign requests with.
128
129 =item B<-keyform PEM|DER>
130
131 the format of the data in the private key file.
132 The default is PEM.
133
134 =item B<-key password>
135
136 the password used to encrypt the private key. Since on some
137 systems the command line arguments are visible (e.g. Unix with
138 the 'ps' utility) this option should be used with caution.
139
140 =item B<-selfsign>
141
142 indicates the issued certificates are to be signed with the key
143 the certificate requests were signed with (given with B<-keyfile>).
144 Certificate requests signed with a different key are ignored.  If
145 B<-spkac>, B<-ss_cert> or B<-gencrl> are given, B<-selfsign> is
146 ignored.
147
148 A consequence of using B<-selfsign> is that the self-signed
149 certificate appears among the entries in the certificate database
150 (see the configuration option B<database>), and uses the same
151 serial number counter as all other certificates sign with the
152 self-signed certificate.
153
154 =item B<-passin arg>
155
156 the key password source. For more information about the format of B<arg>
157 see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
158
159 =item B<-notext>
160
161 don't output the text form of a certificate to the output file.
162
163 =item B<-startdate date>
164
165 this allows the start date to be explicitly set. The format of the
166 date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
167
168 =item B<-enddate date>
169
170 this allows the expiry date to be explicitly set. The format of the
171 date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
172
173 =item B<-days arg>
174
175 the number of days to certify the certificate for.
176
177 =item B<-md alg>
178
179 the message digest to use.
180 Any digest supported by the OpenSSL B<dgst> command can be used.
181 This option also applies to CRLs.
182
183 =item B<-policy arg>
184
185 this option defines the CA "policy" to use. This is a section in
186 the configuration file which decides which fields should be mandatory
187 or match the CA certificate. Check out the B<POLICY FORMAT> section
188 for more information.
189
190 =item B<-msie_hack>
191
192 this is a legacy option to make B<ca> work with very old versions of
193 the IE certificate enrollment control "certenr3". It used UniversalStrings
194 for almost everything. Since the old control has various security bugs
195 its use is strongly discouraged. The newer control "Xenroll" does not
196 need this option.
197
198 =item B<-preserveDN>
199
200 Normally the DN order of a certificate is the same as the order of the
201 fields in the relevant policy section. When this option is set the order
202 is the same as the request. This is largely for compatibility with the
203 older IE enrollment control which would only accept certificates if their
204 DNs match the order of the request. This is not needed for Xenroll.
205
206 =item B<-noemailDN>
207
208 The DN of a certificate can contain the EMAIL field if present in the
209 request DN, however it is good policy just having the e-mail set into
210 the altName extension of the certificate. When this option is set the
211 EMAIL field is removed from the certificate' subject and set only in
212 the, eventually present, extensions. The B<email_in_dn> keyword can be
213 used in the configuration file to enable this behaviour.
214
215 =item B<-batch>
216
217 this sets the batch mode. In this mode no questions will be asked
218 and all certificates will be certified automatically.
219
220 =item B<-extensions section>
221
222 the section of the configuration file containing certificate extensions
223 to be added when a certificate is issued (defaults to B<x509_extensions>
224 unless the B<-extfile> option is used). If no extension section is
225 present then, a V1 certificate is created. If the extension section
226 is present (even if it is empty), then a V3 certificate is created. See the:w
227 L<x509v3_config(5)> manual page for details of the
228 extension section format.
229
230 =item B<-extfile file>
231
232 an additional configuration file to read certificate extensions from
233 (using the default section unless the B<-extensions> option is also
234 used).
235
236 =item B<-engine id>
237
238 specifying an engine (by its unique B<id> string) will cause B<ca>
239 to attempt to obtain a functional reference to the specified engine,
240 thus initialising it if needed. The engine will then be set as the default
241 for all available algorithms.
242
243 =item B<-subj arg>
244
245 supersedes subject name given in the request.
246 The arg must be formatted as I</type0=value0/type1=value1/type2=...>,
247 characters may be escaped by \ (backslash), no spaces are skipped.
248
249 =item B<-utf8>
250
251 this option causes field values to be interpreted as UTF8 strings, by
252 default they are interpreted as ASCII. This means that the field
253 values, whether prompted from a terminal or obtained from a
254 configuration file, must be valid UTF8 strings.
255
256 =item B<-create_serial>
257
258 if reading serial from the text file as specified in the configuration
259 fails, specifying this option creates a new random serial to be used as next
260 serial number.
261
262 =item B<-multivalue-rdn>
263
264 This option causes the -subj argument to be interpreted with full
265 support for multivalued RDNs. Example:
266
267 I</DC=org/DC=OpenSSL/DC=users/UID=123456+CN=John Doe>
268
269 If -multi-rdn is not used then the UID value is I<123456+CN=John Doe>.
270
271 =back
272
273 =head1 CRL OPTIONS
274
275 =over 4
276
277 =item B<-gencrl>
278
279 this option generates a CRL based on information in the index file.
280
281 =item B<-crldays num>
282
283 the number of days before the next CRL is due. That is the days from
284 now to place in the CRL nextUpdate field.
285
286 =item B<-crlhours num>
287
288 the number of hours before the next CRL is due.
289
290 =item B<-revoke filename>
291
292 a filename containing a certificate to revoke.
293
294 =item B<-valid filename>
295
296 a filename containing a certificate to add a Valid certificate entry.
297
298 =item B<-status serial>
299
300 displays the revocation status of the certificate with the specified
301 serial number and exits.
302
303 =item B<-updatedb>
304
305 Updates the database index to purge expired certificates.
306
307 =item B<-crl_reason reason>
308
309 revocation reason, where B<reason> is one of: B<unspecified>, B<keyCompromise>,
310 B<CACompromise>, B<affiliationChanged>, B<superseded>, B<cessationOfOperation>,
311 B<certificateHold> or B<removeFromCRL>. The matching of B<reason> is case
312 insensitive. Setting any revocation reason will make the CRL v2.
313
314 In practice B<removeFromCRL> is not particularly useful because it is only used
315 in delta CRLs which are not currently implemented.
316
317 =item B<-crl_hold instruction>
318
319 This sets the CRL revocation reason code to B<certificateHold> and the hold
320 instruction to B<instruction> which must be an OID. Although any OID can be
321 used only B<holdInstructionNone> (the use of which is discouraged by RFC2459)
322 B<holdInstructionCallIssuer> or B<holdInstructionReject> will normally be used.
323
324 =item B<-crl_compromise time>
325
326 This sets the revocation reason to B<keyCompromise> and the compromise time to
327 B<time>. B<time> should be in GeneralizedTime format that is B<YYYYMMDDHHMMSSZ>.
328
329 =item B<-crl_CA_compromise time>
330
331 This is the same as B<crl_compromise> except the revocation reason is set to
332 B<CACompromise>.
333
334 =item B<-crlexts section>
335
336 the section of the configuration file containing CRL extensions to
337 include. If no CRL extension section is present then a V1 CRL is
338 created, if the CRL extension section is present (even if it is
339 empty) then a V2 CRL is created. The CRL extensions specified are
340 CRL extensions and B<not> CRL entry extensions.  It should be noted
341 that some software (for example Netscape) can't handle V2 CRLs. See
342 L<x509v3_config(5)> manual page for details of the
343 extension section format.
344
345 =back
346
347 =head1 CONFIGURATION FILE OPTIONS
348
349 The section of the configuration file containing options for B<ca>
350 is found as follows: If the B<-name> command line option is used,
351 then it names the section to be used. Otherwise the section to
352 be used must be named in the B<default_ca> option of the B<ca> section
353 of the configuration file (or in the default section of the
354 configuration file). Besides B<default_ca>, the following options are
355 read directly from the B<ca> section:
356  RANDFILE
357  preserve
358  msie_hack
359 With the exception of B<RANDFILE>, this is probably a bug and may
360 change in future releases.
361
362 Many of the configuration file options are identical to command line
363 options. Where the option is present in the configuration file
364 and the command line the command line value is used. Where an
365 option is described as mandatory then it must be present in
366 the configuration file or the command line equivalent (if
367 any) used.
368
369 =over 4
370
371 =item B<oid_file>
372
373 This specifies a file containing additional B<OBJECT IDENTIFIERS>.
374 Each line of the file should consist of the numerical form of the
375 object identifier followed by white space then the short name followed
376 by white space and finally the long name.
377
378 =item B<oid_section>
379
380 This specifies a section in the configuration file containing extra
381 object identifiers. Each line should consist of the short name of the
382 object identifier followed by B<=> and the numerical form. The short
383 and long names are the same when this option is used.
384
385 =item B<new_certs_dir>
386
387 the same as the B<-outdir> command line option. It specifies
388 the directory where new certificates will be placed. Mandatory.
389
390 =item B<certificate>
391
392 the same as B<-cert>. It gives the file containing the CA
393 certificate. Mandatory.
394
395 =item B<private_key>
396
397 same as the B<-keyfile> option. The file containing the
398 CA private key. Mandatory.
399
400 =item B<RANDFILE>
401
402 a file used to read and write random number seed information, or
403 an EGD socket (see L<RAND_egd(3)>).
404
405 =item B<default_days>
406
407 the same as the B<-days> option. The number of days to certify
408 a certificate for.
409
410 =item B<default_startdate>
411
412 the same as the B<-startdate> option. The start date to certify
413 a certificate for. If not set the current time is used.
414
415 =item B<default_enddate>
416
417 the same as the B<-enddate> option. Either this option or
418 B<default_days> (or the command line equivalents) must be
419 present.
420
421 =item B<default_crl_hours default_crl_days>
422
423 the same as the B<-crlhours> and the B<-crldays> options. These
424 will only be used if neither command line option is present. At
425 least one of these must be present to generate a CRL.
426
427 =item B<default_md>
428
429 the same as the B<-md> option. Mandatory.
430
431 =item B<database>
432
433 the text database file to use. Mandatory. This file must be present
434 though initially it will be empty.
435
436 =item B<unique_subject>
437
438 if the value B<yes> is given, the valid certificate entries in the
439 database must have unique subjects.  if the value B<no> is given,
440 several valid certificate entries may have the exact same subject.
441 The default value is B<yes>, to be compatible with older (pre 0.9.8)
442 versions of OpenSSL.  However, to make CA certificate roll-over easier,
443 it's recommended to use the value B<no>, especially if combined with
444 the B<-selfsign> command line option.
445
446 Note that it is valid in some circumstances for certificates to be created
447 without any subject. In the case where there are multiple certificates without
448 subjects this does not count as a duplicate.
449
450 =item B<serial>
451
452 a text file containing the next serial number to use in hex. Mandatory.
453 This file must be present and contain a valid serial number.
454
455 =item B<crlnumber>
456
457 a text file containing the next CRL number to use in hex. The crl number
458 will be inserted in the CRLs only if this file exists. If this file is
459 present, it must contain a valid CRL number.
460
461 =item B<x509_extensions>
462
463 the same as B<-extensions>.
464
465 =item B<crl_extensions>
466
467 the same as B<-crlexts>.
468
469 =item B<preserve>
470
471 the same as B<-preserveDN>
472
473 =item B<email_in_dn>
474
475 the same as B<-noemailDN>. If you want the EMAIL field to be removed
476 from the DN of the certificate simply set this to 'no'. If not present
477 the default is to allow for the EMAIL filed in the certificate's DN.
478
479 =item B<msie_hack>
480
481 the same as B<-msie_hack>
482
483 =item B<policy>
484
485 the same as B<-policy>. Mandatory. See the B<POLICY FORMAT> section
486 for more information.
487
488 =item B<name_opt>, B<cert_opt>
489
490 these options allow the format used to display the certificate details
491 when asking the user to confirm signing. All the options supported by
492 the B<x509> utilities B<-nameopt> and B<-certopt> switches can be used
493 here, except the B<no_signame> and B<no_sigdump> are permanently set
494 and cannot be disabled (this is because the certificate signature cannot
495 be displayed because the certificate has not been signed at this point).
496
497 For convenience the values B<ca_default> are accepted by both to produce
498 a reasonable output.
499
500 If neither option is present the format used in earlier versions of
501 OpenSSL is used. Use of the old format is B<strongly> discouraged because
502 it only displays fields mentioned in the B<policy> section, mishandles
503 multicharacter string types and does not display extensions.
504
505 =item B<copy_extensions>
506
507 determines how extensions in certificate requests should be handled.
508 If set to B<none> or this option is not present then extensions are
509 ignored and not copied to the certificate. If set to B<copy> then any
510 extensions present in the request that are not already present are copied
511 to the certificate. If set to B<copyall> then all extensions in the
512 request are copied to the certificate: if the extension is already present
513 in the certificate it is deleted first. See the B<WARNINGS> section before
514 using this option.
515
516 The main use of this option is to allow a certificate request to supply
517 values for certain extensions such as subjectAltName.
518
519 =back
520
521 =head1 POLICY FORMAT
522
523 The policy section consists of a set of variables corresponding to
524 certificate DN fields. If the value is "match" then the field value
525 must match the same field in the CA certificate. If the value is
526 "supplied" then it must be present. If the value is "optional" then
527 it may be present. Any fields not mentioned in the policy section
528 are silently deleted, unless the B<-preserveDN> option is set but
529 this can be regarded more of a quirk than intended behaviour.
530
531 =head1 SPKAC FORMAT
532
533 The input to the B<-spkac> command line option is a Netscape
534 signed public key and challenge. This will usually come from
535 the B<KEYGEN> tag in an HTML form to create a new private key.
536 It is however possible to create SPKACs using the B<spkac> utility.
537
538 The file should contain the variable SPKAC set to the value of
539 the SPKAC and also the required DN components as name value pairs.
540 If you need to include the same component twice then it can be
541 preceded by a number and a '.'.
542
543 When processing SPKAC format, the output is DER if the B<-out>
544 flag is used, but PEM format if sending to stdout or the B<-outdir>
545 flag is used.
546
547 =head1 EXAMPLES
548
549 Note: these examples assume that the B<ca> directory structure is
550 already set up and the relevant files already exist. This usually
551 involves creating a CA certificate and private key with B<req>, a
552 serial number file and an empty index file and placing them in
553 the relevant directories.
554
555 To use the sample configuration file below the directories demoCA,
556 demoCA/private and demoCA/newcerts would be created. The CA
557 certificate would be copied to demoCA/cacert.pem and its private
558 key to demoCA/private/cakey.pem. A file demoCA/serial would be
559 created containing for example "01" and the empty index file
560 demoCA/index.txt.
561
562
563 Sign a certificate request:
564
565  openssl ca -in req.pem -out newcert.pem
566
567 Sign a certificate request, using CA extensions:
568
569  openssl ca -in req.pem -extensions v3_ca -out newcert.pem
570
571 Generate a CRL
572
573  openssl ca -gencrl -out crl.pem
574
575 Sign several requests:
576
577  openssl ca -infiles req1.pem req2.pem req3.pem
578
579 Certify a Netscape SPKAC:
580
581  openssl ca -spkac spkac.txt
582
583 A sample SPKAC file (the SPKAC line has been truncated for clarity):
584
585  SPKAC=MIG0MGAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAn7PDhCeV/xIxUg8V70YRxK2A5
586  CN=Steve Test
587  emailAddress=steve@openssl.org
588  0.OU=OpenSSL Group
589  1.OU=Another Group
590
591 A sample configuration file with the relevant sections for B<ca>:
592
593  [ ca ]
594  default_ca      = CA_default            # The default ca section
595
596  [ CA_default ]
597
598  dir            = ./demoCA              # top dir
599  database       = $dir/index.txt        # index file.
600  new_certs_dir  = $dir/newcerts         # new certs dir
601
602  certificate    = $dir/cacert.pem       # The CA cert
603  serial         = $dir/serial           # serial no file
604  private_key    = $dir/private/cakey.pem# CA private key
605  RANDFILE       = $dir/private/.rand    # random number file
606
607  default_days   = 365                   # how long to certify for
608  default_crl_days= 30                   # how long before next CRL
609  default_md     = md5                   # md to use
610
611  policy         = policy_any            # default policy
612  email_in_dn    = no                    # Don't add the email into cert DN
613
614  name_opt       = ca_default            # Subject name display option
615  cert_opt       = ca_default            # Certificate display option
616  copy_extensions = none                 # Don't copy extensions from request
617
618  [ policy_any ]
619  countryName            = supplied
620  stateOrProvinceName    = optional
621  organizationName       = optional
622  organizationalUnitName = optional
623  commonName             = supplied
624  emailAddress           = optional
625
626 =head1 FILES
627
628 Note: the location of all files can change either by compile time options,
629 configuration file entries, environment variables or command line options.
630 The values below reflect the default values.
631
632  /usr/local/ssl/lib/openssl.cnf - master configuration file
633  ./demoCA                       - main CA directory
634  ./demoCA/cacert.pem            - CA certificate
635  ./demoCA/private/cakey.pem     - CA private key
636  ./demoCA/serial                - CA serial number file
637  ./demoCA/serial.old            - CA serial number backup file
638  ./demoCA/index.txt             - CA text database file
639  ./demoCA/index.txt.old         - CA text database backup file
640  ./demoCA/certs                 - certificate output file
641  ./demoCA/.rnd                  - CA random seed information
642
643 =head1 RESTRICTIONS
644
645 The text database index file is a critical part of the process and
646 if corrupted it can be difficult to fix. It is theoretically possible
647 to rebuild the index file from all the issued certificates and a current
648 CRL: however there is no option to do this.
649
650 V2 CRL features like delta CRLs are not currently supported.
651
652 Although several requests can be input and handled at once it is only
653 possible to include one SPKAC or self-signed certificate.
654
655 =head1 BUGS
656
657 The use of an in-memory text database can cause problems when large
658 numbers of certificates are present because, as the name implies
659 the database has to be kept in memory.
660
661 The B<ca> command really needs rewriting or the required functionality
662 exposed at either a command or interface level so a more friendly utility
663 (perl script or GUI) can handle things properly. The script
664 B<CA.pl> helps a little but not very much.
665
666 Any fields in a request that are not present in a policy are silently
667 deleted. This does not happen if the B<-preserveDN> option is used. To
668 enforce the absence of the EMAIL field within the DN, as suggested by
669 RFCs, regardless the contents of the request' subject the B<-noemailDN>
670 option can be used. The behaviour should be more friendly and
671 configurable.
672
673 Canceling some commands by refusing to certify a certificate can
674 create an empty file.
675
676 =head1 WARNINGS
677
678 The B<ca> command is quirky and at times downright unfriendly.
679
680 The B<ca> utility was originally meant as an example of how to do things
681 in a CA. It was not supposed to be used as a full blown CA itself:
682 nevertheless some people are using it for this purpose.
683
684 The B<ca> command is effectively a single user command: no locking is
685 done on the various files and attempts to run more than one B<ca> command
686 on the same database can have unpredictable results.
687
688 The B<copy_extensions> option should be used with caution. If care is
689 not taken then it can be a security risk. For example if a certificate
690 request contains a basicConstraints extension with CA:TRUE and the
691 B<copy_extensions> value is set to B<copyall> and the user does not spot
692 this when the certificate is displayed then this will hand the requester
693 a valid CA certificate.
694
695 This situation can be avoided by setting B<copy_extensions> to B<copy>
696 and including basicConstraints with CA:FALSE in the configuration file.
697 Then if the request contains a basicConstraints extension it will be
698 ignored.
699
700 It is advisable to also include values for other extensions such
701 as B<keyUsage> to prevent a request supplying its own values.
702
703 Additional restrictions can be placed on the CA certificate itself.
704 For example if the CA certificate has:
705
706  basicConstraints = CA:TRUE, pathlen:0
707
708 then even if a certificate is issued with CA:TRUE it will not be valid.
709
710 =head1 SEE ALSO
711
712 L<req(1)>, L<spkac(1)>, L<x509(1)>, L<CA.pl(1)>,
713 L<config(5)>, L<x509v3_config(5)>
714
715 =head1 COPYRIGHT
716
717 Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
718
719 Licensed under the OpenSSL license (the "License").  You may not use
720 this file except in compliance with the License.  You can obtain a copy
721 in the file LICENSE in the source distribution or at
722 L<https://www.openssl.org/source/license.html>.
723
724 =cut