xref: /freebsd/secure/lib/libcrypto/man/man3/SSL_CTX_set_alpn_select_cb.3 (revision 174c0ac687ec4ccb0b56ee30d48c0a7b8b9c4e15)
Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)

Standard preamble:
========================================================================
..
..
.. Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.

If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.

Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================

Title "SSL_CTX_SET_ALPN_SELECT_CB 3ossl"
SSL_CTX_SET_ALPN_SELECT_CB 3ossl "2023-09-19" "3.0.11" "OpenSSL"
For nroff, turn off justification. Always turn off hyphenation; it makes
way too many mistakes in technical documents.
"NAME"
SSL_CTX_set_alpn_protos, SSL_set_alpn_protos, SSL_CTX_set_alpn_select_cb, SSL_CTX_set_next_proto_select_cb, SSL_CTX_set_next_protos_advertised_cb, SSL_select_next_proto, SSL_get0_alpn_selected, SSL_get0_next_proto_negotiated \- handle application layer protocol negotiation (ALPN)
"SYNOPSIS"
Header "SYNOPSIS" .Vb 1 #include <openssl/ssl.h> \& int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, unsigned int protos_len); int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, unsigned int protos_len); void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, int (*cb) (SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg), void *arg); void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data, unsigned int *len); \& void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *ctx, int (*cb)(SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg), void *arg); void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb)(SSL *s, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg), void *arg); int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, const unsigned char *server, unsigned int server_len, const unsigned char *client, unsigned int client_len); void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, unsigned *len); .Ve
"DESCRIPTION"
Header "DESCRIPTION" \fBSSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() are used by the client to set the list of protocols available to be negotiated. The protos must be in protocol-list format, described below. The length of protos is specified in \fBprotos_len.

\fBSSL_CTX_set_alpn_select_cb() sets the application callback cb used by a server to select which protocol to use for the incoming connection. When cb is \s-1NULL, ALPN\s0 is not used. The arg value is a pointer which is passed to the application callback.

\fBcb is the application defined callback. The in, inlen parameters are a vector in protocol-list format. The value of the out, outlen vector should be set to the value of a single protocol selected from the in, \fBinlen vector. The out buffer may point directly into in, or to a buffer that outlives the handshake. The arg parameter is the pointer set via \fBSSL_CTX_set_alpn_select_cb().

\fBSSL_select_next_proto() is a helper function used to select protocols. It implements the standard protocol selection. It is expected that this function is called from the application callback cb. The protocol data in server, \fBserver_len and client, client_len must be in the protocol-list format described below. The first item in the server, server_len list that matches an item in the client, client_len list is selected, and returned in out, outlen. The out value will point into either server or \fBclient, so it should be copied immediately. If no match is found, the first item in client, client_len is returned in out, outlen. This function can also be used in the \s-1NPN\s0 callback.

\fBSSL_CTX_set_next_proto_select_cb() sets a callback cb that is called when a client needs to select a protocol from the server's provided list, and a user-defined pointer argument arg which will be passed to this callback. For the callback itself, out must be set to point to the selected protocol (which may be within in). The length of the protocol name must be written into outlen. The server's advertised protocols are provided in in and inlen. The callback can assume that in is syntactically valid. The client must select a protocol. It is fatal to the connection if this callback returns a value other than \s-1SSL_TLSEXT_ERR_OK\s0. The arg parameter is the pointer set via SSL_CTX_set_next_proto_select_cb().

\fBSSL_CTX_set_next_protos_advertised_cb() sets a callback cb that is called when a \s-1TLS\s0 server needs a list of supported protocols for Next Protocol Negotiation. The returned list must be in protocol-list format, described below. The list is returned by setting out to point to it and outlen to its length. This memory will not be modified, but the \s-1SSL\s0 does keep a reference to it. The callback should return \s-1SSL_TLSEXT_ERR_OK\s0 if it wishes to advertise. Otherwise, no such extension will be included in the ServerHello.

