Doc nits: callback function typedefs
[openssl.git] / doc / man3 / SSL_extension_supported.pod
1 =pod
2
3 =head1 NAME
4
5 SSL_extension_supported,
6 SSL_CTX_add_client_custom_ext, SSL_CTX_add_server_custom_ext,
7 custom_ext_add_cb, custom_ext_free_cb, custom_ext_parse_cb
8 - custom TLS extension handling
9
10 =head1 SYNOPSIS
11
12  #include <openssl/ssl.h>
13
14  int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
15                                    custom_ext_add_cb add_cb,
16                                    custom_ext_free_cb free_cb, void *add_arg,
17                                    custom_ext_parse_cb parse_cb,
18                                    void *parse_arg);
19
20  int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
21                                    custom_ext_add_cb add_cb,
22                                    custom_ext_free_cb free_cb, void *add_arg,
23                                    custom_ext_parse_cb parse_cb,
24                                    void *parse_arg);
25
26  int SSL_extension_supported(unsigned int ext_type);
27
28  typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type,
29                                   const unsigned char **out,
30                                   size_t *outlen, int *al,
31                                   void *add_arg);
32
33  typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type,
34                                     const unsigned char *out,
35                                     void *add_arg);
36
37  typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type,
38                                     const unsigned char *in,
39                                     size_t inlen, int *al,
40                                     void *parse_arg);
41
42
43 =head1 DESCRIPTION
44
45 SSL_CTX_add_client_custom_ext() adds a custom extension for a TLS client
46 with extension type B<ext_type> and callbacks B<add_cb>, B<free_cb> and
47 B<parse_cb>.
48
49 SSL_CTX_add_server_custom_ext() adds a custom extension for a TLS server
50 with extension type B<ext_type> and callbacks B<add_cb>, B<free_cb> and
51 B<parse_cb>.
52
53 In both cases the extension type must not be handled by OpenSSL internally
54 or an error occurs.
55
56 SSL_extension_supported() returns 1 if the extension B<ext_type> is handled
57 internally by OpenSSL and 0 otherwise.
58
59 =head1 EXTENSION CALLBACKS
60
61 The callback B<add_cb> is called to send custom extension data to be
62 included in ClientHello for TLS clients or ServerHello for servers. The
63 B<ext_type> parameter is set to the extension type which will be added and
64 B<add_arg> to the value set when the extension handler was added.
65
66 If the application wishes to include the extension B<ext_type> it should
67 set B<*out> to the extension data, set B<*outlen> to the length of the
68 extension data and return 1.
69
70 If the B<add_cb> does not wish to include the extension it must return 0.
71
72 If B<add_cb> returns -1 a fatal handshake error occurs using the TLS
73 alert value specified in B<*al>.
74
75 For clients (but not servers) if B<add_cb> is set to NULL a zero length
76 extension is added for B<ext_type>.
77
78 For clients every registered B<add_cb> is always called to see if the
79 application wishes to add an extension to ClientHello.
80
81 For servers every registered B<add_cb> is called once if and only if the
82 corresponding extension was received in ClientHello to see if the application
83 wishes to add the extension to ServerHello. That is, if no corresponding extension
84 was received in ClientHello then B<add_cb> will not be called.
85
86 If an extension is added (that is B<add_cb> returns 1) B<free_cb> is called
87 (if it is set) with the value of B<out> set by the add callback. It can be
88 used to free up any dynamic extension data set by B<add_cb>. Since B<out> is
89 constant (to permit use of constant data in B<add_cb>) applications may need to
90 cast away const to free the data.
91
92 The callback B<parse_cb> receives data for TLS extensions. For TLS clients
93 the extension data will come from ServerHello and for TLS servers it will
94 come from ClientHello.
95
96 The extension data consists of B<inlen> bytes in the buffer B<in> for the
97 extension B<extension_type>.
98
99 If the B<parse_cb> considers the extension data acceptable it must return
100 1. If it returns 0 or a negative value a fatal handshake error occurs
101 using the TLS alert value specified in B<*al>.
102
103 The buffer B<in> is a temporary internal buffer which will not be valid after
104 the callback returns.
105
106 =head1 NOTES
107
108 The B<add_arg> and B<parse_arg> parameters can be set to arbitrary values
109 which will be passed to the corresponding callbacks. They can, for example,
110 be used to store the extension data received in a convenient structure or
111 pass the extension data to be added or freed when adding extensions.
112
113 The B<ext_type> parameter corresponds to the B<extension_type> field of
114 RFC5246 et al. It is B<not> a NID.
115
116 If the same custom extension type is received multiple times a fatal
117 B<decode_error> alert is sent and the handshake aborts. If a custom extension
118 is received in ServerHello which was not sent in ClientHello a fatal
119 B<unsupported_extension> alert is sent and the handshake is aborted. The
120 ServerHello B<add_cb> callback is only called if the corresponding extension
121 was received in ClientHello. This is compliant with the TLS specifications.
122 This behaviour ensures that each callback is called at most once and that
123 an application can never send unsolicited extensions.
124
125 =head1 RETURN VALUES
126
127 SSL_CTX_add_client_custom_ext() and SSL_CTX_add_server_custom_ext() return 1 for
128 success and 0 for failure. A failure can occur if an attempt is made to
129 add the same B<ext_type> more than once, if an attempt is made to use an
130 extension type handled internally by OpenSSL or if an internal error occurs
131 (for example a memory allocation failure).
132
133 SSL_extension_supported() returns 1 if the extension B<ext_type> is handled
134 internally by OpenSSL and 0 otherwise.
135
136 =head1 COPYRIGHT
137
138 Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
139
140 Licensed under the OpenSSL license (the "License").  You may not use
141 this file except in compliance with the License.  You can obtain a copy
142 in the file LICENSE in the source distribution or at
143 L<https://www.openssl.org/source/license.html>.
144
145 =cut