1SSL_CTX_SET_PSK_CLIENT_CALLBACK(3osslO)penSSSSLL_CTX_SET_PSK_CLIENT_CALLBACK(3ossl)
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 NUL-terminated PSK identity hint sent by
104 the server in parameter hint, a buffer identity of length
105 max_identity_len bytes (including the NUL-terminator) where the
106 resulting NUL-terminated identity is to be stored, and a buffer psk of
107 length max_psk_len bytes where the resulting pre-shared key is to be
108 stored.
109
110 The callback for use in TLSv1.2 will also work in TLSv1.3 although it
111 is recommended to use SSL_CTX_set_psk_use_session_callback() or
112 SSL_set_psk_use_session_callback() for this purpose instead. If TLSv1.3
113 has been negotiated then OpenSSL will first check to see if a callback
114 has been set via SSL_CTX_set_psk_use_session_callback() or
115 SSL_set_psk_use_session_callback() and it will use that in preference.
116 If no such callback is present then it will check to see if a callback
117 has been set via SSL_CTX_set_psk_client_callback() or
118 SSL_set_psk_client_callback() and use that. In this case the hint value
119 will always be NULL and the handshake digest will default to SHA-256
120 for any returned PSK. TLSv1.3 early data exchanges are possible in PSK
121 connections only with the SSL_psk_use_session_cb_func callback, and are
122 not possible with the SSL_psk_client_cb_func callback.
123
125 Note that parameter hint given to the callback may be NULL.
126
127 A connection established via a TLSv1.3 PSK will appear as if session
128 resumption has occurred so that SSL_session_reused(3) will return true.
129
130 There are no known security issues with sharing the same PSK between
131 TLSv1.2 (or below) and TLSv1.3. However, the RFC has this note of
132 caution:
133
134 "While there is no known way in which the same PSK might produce
135 related output in both versions, only limited analysis has been done.
136 Implementations can ensure safety from cross-protocol related output by
137 not reusing PSKs between TLS 1.3 and TLS 1.2."
138
140 Return values from the SSL_psk_client_cb_func callback are interpreted
141 as follows:
142
143 On success (callback found a PSK identity and a pre-shared key to use)
144 the length (> 0) of psk in bytes is returned.
145
146 Otherwise or on errors the callback should return 0. In this case the
147 connection setup fails.
148
149 The SSL_psk_use_session_cb_func callback should return 1 on success or
150 0 on failure. In the event of failure the connection setup fails.
151
153 ssl(7), SSL_CTX_set_psk_find_session_callback(3),
154 SSL_set_psk_find_session_callback(3)
155
157 SSL_CTX_set_psk_use_session_callback() and
158 SSL_set_psk_use_session_callback() were added in OpenSSL 1.1.1.
159
161 Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
162
163 Licensed under the Apache License 2.0 (the "License"). You may not use
164 this file except in compliance with the License. You can obtain a copy
165 in the file LICENSE in the source distribution or at
166 <https://www.openssl.org/source/license.html>.
167
168
169
1703.0.9 2023-07S-S2L7_CTX_SET_PSK_CLIENT_CALLBACK(3ossl)