ossl-guide-quic-introduction.7ossl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "OSSL-GUIDE-QUIC-INTRODUCTION 7ossl"
  136. .TH OSSL-GUIDE-QUIC-INTRODUCTION 7ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. ossl\-guide\-quic\-introduction
  143. \&\- OpenSSL Guide: An introduction to QUIC in OpenSSL
  144. .SH "INTRODUCTION"
  145. .IX Header "INTRODUCTION"
  146. This page will provide an introduction to some basic \s-1QUIC\s0 concepts and
  147. background and how it is used within OpenSSL. It assumes that you have a basic
  148. understanding of \s-1UDP/IP\s0 and sockets. It also assumes that you are familiar with
  149. some OpenSSL and \s-1TLS\s0 fundamentals (see \fBossl\-guide\-libraries\-introduction\fR\|(7)
  150. and \fBossl\-guide\-tls\-introduction\fR\|(7)).
  151. .SH "WHAT IS QUIC?"
  152. .IX Header "WHAT IS QUIC?"
  153. \&\s-1QUIC\s0 is a general purpose protocol for enabling applications to securely
  154. communicate over a network. It is defined in \s-1RFC9000\s0 (see
  155. <https://datatracker.ietf.org/doc/rfc9000/>). \s-1QUIC\s0 integrates parts of the
  156. \&\s-1TLS\s0 protocol for connection establishment but independently protects packets.
  157. It provides similar security guarantees to \s-1TLS\s0 such as confidentiality,
  158. integrity and authentication (see \fBossl\-guide\-tls\-introduction\fR\|(7)).
  159. .PP
  160. \&\s-1QUIC\s0 delivers a number of advantages:
  161. .IP "Multiple streams" 4
  162. .IX Item "Multiple streams"
  163. It supports multiple streams of communication (see \*(L"\s-1QUIC STREAMS\*(R"\s0 below),
  164. allowing application protocols built on \s-1QUIC\s0 to create arbitrarily many
  165. bytestreams for communication between a client and server. This allows an
  166. application protocol to avoid problems where one packet of data is held up
  167. waiting on another packet being delivered (commonly referred to as
  168. \&\*(L"head-of-line blocking\*(R"). It also enables an application to open additional
  169. logical streams without requiring a round-trip exchange of packets between the
  170. client and server as is required when opening an additional \s-1TLS/TCP\s0
  171. connection.
  172. .IP "\s-1HTTP/3\s0" 4
  173. .IX Item "HTTP/3"
  174. Since \s-1QUIC\s0 is the basis of \s-1HTTP/3,\s0 support for \s-1QUIC\s0 also enables applications
  175. to use \s-1HTTP/3\s0 using a suitable third-party library.
  176. .IP "Fast connection initiation" 4
  177. .IX Item "Fast connection initiation"
  178. Future versions of OpenSSL will offer support for 0\-RTT connection initiation,
  179. allowing a connection to be initiated to a server and application data to be
  180. transmitted without any waiting time. This is similar to \s-1TLS 1.3\s0's 0\-RTT
  181. functionality but also avoids the round trip needed to open a \s-1TCP\s0 socket; thus,
  182. it is similar to a combination of \s-1TLS 1.3 0\-RTT\s0 and \s-1TCP\s0 Fast Open.
  183. .IP "Connection migration" 4
  184. .IX Item "Connection migration"
  185. Future versions of OpenSSL will offer support for connection migration, allowing
  186. connections to seamlessly survive \s-1IP\s0 address changes.
  187. .IP "Datagram based use cases" 4
  188. .IX Item "Datagram based use cases"
  189. Future versions of OpenSSL will offer support for the \s-1QUIC\s0 datagram extension,
  190. allowing support for both \s-1TLS\s0 and DTLS-style use cases on a single connection.
  191. .IP "Implemented as application library" 4
  192. .IX Item "Implemented as application library"
  193. Because most \s-1QUIC\s0 implementations, including OpenSSL's implementation, are
  194. implemented as an application library rather than by an operating system, an
  195. application can gain the benefit of \s-1QUIC\s0 without needing to wait for an \s-1OS\s0
  196. update to be deployed. Future evolutions and enhancements to the \s-1QUIC\s0 protocol
  197. can be delivered as quickly as an application can be updated without dependency
  198. on an \s-1OS\s0 update cadence.
  199. .IP "Multiplexing over a single \s-1UDP\s0 socket" 4
  200. .IX Item "Multiplexing over a single UDP socket"
  201. Because \s-1QUIC\s0 is UDP-based, it is possible to multiplex a \s-1QUIC\s0 connection on the
  202. same \s-1UDP\s0 socket as some other UDP-based protocols, such as \s-1RTP.\s0
  203. .SH "QUIC TIME BASED EVENTS"
  204. .IX Header "QUIC TIME BASED EVENTS"
  205. A key difference between the \s-1TLS\s0 implementation and the \s-1QUIC\s0 implementation in
  206. OpenSSL is how time is handled. The \s-1QUIC\s0 protocol requires various actions to be
  207. performed on a regular basis regardless of whether application data is being
  208. transmitted or received.
  209. .PP
  210. OpenSSL introduces a new function \fBSSL_handle_events\fR\|(3) that will
  211. automatically process any outstanding time based events that must be handled.
  212. Alternatively calling any I/O function such as \fBSSL_read_ex\fR\|(3) or
  213. \&\fBSSL_write_ex\fR\|(3) will also process these events. There is also
  214. \&\fBSSL_get_event_timeout\fR\|(3) which tells an application the amount of time that
  215. remains until \fBSSL_handle_events\fR\|(3) (or any I/O function) must be called.
  216. .PP
  217. Fortunately a blocking application that does not leave the \s-1QUIC\s0 connection idle,
  218. and is regularly calling I/O functions does not typically need to worry about
  219. this. However if you are developing a nonblocking application or one that may
  220. leave the \s-1QUIC\s0 connection idle for a period of time then you will need to
  221. arrange to call these functions.
  222. .PP
  223. OpenSSL provides an optional \*(L"thread assisted mode\*(R" that will automatically
  224. create a background thread and will regularly call \fBSSL_handle_events\fR\|(3) in a
  225. thread safe manner. This provides a simple way for an application to satisfy the
  226. \&\s-1QUIC\s0 requirements for time based events without having to implement special
  227. logic to accomplish it.
  228. .SH "QUIC AND TLS"
  229. .IX Header "QUIC AND TLS"
  230. \&\s-1QUIC\s0 reuses parts of the \s-1TLS\s0 protocol in its implementation. Specifically the
  231. \&\s-1TLS\s0 handshake also exists in \s-1QUIC.\s0 The \s-1TLS\s0 handshake messages are wrapped up in
  232. \&\s-1QUIC\s0 protocol messages in order to send them to the peer. Once the \s-1TLS\s0 handshake
  233. is complete all application data is sent entirely using \s-1QUIC\s0 protocol messages
  234. without using \s-1TLS\s0 \- although some \s-1TLS\s0 handshake messages may still be sent in
  235. some circumstances.
  236. .PP
  237. This relationship between \s-1QUIC\s0 and \s-1TLS\s0 means that many of the \s-1API\s0 functions in
  238. OpenSSL that apply to \s-1TLS\s0 connections also apply to \s-1QUIC\s0 connections and
  239. applications can use them in exactly the same way. Some functions do not apply
  240. to \s-1QUIC\s0 at all, and others have altered semantics. You should refer to the
  241. documentation pages for each function for information on how it applies to \s-1QUIC.\s0
  242. Typically if \s-1QUIC\s0 is not mentioned in the manual pages then the functions apply
  243. to both \s-1TLS\s0 and \s-1QUIC.\s0
  244. .SH "QUIC STREAMS"
  245. .IX Header "QUIC STREAMS"
  246. \&\s-1QUIC\s0 introduces the concept of \*(L"streams\*(R". A stream provides a reliable
  247. mechanism for sending and receiving application data between the endpoints. The
  248. bytes transmitted are guaranteed to be received in the same order they were sent
  249. without any loss of data or reordering of the bytes. A \s-1TLS\s0 application
  250. effectively has one bi-directional stream available to it per \s-1TLS\s0 connection. A
  251. \&\s-1QUIC\s0 application can have multiple uni-directional or bi-directional streams
  252. available to it for each connection.
  253. .PP
  254. In OpenSSL an \fB\s-1SSL\s0\fR object is used to represent both connections and streams.
  255. A \s-1QUIC\s0 application creates an initial \fB\s-1SSL\s0\fR object to represent the connection
  256. (known as the connection \fB\s-1SSL\s0\fR object). Once the connection is complete
  257. additional \fB\s-1SSL\s0\fR objects can be created to represent streams (known as stream
  258. \&\fB\s-1SSL\s0\fR objects). Unless configured otherwise, a \*(L"default\*(R" stream is also
  259. associated with the connection \fB\s-1SSL\s0\fR object so you can still write data and
  260. read data to/from it. Some OpenSSL \s-1API\s0 functions can only be used with
  261. connection \fB\s-1SSL\s0\fR objects, and some can only be used with stream \fB\s-1SSL\s0\fR objects.
  262. Check the documentation for each function to confirm what type of \fB\s-1SSL\s0\fR object
  263. can be used in any particular context. A connection \fB\s-1SSL\s0\fR object that has a
  264. default stream attached to it can be used in contexts that require a connection
  265. \&\fB\s-1SSL\s0\fR object or in contexts that require a stream \fB\s-1SSL\s0\fR object.
  266. .SH "SOCKETS AND BLOCKING"
  267. .IX Header "SOCKETS AND BLOCKING"
  268. \&\s-1TLS\s0 assumes \*(L"stream\*(R" type semantics for its underlying transport layer protocol
  269. (usually achieved by using \s-1TCP\s0). However \s-1QUIC\s0 assumes \*(L"datagram\*(R" type semantics
  270. by using \s-1UDP.\s0 An OpenSSL application using \s-1QUIC\s0 is responsible for creating a
  271. \&\s-1BIO\s0 to represent the underlying transport layer. This \s-1BIO\s0 must support datagrams
  272. and is typically \fBBIO_s_datagram\fR\|(3), but other \fB\s-1BIO\s0\fR choices are available.
  273. See \fBbio\fR\|(7) for an introduction to OpenSSL's \fB\s-1BIO\s0\fR concept.
  274. .PP
  275. A significant difference between OpenSSL \s-1TLS\s0 applications and OpenSSL \s-1QUIC\s0
  276. applications is the way that blocking is implemented. In \s-1TLS\s0 if your application
  277. expects blocking behaviour then you configure the underlying socket for
  278. blocking. Conversely if your application wants nonblocking behaviour then the
  279. underlying socket is configured to be nonblocking.
  280. .PP
  281. With an OpenSSL \s-1QUIC\s0 application the underlying socket must always be configured
  282. to be nonblocking. Howevever the \fB\s-1SSL\s0\fR object will, by default, still operate
  283. in blocking mode. So, from an application's perspective, calls to functions such
  284. as \fBSSL_read_ex\fR\|(3), \fBSSL_write_ex\fR\|(3) and other I/O functions will still
  285. block. OpenSSL itself provides that blocking capability for \s-1QUIC\s0 instead of the
  286. socket. If nonblocking behaviour is desired then the application must call
  287. \&\fBSSL_set_blocking_mode\fR\|(3).
  288. .SH "FURTHER READING"
  289. .IX Header "FURTHER READING"
  290. See \fBossl\-guide\-quic\-client\-block\fR\|(7) to see an example of applying these
  291. concepts in order to write a simple blocking \s-1QUIC\s0 client.
  292. .SH "SEE ALSO"
  293. .IX Header "SEE ALSO"
  294. \&\fBossl\-guide\-introduction\fR\|(7), \fBossl\-guide\-libraries\-introduction\fR\|(7),
  295. \&\fBossl\-guide\-libssl\-introduction\fR\|(7), \fBossl\-guide\-tls\-introduction\fR\|(7),
  296. \&\fBossl\-guide\-tls\-client\-block\fR\|(7), \fBossl\-guide\-quic\-client\-block\fR\|(7), \fBbio\fR\|(7)
  297. .SH "COPYRIGHT"
  298. .IX Header "COPYRIGHT"
  299. Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
  300. .PP
  301. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  302. this file except in compliance with the License. You can obtain a copy
  303. in the file \s-1LICENSE\s0 in the source distribution or at
  304. <https://www.openssl.org/source/license.html>.