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