SSL_CTX_set_client_hello_cb.pod 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set_client_hello_cb, SSL_client_hello_cb_fn, SSL_client_hello_isv2, SSL_client_hello_get0_legacy_version, SSL_client_hello_get0_random, SSL_client_hello_get0_session_id, SSL_client_hello_get0_ciphers, SSL_client_hello_get0_compression_methods, SSL_client_hello_get1_extensions_present, SSL_client_hello_get_extension_order, SSL_client_hello_get0_ext - callback functions for early server-side ClientHello processing
  4. =head1 SYNOPSIS
  5. typedef int (*SSL_client_hello_cb_fn)(SSL *s, int *al, void *arg);
  6. void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn *f,
  7. void *arg);
  8. int SSL_client_hello_isv2(SSL *s);
  9. unsigned int SSL_client_hello_get0_legacy_version(SSL *s);
  10. size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out);
  11. size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out);
  12. size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out);
  13. size_t SSL_client_hello_get0_compression_methods(SSL *s,
  14. const unsigned char **out);
  15. int SSL_client_hello_get1_extensions_present(SSL *s, int **out,
  16. size_t *outlen);
  17. int SSL_client_hello_get_extension_order(SSL *s, uint16_t *exts,
  18. size_t *num_exts);
  19. int SSL_client_hello_get0_ext(SSL *s, unsigned int type, const unsigned char **out,
  20. size_t *outlen);
  21. =head1 DESCRIPTION
  22. SSL_CTX_set_client_hello_cb() sets the callback function, which is automatically
  23. called during the early stages of ClientHello processing on the server.
  24. The argument supplied when setting the callback is passed back to the
  25. callback at run time. A callback that returns failure (0) will cause the
  26. connection to terminate, and callbacks returning failure should indicate
  27. what alert value is to be sent in the B<al> parameter. A callback may
  28. also return a negative value to suspend the handshake, and the handshake
  29. function will return immediately. L<SSL_get_error(3)> will return
  30. SSL_ERROR_WANT_CLIENT_HELLO_CB to indicate that the handshake was suspended.
  31. It is the job of the ClientHello callback to store information about the state
  32. of the last call if needed to continue. On the next call into the handshake
  33. function, the ClientHello callback will be called again, and, if it returns
  34. success, normal handshake processing will continue from that point.
  35. SSL_client_hello_isv2() indicates whether the ClientHello was carried in a
  36. SSLv2 record and is in the SSLv2 format. The SSLv2 format has substantial
  37. differences from the normal SSLv3 format, including using three bytes per
  38. cipher suite, and not allowing extensions. Additionally, the SSLv2 format
  39. 'challenge' field is exposed via SSL_client_hello_get0_random(), padded to
  40. SSL3_RANDOM_SIZE bytes with zeros if needed. For SSLv2 format ClientHellos,
  41. SSL_client_hello_get0_compression_methods() returns a dummy list that only includes
  42. the null compression method, since the SSLv2 format does not include a
  43. mechanism by which to negotiate compression.
  44. SSL_client_hello_get0_random(), SSL_client_hello_get0_session_id(),
  45. SSL_client_hello_get0_ciphers(), and
  46. SSL_client_hello_get0_compression_methods() provide access to the corresponding
  47. ClientHello fields, returning the field length and optionally setting an out
  48. pointer to the octets of that field.
  49. Similarly, SSL_client_hello_get0_ext() provides access to individual extensions
  50. from the ClientHello on a per-extension basis. For the provided wire
  51. protocol extension type value, the extension value and length are returned
  52. in the output parameters (if present).
  53. SSL_client_hello_get1_extensions_present() can be used prior to
  54. SSL_client_hello_get0_ext(), to determine which extensions are present in the
  55. ClientHello before querying for them. The B<out> and B<outlen> parameters are
  56. both required, and on success the caller must release the storage allocated for
  57. B<*out> using OPENSSL_free(). The contents of B<*out> is an array of integers
  58. holding the numerical value of the TLS extension types in the order they appear
  59. in the ClientHello. B<*outlen> contains the number of elements in the array.
  60. In situations when the ClientHello has no extensions, the function will return
  61. success with B<*out> set to NULL and B<*outlen> set to 0.
  62. SSL_client_hello_get_extension_order() is similar to
  63. SSL_client_hello_get1_extensions_present(), without internal memory allocation.
  64. When called with B<exts> set to NULL, returns the number of extensions
  65. (e.g., to allocate storage for a subsequent call). Otherwise, B<*exts> is populated
  66. with the ExtensionType values in the order that the corresponding extensions
  67. appeared in the ClientHello. B<*num_exts> is an input/output parameter, used
  68. as input to supply the size of storage allocated by the caller, and as output to
  69. indicate how many ExtensionType values were written. If the input B<*num_exts>
  70. is smaller then the number of extensions in question, that is treated as an error.
  71. A subsequent call with B<exts> set to NULL can retrieve the size of storage needed.
  72. A ClientHello that contained no extensions is treated as success, with B<*num_exts>
  73. set to 0.
  74. =head1 NOTES
  75. The ClientHello callback provides a vast window of possibilities for application
  76. code to affect the TLS handshake. A primary use of the callback is to
  77. allow the server to examine the server name indication extension provided
  78. by the client in order to select an appropriate certificate to present,
  79. and make other configuration adjustments relevant to that server name
  80. and its configuration. Such configuration changes can include swapping out
  81. the associated SSL_CTX pointer, modifying the server's list of permitted TLS
  82. versions, changing the server's cipher list in response to the client's
  83. cipher list, etc.
  84. It is also recommended that applications utilize a ClientHello callback and
  85. not use a servername callback, in order to avoid unexpected behavior that
  86. occurs due to the relative order of processing between things like session
  87. resumption and the historical servername callback.
  88. The SSL_client_hello_* family of functions may only be called from code executing
  89. within a ClientHello callback.
  90. =head1 RETURN VALUES
  91. The application's supplied ClientHello callback returns
  92. SSL_CLIENT_HELLO_SUCCESS on success, SSL_CLIENT_HELLO_ERROR on failure, and
  93. SSL_CLIENT_HELLO_RETRY to suspend processing.
  94. SSL_client_hello_isv2() returns 1 for SSLv2-format ClientHellos and 0 otherwise.
  95. SSL_client_hello_get0_random(), SSL_client_hello_get0_session_id(),
  96. SSL_client_hello_get0_ciphers(), and
  97. SSL_client_hello_get0_compression_methods() return the length of the
  98. corresponding ClientHello fields. If zero is returned, the output pointer
  99. should not be assumed to be valid.
  100. SSL_client_hello_get0_ext() returns 1 if the extension of type 'type' is present, and
  101. 0 otherwise.
  102. SSL_client_hello_get1_extensions_present() returns 1 on success and 0 on failure.
  103. SSL_client_hello_get_extension_order() returns 1 on success and 0 on failure.
  104. =head1 SEE ALSO
  105. L<ssl(7)>, L<SSL_CTX_set_tlsext_servername_callback(3)>,
  106. L<SSL_bytes_to_cipher_list(3)>
  107. =head1 HISTORY
  108. The SSL ClientHello callback, SSL_client_hello_isv2(),
  109. SSL_client_hello_get0_random(), SSL_client_hello_get0_session_id(),
  110. SSL_client_hello_get0_ciphers(), SSL_client_hello_get0_compression_methods(),
  111. SSL_client_hello_get0_ext(), and SSL_client_hello_get1_extensions_present()
  112. were added in OpenSSL 1.1.1.
  113. SSL_client_hello_get_extension_order()
  114. was added in OpenSSL 3.1.0.
  115. =head1 COPYRIGHT
  116. Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved.
  117. Licensed under the Apache License 2.0 (the "License"). You may not use
  118. this file except in compliance with the License. You can obtain a copy
  119. in the file LICENSE in the source distribution or at
  120. L<https://www.openssl.org/source/license.html>.
  121. =cut