1SSL_CTX_SET_PSK_CLIENT_CALLBACK(3) OpenSSL SSL_CTX_SET_PSK_CLIENT_CALLBACK(3)
2
3
4
6 SSL_psk_client_cb_func, SSL_psk_use_session_cb_func,
7 SSL_CTX_set_psk_client_callback, SSL_set_psk_client_callback,
8 SSL_CTX_set_psk_use_session_callback, SSL_set_psk_use_session_callback
9 - set PSK client callback
10
12 #include <openssl/ssl.h>
13
14 typedef int (*SSL_psk_use_session_cb_func)(SSL *ssl, const EVP_MD *md,
15 const unsigned char **id,
16 size_t *idlen,
17 SSL_SESSION **sess);
18
19
20 void SSL_CTX_set_psk_use_session_callback(SSL_CTX *ctx,
21 SSL_psk_use_session_cb_func cb);
22 void SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb);
23
24
25 typedef unsigned int (*SSL_psk_client_cb_func)(SSL *ssl,
26 const char *hint,
27 char *identity,
28 unsigned int max_identity_len,
29 unsigned char *psk,
30 unsigned int max_psk_len);
31
32 void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, SSL_psk_client_cb_func cb);
33 void SSL_set_psk_client_callback(SSL *ssl, SSL_psk_client_cb_func cb);
34
36 A client application wishing to use TLSv1.3 PSKs should use either
37 SSL_CTX_set_psk_use_session_callback() or
38 SSL_set_psk_use_session_callback() as appropriate. These functions
39 cannot be used for TLSv1.2 and below PSKs.
40
41 The callback function is given a pointer to the SSL connection in ssl.
42
43 The first time the callback is called for a connection the md parameter
44 is NULL. In some circumstances the callback will be called a second
45 time. In that case the server will have specified a ciphersuite to use
46 already and the PSK must be compatible with the digest for that
47 ciphersuite. The digest will be given in md. The PSK returned by the
48 callback is allowed to be different between the first and second time
49 it is called.
50
51 On successful completion the callback must store a pointer to an
52 identifier for the PSK in *id. The identifier length in bytes should be
53 stored in *idlen. The memory pointed to by *id remains owned by the
54 application and should be freed by it as required at any point after
55 the handshake is complete.
56
57 Additionally the callback should store a pointer to an SSL_SESSION
58 object in *sess. This is used as the basis for the PSK, and should, at
59 a minimum, have the following fields set:
60
61 The master key
62 This can be set via a call to SSL_SESSION_set1_master_key(3).
63
64 A ciphersuite
65 Only the handshake digest associated with the ciphersuite is
66 relevant for the PSK (the server may go on to negotiate any
67 ciphersuite which is compatible with the digest). The application
68 can use any TLSv1.3 ciphersuite. If md is not NULL the handshake
69 digest for the ciphersuite should be the same. The ciphersuite can
70 be set via a call to <SSL_SESSION_set_cipher(3)>. The handshake
71 digest of an SSL_CIPHER object can be checked using
72 <SSL_CIPHER_get_handshake_digest(3)>.
73
74 The protocol version
75 This can be set via a call to SSL_SESSION_set_protocol_version(3)
76 and should be TLS1_3_VERSION.
77
78 Additionally the maximum early data value should be set via a call to
79 SSL_SESSION_set_max_early_data(3) if the PSK will be used for sending
80 early data.
81
82 Alternatively an SSL_SESSION created from a previous non-PSK handshake
83 may also be used as the basis for a PSK.
84
85 Ownership of the SSL_SESSION object is passed to the OpenSSL library
86 and so it should not be freed by the application.
87
88 It is also possible for the callback to succeed but not supply a PSK.
89 In this case no PSK will be sent to the server but the handshake will
90 continue. To do this the callback should return successfully and ensure
91 that *sess is NULL. The contents of *id and *idlen will be ignored.
92
93 A client application wishing to use PSK ciphersuites for TLSv1.2 and
94 below must provide a different callback function. This function will be
95 called when the client is sending the ClientKeyExchange message to the
96 server.
97
98 The purpose of the callback function is to select the PSK identity and
99 the pre-shared key to use during the connection setup phase.
100
101 The callback is set using functions SSL_CTX_set_psk_client_callback()
102 or SSL_set_psk_client_callback(). The callback function is given the
103 connection in parameter ssl, a NULL-terminated PSK identity hint sent
104 by the server in parameter hint, a buffer identity of length
105 max_identity_len bytes where the resulting NUL-terminated identity is
106 to be stored, and a buffer psk of length max_psk_len bytes where the
107 resulting pre-shared key is to be stored.
108
109 The callback for use in TLSv1.2 will also work in TLSv1.3 although it
110 is recommended to use SSL_CTX_set_psk_use_session_callback() or
111 SSL_set_psk_use_session_callback() for this purpose instead. If TLSv1.3
112 has been negotiated then OpenSSL will first check to see if a callback
113 has been set via SSL_CTX_set_psk_use_session_callback() or
114 SSL_set_psk_use_session_callback() and it will use that in preference.
115 If no such callback is present then it will check to see if a callback
116 has been set via SSL_CTX_set_psk_client_callback() or
117 SSL_set_psk_client_callback() and use that. In this case the hint value
118 will always be NULL and the handshake digest will default to SHA-256
119 for any returned PSK.
120
122 Note that parameter hint given to the callback may be NULL.
123
124 A connection established via a TLSv1.3 PSK will appear as if session
125 resumption has occurred so that SSL_session_reused(3) will return true.
126
127 There are no known security issues with sharing the same PSK between
128 TLSv1.2 (or below) and TLSv1.3. However the RFC has this note of
129 caution:
130
131 "While there is no known way in which the same PSK might produce
132 related output in both versions, only limited analysis has been done.
133 Implementations can ensure safety from cross-protocol related output by
134 not reusing PSKs between TLS 1.3 and TLS 1.2."
135
137 Return values from the SSL_psk_client_cb_func callback are interpreted
138 as follows:
139
140 On success (callback found a PSK identity and a pre-shared key to use)
141 the length (> 0) of psk in bytes is returned.
142
143 Otherwise or on errors the callback should return 0. In this case the
144 connection setup fails.
145
146 The SSL_psk_use_session_cb_func callback should return 1 on success or
147 0 on failure. In the event of failure the connection setup fails.
148
150 SSL_CTX_set_psk_find_session_callback(3),
151 SSL_set_psk_find_session_callback(3)
152
154 SSL_CTX_set_psk_use_session_callback() and
155 SSL_set_psk_use_session_callback() were added in OpenSSL 1.1.1.
156
158 Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
159
160 Licensed under the OpenSSL license (the "License"). You may not use
161 this file except in compliance with the License. You can obtain a copy
162 in the file LICENSE in the source distribution or at
163 <https://www.openssl.org/source/license.html>.
164
165
166
1671.1.1c 2019-05-28SSL_CTX_SET_PSK_CLIENT_CALLBACK(3)