SSL_CTX_set_alpn_select_cb.pod 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set_alpn_protos, SSL_set_alpn_protos, SSL_CTX_set_alpn_select_cb,
  4. SSL_select_next_proto, SSL_get0_alpn_selected - handle application layer
  5. protocol negotiation (ALPN)
  6. =head1 SYNOPSIS
  7. #include <openssl/ssl.h>
  8. int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
  9. unsigned protos_len);
  10. int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
  11. unsigned protos_len);
  12. void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
  13. int (*cb) (SSL *ssl,
  14. const unsigned char **out,
  15. unsigned char *outlen,
  16. const unsigned char *in,
  17. unsigned int inlen,
  18. void *arg), void *arg);
  19. int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
  20. const unsigned char *server,
  21. unsigned int server_len,
  22. const unsigned char *client,
  23. unsigned int client_len)
  24. void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
  25. unsigned int *len);
  26. =head1 DESCRIPTION
  27. SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() are used by the client to
  28. set the list of protocols available to be negotiated. The B<protos> must be in
  29. protocol-list format, described below. The length of B<protos> is specified in
  30. B<protos_len>.
  31. SSL_CTX_set_alpn_select_cb() sets the application callback B<cb> used by a
  32. server to select which protocol to use for the incoming connection. When B<cb>
  33. is NULL, ALPN is not used. The B<arg> value is a pointer which is passed to
  34. the application callback.
  35. B<cb> is the application defined callback. The B<in>, B<inlen> parameters are a
  36. vector in protocol-list format. The value of the B<out>, B<outlen> vector
  37. should be set to the value of a single protocol selected from the B<in>,
  38. B<inlen> vector. The B<arg> parameter is the pointer set via
  39. SSL_CTX_set_alpn_select_cb().
  40. SSL_select_next_proto() is a helper function used to select protocols. It
  41. implements the standard protocol selection. It is expected that this function
  42. is called from the application callback B<cb>. The protocol data in B<server>,
  43. B<server_len> and B<client>, B<client_len> must be in the protocol-list format
  44. described below. The first item in the B<server>, B<server_len> list that
  45. matches an item in the B<client>, B<client_len> list is selected, and returned
  46. in B<out>, B<outlen>. The B<out> value will point into either B<server> or
  47. B<client>, so it should be copied immediately. If no match is found, the first
  48. item in B<client>, B<client_len> is returned in B<out>, B<outlen>. This
  49. function can also be used in the NPN callback.
  50. SSL_get0_alpn_selected() returns a pointer to the selected protocol in B<data>
  51. with length B<len>. It is not NUL-terminated. B<data> is set to NULL and B<len>
  52. is set to 0 if no protocol has been selected. B<data> must not be freed.
  53. =head1 NOTES
  54. The protocol-lists must be in wire-format, which is defined as a vector of
  55. non-empty, 8-bit length-prefixed, byte strings. The length-prefix byte is not
  56. included in the length. Each string is limited to 255 bytes. A byte-string
  57. length of 0 is invalid. A truncated byte-string is invalid. The length of the
  58. vector is not in the vector itself, but in a separate variable.
  59. Example:
  60. unsigned char vector[] = {
  61. 6, 's', 'p', 'd', 'y', '/', '1',
  62. 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
  63. };
  64. unsigned int length = sizeof(vector);
  65. The ALPN callback is executed after the servername callback; as that servername
  66. callback may update the SSL_CTX, and subsequently, the ALPN callback.
  67. If there is no ALPN proposed in the ClientHello, the ALPN callback is not
  68. invoked.
  69. =head1 RETURN VALUES
  70. SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() return 0 on success, and
  71. non-0 on failure. WARNING: these functions reverse the return value convention.
  72. SSL_select_next_proto() returns one of the following:
  73. =over 4
  74. =item OPENSSL_NPN_NEGOTIATED
  75. A match was found and is returned in B<out>, B<outlen>.
  76. =item OPENSSL_NPN_NO_OVERLAP
  77. No match was found. The first item in B<client>, B<client_len> is returned in
  78. B<out>, B<outlen>.
  79. =back
  80. The ALPN select callback B<cb>, must return one of the following:
  81. =over 4
  82. =item SSL_TLSEXT_ERR_OK
  83. ALPN protocol selected.
  84. =item SSL_TLSEXT_ERR_NOACK
  85. ALPN protocol not selected.
  86. =back
  87. =head1 SEE ALSO
  88. L<ssl(3)>, L<SSL_CTX_set_tlsext_servername_callback(3)>,
  89. L<SSL_CTX_set_tlsext_servername_arg(3)>
  90. =cut