2
0

SSL_CTX_use_psk_identity_hint.pod 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. =pod
  2. =head1 NAME
  3. SSL_psk_server_cb_func,
  4. SSL_psk_find_session_cb_func,
  5. SSL_CTX_use_psk_identity_hint,
  6. SSL_use_psk_identity_hint,
  7. SSL_CTX_set_psk_server_callback,
  8. SSL_set_psk_server_callback,
  9. SSL_CTX_set_psk_find_session_callback,
  10. SSL_set_psk_find_session_callback
  11. - set PSK identity hint to use
  12. =head1 SYNOPSIS
  13. #include <openssl/ssl.h>
  14. typedef int (*SSL_psk_find_session_cb_func)(SSL *ssl,
  15. const unsigned char *identity,
  16. size_t identity_len,
  17. SSL_SESSION **sess);
  18. void SSL_CTX_set_psk_find_session_callback(SSL_CTX *ctx,
  19. SSL_psk_find_session_cb_func cb);
  20. void SSL_set_psk_find_session_callback(SSL *s, SSL_psk_find_session_cb_func cb);
  21. typedef unsigned int (*SSL_psk_server_cb_func)(SSL *ssl,
  22. const char *identity,
  23. unsigned char *psk,
  24. unsigned int max_psk_len);
  25. int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *hint);
  26. int SSL_use_psk_identity_hint(SSL *ssl, const char *hint);
  27. void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, SSL_psk_server_cb_func cb);
  28. void SSL_set_psk_server_callback(SSL *ssl, SSL_psk_server_cb_func cb);
  29. =head1 DESCRIPTION
  30. A server application wishing to use TLSv1.3 PSKs should set a callback
  31. using either SSL_CTX_set_psk_find_session_callback() or
  32. SSL_set_psk_find_session_callback() as appropriate.
  33. The callback function is given a pointer to the SSL connection in B<ssl> and
  34. an identity in B<identity> of length B<identity_len>. The callback function
  35. should identify an SSL_SESSION object that provides the PSK details and store it
  36. in B<*sess>. The SSL_SESSION object should, as a minimum, set the master key,
  37. the ciphersuite and the protocol version. See
  38. L<SSL_CTX_set_psk_use_session_callback(3)> for details.
  39. It is also possible for the callback to succeed but not supply a PSK. In this
  40. case no PSK will be used but the handshake will continue. To do this the
  41. callback should return successfully and ensure that B<*sess> is
  42. NULL.
  43. Identity hints are not relevant for TLSv1.3. A server application wishing to use
  44. PSK ciphersuites for TLSv1.2 and below may call SSL_CTX_use_psk_identity_hint()
  45. to set the given B<NUL>-terminated PSK identity hint B<hint> for SSL context
  46. object B<ctx>. SSL_use_psk_identity_hint() sets the given B<NUL>-terminated PSK
  47. identity hint B<hint> for the SSL connection object B<ssl>. If B<hint> is
  48. B<NULL> the current hint from B<ctx> or B<ssl> is deleted.
  49. In the case where PSK identity hint is B<NULL>, the server does not send the
  50. ServerKeyExchange message to the client.
  51. A server application wishing to use PSKs for TLSv1.2 and below must provide a
  52. callback function which is called when the server receives the
  53. ClientKeyExchange message from the client. The purpose of the callback function
  54. is to validate the received PSK identity and to fetch the pre-shared key used
  55. during the connection setup phase. The callback is set using the functions
  56. SSL_CTX_set_psk_server_callback() or SSL_set_psk_server_callback(). The callback
  57. function is given the connection in parameter B<ssl>, B<NUL>-terminated PSK
  58. identity sent by the client in parameter B<identity>, and a buffer B<psk> of
  59. length B<max_psk_len> bytes where the pre-shared key is to be stored.
  60. The callback for use in TLSv1.2 will also work in TLSv1.3 although it is
  61. recommended to use SSL_CTX_set_psk_find_session_callback()
  62. or SSL_set_psk_find_session_callback() for this purpose instead. If TLSv1.3 has
  63. been negotiated then OpenSSL will first check to see if a callback has been set
  64. via SSL_CTX_set_psk_find_session_callback() or SSL_set_psk_find_session_callback()
  65. and it will use that in preference. If no such callback is present then it will
  66. check to see if a callback has been set via SSL_CTX_set_psk_server_callback() or
  67. SSL_set_psk_server_callback() and use that. In this case the handshake digest
  68. will default to SHA-256 for any returned PSK. TLSv1.3 early data exchanges are
  69. possible in PSK connections only with the B<SSL_psk_find_session_cb_func>
  70. callback, and are not possible with the B<SSL_psk_server_cb_func> callback.
  71. A connection established via a TLSv1.3 PSK will appear as if session resumption
  72. has occurred so that L<SSL_session_reused(3)> will return true.
  73. =head1 RETURN VALUES
  74. B<SSL_CTX_use_psk_identity_hint()> and B<SSL_use_psk_identity_hint()> return
  75. 1 on success, 0 otherwise.
  76. Return values from the TLSv1.2 and below server callback are interpreted as
  77. follows:
  78. =over 4
  79. =item Z<>0
  80. PSK identity was not found. An "unknown_psk_identity" alert message
  81. will be sent and the connection setup fails.
  82. =item E<gt>0
  83. PSK identity was found and the server callback has provided the PSK
  84. successfully in parameter B<psk>. Return value is the length of
  85. B<psk> in bytes. It is an error to return a value greater than
  86. B<max_psk_len>.
  87. If the PSK identity was not found but the callback instructs the
  88. protocol to continue anyway, the callback must provide some random
  89. data to B<psk> and return the length of the random data, so the
  90. connection will fail with decryption_error before it will be finished
  91. completely.
  92. =back
  93. The B<SSL_psk_find_session_cb_func> callback should return 1 on success or 0 on
  94. failure. In the event of failure the connection setup fails.
  95. =head1 NOTES
  96. There are no known security issues with sharing the same PSK between TLSv1.2 (or
  97. below) and TLSv1.3. However, the RFC has this note of caution:
  98. "While there is no known way in which the same PSK might produce related output
  99. in both versions, only limited analysis has been done. Implementations can
  100. ensure safety from cross-protocol related output by not reusing PSKs between
  101. TLS 1.3 and TLS 1.2."
  102. =head1 SEE ALSO
  103. L<ssl(7)>,
  104. L<SSL_CTX_set_psk_use_session_callback(3)>,
  105. L<SSL_set_psk_use_session_callback(3)>
  106. =head1 HISTORY
  107. SSL_CTX_set_psk_find_session_callback() and SSL_set_psk_find_session_callback()
  108. were added in OpenSSL 1.1.1.
  109. =head1 COPYRIGHT
  110. Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
  111. Licensed under the Apache License 2.0 (the "License"). You may not use
  112. this file except in compliance with the License. You can obtain a copy
  113. in the file LICENSE in the source distribution or at
  114. L<https://www.openssl.org/source/license.html>.
  115. =cut