Blame doc/man3/SSL_CTX_set_alpn_select_cb.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
SSL_CTX_set_alpn_protos, SSL_set_alpn_protos, SSL_CTX_set_alpn_select_cb,
Packit c4476c
SSL_CTX_set_next_proto_select_cb, SSL_CTX_set_next_protos_advertised_cb,
Packit c4476c
SSL_select_next_proto, SSL_get0_alpn_selected, SSL_get0_next_proto_negotiated
Packit c4476c
- handle application layer protocol negotiation (ALPN)
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/ssl.h>
Packit c4476c
Packit c4476c
 int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
Packit c4476c
                             unsigned int protos_len);
Packit c4476c
 int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
Packit c4476c
                         unsigned int protos_len);
Packit c4476c
 void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
Packit c4476c
                                 int (*cb) (SSL *ssl,
Packit c4476c
                                            const unsigned char **out,
Packit c4476c
                                            unsigned char *outlen,
Packit c4476c
                                            const unsigned char *in,
Packit c4476c
                                            unsigned int inlen,
Packit c4476c
                                            void *arg), void *arg);
Packit c4476c
 void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
Packit c4476c
                             unsigned int *len);
Packit c4476c
Packit c4476c
 void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *ctx,
Packit c4476c
                                            int (*cb)(SSL *ssl,
Packit c4476c
                                                      const unsigned char **out,
Packit c4476c
                                                      unsigned int *outlen,
Packit c4476c
                                                      void *arg),
Packit c4476c
                                            void *arg);
Packit c4476c
 void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx,
Packit c4476c
                               int (*cb)(SSL *s,
Packit c4476c
                                         unsigned char **out,
Packit c4476c
                                         unsigned char *outlen,
Packit c4476c
                                         const unsigned char *in,
Packit c4476c
                                         unsigned int inlen,
Packit c4476c
                                         void *arg),
Packit c4476c
                               void *arg);
Packit c4476c
 int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
Packit c4476c
                           const unsigned char *server,
Packit c4476c
                           unsigned int server_len,
Packit c4476c
                           const unsigned char *client,
Packit c4476c
                           unsigned int client_len)
Packit c4476c
 void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
Packit c4476c
                             unsigned *len);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() are used by the client to
Packit c4476c
set the list of protocols available to be negotiated. The B<protos> must be in
Packit c4476c
protocol-list format, described below. The length of B<protos> is specified in
Packit c4476c
B<protos_len>.
Packit c4476c
Packit c4476c
SSL_CTX_set_alpn_select_cb() sets the application callback B<cb> used by a
Packit c4476c
server to select which protocol to use for the incoming connection. When B<cb>
Packit c4476c
is NULL, ALPN is not used. The B<arg> value is a pointer which is passed to
Packit c4476c
the application callback.
Packit c4476c
Packit c4476c
B<cb> is the application defined callback. The B<in>, B<inlen> parameters are a
Packit c4476c
vector in protocol-list format. The value of the B<out>, B<outlen> vector
Packit c4476c
should be set to the value of a single protocol selected from the B<in>,
Packit c4476c
B<inlen> vector. The B<out> buffer may point directly into B<in>, or to a
Packit c4476c
buffer that outlives the handshake. The B<arg> parameter is the pointer set via
Packit c4476c
SSL_CTX_set_alpn_select_cb().
Packit c4476c
Packit c4476c
SSL_select_next_proto() is a helper function used to select protocols. It
Packit c4476c
implements the standard protocol selection. It is expected that this function
Packit c4476c
is called from the application callback B<cb>. The protocol data in B<server>,
Packit c4476c
B<server_len> and B<client>, B<client_len> must be in the protocol-list format
Packit c4476c
described below. The first item in the B<server>, B<server_len> list that
Packit c4476c
matches an item in the B<client>, B<client_len> list is selected, and returned
Packit c4476c
in B<out>, B<outlen>. The B<out> value will point into either B<server> or
Packit c4476c
B<client>, so it should be copied immediately. If no match is found, the first
Packit c4476c
item in B<client>, B<client_len> is returned in B<out>, B<outlen>. This
Packit c4476c
function can also be used in the NPN callback.
Packit c4476c
Packit c4476c
SSL_CTX_set_next_proto_select_cb() sets a callback B<cb> that is called when a
Packit c4476c
client needs to select a protocol from the server's provided list, and a
Packit c4476c
user-defined pointer argument B<arg> which will be passed to this callback.
Packit c4476c
For the callback itself, B<out>
Packit c4476c
must be set to point to the selected protocol (which may be within B<in>).
Packit c4476c
The length of the protocol name must be written into B<outlen>. The
Packit c4476c
server's advertised protocols are provided in B<in> and B<inlen>. The
Packit c4476c
callback can assume that B<in> is syntactically valid. The client must
Packit c4476c
select a protocol. It is fatal to the connection if this callback returns
Packit c4476c
a value other than B<SSL_TLSEXT_ERR_OK>. The B<arg> parameter is the pointer
Packit c4476c
set via SSL_CTX_set_next_proto_select_cb().
Packit c4476c
Packit c4476c
SSL_CTX_set_next_protos_advertised_cb() sets a callback B<cb> that is called
Packit c4476c
when a TLS server needs a list of supported protocols for Next Protocol
Packit c4476c
Negotiation. The returned list must be in protocol-list format, described
Packit c4476c
below.  The list is
Packit c4476c
returned by setting B<out> to point to it and B<outlen> to its length. This
Packit c4476c
memory will not be modified, but the B<SSL> does keep a
Packit c4476c
reference to it. The callback should return B<SSL_TLSEXT_ERR_OK> if it
Packit c4476c
wishes to advertise. Otherwise, no such extension will be included in the
Packit c4476c
ServerHello.
Packit c4476c
Packit c4476c
SSL_get0_alpn_selected() returns a pointer to the selected protocol in B<data>
Packit c4476c
with length B<len>. It is not NUL-terminated. B<data> is set to NULL and B<len>
Packit c4476c
is set to 0 if no protocol has been selected. B<data> must not be freed.
Packit c4476c
Packit c4476c
SSL_get0_next_proto_negotiated() sets B<data> and B<len> to point to the
Packit c4476c
client's requested protocol for this connection. If the client did not
Packit c4476c
request any protocol or NPN is not enabled, then B<data> is set to NULL and
Packit c4476c
B<len> to 0. Note that
Packit c4476c
the client can request any protocol it chooses. The value returned from
Packit c4476c
this function need not be a member of the list of supported protocols
Packit c4476c
provided by the callback.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
The protocol-lists must be in wire-format, which is defined as a vector of
Packit c4476c
non-empty, 8-bit length-prefixed, byte strings. The length-prefix byte is not
Packit c4476c
included in the length. Each string is limited to 255 bytes. A byte-string
Packit c4476c
length of 0 is invalid. A truncated byte-string is invalid. The length of the
Packit c4476c
vector is not in the vector itself, but in a separate variable.
Packit c4476c
Packit c4476c
Example:
Packit c4476c
Packit c4476c
 unsigned char vector[] = {
Packit c4476c
     6, 's', 'p', 'd', 'y', '/', '1',
Packit c4476c
     8, 'h', 't', 't', 'p', '/', '1', '.', '1'
Packit c4476c
 };
