openssl-verification-options.pod 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. =pod
  2. =head1 NAME
  3. openssl-verification-options - generic X.509 certificate verification options
  4. =head1 SYNOPSIS
  5. B<openssl>
  6. I<command>
  7. [ I<options> ... ]
  8. [ I<parameters> ... ]
  9. =head1 DESCRIPTION
  10. Many OpenSSL commands and various other uses of the crypto library function
  11. L<X509_verify_cert(3)> verify X.509 certificates. The details of how each
  12. command handles errors are documented on the specific command page.
  13. Certificate verification is a complicated process, consisting of
  14. a number of separate steps that are detailed in the following paragraphs.
  15. First, a certificate chain is built up starting from the target certificate
  16. and typically ending in a self-signed "root" CA certificate.
  17. It is an error if the whole chain cannot be built up
  18. unless the B<-partial_chain> option is given.
  19. The chain is built up iteratively, looking up in turn
  20. the certificate of the signer ("issuer") of the current certificate.
  21. If a certificate is found that appears to be its own issuer
  22. it is assumed to be the self-signed root, which must be trusted.
  23. The process of looking up the issuer's certificate itself involves a number
  24. of steps.
  25. All available certificates with a subject name that matches the issuer
  26. name of the current certificate are subject to further tests.
  27. The relevant authority key identifier components of the current certificate
  28. (if present) must match the subject key identifier (if present)
  29. and issuer and serial number of the candidate issuer certificate.
  30. If there is such a certificate, the first one found that is currently valid
  31. is taken, otherwise the one that expired most recently of all such certificates.
  32. The lookup first searches for issuer certificates in the trust store.
  33. If it does not find a match there it consults
  34. the list of untrusted "intermediate" CA certificates (if provided).
  35. The last certificate (which typically is of a root CA) is always looked up
  36. in the trusted certificate list; an exact match must be found there.
  37. The second step is to check the extensions of every untrusted certificate
  38. for consistency with the supplied purpose.
  39. If the B<-purpose> option is not included then no checks are done.
  40. The target or "leaf" certificate must have extensions compatible with the
  41. supplied purpose and all other certificates must also be valid CA certificates.
  42. The precise extensions required are described in more detail in
  43. L<openssl-x509(1)/CERTIFICATE EXTENSIONS>.
  44. The third step is to check the trust settings on the last certficate,
  45. typically of a root CA.
  46. It should be trusted for the supplied purpose.
  47. For compatibility with previous versions of OpenSSL,
  48. a certificate with no trust settings is considered to be valid for all purposes.
  49. The fourth, and final, step is to check the validity of the certificate chain.
  50. For each element in the chain, including the root CA certificate,
  51. the validity period as specified by the C<notBefore> and C<notAfter> fields
  52. is checked against the current system time.
  53. The B<-attime> flag may be used to use a reference time other than "now."
  54. The certificate signature is checked as well
  55. (except for the signature of the typically self-signed root CA certificate,
  56. which is verified only if the B<-check_ss_sig> option is given).
  57. When verifying a certificate signature
  58. the keyUsage extension (if present) of the candidate issuer certificate
  59. is checked to permit digitalSignature for signing proxy certificates
  60. or to permit keyCertSign for signing other certificates, respectively.
  61. If all operations complete successfully then certificate is considered
  62. valid. If any operation fails then the certificate is not valid.
  63. =head1 OPTIONS
  64. =head2 Trusted Certificate Options
  65. The following options specify how to select the trusted root certificates,
  66. also known as trust anchors.
  67. A collection of trusted roots is called a I<trust store>.
  68. Note that OpenSSL does not provide a default set of trust anchors. Many
  69. Linux distributions include a system default and configure OpenSSL to point
  70. to that. Mozilla maintains an influential trust store that can be found at
  71. L<https://www.mozilla.org/en-US/about/governance/policies/security-group/certs/>.
  72. The certificates to trust can be specified using following options.
  73. =over 4
  74. =item B<-CAfile> I<file>
  75. Load the specified file which contains one or more PEM-format certificates
  76. of CA's that are trusted.
  77. =item B<-no-CAfile>
  78. Do not load the default file of trusted certificates.
  79. =item B<-CApath> I<dir>
  80. Use the specified directory as a list of trust certificates. That is,
  81. files should be named with the hash of the X.509 SubjectName of each
  82. certificate. This is so that the library can extract the IssuerName,
  83. hash it, and directly lookup the file to get the issuer certificate.
  84. See L<openssl-rehash(1)> for information on creating this type of directory.
  85. =item B<-no-CApath>
  86. Do not use the default directory of trusted certificates.
  87. =item B<-CAstore> I<uri>
  88. Use I<uri> as a store of trusted CA certificates. The URI may
  89. indicate a single certificate, as well as a collection of them.
  90. With URIs in the C<file:> scheme, this acts as B<-CAfile> or
  91. B<-CApath>, depending on if the URI indicates a single file or
  92. directory.
  93. See L<ossl_store-file(7)> for more information on the C<file:> scheme.
  94. These certificates are also used when building the server certificate
  95. chain (for example with L<openssl-s_server(1)>) or client certificate
  96. chain (for example with L<openssl-s_time(1)>).
  97. =item B<-no-CAstore>
  98. Do not use the default store.
  99. =back
  100. =head2 Verification Options
  101. The certificate verification can be fine-tuned with the following flags.
  102. =over 4
  103. =item B<-verbose>
  104. Print extra information about the operations being performed.
  105. =item B<-attime> I<timestamp>
  106. Perform validation checks using time specified by I<timestamp> and not
  107. current system time. I<timestamp> is the number of seconds since
  108. January 1, 1970 (i.e., the Unix Epoch).
  109. =item B<-no_check_time>
  110. This option suppresses checking the validity period of certificates and CRLs
  111. against the current time. If option B<-attime> is used to specify
  112. a verification time, the check is not suppressed.
  113. =item B<-x509_strict>
  114. This disables non-compliant workarounds for broken certificates.
  115. Thus errors are thrown on certificates not compliant with RFC 5280.
  116. When this option is set,
  117. among others, the following certificate well-formedness conditions are checked:
  118. =over 4
  119. =item -
  120. The basicConstraints of CA certificates must be marked critical.
  121. =item -
  122. CA certificates must explicitly include the keyUsage extension.
  123. =item -
  124. If a pathlenConstraint is given the key usage keyCertSign must be allowed.
  125. =item -
  126. The pathlenConstraint must not be given for non-CA certificates.
  127. =item -
  128. The issuer name of any certificate must not be empty.
  129. =item -
  130. The subject name of CA certs, certs with keyUsage crlSign, and certs
  131. without subjectAlternativeName must not be empty.
  132. =item -
  133. If a subjectAlternativeName extension is given it must not be empty.
  134. =item -
  135. The signatureAlgorithm field and the cert signature must be consistent.
  136. =item -
  137. Any given authorityKeyIdentifier and any given subjectKeyIdentifier
  138. must not be marked critical.
  139. =item -
  140. The authorityKeyIdentifier must be given for X.509v3 certs unless they
  141. are self-signed.
  142. =item -
  143. The subjectKeyIdentifier must be given for all X.509v3 CA certs.
  144. =back
  145. =item B<-ignore_critical>
  146. Normally if an unhandled critical extension is present that is not
  147. supported by OpenSSL the certificate is rejected (as required by RFC5280).
  148. If this option is set critical extensions are ignored.
  149. =item B<-issuer_checks>
  150. Ignored.
  151. =item B<-crl_check>
  152. Checks end entity certificate validity by attempting to look up a valid CRL.
  153. If a valid CRL cannot be found an error occurs.
  154. =item B<-crl_check_all>
  155. Checks the validity of B<all> certificates in the chain by attempting
  156. to look up valid CRLs.
  157. =item B<-use_deltas>
  158. Enable support for delta CRLs.
  159. =item B<-extended_crl>
  160. Enable extended CRL features such as indirect CRLs and alternate CRL
  161. signing keys.
  162. =item B<-suiteB_128_only>, B<-suiteB_128>, B<-suiteB_192>
  163. Enable the Suite B mode operation at 128 bit Level of Security, 128 bit or
  164. 192 bit, or only 192 bit Level of Security respectively.
  165. See RFC6460 for details. In particular the supported signature algorithms are
  166. reduced to support only ECDSA and SHA256 or SHA384 and only the elliptic curves
  167. P-256 and P-384.
  168. =item B<-auth_level> I<level>
  169. Set the certificate chain authentication security level to I<level>.
  170. The authentication security level determines the acceptable signature and
  171. public key strength when verifying certificate chains. For a certificate
  172. chain to validate, the public keys of all the certificates must meet the
  173. specified security I<level>. The signature algorithm security level is
  174. enforced for all the certificates in the chain except for the chain's
  175. I<trust anchor>, which is either directly trusted or validated by means
  176. other than its signature. See L<SSL_CTX_set_security_level(3)> for the
  177. definitions of the available levels. The default security level is -1,
  178. or "not set". At security level 0 or lower all algorithms are acceptable.
  179. Security level 1 requires at least 80-bit-equivalent security and is broadly
  180. interoperable, though it will, for example, reject MD5 signatures or RSA
  181. keys shorter than 1024 bits.
  182. =item B<-partial_chain>
  183. Allow verification to succeed even if a I<complete> chain cannot be built to a
  184. self-signed trust-anchor, provided it is possible to construct a chain to a
  185. trusted certificate that might not be self-signed.
  186. This certificate may be self-issued or belong to an intermediate CA.
  187. =item B<-check_ss_sig>
  188. Verify the signature of
  189. the last certificate in a chain if the certificate is supposedly self-signed.
  190. This is prohibited and will result in an error if it is a non-conforming CA
  191. certificate with key usage restrictions not including the keyCertSign bit.
  192. This verification is disabled by default because it doesn't add any security.
  193. =item B<-allow_proxy_certs>
  194. Allow the verification of proxy certificates.
  195. =item B<-trusted_first>
  196. As of OpenSSL 1.1.0 this option is on by default and cannot be disabled.
  197. When constructing the certificate chain, the trusted certificates specified
  198. via B<-CAfile>, B<-CApath>, B<-CAstore> or B<-trusted> are always used
  199. before any certificates specified via B<-untrusted>.
  200. =item B<-no_alt_chains>
  201. As of OpenSSL 1.1.0, since B<-trusted_first> always on, this option has no
  202. effect.
  203. =item B<-trusted> I<file>
  204. Parse I<file> as a set of one or more certificates in PEM format.
  205. All certificates must be self-signed, unless the
  206. B<-partial_chain> option is specified.
  207. This option implies the B<-no-CAfile>, B<-no-CApath>, and B<-no-CAstore> options
  208. and it cannot be used with the B<-CAfile>, B<-CApath> or B<-CAstore> options, so
  209. only certificates in the file are trust anchors.
  210. This option may be used multiple times.
  211. =item B<-untrusted> I<file>
  212. Parse I<file> as a set of one or more certificates in PEM format.
  213. All certificates are untrusted certificates (typically of intermedate CAs)
  214. that may be used to
  215. construct a certificate chain from the subject certificate to a trust anchor.
  216. This option may be used multiple times.
  217. =item B<-policy> I<arg>
  218. Enable policy processing and add I<arg> to the user-initial-policy-set (see
  219. RFC5280). The policy I<arg> can be an object name an OID in numeric form.
  220. This argument can appear more than once.
  221. =item B<-explicit_policy>
  222. Set policy variable require-explicit-policy (see RFC5280).
  223. =item B<-policy_check>
  224. Enables certificate policy processing.
  225. =item B<-policy_print>
  226. Print out diagnostics related to policy processing.
  227. =item B<-inhibit_any>
  228. Set policy variable inhibit-any-policy (see RFC5280).
  229. =item B<-inhibit_map>
  230. Set policy variable inhibit-policy-mapping (see RFC5280).
  231. =item B<-purpose> I<purpose>
  232. The intended use for the certificate. If this option is not specified, this
  233. command will not consider certificate purpose during chain verification.
  234. Currently accepted uses are B<sslclient>, B<sslserver>, B<nssslserver>,
  235. B<smimesign>, B<smimeencrypt>.
  236. =item B<-verify_depth> I<num>
  237. Limit the certificate chain to I<num> intermediate CA certificates.
  238. A maximal depth chain can have up to I<num>+2 certificates, since neither the
  239. end-entity certificate nor the trust-anchor certificate count against the
  240. B<-verify_depth> limit.
  241. =item B<-verify_email> I<email>
  242. Verify if I<email> matches the email address in Subject Alternative Name or
  243. the email in the subject Distinguished Name.
  244. =item B<-verify_hostname> I<hostname>
  245. Verify if I<hostname> matches DNS name in Subject Alternative Name or
  246. Common Name in the subject certificate.
  247. =item B<-verify_ip> I<ip>
  248. Verify if I<ip> matches the IP address in Subject Alternative Name of
  249. the subject certificate.
  250. =item B<-verify_name> I<name>
  251. Use default verification policies like trust model and required certificate
  252. policies identified by I<name>.
  253. The trust model determines which auxiliary trust or reject OIDs are applicable
  254. to verifying the given certificate chain.
  255. See the B<-addtrust> and B<-addreject> options for L<openssl-x509(1)>.
  256. Supported policy names include: B<default>, B<pkcs7>, B<smime_sign>,
  257. B<ssl_client>, B<ssl_server>.
  258. These mimics the combinations of purpose and trust settings used in SSL, CMS
  259. and S/MIME.
  260. As of OpenSSL 1.1.0, the trust model is inferred from the purpose when not
  261. specified, so the B<-verify_name> options are functionally equivalent to the
  262. corresponding B<-purpose> settings.
  263. =back
  264. =head2 Extended Verification Options
  265. Sometimes there may be more than one certificate chain leading to an
  266. end-entity certificate.
  267. This usually happens when a root or intermediate CA signs a certificate
  268. for another a CA in other organization.
  269. Another reason is when a CA might have intermediates that use two different
  270. signature formats, such as a SHA-1 and a SHA-256 digest.
  271. The following options can be used to provide data that will allow the
  272. OpenSSL command to generate an alternative chain.
  273. =over 4
  274. =item B<-xkey> I<infile>, B<-xcert> I<infile>, B<-xchain>
  275. Specify an extra certificate, private key and certificate chain. These behave
  276. in the same manner as the B<-cert>, B<-key> and B<-cert_chain> options. When
  277. specified, the callback returning the first valid chain will be in use by the
  278. client.
  279. =item B<-xchain_build>
  280. Specify whether the application should build the certificate chain to be
  281. provided to the server for the extra certificates via the B<-xkey>,
  282. B<-xcert>, and B<-xchain> options.
  283. =item B<-xcertform> B<DER>|B<PEM>|B<P12>
  284. The input format for the extra certificate.
  285. This option has no effect and is retained for backward compatibility only.
  286. =item B<-xkeyform> B<DER>|B<PEM>|B<P12>
  287. The input format for the extra key.
  288. This option has no effect and is retained for backward compatibility only.
  289. =back
  290. =head1 SEE ALSO
  291. L<X509_verify_cert(3)>,
  292. L<openssl-verify(1)>,
  293. L<openssl-ocsp(1)>,
  294. L<openssl-ts(1)>,
  295. L<openssl-s_client(1)>,
  296. L<openssl-s_server(1)>,
  297. L<openssl-smime(1)>,
  298. L<openssl-cmp(1)>,
  299. L<openssl-cms(1)>
  300. =head1 HISTORY
  301. The checks enabled by B<-x509_strict> have been extended in OpenSSL 3.0.
  302. =head1 COPYRIGHT
  303. Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
  304. Licensed under the Apache License 2.0 (the "License"). You may not use
  305. this file except in compliance with the License. You can obtain a copy
  306. in the file LICENSE in the source distribution or at
  307. L<https://www.openssl.org/source/license.html>.
  308. =cut