X509_check_host.3ossl 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "X509_CHECK_HOST 3ossl"
  58. .TH X509_CHECK_HOST 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. X509_check_host, X509_check_email, X509_check_ip, X509_check_ip_asc \- X.509 certificate matching
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 1
  68. \& #include <openssl/x509v3.h>
  69. \&
  70. \& int X509_check_host(X509 *, const char *name, size_t namelen,
  71. \& unsigned int flags, char **peername);
  72. \& int X509_check_email(X509 *, const char *address, size_t addresslen,
  73. \& unsigned int flags);
  74. \& int X509_check_ip(X509 *, const unsigned char *address, size_t addresslen,
  75. \& unsigned int flags);
  76. \& int X509_check_ip_asc(X509 *, const char *address, unsigned int flags);
  77. .Ve
  78. .SH DESCRIPTION
  79. .IX Header "DESCRIPTION"
  80. The certificate matching functions are used to check whether a
  81. certificate matches a given hostname, email address, or IP address.
  82. The validity of the certificate and its trust level has to be checked by
  83. other means.
  84. .PP
  85. \&\fBX509_check_host()\fR checks if the certificate Subject Alternative
  86. Name (SAN) or Subject CommonName (CN) matches the specified hostname,
  87. which must be encoded in the preferred name syntax described
  88. in section 3.5 of RFC 1034. By default, wildcards are supported
  89. and they match only in the left-most label; but they may match
  90. part of that label with an explicit prefix or suffix. For example,
  91. by default, the host \fBname\fR "www.example.com" would match a
  92. certificate with a SAN or CN value of "*.example.com", "w*.example.com"
  93. or "*w.example.com".
  94. .PP
  95. Per section 6.4.2 of RFC 6125, \fBname\fR values representing international
  96. domain names must be given in A\-label form. The \fBnamelen\fR argument
  97. must be the number of characters in the name string or zero in which
  98. case the length is calculated with strlen(\fBname\fR). When \fBname\fR starts
  99. with a dot (e.g. ".example.com"), it will be matched by a certificate
  100. valid for any sub-domain of \fBname\fR, (see also
  101. \&\fBX509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS\fR below).
  102. .PP
  103. When the certificate is matched, and \fBpeername\fR is not NULL, a
  104. pointer to a copy of the matching SAN or CN from the peer certificate
  105. is stored at the address passed in \fBpeername\fR. The application
  106. is responsible for freeing the peername via \fBOPENSSL_free()\fR when it
  107. is no longer needed.
  108. .PP
  109. \&\fBX509_check_email()\fR checks if the certificate matches the specified
  110. email \fBaddress\fR. The mailbox syntax of RFC 822 is supported,
  111. comments are not allowed, and no attempt is made to normalize quoted
  112. characters. The mailbox syntax of RFC 6531 is supported for
  113. SmtpUTF8Mailbox address in subjectAltName according to RFC 8398,
  114. with similar limitations as for RFC 822 syntax, and no attempt
  115. is made to convert from A\-label to U\-label before comparison.
  116. The \fBaddresslen\fR argument must be the number of
  117. characters in the address string or zero in which case the length
  118. is calculated with strlen(\fBaddress\fR).
  119. .PP
  120. \&\fBX509_check_ip()\fR checks if the certificate matches a specified IPv4 or
  121. IPv6 address. The \fBaddress\fR array is in binary format, in network
  122. byte order. The length is either 4 (IPv4) or 16 (IPv6). Only
  123. explicitly marked addresses in the certificates are considered; IP
  124. addresses stored in DNS names and Common Names are ignored. There are
  125. currently no \fBflags\fR that would affect the behavior of this call.
  126. .PP
  127. \&\fBX509_check_ip_asc()\fR is similar, except that the NUL-terminated
  128. string \fBaddress\fR is first converted to the internal representation.
  129. .PP
  130. The \fBflags\fR argument is usually 0. It can be the bitwise OR of the
  131. flags:
  132. .IP \fBX509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT\fR, 4
  133. .IX Item "X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT,"
  134. .PD 0
  135. .IP \fBX509_CHECK_FLAG_NEVER_CHECK_SUBJECT\fR, 4
  136. .IX Item "X509_CHECK_FLAG_NEVER_CHECK_SUBJECT,"
  137. .IP \fBX509_CHECK_FLAG_NO_WILDCARDS\fR, 4
  138. .IX Item "X509_CHECK_FLAG_NO_WILDCARDS,"
  139. .IP \fBX509_CHECK_FLAG_NO_PARTIAL_WILDCARDS\fR, 4
  140. .IX Item "X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS,"
  141. .IP \fBX509_CHECK_FLAG_MULTI_LABEL_WILDCARDS\fR. 4
  142. .IX Item "X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS."
  143. .IP \fBX509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS\fR. 4
  144. .IX Item "X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS."
  145. .PD
  146. .PP
  147. The \fBX509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT\fR flag causes the function
  148. to consider the subject DN even if the certificate contains at least
  149. one subject alternative name of the right type (DNS name or email
  150. address as appropriate); the default is to ignore the subject DN
  151. when at least one corresponding subject alternative names is present.
  152. .PP
  153. The \fBX509_CHECK_FLAG_NEVER_CHECK_SUBJECT\fR flag causes the function to never
  154. consider the subject DN even if the certificate contains no subject alternative
  155. names of the right type (DNS name or email address as appropriate); the default
  156. is to use the subject DN when no corresponding subject alternative names are
  157. present.
  158. If both \fBX509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT\fR and
  159. \&\fBX509_CHECK_FLAG_NEVER_CHECK_SUBJECT\fR are specified, the latter takes
  160. precedence and the subject DN is not checked for matching names.
  161. .PP
  162. If set, \fBX509_CHECK_FLAG_NO_WILDCARDS\fR disables wildcard
  163. expansion; this only applies to \fBX509_check_host\fR.
  164. .PP
  165. If set, \fBX509_CHECK_FLAG_NO_PARTIAL_WILDCARDS\fR suppresses support
  166. for "*" as wildcard pattern in labels that have a prefix or suffix,
  167. such as: "www*" or "*www"; this only applies to \fBX509_check_host\fR.
  168. .PP
  169. If set, \fBX509_CHECK_FLAG_MULTI_LABEL_WILDCARDS\fR allows a "*" that
  170. constitutes the complete label of a DNS name (e.g. "*.example.com")
  171. to match more than one label in \fBname\fR; this flag only applies
  172. to \fBX509_check_host\fR.
  173. .PP
  174. If set, \fBX509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS\fR restricts \fBname\fR
  175. values which start with ".", that would otherwise match any sub-domain
  176. in the peer certificate, to only match direct child sub-domains.
  177. Thus, for instance, with this flag set a \fBname\fR of ".example.com"
  178. would match a peer certificate with a DNS name of "www.example.com",
  179. but would not match a peer certificate with a DNS name of
  180. "www.sub.example.com"; this flag only applies to \fBX509_check_host\fR.
  181. .SH "RETURN VALUES"
  182. .IX Header "RETURN VALUES"
  183. The functions return 1 for a successful match, 0 for a failed match
  184. and \-1 for an internal error: typically a memory allocation failure
  185. or an ASN.1 decoding error.
  186. .PP
  187. All functions can also return \-2 if the input is malformed. For example,
  188. \&\fBX509_check_host()\fR returns \-2 if the provided \fBname\fR contains embedded
  189. NULs.
  190. .SH NOTES
  191. .IX Header "NOTES"
  192. Applications are encouraged to use \fBX509_VERIFY_PARAM_set1_host()\fR
  193. rather than explicitly calling \fBX509_check_host\fR\|(3). Hostname
  194. checks may be out of scope with the \fBDANE\-EE\fR\|(3) certificate usage,
  195. and the internal checks will be suppressed as appropriate when
  196. DANE support is enabled.
  197. .SH "SEE ALSO"
  198. .IX Header "SEE ALSO"
  199. \&\fBSSL_get_verify_result\fR\|(3),
  200. \&\fBX509_VERIFY_PARAM_set1_host\fR\|(3),
  201. \&\fBX509_VERIFY_PARAM_add1_host\fR\|(3),
  202. \&\fBX509_VERIFY_PARAM_set1_email\fR\|(3),
  203. \&\fBX509_VERIFY_PARAM_set1_ip\fR\|(3)
  204. .SH HISTORY
  205. .IX Header "HISTORY"
  206. These functions were added in OpenSSL 1.0.2.
  207. .SH COPYRIGHT
  208. .IX Header "COPYRIGHT"
  209. Copyright 2012\-2022 The OpenSSL Project Authors. All Rights Reserved.
  210. .PP
  211. Licensed under the Apache License 2.0 (the "License"). You may not use
  212. this file except in compliance with the License. You can obtain a copy
  213. in the file LICENSE in the source distribution or at
  214. <https://www.openssl.org/source/license.html>.