]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/SSL_CTX_set_alpn_select_cb.pod
Copyright year updates
[thirdparty/openssl.git] / doc / man3 / SSL_CTX_set_alpn_select_cb.pod
CommitLineData
817cd0d5
TS
1=pod
2
3=head1 NAME
4
0351baae 5SSL_CTX_set_alpn_protos, SSL_set_alpn_protos, SSL_CTX_set_alpn_select_cb,
87b81496
RS
6SSL_CTX_set_next_proto_select_cb, SSL_CTX_set_next_protos_advertised_cb,
7SSL_select_next_proto, SSL_get0_alpn_selected, SSL_get0_next_proto_negotiated
8- handle application layer protocol negotiation (ALPN)
817cd0d5
TS
9
10=head1 SYNOPSIS
11
12 #include <openssl/ssl.h>
13
14 int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
15 unsigned int protos_len);
16 int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
17 unsigned int protos_len);
18 void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
19 int (*cb) (SSL *ssl,
20 const unsigned char **out,
21 unsigned char *outlen,
22 const unsigned char *in,
23 unsigned int inlen,
24 void *arg), void *arg);
87b81496
RS
25 void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
26 unsigned int *len);
27
28 void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *ctx,
29 int (*cb)(SSL *ssl,
30 const unsigned char **out,
31 unsigned int *outlen,
32 void *arg),
33 void *arg);
34 void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx,
35 int (*cb)(SSL *s,
36 unsigned char **out,
37 unsigned char *outlen,
38 const unsigned char *in,
39 unsigned int inlen,
40 void *arg),
41 void *arg);
817cd0d5
TS
42 int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
43 const unsigned char *server,
44 unsigned int server_len,
45 const unsigned char *client,
f64f17c3 46 unsigned int client_len);
87b81496
RS
47 void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
48 unsigned *len);
817cd0d5
TS
49
50=head1 DESCRIPTION
51
52SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() are used by the client to
53set the list of protocols available to be negotiated. The B<protos> must be in
54protocol-list format, described below. The length of B<protos> is specified in
55B<protos_len>.
56
57SSL_CTX_set_alpn_select_cb() sets the application callback B<cb> used by a
58server to select which protocol to use for the incoming connection. When B<cb>
0351baae 59is NULL, ALPN is not used. The B<arg> value is a pointer which is passed to
817cd0d5
TS
60the application callback.
61
62B<cb> is the application defined callback. The B<in>, B<inlen> parameters are a
63vector in protocol-list format. The value of the B<out>, B<outlen> vector
0351baae 64should be set to the value of a single protocol selected from the B<in>,
ce2cdac2
EK
65B<inlen> vector. The B<out> buffer may point directly into B<in>, or to a
66buffer that outlives the handshake. The B<arg> parameter is the pointer set via
817cd0d5
TS
67SSL_CTX_set_alpn_select_cb().
68
69SSL_select_next_proto() is a helper function used to select protocols. It
70implements the standard protocol selection. It is expected that this function
71is called from the application callback B<cb>. The protocol data in B<server>,
0351baae 72B<server_len> and B<client>, B<client_len> must be in the protocol-list format
817cd0d5
TS
73described below. The first item in the B<server>, B<server_len> list that
74matches an item in the B<client>, B<client_len> list is selected, and returned
75in B<out>, B<outlen>. The B<out> value will point into either B<server> or
76B<client>, so it should be copied immediately. If no match is found, the first
77item in B<client>, B<client_len> is returned in B<out>, B<outlen>. This
78function can also be used in the NPN callback.
79
87b81496
RS
80SSL_CTX_set_next_proto_select_cb() sets a callback B<cb> that is called when a
81client needs to select a protocol from the server's provided list, and a
82user-defined pointer argument B<arg> which will be passed to this callback.
83For the callback itself, B<out>
84must be set to point to the selected protocol (which may be within B<in>).
85The length of the protocol name must be written into B<outlen>. The
86server's advertised protocols are provided in B<in> and B<inlen>. The
87callback can assume that B<in> is syntactically valid. The client must
88select a protocol. It is fatal to the connection if this callback returns
89a value other than B<SSL_TLSEXT_ERR_OK>. The B<arg> parameter is the pointer
90set via SSL_CTX_set_next_proto_select_cb().
91
92SSL_CTX_set_next_protos_advertised_cb() sets a callback B<cb> that is called
93when a TLS server needs a list of supported protocols for Next Protocol
94Negotiation. The returned list must be in protocol-list format, described
95below. The list is
96returned by setting B<out> to point to it and B<outlen> to its length. This
97memory will not be modified, but the B<SSL> does keep a
98reference to it. The callback should return B<SSL_TLSEXT_ERR_OK> if it
99wishes to advertise. Otherwise, no such extension will be included in the
100ServerHello.
101
817cd0d5
TS
102SSL_get0_alpn_selected() returns a pointer to the selected protocol in B<data>
103with length B<len>. It is not NUL-terminated. B<data> is set to NULL and B<len>
0351baae 104is set to 0 if no protocol has been selected. B<data> must not be freed.
817cd0d5 105
87b81496
RS
106SSL_get0_next_proto_negotiated() sets B<data> and B<len> to point to the
107client's requested protocol for this connection. If the client did not
108request any protocol or NPN is not enabled, then B<data> is set to NULL and
109B<len> to 0. Note that
110the client can request any protocol it chooses. The value returned from
111this function need not be a member of the list of supported protocols
112provided by the callback.
113
68dbff4c 114NPN functionality cannot be used with QUIC SSL objects. Use of ALPN is mandatory
d6e7ebba
HL
115when using QUIC SSL objects. SSL_CTX_set_next_protos_advertised_cb() and
116SSL_CTX_set_next_proto_select_cb() have no effect if called on a QUIC SSL
117context.
68dbff4c 118
817cd0d5
TS
119=head1 NOTES
120
121The protocol-lists must be in wire-format, which is defined as a vector of
490c8711 122nonempty, 8-bit length-prefixed, byte strings. The length-prefix byte is not
817cd0d5
TS
123included in the length. Each string is limited to 255 bytes. A byte-string
124length of 0 is invalid. A truncated byte-string is invalid. The length of the
125vector is not in the vector itself, but in a separate variable.
126
127Example:
128
129 unsigned char vector[] = {
130 6, 's', 'p', 'd', 'y', '/', '1',
131 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
132 };
133 unsigned int length = sizeof(vector);
134
135The ALPN callback is executed after the servername callback; as that servername
136callback may update the SSL_CTX, and subsequently, the ALPN callback.
137
138If there is no ALPN proposed in the ClientHello, the ALPN callback is not
139invoked.
140
141=head1 RETURN VALUES
142
143SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() return 0 on success, and
144non-0 on failure. WARNING: these functions reverse the return value convention.
145
146SSL_select_next_proto() returns one of the following:
147
148=over 4
149
150=item OPENSSL_NPN_NEGOTIATED
151
152A match was found and is returned in B<out>, B<outlen>.
153
154=item OPENSSL_NPN_NO_OVERLAP
155
156No match was found. The first item in B<client>, B<client_len> is returned in
157B<out>, B<outlen>.
158
159=back
160
161The ALPN select callback B<cb>, must return one of the following:
162
163=over 4
164
165=item SSL_TLSEXT_ERR_OK
166
167ALPN protocol selected.
168
8313a787
BK
169=item SSL_TLSEXT_ERR_ALERT_FATAL
170
171There was no overlap between the client's supplied list and the server
172configuration.
173
817cd0d5
TS
174=item SSL_TLSEXT_ERR_NOACK
175
8313a787
BK
176ALPN protocol not selected, e.g., because no ALPN protocols are configured for
177this connection.
817cd0d5
TS
178
179=back
180
87b81496
RS
181The callback set using SSL_CTX_set_next_proto_select_cb() should return
182B<SSL_TLSEXT_ERR_OK> if successful. Any other value is fatal to the connection.
183
184The callback set using SSL_CTX_set_next_protos_advertised_cb() should return
185B<SSL_TLSEXT_ERR_OK> if it wishes to advertise. Otherwise, no such extension
186will be included in the ServerHello.
187
817cd0d5
TS
188=head1 SEE ALSO
189
b97fdb57 190L<ssl(7)>, L<SSL_CTX_set_tlsext_servername_callback(3)>,
817cd0d5
TS
191L<SSL_CTX_set_tlsext_servername_arg(3)>
192
e2f92610
RS
193=head1 COPYRIGHT
194
da1c088f 195Copyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved.
e2f92610 196
4746f25a 197Licensed under the Apache License 2.0 (the "License"). You may not use
e2f92610
RS
198this file except in compliance with the License. You can obtain a copy
199in the file LICENSE in the source distribution or at
200L<https://www.openssl.org/source/license.html>.
201
202=cut