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