ca.pod 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. =pod
  2. =head1 NAME
  3. ca - sample minimal CA application
  4. =head1 SYNOPSIS
  5. B<openssl> B<ca>
  6. [B<-verbose>]
  7. [B<-config filename>]
  8. [B<-name section>]
  9. [B<-gencrl>]
  10. [B<-revoke file>]
  11. [B<-crl_reason reason>]
  12. [B<-crl_hold instruction>]
  13. [B<-crl_compromise time>]
  14. [B<-crl_CA_compromise time>]
  15. [B<-crldays days>]
  16. [B<-crlhours hours>]
  17. [B<-crlexts section>]
  18. [B<-startdate date>]
  19. [B<-enddate date>]
  20. [B<-days arg>]
  21. [B<-md arg>]
  22. [B<-policy arg>]
  23. [B<-keyfile arg>]
  24. [B<-key arg>]
  25. [B<-passin arg>]
  26. [B<-cert file>]
  27. [B<-selfsign>]
  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<-noemailDN>]
  37. [B<-batch>]
  38. [B<-msie_hack>]
  39. [B<-extensions section>]
  40. [B<-extfile section>]
  41. [B<-engine id>]
  42. [B<-subj arg>]
  43. [B<-utf8>]
  44. [B<-multivalue-rdn>]
  45. =head1 DESCRIPTION
  46. The B<ca> command is a minimal CA application. It can be used
  47. to sign certificate requests in a variety of forms and generate
  48. CRLs it also maintains a text database of issued certificates
  49. and their status.
  50. The options descriptions will be divided into each purpose.
  51. =head1 CA OPTIONS
  52. =over 4
  53. =item B<-config filename>
  54. specifies the configuration file to use.
  55. =item B<-name section>
  56. specifies the configuration file section to use (overrides
  57. B<default_ca> in the B<ca> section).
  58. =item B<-in filename>
  59. an input filename containing a single certificate request to be
  60. signed by the CA.
  61. =item B<-ss_cert filename>
  62. a single self signed certificate to be signed by the CA.
  63. =item B<-spkac filename>
  64. a file containing a single Netscape signed public key and challenge
  65. and additional field values to be signed by the CA. See the B<SPKAC FORMAT>
  66. section for information on the required format.
  67. =item B<-infiles>
  68. if present this should be the last option, all subsequent arguments
  69. are assumed to the the names of files containing certificate requests.
  70. =item B<-out filename>
  71. the output file to output certificates to. The default is standard
  72. output. The certificate details will also be printed out to this
  73. file.
  74. =item B<-outdir directory>
  75. the directory to output certificates to. The certificate will be
  76. written to a filename consisting of the serial number in hex with
  77. ".pem" appended.
  78. =item B<-cert>
  79. the CA certificate file.
  80. =item B<-keyfile filename>
  81. the private key to sign requests with.
  82. =item B<-key password>
  83. the password used to encrypt the private key. Since on some
  84. systems the command line arguments are visible (e.g. Unix with
  85. the 'ps' utility) this option should be used with caution.
  86. =item B<-selfsign>
  87. indicates the issued certificates are to be signed with the key
  88. the certificate requests were signed with (given with B<-keyfile>).
  89. Cerificate requests signed with a different key are ignored. If
  90. B<-spkac>, B<-ss_cert> or B<-gencrl> are given, B<-selfsign> is
  91. ignored.
  92. A consequence of using B<-selfsign> is that the self-signed
  93. certificate appears among the entries in the certificate database
  94. (see the configuration option B<database>), and uses the same
  95. serial number counter as all other certificates sign with the
  96. self-signed certificate.
  97. =item B<-passin arg>
  98. the key password source. For more information about the format of B<arg>
  99. see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
  100. =item B<-verbose>
  101. this prints extra details about the operations being performed.
  102. =item B<-notext>
  103. don't output the text form of a certificate to the output file.
  104. =item B<-startdate date>
  105. this allows the start date to be explicitly set. The format of the
  106. date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
  107. =item B<-enddate date>
  108. this allows the expiry date to be explicitly set. The format of the
  109. date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
  110. =item B<-days arg>
  111. the number of days to certify the certificate for.
  112. =item B<-md alg>
  113. the message digest to use. Possible values include md5, sha1 and mdc2.
  114. This option also applies to CRLs.
  115. =item B<-policy arg>
  116. this option defines the CA "policy" to use. This is a section in
  117. the configuration file which decides which fields should be mandatory
  118. or match the CA certificate. Check out the B<POLICY FORMAT> section
  119. for more information.
  120. =item B<-msie_hack>
  121. this is a legacy option to make B<ca> work with very old versions of
  122. the IE certificate enrollment control "certenr3". It used UniversalStrings
  123. for almost everything. Since the old control has various security bugs
  124. its use is strongly discouraged. The newer control "Xenroll" does not
  125. need this option.
  126. =item B<-preserveDN>
  127. Normally the DN order of a certificate is the same as the order of the
  128. fields in the relevant policy section. When this option is set the order
  129. is the same as the request. This is largely for compatibility with the
  130. older IE enrollment control which would only accept certificates if their
  131. DNs match the order of the request. This is not needed for Xenroll.
  132. =item B<-noemailDN>
  133. The DN of a certificate can contain the EMAIL field if present in the
  134. request DN, however it is good policy just having the e-mail set into
  135. the altName extension of the certificate. When this option is set the
  136. EMAIL field is removed from the certificate' subject and set only in
  137. the, eventually present, extensions. The B<email_in_dn> keyword can be
  138. used in the configuration file to enable this behaviour.
  139. =item B<-batch>
  140. this sets the batch mode. In this mode no questions will be asked
  141. and all certificates will be certified automatically.
  142. =item B<-extensions section>
  143. the section of the configuration file containing certificate extensions
  144. to be added when a certificate is issued (defaults to B<x509_extensions>
  145. unless the B<-extfile> option is used). If no extension section is
  146. present then, a V1 certificate is created. If the extension section
  147. is present (even if it is empty), then a V3 certificate is created. See the:w
  148. L<x509v3_config(5)|x509v3_config(5)> manual page for details of the
  149. extension section format.
  150. =item B<-extfile file>
  151. an additional configuration file to read certificate extensions from
  152. (using the default section unless the B<-extensions> option is also
  153. used).
  154. =item B<-engine id>
  155. specifying an engine (by its unique B<id> string) will cause B<ca>
  156. to attempt to obtain a functional reference to the specified engine,
  157. thus initialising it if needed. The engine will then be set as the default
  158. for all available algorithms.
  159. =item B<-subj arg>
  160. supersedes subject name given in the request.
  161. The arg must be formatted as I</type0=value0/type1=value1/type2=...>,
  162. characters may be escaped by \ (backslash), no spaces are skipped.
  163. =item B<-utf8>
  164. this option causes field values to be interpreted as UTF8 strings, by
  165. default they are interpreted as ASCII. This means that the field
  166. values, whether prompted from a terminal or obtained from a
  167. configuration file, must be valid UTF8 strings.
  168. =item B<-multivalue-rdn>
  169. this option causes the -subj argument to be interpretedt with full
  170. support for multivalued RDNs. Example:
  171. I</DC=org/DC=OpenSSL/DC=users/UID=123456+CN=John Doe>
  172. If -multi-rdn is not used then the UID value is I<123456+CN=John Doe>.
  173. =back
  174. =head1 CRL OPTIONS
  175. =over 4
  176. =item B<-gencrl>
  177. this option generates a CRL based on information in the index file.
  178. =item B<-crldays num>
  179. the number of days before the next CRL is due. That is the days from
  180. now to place in the CRL nextUpdate field.
  181. =item B<-crlhours num>
  182. the number of hours before the next CRL is due.
  183. =item B<-revoke filename>
  184. a filename containing a certificate to revoke.
  185. =item B<-crl_reason reason>
  186. revocation reason, where B<reason> is one of: B<unspecified>, B<keyCompromise>,
  187. B<CACompromise>, B<affiliationChanged>, B<superseded>, B<cessationOfOperation>,
  188. B<certificateHold> or B<removeFromCRL>. The matching of B<reason> is case
  189. insensitive. Setting any revocation reason will make the CRL v2.
  190. In practive B<removeFromCRL> is not particularly useful because it is only used
  191. in delta CRLs which are not currently implemented.
  192. =item B<-crl_hold instruction>
  193. This sets the CRL revocation reason code to B<certificateHold> and the hold
  194. instruction to B<instruction> which must be an OID. Although any OID can be
  195. used only B<holdInstructionNone> (the use of which is discouraged by RFC2459)
  196. B<holdInstructionCallIssuer> or B<holdInstructionReject> will normally be used.
  197. =item B<-crl_compromise time>
  198. This sets the revocation reason to B<keyCompromise> and the compromise time to
  199. B<time>. B<time> should be in GeneralizedTime format that is B<YYYYMMDDHHMMSSZ>.
  200. =item B<-crl_CA_compromise time>
  201. This is the same as B<crl_compromise> except the revocation reason is set to
  202. B<CACompromise>.
  203. =item B<-crlexts section>
  204. the section of the configuration file containing CRL extensions to
  205. include. If no CRL extension section is present then a V1 CRL is
  206. created, if the CRL extension section is present (even if it is
  207. empty) then a V2 CRL is created. The CRL extensions specified are
  208. CRL extensions and B<not> CRL entry extensions. It should be noted
  209. that some software (for example Netscape) can't handle V2 CRLs. See
  210. L<x509v3_config(5)|x509v3_config(5)> manual page for details of the
  211. extension section format.
  212. =back
  213. =head1 CONFIGURATION FILE OPTIONS
  214. The section of the configuration file containing options for B<ca>
  215. is found as follows: If the B<-name> command line option is used,
  216. then it names the section to be used. Otherwise the section to
  217. be used must be named in the B<default_ca> option of the B<ca> section
  218. of the configuration file (or in the default section of the
  219. configuration file). Besides B<default_ca>, the following options are
  220. read directly from the B<ca> section:
  221. RANDFILE
  222. preserve
  223. msie_hack
  224. With the exception of B<RANDFILE>, this is probably a bug and may
  225. change in future releases.
  226. Many of the configuration file options are identical to command line
  227. options. Where the option is present in the configuration file
  228. and the command line the command line value is used. Where an
  229. option is described as mandatory then it must be present in
  230. the configuration file or the command line equivalent (if
  231. any) used.
  232. =over 4
  233. =item B<oid_file>
  234. This specifies a file containing additional B<OBJECT IDENTIFIERS>.
  235. Each line of the file should consist of the numerical form of the
  236. object identifier followed by white space then the short name followed
  237. by white space and finally the long name.
  238. =item B<oid_section>
  239. This specifies a section in the configuration file containing extra
  240. object identifiers. Each line should consist of the short name of the
  241. object identifier followed by B<=> and the numerical form. The short
  242. and long names are the same when this option is used.
  243. =item B<new_certs_dir>
  244. the same as the B<-outdir> command line option. It specifies
  245. the directory where new certificates will be placed. Mandatory.
  246. =item B<certificate>
  247. the same as B<-cert>. It gives the file containing the CA
  248. certificate. Mandatory.
  249. =item B<private_key>
  250. same as the B<-keyfile> option. The file containing the
  251. CA private key. Mandatory.
  252. =item B<RANDFILE>
  253. a file used to read and write random number seed information, or
  254. an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
  255. =item B<default_days>
  256. the same as the B<-days> option. The number of days to certify
  257. a certificate for.
  258. =item B<default_startdate>
  259. the same as the B<-startdate> option. The start date to certify
  260. a certificate for. If not set the current time is used.
  261. =item B<default_enddate>
  262. the same as the B<-enddate> option. Either this option or
  263. B<default_days> (or the command line equivalents) must be
  264. present.
  265. =item B<default_crl_hours default_crl_days>
  266. the same as the B<-crlhours> and the B<-crldays> options. These
  267. will only be used if neither command line option is present. At
  268. least one of these must be present to generate a CRL.
  269. =item B<default_md>
  270. the same as the B<-md> option. The message digest to use. Mandatory.
  271. =item B<database>
  272. the text database file to use. Mandatory. This file must be present
  273. though initially it will be empty.
  274. =item B<unique_subject>
  275. if the value B<yes> is given, the valid certificate entries in the
  276. database must have unique subjects. if the value B<no> is given,
  277. several valid certificate entries may have the exact same subject.
  278. The default value is B<yes>, to be compatible with older (pre 0.9.8)
  279. versions of OpenSSL. However, to make CA certificate roll-over easier,
  280. it's recommended to use the value B<no>, especially if combined with
  281. the B<-selfsign> command line option.
  282. =item B<serial>
  283. a text file containing the next serial number to use in hex. Mandatory.
  284. This file must be present and contain a valid serial number.
  285. =item B<crlnumber>
  286. a text file containing the next CRL number to use in hex. The crl number
  287. will be inserted in the CRLs only if this file exists. If this file is
  288. present, it must contain a valid CRL number.
  289. =item B<x509_extensions>
  290. the same as B<-extensions>.
  291. =item B<crl_extensions>
  292. the same as B<-crlexts>.
  293. =item B<preserve>
  294. the same as B<-preserveDN>
  295. =item B<email_in_dn>
  296. the same as B<-noemailDN>. If you want the EMAIL field to be removed
  297. from the DN of the certificate simply set this to 'no'. If not present
  298. the default is to allow for the EMAIL filed in the certificate's DN.
  299. =item B<msie_hack>
  300. the same as B<-msie_hack>
  301. =item B<policy>
  302. the same as B<-policy>. Mandatory. See the B<POLICY FORMAT> section
  303. for more information.
  304. =item B<name_opt>, B<cert_opt>
  305. these options allow the format used to display the certificate details
  306. when asking the user to confirm signing. All the options supported by
  307. the B<x509> utilities B<-nameopt> and B<-certopt> switches can be used
  308. here, except the B<no_signame> and B<no_sigdump> are permanently set
  309. and cannot be disabled (this is because the certificate signature cannot
  310. be displayed because the certificate has not been signed at this point).
  311. For convenience the values B<ca_default> are accepted by both to produce
  312. a reasonable output.
  313. If neither option is present the format used in earlier versions of
  314. OpenSSL is used. Use of the old format is B<strongly> discouraged because
  315. it only displays fields mentioned in the B<policy> section, mishandles
  316. multicharacter string types and does not display extensions.
  317. =item B<copy_extensions>
  318. determines how extensions in certificate requests should be handled.
  319. If set to B<none> or this option is not present then extensions are
  320. ignored and not copied to the certificate. If set to B<copy> then any
  321. extensions present in the request that are not already present are copied
  322. to the certificate. If set to B<copyall> then all extensions in the
  323. request are copied to the certificate: if the extension is already present
  324. in the certificate it is deleted first. See the B<WARNINGS> section before
  325. using this option.
  326. The main use of this option is to allow a certificate request to supply
  327. values for certain extensions such as subjectAltName.
  328. =back
  329. =head1 POLICY FORMAT
  330. The policy section consists of a set of variables corresponding to
  331. certificate DN fields. If the value is "match" then the field value
  332. must match the same field in the CA certificate. If the value is
  333. "supplied" then it must be present. If the value is "optional" then
  334. it may be present. Any fields not mentioned in the policy section
  335. are silently deleted, unless the B<-preserveDN> option is set but
  336. this can be regarded more of a quirk than intended behaviour.
  337. =head1 SPKAC FORMAT
  338. The input to the B<-spkac> command line option is a Netscape
  339. signed public key and challenge. This will usually come from
  340. the B<KEYGEN> tag in an HTML form to create a new private key.
  341. It is however possible to create SPKACs using the B<spkac> utility.
  342. The file should contain the variable SPKAC set to the value of
  343. the SPKAC and also the required DN components as name value pairs.
  344. If you need to include the same component twice then it can be
  345. preceded by a number and a '.'.
  346. =head1 EXAMPLES
  347. Note: these examples assume that the B<ca> directory structure is
  348. already set up and the relevant files already exist. This usually
  349. involves creating a CA certificate and private key with B<req>, a
  350. serial number file and an empty index file and placing them in
  351. the relevant directories.
  352. To use the sample configuration file below the directories demoCA,
  353. demoCA/private and demoCA/newcerts would be created. The CA
  354. certificate would be copied to demoCA/cacert.pem and its private
  355. key to demoCA/private/cakey.pem. A file demoCA/serial would be
  356. created containing for example "01" and the empty index file
  357. demoCA/index.txt.
  358. Sign a certificate request:
  359. openssl ca -in req.pem -out newcert.pem
  360. Sign a certificate request, using CA extensions:
  361. openssl ca -in req.pem -extensions v3_ca -out newcert.pem
  362. Generate a CRL
  363. openssl ca -gencrl -out crl.pem
  364. Sign several requests:
  365. openssl ca -infiles req1.pem req2.pem req3.pem
  366. Certify a Netscape SPKAC:
  367. openssl ca -spkac spkac.txt
  368. A sample SPKAC file (the SPKAC line has been truncated for clarity):
  369. SPKAC=MIG0MGAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAn7PDhCeV/xIxUg8V70YRxK2A5
  370. CN=Steve Test
  371. emailAddress=steve@openssl.org
  372. 0.OU=OpenSSL Group
  373. 1.OU=Another Group
  374. A sample configuration file with the relevant sections for B<ca>:
  375. [ ca ]
  376. default_ca = CA_default # The default ca section
  377. [ CA_default ]
  378. dir = ./demoCA # top dir
  379. database = $dir/index.txt # index file.
  380. new_certs_dir = $dir/newcerts # new certs dir
  381. certificate = $dir/cacert.pem # The CA cert
  382. serial = $dir/serial # serial no file
  383. private_key = $dir/private/cakey.pem# CA private key
  384. RANDFILE = $dir/private/.rand # random number file
  385. default_days = 365 # how long to certify for
  386. default_crl_days= 30 # how long before next CRL
  387. default_md = md5 # md to use
  388. policy = policy_any # default policy
  389. email_in_dn = no # Don't add the email into cert DN
  390. name_opt = ca_default # Subject name display option
  391. cert_opt = ca_default # Certificate display option
  392. copy_extensions = none # Don't copy extensions from request
  393. [ policy_any ]
  394. countryName = supplied
  395. stateOrProvinceName = optional
  396. organizationName = optional
  397. organizationalUnitName = optional
  398. commonName = supplied
  399. emailAddress = optional
  400. =head1 FILES
  401. Note: the location of all files can change either by compile time options,
  402. configuration file entries, environment variables or command line options.
  403. The values below reflect the default values.
  404. /usr/local/ssl/lib/openssl.cnf - master configuration file
  405. ./demoCA - main CA directory
  406. ./demoCA/cacert.pem - CA certificate
  407. ./demoCA/private/cakey.pem - CA private key
  408. ./demoCA/serial - CA serial number file
  409. ./demoCA/serial.old - CA serial number backup file
  410. ./demoCA/index.txt - CA text database file
  411. ./demoCA/index.txt.old - CA text database backup file
  412. ./demoCA/certs - certificate output file
  413. ./demoCA/.rnd - CA random seed information
  414. =head1 ENVIRONMENT VARIABLES
  415. B<OPENSSL_CONF> reflects the location of master configuration file it can
  416. be overridden by the B<-config> command line option.
  417. =head1 RESTRICTIONS
  418. The text database index file is a critical part of the process and
  419. if corrupted it can be difficult to fix. It is theoretically possible
  420. to rebuild the index file from all the issued certificates and a current
  421. CRL: however there is no option to do this.
  422. V2 CRL features like delta CRLs are not currently supported.
  423. Although several requests can be input and handled at once it is only
  424. possible to include one SPKAC or self signed certificate.
  425. =head1 BUGS
  426. The use of an in memory text database can cause problems when large
  427. numbers of certificates are present because, as the name implies
  428. the database has to be kept in memory.
  429. The B<ca> command really needs rewriting or the required functionality
  430. exposed at either a command or interface level so a more friendly utility
  431. (perl script or GUI) can handle things properly. The scripts B<CA.sh> and
  432. B<CA.pl> help a little but not very much.
  433. Any fields in a request that are not present in a policy are silently
  434. deleted. This does not happen if the B<-preserveDN> option is used. To
  435. enforce the absence of the EMAIL field within the DN, as suggested by
  436. RFCs, regardless the contents of the request' subject the B<-noemailDN>
  437. option can be used. The behaviour should be more friendly and
  438. configurable.
  439. Cancelling some commands by refusing to certify a certificate can
  440. create an empty file.
  441. =head1 WARNINGS
  442. The B<ca> command is quirky and at times downright unfriendly.
  443. The B<ca> utility was originally meant as an example of how to do things
  444. in a CA. It was not supposed to be used as a full blown CA itself:
  445. nevertheless some people are using it for this purpose.
  446. The B<ca> command is effectively a single user command: no locking is
  447. done on the various files and attempts to run more than one B<ca> command
  448. on the same database can have unpredictable results.
  449. The B<copy_extensions> option should be used with caution. If care is
  450. not taken then it can be a security risk. For example if a certificate
  451. request contains a basicConstraints extension with CA:TRUE and the
  452. B<copy_extensions> value is set to B<copyall> and the user does not spot
  453. this when the certificate is displayed then this will hand the requestor
  454. a valid CA certificate.
  455. This situation can be avoided by setting B<copy_extensions> to B<copy>
  456. and including basicConstraints with CA:FALSE in the configuration file.
  457. Then if the request contains a basicConstraints extension it will be
  458. ignored.
  459. It is advisable to also include values for other extensions such
  460. as B<keyUsage> to prevent a request supplying its own values.
  461. Additional restrictions can be placed on the CA certificate itself.
  462. For example if the CA certificate has:
  463. basicConstraints = CA:TRUE, pathlen:0
  464. then even if a certificate is issued with CA:TRUE it will not be valid.
  465. =head1 SEE ALSO
  466. L<req(1)|req(1)>, L<spkac(1)|spkac(1)>, L<x509(1)|x509(1)>, L<CA.pl(1)|CA.pl(1)>,
  467. L<config(5)|config(5)>, L<x509v3_config(5)|x509v3_config(5)>
  468. =cut