ca.pod revision 89837
1
2=pod
3
4=head1 NAME
5
6ca - sample minimal CA application
7
8=head1 SYNOPSIS
9
10B<openssl> B<ca>
11[B<-verbose>]
12[B<-config filename>]
13[B<-name section>]
14[B<-gencrl>]
15[B<-revoke file>]
16[B<-crldays days>]
17[B<-crlhours hours>]
18[B<-crlexts section>]
19[B<-startdate date>]
20[B<-enddate date>]
21[B<-days arg>]
22[B<-md arg>]
23[B<-policy arg>]
24[B<-keyfile arg>]
25[B<-key arg>]
26[B<-passin arg>]
27[B<-cert file>]
28[B<-in file>]
29[B<-out file>]
30[B<-notext>]
31[B<-outdir dir>]
32[B<-infiles>]
33[B<-spkac file>]
34[B<-ss_cert file>]
35[B<-preserveDN>]
36[B<-batch>]
37[B<-msie_hack>]
38[B<-extensions section>]
39
40=head1 DESCRIPTION
41
42The B<ca> command is a minimal CA application. It can be used
43to sign certificate requests in a variety of forms and generate
44CRLs it also maintains a text database of issued certificates
45and their status.
46
47The options descriptions will be divided into each purpose.
48
49=head1 CA OPTIONS
50
51=over 4
52
53=item B<-config filename>
54
55specifies the configuration file to use.
56
57=item B<-name section>
58
59specifies the configuration file section to use (overrides
60B<default_ca> in the B<ca> section).
61
62=item B<-in filename>
63
64an input filename containing a single certificate request to be
65signed by the CA.
66
67=item B<-ss_cert filename>
68
69a single self signed certificate to be signed by the CA.
70
71=item B<-spkac filename>
72
73a file containing a single Netscape signed public key and challenge
74and additional field values to be signed by the CA. See the B<NOTES>
75section for information on the required format.
76
77=item B<-infiles>
78
79if present this should be the last option, all subsequent arguments
80are assumed to the the names of files containing certificate requests. 
81
82=item B<-out filename>
83
84the output file to output certificates to. The default is standard
85output. The certificate details will also be printed out to this
86file.
87
88=item B<-outdir directory>
89
90the directory to output certificates to. The certificate will be
91written to a filename consisting of the serial number in hex with
92".pem" appended.
93
94=item B<-cert>
95
96the CA certificate file.
97
98=item B<-keyfile filename>
99
100the private key to sign requests with.
101
102=item B<-key password>
103
104the password used to encrypt the private key. Since on some
105systems the command line arguments are visible (e.g. Unix with
106the 'ps' utility) this option should be used with caution.
107
108=item B<-passin arg>
109
110the key password source. For more information about the format of B<arg>
111see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
112=item B<-verbose>
113
114this prints extra details about the operations being performed.
115
116=item B<-notext>
117
118don't output the text form of a certificate to the output file.
119
120=item B<-startdate date>
121
122this allows the start date to be explicitly set. The format of the
123date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
124
125=item B<-enddate date>
126
127this allows the expiry date to be explicitly set. The format of the
128date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
129
130=item B<-days arg>
131
132the number of days to certify the certificate for.
133
134=item B<-md alg>
135
136the message digest to use. Possible values include md5, sha1 and mdc2.
137This option also applies to CRLs.
138
139=item B<-policy arg>
140
141this option defines the CA "policy" to use. This is a section in
142the configuration file which decides which fields should be mandatory
143or match the CA certificate. Check out the B<POLICY FORMAT> section
144for more information.
145
146=item B<-msie_hack>
147
148this is a legacy option to make B<ca> work with very old versions of
149the IE certificate enrollment control "certenr3". It used UniversalStrings
150for almost everything. Since the old control has various security bugs
151its use is strongly discouraged. The newer control "Xenroll" does not
152need this option.
153
154=item B<-preserveDN>
155
156Normally the DN order of a certificate is the same as the order of the
157fields in the relevant policy section. When this option is set the order 
158is the same as the request. This is largely for compatibility with the
159older IE enrollment control which would only accept certificates if their
160DNs match the order of the request. This is not needed for Xenroll.
161
162=item B<-batch>
163
164this sets the batch mode. In this mode no questions will be asked
165and all certificates will be certified automatically.
166
167=item B<-extensions section>
168
169the section of the configuration file containing certificate extensions
170to be added when a certificate is issued. If no extension section is
171present then a V1 certificate is created. If the extension section
172is present (even if it is empty) then a V3 certificate is created.
173
174=back
175
176=head1 CRL OPTIONS
177
178=over 4
179
180=item B<-gencrl>
181
182this option generates a CRL based on information in the index file.
183
184=item B<-crldays num>
185
186the number of days before the next CRL is due. That is the days from
187now to place in the CRL nextUpdate field.
188
189=item B<-crlhours num>
190
191the number of hours before the next CRL is due.
192
193=item B<-revoke filename>
194
195a filename containing a certificate to revoke.
196
197=item B<-crlexts section>
198
199the section of the configuration file containing CRL extensions to
200include. If no CRL extension section is present then a V1 CRL is
201created, if the CRL extension section is present (even if it is
202empty) then a V2 CRL is created. The CRL extensions specified are
203CRL extensions and B<not> CRL entry extensions.  It should be noted
204that some software (for example Netscape) can't handle V2 CRLs. 
205
206=back
207
208=head1 CONFIGURATION FILE OPTIONS
209
210The section of the configuration file containing options for B<ca>
211is found as follows: If the B<-name> command line option is used,
212then it names the section to be used. Otherwise the section to
213be used must be named in the B<default_ca> option of the B<ca> section
214of the configuration file (or in the default section of the
215configuration file). Besides B<default_ca>, the following options are
216read directly from the B<ca> section:
217 RANDFILE
218 preserve
219 msie_hack
220With the exception of B<RANDFILE>, this is probably a bug and may
221change in future releases.
222
223Many of the configuration file options are identical to command line
224options. Where the option is present in the configuration file
225and the command line the command line value is used. Where an
226option is described as mandatory then it must be present in
227the configuration file or the command line equivalent (if
228any) used.
229
230=over 4
231
232=item B<oid_file>
233
234This specifies a file containing additional B<OBJECT IDENTIFIERS>.
235Each line of the file should consist of the numerical form of the
236object identifier followed by white space then the short name followed
237by white space and finally the long name. 
238
239=item B<oid_section>
240
241This specifies a section in the configuration file containing extra
242object identifiers. Each line should consist of the short name of the
243object identifier followed by B<=> and the numerical form. The short
244and long names are the same when this option is used.
245
246=item B<new_certs_dir>
247
248the same as the B<-outdir> command line option. It specifies
249the directory where new certificates will be placed. Mandatory.
250
251=item B<certificate>
252
253the same as B<-cert>. It gives the file containing the CA
254certificate. Mandatory.
255
256=item B<private_key>
257
258same as the B<-keyfile> option. The file containing the
259CA private key. Mandatory.
260
261=item B<RANDFILE>
262
263a file used to read and write random number seed information, or
264an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
265
266=item B<default_days>
267
268the same as the B<-days> option. The number of days to certify
269a certificate for. 
270
271=item B<default_startdate>
272
273the same as the B<-startdate> option. The start date to certify
274a certificate for. If not set the current time is used.
275
276=item B<default_enddate>
277
278the same as the B<-enddate> option. Either this option or
279B<default_days> (or the command line equivalents) must be
280present.
281
282=item B<default_crl_hours default_crl_days>
283
284the same as the B<-crlhours> and the B<-crldays> options. These
285will only be used if neither command line option is present. At
286least one of these must be present to generate a CRL.
287
288=item B<default_md>
289
290the same as the B<-md> option. The message digest to use. Mandatory.
291
292=item B<database>
293
294the text database file to use. Mandatory. This file must be present
295though initially it will be empty.
296
297=item B<serialfile>
298
299a text file containing the next serial number to use in hex. Mandatory.
300This file must be present and contain a valid serial number.
301
302=item B<x509_extensions>
303
304the same as B<-extensions>.
305
306=item B<crl_extensions>
307
308the same as B<-crlexts>.
309
310=item B<preserve>
311
312the same as B<-preserveDN>
313
314=item B<msie_hack>
315
316the same as B<-msie_hack>
317
318=item B<policy>
319
320the same as B<-policy>. Mandatory. See the B<POLICY FORMAT> section
321for more information.
322
323=back
324
325=head1 POLICY FORMAT
326
327The policy section consists of a set of variables corresponding to
328certificate DN fields. If the value is "match" then the field value
329must match the same field in the CA certificate. If the value is
330"supplied" then it must be present. If the value is "optional" then
331it may be present. Any fields not mentioned in the policy section
332are silently deleted, unless the B<-preserveDN> option is set but
333this can be regarded more of a quirk than intended behaviour.
334
335=head1 SPKAC FORMAT
336
337The input to the B<-spkac> command line option is a Netscape
338signed public key and challenge. This will usually come from
339the B<KEYGEN> tag in an HTML form to create a new private key. 
340It is however possible to create SPKACs using the B<spkac> utility.
341
342The file should contain the variable SPKAC set to the value of
343the SPKAC and also the required DN components as name value pairs.
344If you need to include the same component twice then it can be
345preceded by a number and a '.'.
346
347=head1 EXAMPLES
348
349Note: these examples assume that the B<ca> directory structure is
350already set up and the relevant files already exist. This usually
351involves creating a CA certificate and private key with B<req>, a
352serial number file and an empty index file and placing them in
353the relevant directories.
354
355To use the sample configuration file below the directories demoCA,
356demoCA/private and demoCA/newcerts would be created. The CA
357certificate would be copied to demoCA/cacert.pem and its private
358key to demoCA/private/cakey.pem. A file demoCA/serial would be
359created containing for example "01" and the empty index file
360demoCA/index.txt.
361
362
363Sign a certificate request:
364
365 openssl ca -in req.pem -out newcert.pem
366
367Sign a certificate request, using CA extensions:
368
369 openssl ca -in req.pem -extensions v3_ca -out newcert.pem
370
371Generate a CRL
372
373 openssl ca -gencrl -out crl.pem
374
375Sign several requests:
376
377 openssl ca -infiles req1.pem req2.pem req3.pem
378
379Certify a Netscape SPKAC:
380
381 openssl ca -spkac spkac.txt
382
383A sample SPKAC file (the SPKAC line has been truncated for clarity):
384
385 SPKAC=MIG0MGAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAn7PDhCeV/xIxUg8V70YRxK2A5
386 CN=Steve Test
387 emailAddress=steve@openssl.org
388 0.OU=OpenSSL Group
389 1.OU=Another Group
390
391A sample configuration file with the relevant sections for B<ca>:
392
393 [ ca ]
394 default_ca      = CA_default            # The default ca section
395 
396 [ CA_default ]
397
398 dir            = ./demoCA              # top dir
399 database       = $dir/index.txt        # index file.
400 new_certs_dir	= $dir/newcerts         # new certs dir
401 
402 certificate    = $dir/cacert.pem       # The CA cert
403 serial         = $dir/serial           # serial no file
404 private_key    = $dir/private/cakey.pem# CA private key
405 RANDFILE       = $dir/private/.rand    # random number file
406 
407 default_days   = 365                   # how long to certify for
408 default_crl_days= 30                   # how long before next CRL
409 default_md     = md5                   # md to use
410
411 policy         = policy_any            # default policy
412
413 [ policy_any ]
414 countryName            = supplied
415 stateOrProvinceName    = optional
416 organizationName       = optional
417 organizationalUnitName = optional
418 commonName             = supplied
419 emailAddress           = optional
420
421=head1 WARNINGS
422
423The B<ca> command is quirky and at times downright unfriendly.
424
425The B<ca> utility was originally meant as an example of how to do things
426in a CA. It was not supposed be be used as a full blown CA itself:
427nevertheless some people are using it for this purpose.
428
429The B<ca> command is effectively a single user command: no locking is
430done on the various files and attempts to run more than one B<ca> command
431on the same database can have unpredictable results.
432
433=head1 FILES
434
435Note: the location of all files can change either by compile time options,
436configuration file entries, environment variables or command line options.
437The values below reflect the default values.
438
439 /usr/local/ssl/lib/openssl.cnf - master configuration file
440 ./demoCA                       - main CA directory
441 ./demoCA/cacert.pem            - CA certificate
442 ./demoCA/private/cakey.pem     - CA private key
443 ./demoCA/serial                - CA serial number file
444 ./demoCA/serial.old            - CA serial number backup file
445 ./demoCA/index.txt             - CA text database file
446 ./demoCA/index.txt.old         - CA text database backup file
447 ./demoCA/certs                 - certificate output file
448 ./demoCA/.rnd                  - CA random seed information
449
450=head1 ENVIRONMENT VARIABLES
451
452B<OPENSSL_CONF> reflects the location of master configuration file it can
453be overridden by the B<-config> command line option.
454
455=head1 RESTRICTIONS
456
457The text database index file is a critical part of the process and 
458if corrupted it can be difficult to fix. It is theoretically possible
459to rebuild the index file from all the issued certificates and a current
460CRL: however there is no option to do this.
461
462CRL entry extensions cannot currently be created: only CRL extensions
463can be added.
464
465V2 CRL features like delta CRL support and CRL numbers are not currently
466supported.
467
468Although several requests can be input and handled at once it is only
469possible to include one SPKAC or self signed certificate.
470
471=head1 BUGS
472
473The use of an in memory text database can cause problems when large
474numbers of certificates are present because, as the name implies
475the database has to be kept in memory.
476
477Certificate request extensions are ignored: some kind of "policy" should
478be included to use certain static extensions and certain extensions
479from the request.
480
481It is not possible to certify two certificates with the same DN: this
482is a side effect of how the text database is indexed and it cannot easily
483be fixed without introducing other problems. Some S/MIME clients can use
484two certificates with the same DN for separate signing and encryption
485keys.
486
487The B<ca> command really needs rewriting or the required functionality
488exposed at either a command or interface level so a more friendly utility
489(perl script or GUI) can handle things properly. The scripts B<CA.sh> and
490B<CA.pl> help a little but not very much.
491
492Any fields in a request that are not present in a policy are silently
493deleted. This does not happen if the B<-preserveDN> option is used but
494the extra fields are not displayed when the user is asked to certify
495a request. The behaviour should be more friendly and configurable.
496
497Cancelling some commands by refusing to certify a certificate can
498create an empty file.
499
500=head1 SEE ALSO
501
502L<req(1)|req(1)>, L<spkac(1)|spkac(1)>, L<x509(1)|x509(1)>, L<CA.pl(1)|CA.pl(1)>,
503L<config(5)|config(5)>
504
505=cut
506