Packit c4476c
 unsigned int length = sizeof(vector);
Packit c4476c
Packit c4476c
The ALPN callback is executed after the servername callback; as that servername
Packit c4476c
callback may update the SSL_CTX, and subsequently, the ALPN callback.
Packit c4476c
Packit c4476c
If there is no ALPN proposed in the ClientHello, the ALPN callback is not
Packit c4476c
invoked.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() return 0 on success, and
Packit c4476c
non-0 on failure. WARNING: these functions reverse the return value convention.
Packit c4476c
Packit c4476c
SSL_select_next_proto() returns one of the following:
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item OPENSSL_NPN_NEGOTIATED
Packit c4476c
Packit c4476c
A match was found and is returned in B<out>, B<outlen>.
Packit c4476c
Packit c4476c
=item OPENSSL_NPN_NO_OVERLAP
Packit c4476c
Packit c4476c
No match was found. The first item in B<client>, B<client_len> is returned in
Packit c4476c
B<out>, B<outlen>.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
The ALPN select callback B<cb>, must return one of the following:
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item SSL_TLSEXT_ERR_OK
Packit c4476c
Packit c4476c
ALPN protocol selected.
Packit c4476c
Packit c4476c
=item SSL_TLSEXT_ERR_ALERT_FATAL
Packit c4476c
Packit c4476c
There was no overlap between the client's supplied list and the server
Packit c4476c
configuration.
Packit c4476c
Packit c4476c
=item SSL_TLSEXT_ERR_NOACK
Packit c4476c
Packit c4476c
ALPN protocol not selected, e.g., because no ALPN protocols are configured for
Packit c4476c
this connection.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
The callback set using SSL_CTX_set_next_proto_select_cb() should return
Packit c4476c
B<SSL_TLSEXT_ERR_OK> if successful. Any other value is fatal to the connection.
Packit c4476c
Packit c4476c
The callback set using SSL_CTX_set_next_protos_advertised_cb() should return
Packit c4476c
B<SSL_TLSEXT_ERR_OK> if it wishes to advertise. Otherwise, no such extension
Packit c4476c
will be included in the ServerHello.
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<ssl(7)>, L<SSL_CTX_set_tlsext_servername_callback(3)>,
Packit c4476c
L<SSL_CTX_set_tlsext_servername_arg(3)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut