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