1 .\" $OpenBSD: SSL_CTX_set_alpn_select_cb.3,v 1.5 2017/08/28 17:36:58 jsing Exp $
2 .\" OpenSSL 87b81496 Apr 19 12:38:27 2017 -0400
3 .\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
5 .\" This file was written by Todd Short <tshort@akamai.com>.
6 .\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in
17 .\" the documentation and/or other materials provided with the
20 .\" 3. All advertising materials mentioning features or use of this
21 .\" software must display the following acknowledgment:
22 .\" "This product includes software developed by the OpenSSL Project
23 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 .\" endorse or promote products derived from this software without
27 .\" prior written permission. For written permission, please contact
28 .\" openssl-core@openssl.org.
30 .\" 5. Products derived from this software may not be called "OpenSSL"
31 .\" nor may "OpenSSL" appear in their names without prior written
32 .\" permission of the OpenSSL Project.
34 .\" 6. Redistributions of any form whatsoever must retain the following
36 .\" "This product includes software developed by the OpenSSL Project
37 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
52 .Dd $Mdocdate: August 28 2017 $
53 .Dt SSL_CTX_SET_ALPN_SELECT_CB 3
56 .Nm SSL_CTX_set_alpn_protos ,
57 .Nm SSL_set_alpn_protos ,
58 .Nm SSL_CTX_set_alpn_select_cb ,
59 .Nm SSL_select_next_proto ,
60 .Nm SSL_get0_alpn_selected
61 .Nd handle application layer protocol negotiation (ALPN)
65 .Fo SSL_CTX_set_alpn_protos
67 .Fa "const unsigned char *protos"
68 .Fa "unsigned int protos_len"
71 .Fo SSL_set_alpn_protos
73 .Fa "const unsigned char *protos"
74 .Fa "unsigned int protos_len"
77 .Fo SSL_CTX_set_alpn_select_cb
79 .Fa "int (*cb)(SSL *ssl, const unsigned char **out,\
80 unsigned char *outlen, const unsigned char *in,\
81 unsigned int inlen, void *arg)"
85 .Fo SSL_select_next_proto
86 .Fa "unsigned char **out"
87 .Fa "unsigned char *outlen"
88 .Fa "const unsigned char *server"
89 .Fa "unsigned int server_len"
90 .Fa "const unsigned char *client"
91 .Fa "unsigned int client_len"
94 .Fo SSL_get0_alpn_selected
96 .Fa "const unsigned char **data"
97 .Fa "unsigned int *len"
100 .Fn SSL_CTX_set_alpn_protos
102 .Fn SSL_set_alpn_protos
103 are used by the client to set the list of protocols available to be
107 must be in protocol-list format, described below.
113 .Fn SSL_CTX_set_alpn_select_cb
114 sets the application callback
116 used by a server to select which protocol to use for the incoming
125 value is a pointer which is passed to the application callback.
128 is the application defined callback.
132 parameters are a vector in protocol-list format.
136 vector should be set to the value of a single protocol selected from the
142 buffer may point directly into
144 or to a buffer that outlives the handshake.
147 parameter is the pointer set via
148 .Fn SSL_CTX_set_alpn_select_cb .
150 .Fn SSL_select_next_proto
151 is a helper function used to select protocols.
152 It implements the standard protocol selection.
153 It is expected that this function is called from the application
162 must be in the protocol-list format described below.
163 The first item in the
166 list that matches an item in the
169 list is selected, and returned in
174 value will point into either
178 so it should be copied immediately.
179 If no match is found, the first item in
186 .Fn SSL_get0_alpn_selected
187 returns a pointer to the selected protocol in
191 It is not NUL-terminated.
197 is set to 0 if no protocol has been selected.
201 The protocol-lists must be in wire-format, which is defined as a vector
202 of non-empty, 8-bit length-prefixed byte strings.
203 The length-prefix byte is not included in the length.
204 Each string is limited to 255 bytes.
205 A byte-string length of 0 is invalid.
206 A truncated byte-string is invalid.
207 The length of the vector is not in the vector itself, but in a separate
212 unsigned char vector[] = {
213 6, 's', 'p', 'd', 'y', '/', '1',
214 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
216 unsigned int length = sizeof(vector);
219 The ALPN callback is executed after the servername callback; as that
220 servername callback may update the SSL_CTX, and subsequently, the ALPN
223 If there is no ALPN proposed in the ClientHello, the ALPN callback is
226 .Fn SSL_CTX_set_alpn_protos
228 .Fn SSL_set_alpn_protos
229 return 0 on success or non-zero on failure.
230 WARNING: these functions reverse the return value convention.
232 .Fn SSL_select_next_proto
233 returns one of the following:
235 .It OPENSSL_NPN_NEGOTIATED
236 A match was found and is returned in
239 .It OPENSSL_NPN_NO_OVERLAP
249 The ALPN select callback
251 must return one of the following:
253 .It SSL_TLSEXT_ERR_OK
254 ALPN protocol selected.
255 .It SSL_TLSEXT_ERR_NOACK
256 ALPN protocol not selected.
260 .Xr SSL_CTX_set_tlsext_servername_arg 3 ,
261 .Xr SSL_CTX_set_tlsext_servername_callback 3