ossl-guide-quic-introduction.pod 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. =pod
  2. =head1 NAME
  3. ossl-guide-quic-introduction
  4. - OpenSSL Guide: An introduction to QUIC in OpenSSL
  5. =head1 INTRODUCTION
  6. This page will provide an introduction to some basic QUIC concepts and
  7. background and how it is used within OpenSSL. It assumes that you have a basic
  8. understanding of UDP/IP and sockets. It also assumes that you are familiar with
  9. some OpenSSL and TLS fundamentals (see L<ossl-guide-libraries-introduction(7)>
  10. and L<ossl-guide-tls-introduction(7)>).
  11. =head1 WHAT IS QUIC?
  12. QUIC is a general purpose protocol for enabling applications to securely
  13. communicate over a network. It is defined in RFC9000 (see
  14. L<https://datatracker.ietf.org/doc/rfc9000/>). QUIC integrates parts of the
  15. TLS protocol for connection establishment but independently protects packets.
  16. It provides similar security guarantees to TLS such as confidentiality,
  17. integrity and authentication (see L<ossl-guide-tls-introduction(7)>).
  18. QUIC delivers a number of advantages:
  19. =over 4
  20. =item Multiple streams
  21. It supports multiple streams of communication (see L</QUIC STREAMS> below),
  22. allowing application protocols built on QUIC to create arbitrarily many
  23. bytestreams for communication between a client and server. This allows an
  24. application protocol to avoid problems where one packet of data is held up
  25. waiting on another packet being delivered (commonly referred to as
  26. "head-of-line blocking"). It also enables an application to open additional
  27. logical streams without requiring a round-trip exchange of packets between the
  28. client and server as is required when opening an additional TLS/TCP
  29. connection.
  30. =item HTTP/3
  31. Since QUIC is the basis of HTTP/3, support for QUIC also enables applications
  32. to use HTTP/3 using a suitable third-party library.
  33. =item Fast connection initiation
  34. Future versions of OpenSSL will offer support for 0-RTT connection initiation,
  35. allowing a connection to be initiated to a server and application data to be
  36. transmitted without any waiting time. This is similar to TLS 1.3's 0-RTT
  37. functionality but also avoids the round trip needed to open a TCP socket; thus,
  38. it is similar to a combination of TLS 1.3 0-RTT and TCP Fast Open.
  39. =item Connection migration
  40. Future versions of OpenSSL will offer support for connection migration, allowing
  41. connections to seamlessly survive IP address changes.
  42. =item Datagram based use cases
  43. Future versions of OpenSSL will offer support for the QUIC datagram extension,
  44. allowing support for both TLS and DTLS-style use cases on a single connection.
  45. =item Implemented as application library
  46. Because most QUIC implementations, including OpenSSL's implementation, are
  47. implemented as an application library rather than by an operating system, an
  48. application can gain the benefit of QUIC without needing to wait for an OS
  49. update to be deployed. Future evolutions and enhancements to the QUIC protocol
  50. can be delivered as quickly as an application can be updated without dependency
  51. on an OS update cadence.
  52. =item Multiplexing over a single UDP socket
  53. Because QUIC is UDP-based, it is possible to multiplex a QUIC connection on the
  54. same UDP socket as some other UDP-based protocols, such as RTP.
  55. =back
  56. =head1 QUIC TIME BASED EVENTS
  57. A key difference between the TLS implementation and the QUIC implementation in
  58. OpenSSL is how time is handled. The QUIC protocol requires various actions to be
  59. performed on a regular basis regardless of whether application data is being
  60. transmitted or received.
  61. OpenSSL introduces a new function L<SSL_handle_events(3)> that will
  62. automatically process any outstanding time based events that must be handled.
  63. Alternatively calling any I/O function such as L<SSL_read_ex(3)> or
  64. L<SSL_write_ex(3)> will also process these events. There is also
  65. L<SSL_get_event_timeout(3)> which tells an application the amount of time that
  66. remains until L<SSL_handle_events(3)> (or any I/O function) must be called.
  67. Fortunately a blocking application that does not leave the QUIC connection idle,
  68. and is regularly calling I/O functions does not typically need to worry about
  69. this. However if you are developing a nonblocking application or one that may
  70. leave the QUIC connection idle for a period of time then you will need to
  71. arrange to call these functions.
  72. OpenSSL provides an optional "thread assisted mode" that will automatically
  73. create a background thread and will regularly call L<SSL_handle_events(3)> in a
  74. thread safe manner. This provides a simple way for an application to satisfy the
  75. QUIC requirements for time based events without having to implement special
  76. logic to accomplish it.
  77. =head1 QUIC AND TLS
  78. QUIC reuses parts of the TLS protocol in its implementation. Specifically the
  79. TLS handshake also exists in QUIC. The TLS handshake messages are wrapped up in
  80. QUIC protocol messages in order to send them to the peer. Once the TLS handshake
  81. is complete all application data is sent entirely using QUIC protocol messages
  82. without using TLS - although some TLS handshake messages may still be sent in
  83. some circumstances.
  84. This relationship between QUIC and TLS means that many of the API functions in
  85. OpenSSL that apply to TLS connections also apply to QUIC connections and
  86. applications can use them in exactly the same way. Some functions do not apply
  87. to QUIC at all, and others have altered semantics. You should refer to the
  88. documentation pages for each function for information on how it applies to QUIC.
  89. Typically if QUIC is not mentioned in the manual pages then the functions apply
  90. to both TLS and QUIC.
  91. =head1 QUIC STREAMS
  92. QUIC introduces the concept of "streams". A stream provides a reliable
  93. mechanism for sending and receiving application data between the endpoints. The
  94. bytes transmitted are guaranteed to be received in the same order they were sent
  95. without any loss of data or reordering of the bytes. A TLS application
  96. effectively has one bi-directional stream available to it per TLS connection. A
  97. QUIC application can have multiple uni-directional or bi-directional streams
  98. available to it for each connection.
  99. In OpenSSL an B<SSL> object is used to represent both connections and streams.
  100. A QUIC application creates an initial B<SSL> object to represent the connection
  101. (known as the connection B<SSL> object). Once the connection is complete
  102. additional B<SSL> objects can be created to represent streams (known as stream
  103. B<SSL> objects). Unless configured otherwise, a "default" stream is also
  104. associated with the connection B<SSL> object so you can still write data and
  105. read data to/from it. Some OpenSSL API functions can only be used with
  106. connection B<SSL> objects, and some can only be used with stream B<SSL> objects.
  107. Check the documentation for each function to confirm what type of B<SSL> object
  108. can be used in any particular context. A connection B<SSL> object that has a
  109. default stream attached to it can be used in contexts that require a connection
  110. B<SSL> object or in contexts that require a stream B<SSL> object.
  111. =head1 SOCKETS AND BLOCKING
  112. TLS assumes "stream" type semantics for its underlying transport layer protocol
  113. (usually achieved by using TCP). However QUIC assumes "datagram" type semantics
  114. by using UDP. An OpenSSL application using QUIC is responsible for creating a
  115. BIO to represent the underlying transport layer. This BIO must support datagrams
  116. and is typically L<BIO_s_datagram(3)>, but other B<BIO> choices are available.
  117. See L<bio(7)> for an introduction to OpenSSL's B<BIO> concept.
  118. A significant difference between OpenSSL TLS applications and OpenSSL QUIC
  119. applications is the way that blocking is implemented. In TLS if your application
  120. expects blocking behaviour then you configure the underlying socket for
  121. blocking. Conversely if your application wants nonblocking behaviour then the
  122. underlying socket is configured to be nonblocking.
  123. With an OpenSSL QUIC application the underlying socket must always be configured
  124. to be nonblocking. Howevever the B<SSL> object will, by default, still operate
  125. in blocking mode. So, from an application's perspective, calls to functions such
  126. as L<SSL_read_ex(3)>, L<SSL_write_ex(3)> and other I/O functions will still
  127. block. OpenSSL itself provides that blocking capability for QUIC instead of the
  128. socket. If nonblocking behaviour is desired then the application must call
  129. L<SSL_set_blocking_mode(3)>.
  130. =head1 FURTHER READING
  131. See L<ossl-guide-quic-client-block(7)> to see an example of applying these
  132. concepts in order to write a simple blocking QUIC client.
  133. =head1 SEE ALSO
  134. L<ossl-guide-introduction(7)>, L<ossl-guide-libraries-introduction(7)>,
  135. L<ossl-guide-libssl-introduction(7)>, L<ossl-guide-tls-introduction(7)>,
  136. L<ossl-guide-tls-client-block(7)>, L<ossl-guide-quic-client-block(7)>, L<bio(7)>
  137. =head1 COPYRIGHT
  138. Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
  139. Licensed under the Apache License 2.0 (the "License"). You may not use
  140. this file except in compliance with the License. You can obtain a copy
  141. in the file LICENSE in the source distribution or at
  142. L<https://www.openssl.org/source/license.html>.
  143. =cut