openssl-quic.7ossl 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "OPENSSL-QUIC 7ossl"
  58. .TH OPENSSL-QUIC 7ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. openssl\-quic \- OpenSSL QUIC
  65. .SH DESCRIPTION
  66. .IX Header "DESCRIPTION"
  67. OpenSSL 3.2 and later features support for the QUIC transport protocol.
  68. Currently, only client connectivity is supported. This man page describes the
  69. usage of QUIC client functionality for both existing and new applications.
  70. .PP
  71. QUIC functionality uses the standard SSL API. A QUIC connection is represented
  72. by an SSL object in the same way that a TLS connection is. Only minimal changes
  73. are needed to existing applications making use of the libssl APIs to make use of
  74. QUIC client functionality. To make use of QUIC, use the SSL method
  75. \&\fBOSSL_QUIC_client_method\fR\|(3) or \fBOSSL_QUIC_client_thread_method\fR\|(3) with
  76. \&\fBSSL_CTX_new\fR\|(3).
  77. .PP
  78. When a QUIC connection is created, by default, it operates in default stream
  79. mode, which is intended to provide compatibility with existing non-QUIC
  80. application usage patterns. In this mode, the connection has a single
  81. stream associated with it. Calls to \fBSSL_read\fR\|(3) and
  82. \&\fBSSL_write\fR\|(3) on the QUIC connection SSL object read and write from that
  83. stream. Whether the stream is client-initiated or server-initiated from a QUIC
  84. perspective depends on whether \fBSSL_read\fR\|(3) or \fBSSL_write\fR\|(3) is called
  85. first. See the MODES OF OPERATION section for more information.
  86. .PP
  87. The default stream mode is intended for compatibility with existing
  88. applications. New applications using QUIC are recommended to disable default
  89. stream mode and use the multi-stream API; see the MODES OF OPERATION section and
  90. the RECOMMENDATIONS FOR NEW APPLICATIONS section for more information.
  91. .PP
  92. The remainder of this man page discusses, in order:
  93. .IP \(bu 4
  94. Default stream mode versus multi-stream mode;
  95. .IP \(bu 4
  96. The changes to existing libssl APIs which are driven by QUIC-related implementation
  97. requirements, which existing applications should bear in mind;
  98. .IP \(bu 4
  99. Aspects which must be considered by existing applications when adopting QUIC,
  100. including potential changes which may be needed.
  101. .IP \(bu 4
  102. Recommended usage approaches for new applications.
  103. .IP \(bu 4
  104. New, QUIC-specific APIs.
  105. .SH "MODES OF OPERATION"
  106. .IX Header "MODES OF OPERATION"
  107. .SS "Default Stream Mode"
  108. .IX Subsection "Default Stream Mode"
  109. A QUIC client connection can be used in either default stream mode or
  110. multi-stream mode. By default, a newly created QUIC connection SSL object uses
  111. default stream mode.
  112. .PP
  113. In default stream mode, a stream is implicitly created and bound to the QUIC
  114. connection SSL object; \fBSSL_read\fR\|(3) and \fBSSL_write\fR\|(3) calls to the QUIC
  115. connection SSL object work by default and are mapped to that stream.
  116. .PP
  117. When default stream mode is used, any API function which can be called on a QUIC
  118. stream SSL object can also be called on a QUIC connection SSL object, in which
  119. case it affects the default stream bound to the connection.
  120. .PP
  121. The identity of a QUIC stream, including its stream ID, varies depending on
  122. whether a stream is client-initiated or server-initiated. In default stream
  123. mode, if a client application calls \fBSSL_read\fR\|(3) first before any call to
  124. \&\fBSSL_write\fR\|(3) on the connection, it is assumed that the application protocol
  125. is using a server-initiated stream, and the \fBSSL_read\fR\|(3) call will not
  126. complete (either blocking, or failing appropriately if nonblocking mode is
  127. configured) until the server initiates a stream. Conversely, if the client
  128. application calls \fBSSL_write\fR\|(3) before any call to \fBSSL_read\fR\|(3) on the
  129. connection, it is assumed that a client-initiated stream is to be used
  130. and such a stream is created automatically.
  131. .PP
  132. Default stream mode is intended to aid compatibility with legacy applications.
  133. New applications adopting QUIC should use multi-stream mode, described below,
  134. and avoid use of the default stream functionality.
  135. .PP
  136. It is possible to use additional streams in default stream mode using
  137. \&\fBSSL_new_stream\fR\|(3) and \fBSSL_accept_stream\fR\|(3); note that the default incoming
  138. stream policy will need to be changed using \fBSSL_set_incoming_stream_policy\fR\|(3)
  139. in order to use \fBSSL_accept_stream\fR\|(3) in this case. However, applications
  140. using additional streams are strongly recommended to use multi-stream mode
  141. instead.
  142. .PP
  143. Calling \fBSSL_new_stream\fR\|(3) or \fBSSL_accept_stream\fR\|(3) before a default stream
  144. has been associated with the QUIC connection SSL object will inhibit future
  145. creation of a default stream.
  146. .SS "Multi-Stream Mode"
  147. .IX Subsection "Multi-Stream Mode"
  148. The recommended usage mode for new applications adopting QUIC is multi-stream
  149. mode, in which no default stream is attached to the QUIC connection SSL object
  150. and attempts to call \fBSSL_read\fR\|(3) and \fBSSL_write\fR\|(3) on the QUIC connection
  151. SSL object fail. Instead, an application calls \fBSSL_new_stream\fR\|(3) or
  152. \&\fBSSL_accept_stream\fR\|(3) to create individual stream SSL objects for sending and
  153. receiving application data using \fBSSL_read\fR\|(3) and \fBSSL_write\fR\|(3).
  154. .PP
  155. To use multi-stream mode, call \fBSSL_set_default_stream_mode\fR\|(3) with an
  156. argument of \fBSSL_DEFAULT_STREAM_MODE_NONE\fR; this function must be called prior
  157. to initiating the connection. The default stream mode cannot be changed after
  158. initiating a connection.
  159. .PP
  160. When multi-stream mode is used, meaning that no default stream is associated
  161. with the connection, calls to API functions which are defined as operating on a
  162. QUIC stream fail if called on the QUIC connection SSL object. For example, calls
  163. such as \fBSSL_write\fR\|(3) or \fBSSL_get_stream_id\fR\|(3) will fail.
  164. .SH "CHANGES TO EXISTING APIS"
  165. .IX Header "CHANGES TO EXISTING APIS"
  166. Most SSL APIs, such as \fBSSL_read\fR\|(3) and \fBSSL_write\fR\|(3), function as they do
  167. for TLS connections and do not have changed semantics, with some exceptions. The
  168. changes to the semantics of existing APIs are as follows:
  169. .IP \(bu 4
  170. Since QUIC uses UDP, \fBSSL_set_bio\fR\|(3), \fBSSL_set0_rbio\fR\|(3) and
  171. \&\fBSSL_set0_wbio\fR\|(3) function as before, but must now receive a BIO with datagram
  172. semantics. There are broadly four options for applications to use as a network
  173. BIO:
  174. .RS 4
  175. .IP \(bu 4
  176. \&\fBBIO_s_datagram\fR\|(3), recommended for most applications, replaces
  177. \&\fBBIO_s_socket\fR\|(3) and provides a UDP socket.
  178. .IP \(bu 4
  179. \&\fBBIO_s_dgram_pair\fR\|(3) provides BIO pair-like functionality but with datagram
  180. semantics, and is recommended for existing applications which use a BIO pair or
  181. memory BIO to manage libssl's communication with the network.
  182. .IP \(bu 4
  183. \&\fBBIO_s_dgram_mem\fR\|(3) provides a simple memory BIO-like interface but with
  184. datagram semantics. Unlike \fBBIO_s_dgram_pair\fR\|(3), it is unidirectional.
  185. .IP \(bu 4
  186. An application may also choose to implement a custom BIO. The new
  187. \&\fBBIO_sendmmsg\fR\|(3) and \fBBIO_recvmmsg\fR\|(3) APIs must be supported.
  188. .RE
  189. .RS 4
  190. .RE
  191. .IP \(bu 4
  192. \&\fBSSL_set_fd\fR\|(3), \fBSSL_set_rfd\fR\|(3) and \fBSSL_set_wfd\fR\|(3) traditionally
  193. instantiate a \fBBIO_s_socket\fR\|(3). For QUIC, these functions instead instantiate
  194. a \fBBIO_s_datagram\fR\|(3). This is equivalent to instantiating a
  195. \&\fBBIO_s_datagram\fR\|(3) and using \fBSSL_set0_rbio\fR\|(3) and \fBSSL_set0_wbio\fR\|(3).
  196. .IP \(bu 4
  197. Traditionally, whether the application-level I/O APIs (such as \fBSSL_read\fR\|(3)
  198. and \fBSSL_write\fR\|(3) operated in a blocking fashion was directly correlated with
  199. whether the underlying network socket was configured in a blocking fashion. This
  200. is no longer the case; applications must explicitly configure the desired
  201. application-level blocking mode using \fBSSL_set_blocking_mode\fR\|(3). See
  202. \&\fBSSL_set_blocking_mode\fR\|(3) for details.
  203. .IP \(bu 4
  204. Network-level I/O must always be performed in a nonblocking manner. The
  205. application can still enjoy blocking semantics for calls to application-level
  206. I/O functions such as \fBSSL_read\fR\|(3) and \fBSSL_write\fR\|(3), but the underlying
  207. network BIO provided to QUIC (such as a \fBBIO_s_datagram\fR\|(3)) must be configured
  208. in nonblocking mode. For application-level blocking functionality, see
  209. \&\fBSSL_set_blocking_mode\fR\|(3).
  210. .IP \(bu 4
  211. \&\fBBIO_new_ssl_connect\fR\|(3) has been changed to automatically use a
  212. \&\fBBIO_s_datagram\fR\|(3) when used with QUIC, therefore applications which use this
  213. do not need to change the BIO they use.
  214. .IP \(bu 4
  215. \&\fBBIO_new_buffer_ssl_connect\fR\|(3) cannot be used with QUIC and applications must
  216. change to use \fBBIO_new_ssl_connect\fR\|(3) instead.
  217. .IP \(bu 4
  218. \&\fBSSL_shutdown\fR\|(3) has significant changes in relation to how QUIC connections
  219. must be shut down. In particular, applications should be advised that the full
  220. RFC-conformant QUIC shutdown process may take an extended amount of time. This
  221. may not be suitable for short-lived processes which should exit immediately
  222. after their usage of a QUIC connection is completed. A rapid shutdown mode
  223. is available for such applications. For details, see \fBSSL_shutdown\fR\|(3).
  224. .IP \(bu 4
  225. \&\fBSSL_want\fR\|(3), \fBSSL_want_read\fR\|(3) and \fBSSL_want_write\fR\|(3) no longer reflect
  226. the I/O state of the network BIO passed to the QUIC SSL object, but instead
  227. reflect the flow control state of the QUIC stream associated with the SSL
  228. object.
  229. .Sp
  230. When used in nonblocking mode, \fBSSL_ERROR_WANT_READ\fR indicates that the
  231. receive part of a QUIC stream does not currently have any more data available to
  232. be read, and \fBSSL_ERROR_WANT_WRITE\fR indicates that the stream's internal buffer
  233. is full.
  234. .Sp
  235. To determine if the QUIC implementation currently wishes to be informed of
  236. incoming network datagrams, use the new function \fBSSL_net_read_desired\fR\|(3);
  237. likewise, to determine if the QUIC implementation currently wishes to be
  238. informed when it is possible to transmit network datagrams, use the new function
  239. \&\fBSSL_net_write_desired\fR\|(3). Only applications which wish to manage their own event
  240. loops need to use these functions; see \fBAPPLICATION-DRIVEN EVENT LOOPS\fR for
  241. further discussion.
  242. .IP \(bu 4
  243. The use of ALPN is mandatory when using QUIC. Attempts to connect without
  244. configuring ALPN will fail. For information on how to configure ALPN, see
  245. \&\fBSSL_set_alpn_protos\fR\|(3).
  246. .IP \(bu 4
  247. Whether QUIC operates in a client or server mode is determined by the
  248. \&\fBSSL_METHOD\fR used, rather than by calls to \fBSSL_set_connect_state\fR\|(3) or
  249. \&\fBSSL_set_accept_state\fR\|(3). It is not necessary to call either of
  250. \&\fBSSL_set_connect_state\fR\|(3) or \fBSSL_set_accept_state\fR\|(3) before connecting, but
  251. if either of these are called, the function called must be congruent with the
  252. \&\fBSSL_METHOD\fR being used. Currently, only client mode is supported.
  253. .IP \(bu 4
  254. The \fBSSL_set_min_proto_version\fR\|(3) and \fBSSL_set_max_proto_version\fR\|(3) APIs are
  255. not used and the values passed to them are ignored, as OpenSSL QUIC currently
  256. always uses TLS 1.3.
  257. .IP \(bu 4
  258. The following libssl functionality is not available when used with QUIC.
  259. .RS 4
  260. .IP \(bu 4
  261. Async functionality
  262. .IP \(bu 4
  263. \&\fBSSL_MODE_AUTO_RETRY\fR
  264. .IP \(bu 4
  265. Record Padding and Fragmentation (\fBSSL_set_block_padding\fR\|(3), etc.)
  266. .IP \(bu 4
  267. \&\fBSSL_stateless\fR\|(3) support
  268. .IP \(bu 4
  269. SRTP functionality
  270. .IP \(bu 4
  271. TLSv1.3 Early Data
  272. .IP \(bu 4
  273. TLS Next Protocol Negotiation cannot be used and is superseded by ALPN, which
  274. must be used instead. The use of ALPN is mandatory with QUIC.
  275. .IP \(bu 4
  276. Post-Handshake Client Authentication is not available as QUIC prohibits its use.
  277. .IP \(bu 4
  278. QUIC requires the use of TLSv1.3 or later, therefore functionality only relevant
  279. to older TLS versions is not available.
  280. .IP \(bu 4
  281. Some cipher suites which are generally available for TLSv1.3 are not available
  282. for QUIC, such as \fBTLS_AES_128_CCM_8_SHA256\fR. Your application may need to
  283. adjust the list of acceptable cipher suites it passes to libssl.
  284. .IP \(bu 4
  285. CCM mode is not currently supported.
  286. .RE
  287. .RS 4
  288. .Sp
  289. The following libssl functionality is also not available when used with QUIC,
  290. but calls to the relevant functions are treated as no-ops:
  291. .IP \(bu 4
  292. Readahead (\fBSSL_set_read_ahead\fR\|(3), etc.)
  293. .RE
  294. .RS 4
  295. .RE
  296. .SH "CONSIDERATIONS FOR EXISTING APPLICATIONS"
  297. .IX Header "CONSIDERATIONS FOR EXISTING APPLICATIONS"
  298. Existing applications seeking to adopt QUIC should apply the following list to
  299. determine what changes they will need to make:
  300. .IP \(bu 4
  301. An application wishing to use QUIC must use \fBOSSL_QUIC_client_method\fR\|(3) or
  302. \&\fBOSSL_QUIC_client_thread_method\fR\|(3) as its SSL method. For more information
  303. on the differences between these two methods, see \fBTHREAD ASSISTED MODE\fR.
  304. .IP \(bu 4
  305. Determine how to provide QUIC with network access. Determine which of the below
  306. apply for your application:
  307. .RS 4
  308. .IP \(bu 4
  309. Your application uses \fBBIO_s_socket\fR\|(3) to construct a BIO which is passed to
  310. the SSL object to provide it with network access.
  311. .Sp
  312. Changes needed: Change your application to use \fBBIO_s_datagram\fR\|(3) instead when
  313. using QUIC. The socket must be configured in nonblocking mode. You may or may
  314. not need to use \fBSSL_set1_initial_peer_addr\fR\|(3) to set the initial peer
  315. address; see the \fBQUIC-SPECIFIC APIS\fR section for details.
  316. .IP \(bu 4
  317. Your application uses \fBBIO_new_ssl_connect\fR\|(3) to
  318. construct a BIO which is passed to the SSL object to provide it with network
  319. access.
  320. .Sp
  321. Changes needed: No changes needed. Use of QUIC is detected automatically and a
  322. datagram socket is created instead of a normal TCP socket.
  323. .IP \(bu 4
  324. Your application uses any other I/O strategy in this list but combines it with a
  325. \&\fBBIO_f_buffer\fR\|(3), for example using \fBBIO_push\fR\|(3).
  326. .Sp
  327. Changes needed: Disable the usage of \fBBIO_f_buffer\fR\|(3) when using QUIC. Usage
  328. of such a buffer is incompatible with QUIC as QUIC requires datagram semantics
  329. in its interaction with the network.
  330. .IP \(bu 4
  331. Your application uses a BIO pair to cause the SSL object to read and write
  332. network traffic to a memory buffer. Your application manages the transmission
  333. and reception of buffered data itself in a way unknown to libssl.
  334. .Sp
  335. Changes needed: Switch from using a conventional BIO pair to using
  336. \&\fBBIO_s_dgram_pair\fR\|(3) instead, which has the necessary datagram semantics. You
  337. will need to modify your application to transmit and receive using a UDP socket
  338. and to use datagram semantics when interacting with the \fBBIO_s_dgram_pair\fR\|(3)
  339. instance.
  340. .IP \(bu 4
  341. Your application uses a custom BIO method to provide the SSL object with network
  342. access.
  343. .Sp
  344. Changes needed: The custom BIO must be re-architected to have datagram
  345. semantics. \fBBIO_sendmmsg\fR\|(3) and \fBBIO_recvmmsg\fR\|(3) must be implemented. These
  346. calls must operate in a nonblocking fashion. Optionally, implement the
  347. \&\fBBIO_get_rpoll_descriptor\fR\|(3) and \fBBIO_get_wpoll_descriptor\fR\|(3) methods if
  348. desired. Implementing these methods is required if blocking semantics at the SSL
  349. API level are desired.
  350. .RE
  351. .RS 4
  352. .RE
  353. .IP \(bu 4
  354. An application must explicitly configure whether it wishes to use the SSL APIs
  355. in blocking mode or not. Traditionally, an SSL object has automatically operated
  356. in blocking or nonblocking mode based on whether the underlying network BIO
  357. operates in blocking or nonblocking mode. QUIC requires the use of a
  358. nonblocking network BIO, therefore the blocking mode at the application level
  359. must be explicitly configured by the application using the new
  360. \&\fBSSL_set_blocking_mode\fR\|(3) API. The default mode is blocking. If an application
  361. wishes to use the SSL object APIs at application level in a nonblocking manner,
  362. it must add a call to \fBSSL_set_blocking_mode\fR\|(3) to disable blocking mode.
  363. .IP \(bu 4
  364. If your application does not choose to use thread assisted mode, it must ensure
  365. that it calls an I/O function on the SSL object (for example, \fBSSL_read\fR\|(3) or
  366. \&\fBSSL_write\fR\|(3)), or the new function \fBSSL_handle_events\fR\|(3), regularly. If the
  367. SSL object is used in blocking mode, an ongoing blocking call to an I/O function
  368. satisfies this requirement. This is required to ensure that timer events
  369. required by QUIC are handled in a timely fashion.
  370. .Sp
  371. Most applications will service the SSL object by calling \fBSSL_read\fR\|(3) or
  372. \&\fBSSL_write\fR\|(3) regularly. If an application does not do this, it should ensure
  373. that \fBSSL_handle_events\fR\|(3) is called regularly.
  374. .Sp
  375. \&\fBSSL_get_event_timeout\fR\|(3) can be used to determine when
  376. \&\fBSSL_handle_events\fR\|(3) must next be called.
  377. .Sp
  378. If the SSL object is being used with an underlying network BIO which is pollable
  379. (such as \fBBIO_s_datagram\fR\|(3)), the application can use
  380. \&\fBSSL_get_rpoll_descriptor\fR\|(3), \fBSSL_get_wpoll_descriptor\fR\|(3) to obtain
  381. resources which can be used to determine when \fBSSL_handle_events\fR\|(3) should be
  382. called due to network I/O.
  383. .Sp
  384. Applications which use thread assisted mode do not need to be concerned
  385. with this requirement, as the QUIC implementation ensures timeout events
  386. are handled in a timely manner. See \fBTHREAD ASSISTED MODE\fR for details.
  387. .IP \(bu 4
  388. Ensure that your usage of \fBSSL_want\fR\|(3), \fBSSL_want_read\fR\|(3) and
  389. \&\fBSSL_want_write\fR\|(3) reflects the API changes described in \fBCHANGES TO EXISTING
  390. APIS\fR. In particular, you should use these APIs to determine the ability of a
  391. QUIC stream to receive or provide application data, not to to determine if
  392. network I/O is required.
  393. .IP \(bu 4
  394. Evaluate your application's use of \fBSSL_shutdown\fR\|(3) in light of the changes
  395. discussed in \fBCHANGES TO EXISTING APIS\fR. Depending on whether your application
  396. wishes to prioritise RFC conformance or rapid shutdown, consider using the new
  397. \&\fBSSL_shutdown_ex\fR\|(3) API instead. See \fBQUIC-SPECIFIC APIS\fR for details.
  398. .SH "RECOMMENDED USAGE IN NEW APPLICATIONS"
  399. .IX Header "RECOMMENDED USAGE IN NEW APPLICATIONS"
  400. The recommended usage in new applications varies depending on three independent
  401. design decisions:
  402. .IP \(bu 4
  403. Whether the application will use blocking or nonblocking I/O at the application
  404. level (configured using \fBSSL_set_blocking_mode\fR\|(3)).
  405. .Sp
  406. If the application does nonblocking I/O at the application level it can choose
  407. to manage its own polling and event loop; see \fBAPPLICATION-DRIVEN EVENT LOOPS\fR.
  408. .IP \(bu 4
  409. Whether the application intends to give the QUIC implementation direct access to
  410. a network socket (e.g. via \fBBIO_s_datagram\fR\|(3)) or whether it intends to buffer
  411. transmitted and received datagrams via a \fBBIO_s_dgram_pair\fR\|(3) or custom BIO.
  412. .Sp
  413. The former is preferred where possible as it reduces latency to the network,
  414. which enables QUIC to achieve higher performance and more accurate connection
  415. round trip time (RTT) estimation.
  416. .IP \(bu 4
  417. Whether thread assisted mode will be used (see \fBTHREAD ASSISTED MODE\fR).
  418. .PP
  419. Simple demos for QUIC usage under these various scenarios can be found at
  420. <https://github.com/openssl/openssl/tree/master/doc/designs/ddd>.
  421. .PP
  422. Applications which wish to implement QUIC-specific protocols should be aware of
  423. the APIs listed under \fBQUIC-SPECIFIC APIS\fR which provide access to
  424. QUIC-specific functionality. For example, \fBSSL_stream_conclude\fR\|(3) can be used
  425. to indicate the end of the sending part of a stream, and \fBSSL_shutdown_ex\fR\|(3)
  426. can be used to provide a QUIC application error code when closing a connection.
  427. .PP
  428. Regardless of the design decisions chosen above, it is recommended that new
  429. applications avoid use of the default stream mode and use the multi-stream API
  430. by calling \fBSSL_set_default_stream_mode\fR\|(3); see the MODES OF OPERATION section
  431. for details.
  432. .SH "QUIC-SPECIFIC APIS"
  433. .IX Header "QUIC-SPECIFIC APIS"
  434. This section details new APIs which are directly or indirectly related to QUIC.
  435. For details on the operation of each API, see the referenced man pages.
  436. .PP
  437. The following SSL APIs are new but relevant to both QUIC and DTLS:
  438. .IP \fBSSL_get_event_timeout\fR\|(3) 4
  439. .IX Item "SSL_get_event_timeout"
  440. Determines when the QUIC implementation should next be woken up via a call to
  441. \&\fBSSL_handle_events\fR\|(3) (or another I/O function such as \fBSSL_read\fR\|(3) or
  442. \&\fBSSL_write\fR\|(3)), if ever.
  443. .Sp
  444. This can also be used with DTLS and supersedes \fBDTLSv1_get_timeout\fR\|(3) for new
  445. usage.
  446. .IP \fBSSL_handle_events\fR\|(3) 4
  447. .IX Item "SSL_handle_events"
  448. This is a non-specific I/O operation which makes a best effort attempt to
  449. perform any pending I/O or timeout processing. It can be used to advance the
  450. QUIC state machine by processing incoming network traffic, generating outgoing
  451. network traffic and handling any expired timeout events. Most other I/O
  452. functions on an SSL object, such as \fBSSL_read\fR\|(3) and \fBSSL_write\fR\|(3)
  453. implicitly perform event handling on the SSL object, so calling this function is
  454. only needed if no other I/O function is to be called.
  455. .Sp
  456. This can also be used with DTLS and supersedes \fBDTLSv1_handle_timeout\fR\|(3) for
  457. new usage.
  458. .PP
  459. The following SSL APIs are specific to QUIC:
  460. .IP "\fBSSL_set_blocking_mode\fR\|(3), \fBSSL_get_blocking_mode\fR\|(3)" 4
  461. .IX Item "SSL_set_blocking_mode, SSL_get_blocking_mode"
  462. Configures whether blocking semantics are used at the application level. This
  463. determines whether calls to functions such as \fBSSL_read\fR\|(3) and \fBSSL_write\fR\|(3)
  464. will block.
  465. .IP "\fBSSL_get_rpoll_descriptor\fR\|(3), \fBSSL_get_wpoll_descriptor\fR\|(3)" 4
  466. .IX Item "SSL_get_rpoll_descriptor, SSL_get_wpoll_descriptor"
  467. These functions facilitate operation in nonblocking mode.
  468. .Sp
  469. When an SSL object is being used with an underlying network read BIO which
  470. supports polling, \fBSSL_get_rpoll_descriptor\fR\|(3) outputs an OS resource which
  471. can be used to synchronise on network readability events which should result in
  472. a call to \fBSSL_handle_events\fR\|(3). \fBSSL_get_wpoll_descriptor\fR\|(3) works in an
  473. analogous fashion for the underlying network write BIO.
  474. .Sp
  475. The poll descriptors provided by these functions need only be used when
  476. \&\fBSSL_net_read_desired\fR\|(3) and \fBSSL_net_write_desired\fR\|(3) return 1, respectively.
  477. .IP "\fBSSL_net_read_desired\fR\|(3), \fBSSL_net_write_desired\fR\|(3)" 4
  478. .IX Item "SSL_net_read_desired, SSL_net_write_desired"
  479. These functions facilitate operation in nonblocking mode and are used in
  480. conjunction with \fBSSL_get_rpoll_descriptor\fR\|(3) and
  481. \&\fBSSL_get_wpoll_descriptor\fR\|(3) respectively. They determine whether the
  482. respective poll descriptor is currently relevant for the purposes of polling.
  483. .IP \fBSSL_set1_initial_peer_addr\fR\|(3) 4
  484. .IX Item "SSL_set1_initial_peer_addr"
  485. This function can be used to set the initial peer address for an outgoing QUIC
  486. connection. This function must be used in the general case when creating an
  487. outgoing QUIC connection; however, the correct initial peer address can be
  488. autodetected in some cases. See \fBSSL_set1_initial_peer_addr\fR\|(3) for details.
  489. .IP \fBSSL_shutdown_ex\fR\|(3) 4
  490. .IX Item "SSL_shutdown_ex"
  491. This augments \fBSSL_shutdown\fR\|(3) by allowing an application error code to be
  492. specified. It also allows a client to decide how quickly it wants a shutdown to
  493. be performed, potentially by trading off strict RFC compliance.
  494. .IP \fBSSL_stream_conclude\fR\|(3) 4
  495. .IX Item "SSL_stream_conclude"
  496. This allows an application to indicate the normal end of the sending part of a
  497. QUIC stream. This corresponds to the FIN flag in the QUIC RFC. The receiving
  498. part of a stream remains usable.
  499. .IP \fBSSL_stream_reset\fR\|(3) 4
  500. .IX Item "SSL_stream_reset"
  501. This allows an application to indicate the non-normal termination of the sending
  502. part of a stream. This corresponds to the RESET_STREAM frame in the QUIC RFC.
  503. .IP "\fBSSL_get_stream_write_state\fR\|(3) and \fBSSL_get_stream_read_state\fR\|(3)" 4
  504. .IX Item "SSL_get_stream_write_state and SSL_get_stream_read_state"
  505. This allows an application to determine the current stream states for the
  506. sending and receiving parts of a stream respectively.
  507. .IP "\fBSSL_get_stream_write_error_code\fR\|(3) and \fBSSL_get_stream_read_error_code\fR\|(3)" 4
  508. .IX Item "SSL_get_stream_write_error_code and SSL_get_stream_read_error_code"
  509. This allows an application to determine the application error code which was
  510. signalled by a peer which has performed a non-normal stream termination of the
  511. respective sending or receiving part of a stream, if any.
  512. .IP \fBSSL_get_conn_close_info\fR\|(3) 4
  513. .IX Item "SSL_get_conn_close_info"
  514. This allows an application to determine the error code which was signalled when
  515. the local or remote endpoint terminated the QUIC connection.
  516. .IP \fBSSL_get0_connection\fR\|(3) 4
  517. .IX Item "SSL_get0_connection"
  518. Gets the QUIC connection SSL object from a QUIC stream SSL object.
  519. .IP \fBSSL_is_connection\fR\|(3) 4
  520. .IX Item "SSL_is_connection"
  521. Returns 1 if a SSL object is not a QUIC stream SSL object.
  522. .IP \fBSSL_get_stream_type\fR\|(3) 4
  523. .IX Item "SSL_get_stream_type"
  524. Provides information on the kind of QUIC stream which is attached
  525. to the SSL object.
  526. .IP \fBSSL_get_stream_id\fR\|(3) 4
  527. .IX Item "SSL_get_stream_id"
  528. Returns the QUIC stream ID which the QUIC protocol has associated with a QUIC
  529. stream.
  530. .IP \fBSSL_new_stream\fR\|(3) 4
  531. .IX Item "SSL_new_stream"
  532. Creates a new QUIC stream SSL object representing a new, locally-initiated QUIC
  533. stream.
  534. .IP \fBSSL_accept_stream\fR\|(3) 4
  535. .IX Item "SSL_accept_stream"
  536. Potentially yields a new QUIC stream SSL object representing a new
  537. remotely-initiated QUIC stream, blocking until one is available if the
  538. connection is configured to do so.
  539. .IP \fBSSL_get_accept_stream_queue_len\fR\|(3) 4
  540. .IX Item "SSL_get_accept_stream_queue_len"
  541. Provides information on the number of pending remotely-initiated streams.
  542. .IP \fBSSL_set_incoming_stream_policy\fR\|(3) 4
  543. .IX Item "SSL_set_incoming_stream_policy"
  544. Configures how incoming, remotely-initiated streams are handled. The incoming
  545. stream policy can be used to automatically reject streams created by the peer,
  546. or allow them to be handled using \fBSSL_accept_stream\fR\|(3).
  547. .IP \fBSSL_set_default_stream_mode\fR\|(3) 4
  548. .IX Item "SSL_set_default_stream_mode"
  549. Used to configure or disable default stream mode; see the MODES OF OPERATION
  550. section for details.
  551. .PP
  552. The following BIO APIs are not specific to QUIC but have been added to
  553. facilitate QUIC-specific requirements and are closely associated with its use:
  554. .IP \fBBIO_s_dgram_pair\fR\|(3) 4
  555. .IX Item "BIO_s_dgram_pair"
  556. This is a new BIO method which is similar to a conventional BIO pair but
  557. provides datagram semantics.
  558. .IP "\fBBIO_get_rpoll_descriptor\fR\|(3), \fBBIO_get_wpoll_descriptor\fR\|(3)" 4
  559. .IX Item "BIO_get_rpoll_descriptor, BIO_get_wpoll_descriptor"
  560. This is a new BIO API which allows a BIO to expose a poll descriptor. This API
  561. is used to implement the corresponding SSL APIs \fBSSL_get_rpoll_descriptor\fR\|(3)
  562. and \fBSSL_get_wpoll_descriptor\fR\|(3).
  563. .IP "\fBBIO_sendmmsg\fR\|(3), \fBBIO_recvmmsg\fR\|(3)" 4
  564. .IX Item "BIO_sendmmsg, BIO_recvmmsg"
  565. This is a new BIO API which can be implemented by BIOs which implement datagram
  566. semantics. It is implemented by \fBBIO_s_datagram\fR\|(3) and \fBBIO_s_dgram_pair\fR\|(3).
  567. It is used by the QUIC implementation to send and receive UDP datagrams.
  568. .IP "\fBBIO_dgram_set_no_trunc\fR\|(3), \fBBIO_dgram_get_no_trunc\fR\|(3)" 4
  569. .IX Item "BIO_dgram_set_no_trunc, BIO_dgram_get_no_trunc"
  570. By default, \fBBIO_s_dgram_pair\fR\|(3) has semantics comparable to those of Berkeley
  571. sockets being used with datagram semantics. This allows an alternative mode
  572. to be enabled in which datagrams will not be silently truncated if they are
  573. too large.
  574. .IP "\fBBIO_dgram_set_caps\fR\|(3), \fBBIO_dgram_get_caps\fR\|(3)" 4
  575. .IX Item "BIO_dgram_set_caps, BIO_dgram_get_caps"
  576. These functions are used to allow the user of one end of a
  577. \&\fBBIO_s_dgram_pair\fR\|(3) to indicate its capabilities to the other end of a
  578. \&\fBBIO_s_dgram_pair\fR\|(3). In particular, this allows an application to inform the
  579. QUIC implementation of whether it is prepared to handle local and/or peer
  580. addresses in transmitted datagrams and to provide the applicable information in
  581. received datagrams.
  582. .IP "\fBBIO_dgram_get_local_addr_cap\fR\|(3), \fBBIO_dgram_set_local_addr_enable\fR\|(3), \fBBIO_dgram_get_local_addr_enable\fR\|(3)" 4
  583. .IX Item "BIO_dgram_get_local_addr_cap, BIO_dgram_set_local_addr_enable, BIO_dgram_get_local_addr_enable"
  584. Local addressing support refers to the ability of a BIO with datagram semantics
  585. to allow a source address to be specified on transmission and to report the
  586. destination address on reception. These functions can be used to determine if a
  587. BIO can support local addressing and to enable local addressing support if it
  588. can.
  589. .IP \fBBIO_err_is_non_fatal\fR\|(3) 4
  590. .IX Item "BIO_err_is_non_fatal"
  591. This is used to determine if an error while calling \fBBIO_sendmmsg\fR\|(3) or
  592. \&\fBBIO_recvmmsg\fR\|(3) is ephemeral in nature, such as "would block" errors.
  593. .SH "THREAD ASSISTED MODE"
  594. .IX Header "THREAD ASSISTED MODE"
  595. The optional thread assisted mode can be used with
  596. \&\fBOSSL_QUIC_client_thread_method\fR\|(3). In this mode, a background thread is
  597. created automatically. The OpenSSL QUIC implementation then takes responsibility
  598. for ensuring that timeout events are handled on a timely basis even if no SSL
  599. I/O function such as \fBSSL_read\fR\|(3) or \fBSSL_write\fR\|(3) is called by the
  600. application for a long time.
  601. .PP
  602. All necessary locking is handled automatically internally, but the thread safety
  603. guarantees for the public SSL API are unchanged. Therefore, an application must
  604. still do its own locking if it wishes to make concurrent use of the public SSL
  605. APIs.
  606. .PP
  607. Because this method relies on threads, it is not available on platforms where
  608. threading support is not available or not supported by OpenSSL. However, it
  609. does provide the simplest mode of usage for an application.
  610. .PP
  611. The implementation may or may not use a common thread or thread pool to service
  612. multiple SSL objects in the same \fBSSL_CTX\fR.
  613. .SH "APPLICATION-DRIVEN EVENT LOOPS"
  614. .IX Header "APPLICATION-DRIVEN EVENT LOOPS"
  615. OpenSSL's QUIC implementation is designed to facilitate applications which wish
  616. to use the SSL APIs in a blocking fashion, but is also designed to facilitate
  617. applications which wish to use the SSL APIs in a nonblocking fashion and manage
  618. their own event loops and polling directly. This is useful when it is desirable
  619. to host OpenSSL's QUIC implementation on top of an application's existing
  620. nonblocking I/O infrastructure.
  621. .PP
  622. This is supported via the concept of poll descriptors; see
  623. \&\fBBIO_get_rpoll_descriptor\fR\|(3) for details. Broadly, a \fBBIO_POLL_DESCRIPTOR\fR is
  624. a structure which expresses some kind of OS resource which can be used to
  625. synchronise on I/O events. The QUIC implementation provides a
  626. \&\fBBIO_POLL_DESCRIPTOR\fR based on the poll descriptor provided by the underlying
  627. network BIO. This is typically an OS socket handle, though custom BIOs could
  628. choose to implement their own custom poll descriptor format.
  629. .PP
  630. Broadly, an application which wishes to manage its own event loop should
  631. interact with the SSL object as follows:
  632. .IP \(bu 4
  633. It should provide read and write BIOs with nonblocking datagram semantics to
  634. the SSL object using \fBSSL_set0_rbio\fR\|(3) and \fBSSL_set0_wbio\fR\|(3). This could be
  635. a BIO abstracting a network socket such as \fBBIO_s_datagram\fR\|(3), or a BIO
  636. abstracting some kind of memory buffer such as \fBBIO_s_dgram_pair\fR\|(3). Use of a
  637. custom BIO is also possible.
  638. .IP \(bu 4
  639. It should configure the SSL object into nonblocking mode by calling
  640. \&\fBSSL_set_blocking_mode\fR\|(3).
  641. .IP \(bu 4
  642. It should configure the SSL object as desired, set an initial peer as needed
  643. using \fBSSL_set1_initial_peer_addr\fR\|(3), and trigger the connection process by
  644. calling \fBSSL_connect\fR\|(3).
  645. .IP \(bu 4
  646. If the network read and write BIOs provided were pollable (for example,
  647. a \fBBIO_s_datagram\fR\|(3), or a custom BIO which implements
  648. \&\fBBIO_get_rpoll_descriptor\fR\|(3) and \fBBIO_get_wpoll_descriptor\fR\|(3)), it should
  649. perform the following steps repeatedly:
  650. .RS 4
  651. .IP \(bu 4
  652. The application should call \fBSSL_get_rpoll_descriptor\fR\|(3) and
  653. \&\fBSSL_get_wpoll_descriptor\fR\|(3) to identify OS resources which can be used for
  654. synchronisation.
  655. .IP \(bu 4
  656. It should call \fBSSL_net_read_desired\fR\|(3) and \fBSSL_net_write_desired\fR\|(3) to determine
  657. whether the QUIC implementation is currently interested in readability and
  658. writability events on the underlying network BIO which was provided, and call
  659. \&\fBSSL_get_event_timeout\fR\|(3) to determine if any timeout event will become
  660. applicable in the future.
  661. .IP \(bu 4
  662. It should wait until one of the following events occurs:
  663. .RS 4
  664. .IP \(bu 4
  665. The poll descriptor returned by \fBSSL_get_rpoll_descriptor\fR\|(3) becomes readable
  666. (if \fBSSL_net_read_desired\fR\|(3) returned 1);
  667. .IP \(bu 4
  668. The poll descriptor returned by \fBSSL_get_wpoll_descriptor\fR\|(3) becomes writable
  669. (if \fBSSL_net_write_desired\fR\|(3) returned 1);
  670. .IP \(bu 4
  671. The timeout returned by \fBSSL_get_event_timeout\fR\|(3) (if any) expires.
  672. .RE
  673. .RS 4
  674. .Sp
  675. Once any of these events occurs, \fBSSL_handle_events\fR\|(3) should be called.
  676. .RE
  677. .RE
  678. .RS 4
  679. .RE
  680. .IP \(bu 4
  681. If the network read and write BIOs provided were not pollable (for example, in
  682. the case of \fBBIO_s_dgram_pair\fR\|(3)), the application is responsible for managing
  683. and synchronising network I/O. It should call \fBSSL_handle_events\fR\|(3) after it
  684. writes data to a \fBBIO_s_dgram_pair\fR\|(3) or otherwise takes action so that the
  685. QUIC implementation can read new datagrams via a call to \fBBIO_recvmmsg\fR\|(3) on
  686. the underlying network BIO. The QUIC implementation may output datagrams via a
  687. call to \fBBIO_sendmmsg\fR\|(3) and the application is responsible for ensuring these
  688. are transmitted.
  689. .Sp
  690. The application must call \fBSSL_get_event_timeout\fR\|(3) after every call to
  691. \&\fBSSL_handle_events\fR\|(3) (or another I/O function on the SSL object), and ensure
  692. that a call to \fBSSL_handle_events\fR\|(3) is performed after the specified timeout
  693. (if any).
  694. .SH "SEE ALSO"
  695. .IX Header "SEE ALSO"
  696. \&\fBSSL_handle_events\fR\|(3), \fBSSL_get_event_timeout\fR\|(3),
  697. \&\fBSSL_net_read_desired\fR\|(3), \fBSSL_net_write_desired\fR\|(3),
  698. \&\fBSSL_get_rpoll_descriptor\fR\|(3), \fBSSL_get_wpoll_descriptor\fR\|(3),
  699. \&\fBSSL_set_blocking_mode\fR\|(3), \fBSSL_shutdown_ex\fR\|(3),
  700. \&\fBSSL_set1_initial_peer_addr\fR\|(3), \fBSSL_stream_conclude\fR\|(3),
  701. \&\fBSSL_stream_reset\fR\|(3), \fBSSL_get_stream_read_state\fR\|(3),
  702. \&\fBSSL_get_stream_read_error_code\fR\|(3), \fBSSL_get_conn_close_info\fR\|(3),
  703. \&\fBSSL_get0_connection\fR\|(3), \fBSSL_get_stream_type\fR\|(3), \fBSSL_get_stream_id\fR\|(3),
  704. \&\fBSSL_new_stream\fR\|(3), \fBSSL_accept_stream\fR\|(3),
  705. \&\fBSSL_set_incoming_stream_policy\fR\|(3), \fBSSL_set_default_stream_mode\fR\|(3)
  706. .SH COPYRIGHT
  707. .IX Header "COPYRIGHT"
  708. Copyright 2022\-2023 The OpenSSL Project Authors. All Rights Reserved.
  709. .PP
  710. Licensed under the Apache License 2.0 (the "License"). You may not use
  711. this file except in compliance with the License. You can obtain a copy
  712. in the file LICENSE in the source distribution or at
  713. <https://www.openssl.org/source/license.html>.