\fBSSL_get0_alpn_selected() returns a pointer to the selected protocol in data with length len. It is not NUL-terminated. data is set to \s-1NULL\s0 and len is set to 0 if no protocol has been selected. data must not be freed.

\fBSSL_get0_next_proto_negotiated() sets data and len to point to the client's requested protocol for this connection. If the client did not request any protocol or \s-1NPN\s0 is not enabled, then data is set to \s-1NULL\s0 and \fBlen to 0. Note that the client can request any protocol it chooses. The value returned from this function need not be a member of the list of supported protocols provided by the callback.

"NOTES"
Header "NOTES" The protocol-lists must be in wire-format, which is defined as a vector of nonempty, 8-bit length-prefixed, byte strings. The length-prefix byte is not included in the length. Each string is limited to 255 bytes. A byte-string length of 0 is invalid. A truncated byte-string is invalid. The length of the vector is not in the vector itself, but in a separate variable.

Example:

.Vb 5 unsigned char vector[] = { 6, \*(Aqs\*(Aq, \*(Aqp\*(Aq, \*(Aqd\*(Aq, \*(Aqy\*(Aq, \*(Aq/\*(Aq, \*(Aq1\*(Aq, 8, \*(Aqh\*(Aq, \*(Aqt\*(Aq, \*(Aqt\*(Aq, \*(Aqp\*(Aq, \*(Aq/\*(Aq, \*(Aq1\*(Aq, \*(Aq.\*(Aq, \*(Aq1\*(Aq }; unsigned int length = sizeof(vector); .Ve

The \s-1ALPN\s0 callback is executed after the servername callback; as that servername callback may update the \s-1SSL_CTX,\s0 and subsequently, the \s-1ALPN\s0 callback.

If there is no \s-1ALPN\s0 proposed in the ClientHello, the \s-1ALPN\s0 callback is not invoked.

"RETURN VALUES"
Header "RETURN VALUES" \fBSSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() return 0 on success, and non-0 on failure. \s-1WARNING:\s0 these functions reverse the return value convention.

\fBSSL_select_next_proto() returns one of the following:

"\s-1OPENSSL_NPN_NEGOTIATED\s0" 4
Item "OPENSSL_NPN_NEGOTIATED" A match was found and is returned in out, outlen.
"\s-1OPENSSL_NPN_NO_OVERLAP\s0" 4
Item "OPENSSL_NPN_NO_OVERLAP" No match was found. The first item in client, client_len is returned in \fBout, outlen.

The \s-1ALPN\s0 select callback cb, must return one of the following:

"\s-1SSL_TLSEXT_ERR_OK\s0" 4
Item "SSL_TLSEXT_ERR_OK" \s-1ALPN\s0 protocol selected.
"\s-1SSL_TLSEXT_ERR_ALERT_FATAL\s0" 4
Item "SSL_TLSEXT_ERR_ALERT_FATAL" There was no overlap between the client's supplied list and the server configuration.
"\s-1SSL_TLSEXT_ERR_NOACK\s0" 4
Item "SSL_TLSEXT_ERR_NOACK" \s-1ALPN\s0 protocol not selected, e.g., because no \s-1ALPN\s0 protocols are configured for this connection.

The callback set using SSL_CTX_set_next_proto_select_cb() should return \fB\s-1SSL_TLSEXT_ERR_OK\s0 if successful. Any other value is fatal to the connection.

The callback set using SSL_CTX_set_next_protos_advertised_cb() should return \fB\s-1SSL_TLSEXT_ERR_OK\s0 if it wishes to advertise. Otherwise, no such extension will be included in the ServerHello.

"SEE ALSO"
Header "SEE ALSO" \fBssl\|(7), SSL_CTX_set_tlsext_servername_callback\|(3), \fBSSL_CTX_set_tlsext_servername_arg\|(3)
"COPYRIGHT"
Header "COPYRIGHT" Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.