SSL_CTX_set_cert_verify_callback.pod 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set_cert_verify_callback - set peer certificate verification procedure
  4. =head1 SYNOPSIS
  5. #include <openssl/ssl.h>
  6. void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
  7. int (*callback)(X509_STORE_CTX *, void *),
  8. void *arg);
  9. =head1 DESCRIPTION
  10. SSL_CTX_set_cert_verify_callback() sets the verification callback function for
  11. I<ctx>. SSL objects that are created from I<ctx> inherit the setting valid at
  12. the time when L<SSL_new(3)> is called.
  13. =head1 NOTES
  14. When a peer certificate has been received during a SSL/TLS handshake,
  15. a verification function is called regardless of the verification mode.
  16. If the application does not explicitly specify a verification callback function,
  17. the built-in verification function is used.
  18. If a verification callback I<callback> is specified via
  19. SSL_CTX_set_cert_verify_callback(), the supplied callback function is called
  20. instead with the arguments callback(X509_STORE_CTX *x509_store_ctx, void *arg).
  21. The argument I<arg> is specified by the application when setting I<callback>.
  22. By setting I<callback> to NULL, the default behaviour is restored.
  23. I<callback> should return 1 to indicate verification success
  24. and 0 to indicate verification failure.
  25. In server mode, a return value of 0 leads to handshake failure.
  26. In client mode, the behaviour is as follows.
  27. All values, including 0, are ignored
  28. if the verification mode is B<SSL_VERIFY_NONE>.
  29. Otherwise, when the return value is less than or equal to 0, the handshake will
  30. fail.
  31. In client mode I<callback> may also call the L<SSL_set_retry_verify(3)>
  32. function on the B<SSL> object set in the I<x509_store_ctx> ex data (see
  33. L<SSL_get_ex_data_X509_STORE_CTX_idx(3)>) and return 1. This would be
  34. typically done in case the certificate verification was not yet able
  35. to succeed. This makes the handshake suspend and return control to the
  36. calling application with B<SSL_ERROR_WANT_RETRY_VERIFY>. The app can for
  37. instance fetch further certificates or cert status information needed for
  38. the verification. Calling L<SSL_connect(3)> again resumes the connection
  39. attempt by retrying the server certificate verification step.
  40. This process may even be repeated if need be.
  41. In any case a viable verification result value must be reflected
  42. in the B<error> member of I<x509_store_ctx>,
  43. which can be done using L<X509_STORE_CTX_set_error(3)>.
  44. This is particularly important in case
  45. the I<callback> allows the connection to continue (by returning 1).
  46. Note that the verification status in the store context is a possibly durable
  47. indication of the chain's validity!
  48. This gets recorded in the SSL session (and thus also in session tickets)
  49. and the validity of the originally presented chain is then visible
  50. on resumption, even though no chain is presented int that case.
  51. Moreover, the calling application will be informed about the detailed result of
  52. the verification procedure and may elect to base further decisions on it.
  53. Within I<x509_store_ctx>, I<callback> has access to the I<verify_callback>
  54. function set using L<SSL_CTX_set_verify(3)>.
  55. =head1 RETURN VALUES
  56. SSL_CTX_set_cert_verify_callback() does not return a value.
  57. =head1 WARNINGS
  58. Do not mix the verification callback described in this function with the
  59. B<verify_callback> function called during the verification process. The
  60. latter is set using the L<SSL_CTX_set_verify(3)>
  61. family of functions.
  62. Providing a complete verification procedure including certificate purpose
  63. settings etc is a complex task. The built-in procedure is quite powerful
  64. and in most cases it should be sufficient to modify its behaviour using
  65. the B<verify_callback> function.
  66. =head1 BUGS
  67. SSL_CTX_set_cert_verify_callback() does not provide diagnostic information.
  68. =head1 SEE ALSO
  69. L<ssl(7)>, L<SSL_CTX_set_verify(3)>,
  70. L<X509_STORE_CTX_set_error(3)>,
  71. L<SSL_get_verify_result(3)>,
  72. L<SSL_set_retry_verify(3)>,
  73. L<SSL_CTX_load_verify_locations(3)>
  74. =head1 COPYRIGHT
  75. Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
  76. Licensed under the Apache License 2.0 (the "License"). You may not use
  77. this file except in compliance with the License. You can obtain a copy
  78. in the file LICENSE in the source distribution or at
  79. L<https://www.openssl.org/source/license.html>.
  80. =cut