Blame doc/cha-intro-tls.texi

Packit Service 4684c1
@node Introduction to TLS
Packit Service 4684c1
@chapter Introduction to @acronym{TLS} and @acronym{DTLS}
Packit Service 4684c1
Packit Service 4684c1
@acronym{TLS} stands for ``Transport Layer Security'' and is the
Packit Service 4684c1
successor of SSL, the Secure Sockets Layer protocol @xcite{SSL3}
Packit Service 4684c1
designed by Netscape.  @acronym{TLS} is an Internet protocol, defined
Packit Service 4684c1
by @acronym{IETF}@footnote{IETF, or Internet Engineering Task Force,
Packit Service 4684c1
is a large open international community of network designers,
Packit Service 4684c1
operators, vendors, and researchers concerned with the evolution of
Packit Service 4684c1
the Internet architecture and the smooth operation of the Internet.
Packit Service 4684c1
It is open to any interested individual.}, described in @xcite{RFC5246}.
Packit Service 4684c1
The protocol provides
Packit Service 4684c1
confidentiality, and authentication layers over any reliable transport
Packit Service 4684c1
layer.  The description, above, refers to @acronym{TLS} 1.0 but applies
Packit Service 4684c1
to all other TLS versions as the differences between the protocols are not major.
Packit Service 4684c1
Packit Service 4684c1
The @acronym{DTLS} protocol, or ``Datagram @acronym{TLS}'' @xcite{RFC4347} is a
Packit Service 4684c1
protocol with identical goals as @acronym{TLS}, but can operate
Packit Service 4684c1
under unreliable transport layers such as @acronym{UDP}. The
Packit Service 4684c1
discussions below apply to this protocol as well, except when
Packit Service 4684c1
noted otherwise.
Packit Service 4684c1
Packit Service 4684c1
@menu
Packit Service 4684c1
* TLS layers::
Packit Service 4684c1
* The transport layer::
Packit Service 4684c1
* The TLS record protocol::
Packit Service 4684c1
* The TLS Alert Protocol::
Packit Service 4684c1
* The TLS Handshake Protocol::
Packit Service 4684c1
* TLS Extensions::
Packit Service 4684c1
* How to use TLS in application protocols::
Packit Service 4684c1
* On SSL 2 and older protocols::
Packit Service 4684c1
@end menu
Packit Service 4684c1
Packit Service 4684c1
@node TLS layers
Packit Service 4684c1
@section TLS Layers
Packit Service 4684c1
@cindex TLS layers
Packit Service 4684c1
Packit Service 4684c1
@acronym{TLS} is a layered protocol, and consists of the record
Packit Service 4684c1
protocol, the handshake protocol and the alert protocol. The record
Packit Service 4684c1
protocol is to serve all other protocols and is above the transport
Packit Service 4684c1
layer.  The record protocol offers symmetric encryption, and data
Packit Service 4684c1
authenticity@footnote{In early versions of TLS compression was optionally
Packit Service 4684c1
available as well. This is no longer the case in recent versions of the
Packit Service 4684c1
protocol.}.
Packit Service 4684c1
The alert protocol offers some signaling to the other protocols. It
Packit Service 4684c1
can help informing the peer for the cause of failures and other error
Packit Service 4684c1
conditions.  @xref{The Alert Protocol}, for more information.  The
Packit Service 4684c1
alert protocol is above the record protocol.
Packit Service 4684c1
Packit Service 4684c1
The handshake protocol is responsible for the security parameters'
Packit Service 4684c1
negotiation, the initial key exchange and authentication.
Packit Service 4684c1
@xref{The Handshake Protocol}, for more information about the handshake
Packit Service 4684c1
protocol.  The protocol layering in TLS is shown in @ref{fig-tls-layers}.
Packit Service 4684c1
Packit Service 4684c1
@float Figure,fig-tls-layers
Packit Service 4684c1
@image{gnutls-layers,12cm}
Packit Service 4684c1
@caption{The TLS protocol layers.}
Packit Service 4684c1
@end float
Packit Service 4684c1
Packit Service 4684c1
@node The transport layer
Packit Service 4684c1
@section The Transport Layer
Packit Service 4684c1
@cindex transport protocol
Packit Service 4684c1
@cindex transport layer
Packit Service 4684c1
Packit Service 4684c1
@acronym{TLS} is not limited to any transport layer and can be used
Packit Service 4684c1
above any transport layer, as long as it is a reliable one.  @acronym{DTLS}
Packit Service 4684c1
can be used over reliable and unreliable transport layers.
Packit Service 4684c1
@acronym{GnuTLS} supports TCP and UDP layers transparently using
Packit Service 4684c1
the Berkeley sockets API. However, any transport layer can be used
Packit Service 4684c1
by providing callbacks for @acronym{GnuTLS} to access the transport layer
Packit Service 4684c1
(for details see @ref{Setting up the transport layer}).
Packit Service 4684c1
Packit Service 4684c1
@node The TLS record protocol
Packit Service 4684c1
@section The TLS record protocol
Packit Service 4684c1
@cindex record protocol
Packit Service 4684c1
Packit Service 4684c1
The record protocol is the secure communications provider. Its purpose
Packit Service 4684c1
is to encrypt, and authenticate packets.
Packit Service 4684c1
The record layer functions can be called at any time after
Packit Service 4684c1
the handshake process is finished, when there is need to receive
Packit Service 4684c1
or send data. In @acronym{DTLS} however, due to re-transmission
Packit Service 4684c1
timers used in the handshake out-of-order handshake data might
Packit Service 4684c1
be received for some time (maximum 60 seconds) after the handshake
Packit Service 4684c1
process is finished.
Packit Service 4684c1
Packit Service 4684c1
The functions to access the record protocol are limited to send
Packit Service 4684c1
and receive functions, which might, given
Packit Service 4684c1
the importance of this protocol in @acronym{TLS}, seem awkward.  This is because
Packit Service 4684c1
the record protocol's parameters are all set by the handshake protocol.
Packit Service 4684c1
The record protocol initially starts with NULL parameters, which means
Packit Service 4684c1
no encryption, and no MAC is used. Encryption and authentication begin
Packit Service 4684c1
just after the handshake protocol has finished.
Packit Service 4684c1
Packit Service 4684c1
@menu
Packit Service 4684c1
* Encryption algorithms used in the record layer::
Packit Service 4684c1
* Compression algorithms and the record layer::
Packit Service 4684c1
* On Record Padding::
Packit Service 4684c1
@end menu
Packit Service 4684c1
Packit Service 4684c1
@node Encryption algorithms used in the record layer
Packit Service 4684c1
@subsection Encryption algorithms used in the record layer
Packit Service 4684c1
@cindex symmetric encryption algorithms
Packit Service 4684c1
Packit Service 4684c1
Confidentiality in the record layer is achieved by using symmetric
Packit Service 4684c1
ciphers like @code{AES} or @code{CHACHA20}.  Ciphers are encryption algorithms
Packit Service 4684c1
that use a single, secret, key to encrypt and decrypt data. Early
Packit Service 4684c1
versions of TLS separated between block and stream ciphers and had
Packit Service 4684c1
message authentication plugged in to them by the protocol, though later
Packit Service 4684c1
versions switched to using authenticated-encryption (AEAD) ciphers. The AEAD
Packit Service 4684c1
ciphers are defined to combine encryption and authentication, and as such
Packit Service 4684c1
they are not only more efficient, as the primitives used are designed to
Packit Service 4684c1
interoperate nicely, but they are also known to interoperate in a secure
Packit Service 4684c1
way.
Packit Service 4684c1
Packit Service 4684c1
The supported in @acronym{GnuTLS} ciphers and MAC algorithms are shown in @ref{tab:ciphers} and
Packit Service 4684c1
@ref{tab:macs}.
Packit Service 4684c1
Packit Service 4684c1
@float Table,tab:ciphers
Packit Service 4684c1
@multitable @columnfractions .20 .10 .15 .55
Packit Service 4684c1
@headitem Algorithm @tab Type @tab Applicable Protocols @tab Description
Packit Service 4684c1
@item AES-128-GCM, AES-256-GCM @tab
Packit Service 4684c1
AEAD @tab
Packit Service 4684c1
TLS 1.2, TLS 1.3 @tab
Packit Service 4684c1
This is the AES algorithm in the authenticated encryption GCM mode.
Packit Service 4684c1
This mode combines message authentication and encryption and can
Packit Service 4684c1
be extremely fast on CPUs that support hardware acceleration.
Packit Service 4684c1
Packit Service 4684c1
@item AES-128-CCM, AES-256-CCM @tab
Packit Service 4684c1
AEAD @tab
Packit Service 4684c1
TLS 1.2, TLS 1.3 @tab
Packit Service 4684c1
This is the AES algorithm in the authenticated encryption CCM mode.
Packit Service 4684c1
This mode combines message authentication and encryption and is
Packit Service 4684c1
often used by systems without AES or GCM acceleration support.
Packit Service 4684c1
Packit Service 4684c1
@item CHACHA20-POLY1305 @tab
Packit Service 4684c1
AEAD @tab
Packit Service 4684c1
TLS 1.2, TLS 1.3 @tab
Packit Service 4684c1
CHACHA20-POLY1305 is an authenticated encryption algorithm based on CHACHA20 cipher and
Packit Service 4684c1
POLY1305 MAC. CHACHA20 is a refinement of SALSA20 algorithm, an approved cipher by
Packit Service 4684c1
the European ESTREAM project. POLY1305 is Wegman-Carter, one-time authenticator. The
Packit Service 4684c1
combination provides a fast stream cipher suitable for systems where a hardware AES
Packit Service 4684c1
accelerator is not available.
Packit Service 4684c1
Packit Service 4684c1
@item AES-128-CCM-8, AES-256-CCM-8 @tab
Packit Service 4684c1
AEAD @tab
Packit Service 4684c1
TLS 1.2, TLS 1.3 @tab
Packit Service 4684c1
This is the AES algorithm in the authenticated encryption CCM mode
Packit Service 4684c1
with a truncated to 64-bit authentication tag. This mode is for
Packit Service 4684c1
communication with restricted systems.
Packit Service 4684c1
Packit Service 4684c1
@item CAMELLIA-128-GCM, CAMELLIA-256-GCM @tab
Packit Service 4684c1
AEAD @tab
Packit Service 4684c1
TLS 1.2 @tab
Packit Service 4684c1
This is the CAMELLIA algorithm in the authenticated encryption GCM mode.
Packit Service 4684c1
Packit Service 4684c1
@item AES-128-CBC, AES-256-CBC @tab
Packit Service 4684c1
Legacy (block) @tab
Packit Service 4684c1
TLS 1.0, TLS 1.1, TLS 1.2 @tab
Packit Service 4684c1
AES or RIJNDAEL is the block cipher algorithm that replaces the old
Packit Service 4684c1
DES algorithm.  It has 128 bits block size and is used in CBC mode.
Packit Service 4684c1
Packit Service 4684c1
@item CAMELLIA-128-CBC, CAMELLIA-256-CBC @tab
Packit Service 4684c1
Legacy (block) @tab
Packit Service 4684c1
TLS 1.0, TLS 1.1, TLS 1.2 @tab
Packit Service 4684c1
This is an 128-bit block cipher developed by Mitsubishi and NTT. It
Packit Service 4684c1
is one of the approved ciphers of the European NESSIE and Japanese
Packit Service 4684c1
CRYPTREC projects.
Packit Service 4684c1
Packit Service 4684c1
@item 3DES-CBC @tab
Packit Service 4684c1
Legacy (block) @tab
Packit Service 4684c1
TLS 1.0, TLS 1.1, TLS 1.2 @tab
Packit Service 4684c1
This is the DES block cipher algorithm used with triple
Packit Service 4684c1
encryption (EDE). Has 64 bits block size and is used in CBC mode.
Packit Service 4684c1
Packit Service 4684c1
@item ARCFOUR-128 @tab
Packit Service 4684c1
Legacy (stream) @tab
Packit Service 4684c1
TLS 1.0, TLS 1.1, TLS 1.2 @tab
Packit Service 4684c1
ARCFOUR-128 is a compatible algorithm with RSA's RC4 algorithm, which is considered to be a trade
Packit Service 4684c1
secret. It is a considered to be broken, and is only used for compatibility
Packit Service 4684c1
purposed. For this reason it is not enabled by default.
Packit Service 4684c1
Packit Service 4684c1
@item GOST28147-TC26Z-CNT @tab
Packit Service 4684c1
Legacy (stream) @tab
Packit Service 4684c1
TLS 1.2 @tab
Packit Service 4684c1
This is a 64-bit block cipher GOST 28147-89 with TC26Z S-Box working in CNT
Packit Service 4684c1
mode. It is one of the approved ciphers in Russia. It is not enabled by default.
Packit Service 4684c1
Packit Service 4684c1
@item NULL @tab
Packit Service 4684c1
Legacy (stream) @tab
Packit Service 4684c1
TLS 1.0, TLS 1.1, TLS 1.2 @tab
Packit Service 4684c1
NULL is the empty/identity cipher which doesn't encrypt any data. It can be
Packit Service 4684c1
combined with data authentication under TLS 1.2 or earlier, but is only used
Packit Service 4684c1
transiently under TLS 1.3 until encryption starts. This cipher cannot be negotiated
Packit Service 4684c1
by default (need to be explicitly enabled) under TLS 1.2, and cannot be
Packit Service 4684c1
negotiated at all under TLS 1.3. When enabled, TLS 1.3 (or later) support will be
Packit Service 4684c1
implicitly disabled.
Packit Service 4684c1
Packit Service 4684c1
@end multitable
Packit Service 4684c1
@caption{Supported ciphers in TLS.}
Packit Service 4684c1
@end float
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
@float Table,tab:macs
Packit Service 4684c1
@multitable @columnfractions .20 .70
Packit Service 4684c1
@headitem Algorithm @tab Description
Packit Service 4684c1
@item MAC-MD5 @tab
Packit Service 4684c1
This is an HMAC based on MD5 a cryptographic hash algorithm designed
Packit Service 4684c1
by Ron Rivest. Outputs 128 bits of data.
Packit Service 4684c1
Packit Service 4684c1
@item MAC-SHA1 @tab
Packit Service 4684c1
An HMAC based on the SHA1 cryptographic hash algorithm
Packit Service 4684c1
designed by NSA. Outputs 160 bits of data.
Packit Service 4684c1
Packit Service 4684c1
@item MAC-SHA256 @tab
Packit Service 4684c1
An HMAC based on SHA2-256. Outputs 256 bits of data.
Packit Service 4684c1
Packit Service 4684c1
@item MAC-SHA384 @tab
Packit Service 4684c1
An HMAC based on SHA2-384. Outputs 384 bits of data.
Packit Service 4684c1
Packit Service 4684c1
@item GOST28147-TC26Z-IMIT @tab
Packit Service 4684c1
This is a 64-bit block cipher GOST 28147-89 with TC26Z S-Box working in special
Packit Service 4684c1
MAC mode called Imitovstavks. It is one of the approved MAC algorithms in
Packit Service 4684c1
Russia. Outputs 32 bits of data. It is not enabled by default.
Packit Service 4684c1
Packit Service 4684c1
@item MAC-AEAD @tab
Packit Service 4684c1
This indicates that an authenticated encryption algorithm, such as
Packit Service 4684c1
GCM, is in use.
Packit Service 4684c1
Packit Service 4684c1
@end multitable
Packit Service 4684c1
@caption{Supported MAC algorithms in TLS.}
Packit Service 4684c1
@end float
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
@node Compression algorithms and the record layer
Packit Service 4684c1
@subsection Compression algorithms and the record layer
Packit Service 4684c1
@cindex compression algorithms
Packit Service 4684c1
Packit Service 4684c1
In early versions of TLS the record layer supported compression. However,
Packit Service 4684c1
that proved to be problematic in many ways, and enabled several attacks
Packit Service 4684c1
based on traffic analysis on the transported data. For that newer versions of the protocol no longer
Packit Service 4684c1
offer compression, and @acronym{GnuTLS} since 3.6.0 no longer implements any
Packit Service 4684c1
support for compression.
Packit Service 4684c1
Packit Service 4684c1
@node On Record Padding
Packit Service 4684c1
@subsection On record padding
Packit Service 4684c1
@cindex record padding
Packit Service 4684c1
@cindex bad_record_mac
Packit Service 4684c1
Packit Service 4684c1
The TLS 1.3 protocol allows for extra padding of records to prevent
Packit Service 4684c1
statistical analysis based on the length of exchanged messages.
Packit Service 4684c1
GnuTLS takes advantage of this feature, by allowing the user
Packit Service 4684c1
to specify the amount of padding for a particular message. The simplest
Packit Service 4684c1
interface is provided by @funcref{gnutls_record_send2}, and is made
Packit Service 4684c1
available when under TLS1.3; alternatively @funcref{gnutls_record_can_use_length_hiding}
Packit Service 4684c1
can be queried.
Packit Service 4684c1
Packit Service 4684c1
Note that this interface is not sufficient to completely hide the length of the
Packit Service 4684c1
data. The application code may reveal the data transferred by leaking its
Packit Service 4684c1
data processing time, or by leaking the TLS1.3 record processing time by
Packit Service 4684c1
GnuTLS. That is because under TLS1.3 the padding removal time depends on the
Packit Service 4684c1
padding data for an efficient implementation. To make that processing
Packit Service 4684c1
constant time the @funcref{gnutls_init} function must be called with
Packit Service 4684c1
the flag @code{GNUTLS_SAFE_PADDING_CHECK}.
Packit Service 4684c1
Packit Service 4684c1
@showfuncdesc{gnutls_record_send2}
Packit Service 4684c1
Packit Service 4684c1
Older GnuTLS versions provided an API suitable for cases where the sender
Packit Service 4684c1
sends data that are always within a given range. That API is still
Packit Service 4684c1
available, and consists of the following functions.
Packit Service 4684c1
Packit Service 4684c1
@showfuncB{gnutls_record_can_use_length_hiding,gnutls_record_send_range}
Packit Service 4684c1
Packit Service 4684c1
@node The TLS Alert Protocol
Packit Service 4684c1
@section The TLS alert protocol
Packit Service 4684c1
@anchor{The Alert Protocol}
Packit Service 4684c1
@cindex alert protocol
Packit Service 4684c1
Packit Service 4684c1
The alert protocol is there to allow signals to be sent between peers.
Packit Service 4684c1
These signals are mostly used to inform the peer about the cause of a
Packit Service 4684c1
protocol failure. Some of these signals are used internally by the
Packit Service 4684c1
protocol and the application protocol does not have to cope with them
Packit Service 4684c1
(e.g. @code{GNUTLS_@-A_@-CLOSE_@-NOTIFY}), and others refer to the
Packit Service 4684c1
application protocol solely (e.g. @code{GNUTLS_@-A_@-USER_@-CANCELLED}).  An
Packit Service 4684c1
alert signal includes a level indication which may be either fatal or
Packit Service 4684c1
warning (under TLS1.3 all alerts are fatal). Fatal alerts always terminate
Packit Service 4684c1
the current connection, and prevent future re-negotiations using the current
Packit Service 4684c1
session ID. All supported alert messages are summarized in the table below.
Packit Service 4684c1
Packit Service 4684c1
The alert messages are protected by the record protocol, thus the
Packit Service 4684c1
information that is included does not leak. You must take extreme care
Packit Service 4684c1
for the alert information not to leak to a possible attacker, via
Packit Service 4684c1
public log files etc.
Packit Service 4684c1
Packit Service 4684c1
@include alerts.texi
Packit Service 4684c1
Packit Service 4684c1
@node The TLS Handshake Protocol
Packit Service 4684c1
@section The TLS handshake protocol
Packit Service 4684c1
@anchor{The Handshake Protocol}
Packit Service 4684c1
@cindex handshake protocol
Packit Service 4684c1
Packit Service 4684c1
The handshake protocol is responsible for the ciphersuite negotiation,
Packit Service 4684c1
the initial key exchange, and the authentication of the two peers.
Packit Service 4684c1
This is fully controlled by the application layer, thus your program
Packit Service 4684c1
has to set up the required parameters. The main handshake function
Packit Service 4684c1
is @funcref{gnutls_handshake}. In the next paragraphs we elaborate on
Packit Service 4684c1
the handshake protocol, i.e., the ciphersuite negotiation.
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
@menu
Packit Service 4684c1
* TLS Cipher Suites::           TLS session parameters.
Packit Service 4684c1
* Authentication::              TLS authentication.
Packit Service 4684c1
* Client Authentication::       Requesting a certificate from the client.
Packit Service 4684c1
* Resuming Sessions::           Reusing previously established keys.
Packit Service 4684c1
@end menu
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
@node TLS Cipher Suites
Packit Service 4684c1
@subsection TLS ciphersuites
Packit Service 4684c1
Packit Service 4684c1
The TLS cipher suites have slightly different meaning under different
Packit Service 4684c1
protocols. Under @acronym{TLS 1.3}, a cipher suite indicates the symmetric
Packit Service 4684c1
encryption algorithm in use, as well as the pseudo-random function (PRF)
Packit Service 4684c1
used in the TLS session.
Packit Service 4684c1
Packit Service 4684c1
Under TLS 1.2 or early the handshake protocol negotiates cipher suites of
Packit Service 4684c1
a special form illustrated by the @code{TLS_DHE_RSA_WITH_3DES_CBC_SHA} cipher suite name.
Packit Service 4684c1
A typical cipher suite contains these parameters:
Packit Service 4684c1
Packit Service 4684c1
@itemize
Packit Service 4684c1
Packit Service 4684c1
@item The key exchange algorithm.
Packit Service 4684c1
@code{DHE_RSA} in the example.
Packit Service 4684c1
Packit Service 4684c1
@item The Symmetric encryption algorithm and mode
Packit Service 4684c1
@code{3DES_CBC} in this example.
Packit Service 4684c1
Packit Service 4684c1
@item The MAC@footnote{MAC stands for Message Authentication Code. It can be described as a keyed hash algorithm. See RFC2104.} algorithm used for authentication.
Packit Service 4684c1
@code{MAC_SHA} is used in the above example.
Packit Service 4684c1
Packit Service 4684c1
@end itemize
Packit Service 4684c1
Packit Service 4684c1
The cipher suite negotiated in the handshake protocol will affect the
Packit Service 4684c1
record protocol, by enabling encryption and data authentication.  Note
Packit Service 4684c1
that you should not over rely on @acronym{TLS} to negotiate the
Packit Service 4684c1
strongest available cipher suite. Do not enable ciphers and algorithms
Packit Service 4684c1
that you consider weak.
Packit Service 4684c1
Packit Service 4684c1
All the supported ciphersuites are listed in @ref{ciphersuites}.
Packit Service 4684c1
Packit Service 4684c1
@node Authentication
Packit Service 4684c1
@subsection Authentication
Packit Service 4684c1
Packit Service 4684c1
The key exchange algorithms of the @acronym{TLS} protocol offer
Packit Service 4684c1
authentication, which is a prerequisite for a secure connection.
Packit Service 4684c1
The available authentication methods in @acronym{GnuTLS}, under
Packit Service 4684c1
TLS 1.3 or earlier versions, follow.
Packit Service 4684c1
Packit Service 4684c1
@itemize
Packit Service 4684c1
Packit Service 4684c1
@item Certificate authentication: Authenticated key exchange using public key infrastructure and X.509 certificates.
Packit Service 4684c1
@item @acronym{PSK} authentication: Authenticated key exchange using a pre-shared key.
Packit Service 4684c1
Packit Service 4684c1
@end itemize
Packit Service 4684c1
Packit Service 4684c1
Under TLS 1.2 or earlier versions, the following authentication methods
Packit Service 4684c1
are also available.
Packit Service 4684c1
Packit Service 4684c1
@itemize
Packit Service 4684c1
Packit Service 4684c1
@item @acronym{SRP} authentication: Authenticated key exchange using a password.
Packit Service 4684c1
@item Anonymous authentication: Key exchange without peer authentication.
Packit Service 4684c1
Packit Service 4684c1
@end itemize
Packit Service 4684c1
Packit Service 4684c1
@node Client Authentication
Packit Service 4684c1
@subsection Client authentication
Packit Service 4684c1
@cindex client certificate authentication
Packit Service 4684c1
Packit Service 4684c1
In the case of ciphersuites that use certificate authentication, the
Packit Service 4684c1
authentication of the client is optional in @acronym{TLS}.  A server
Packit Service 4684c1
may request a certificate from the client using the
Packit Service 4684c1
@funcref{gnutls_certificate_server_set_request} function. We elaborate
Packit Service 4684c1
in @ref{Certificate credentials}.
Packit Service 4684c1
Packit Service 4684c1
@node Resuming Sessions
Packit Service 4684c1
@subsection Resuming sessions
Packit Service 4684c1
@anchor{resume}
Packit Service 4684c1
@cindex resuming sessions
Packit Service 4684c1
@cindex session resumption
Packit Service 4684c1
Packit Service 4684c1
The TLS handshake process performs expensive calculations
Packit Service 4684c1
and a busy server might easily be put under load. To
Packit Service 4684c1
reduce the load, session resumption may be used. This
Packit Service 4684c1
is a feature of the @acronym{TLS} protocol which allows a
Packit Service 4684c1
client to connect to a server after a successful handshake, without
Packit Service 4684c1
the expensive calculations.  This is achieved by re-using the previously
Packit Service 4684c1
established keys, meaning the server needs to store the state of established
Packit Service 4684c1
connections (unless session tickets are used -- @ref{Session tickets}).
Packit Service 4684c1
Packit Service 4684c1
Session resumption is an integral part of @acronym{GnuTLS}, and
Packit Service 4684c1
@ref{Session resumption}, @ref{ex-resume-client} illustrate typical
Packit Service 4684c1
uses of it.
Packit Service 4684c1
Packit Service 4684c1
@node TLS Extensions
Packit Service 4684c1
@section TLS extensions
Packit Service 4684c1
@cindex TLS extensions
Packit Service 4684c1
Packit Service 4684c1
A number of extensions to the @acronym{TLS} protocol have been
Packit Service 4684c1
proposed mainly in @xcite{TLSEXT}. The extensions supported
Packit Service 4684c1
in @acronym{GnuTLS} are discussed in the subsections that follow.
Packit Service 4684c1
Packit Service 4684c1
@menu
Packit Service 4684c1
* Maximum fragment length negotiation::
Packit Service 4684c1
* Server name indication::
Packit Service 4684c1
* Session tickets::
Packit Service 4684c1
* HeartBeat::
Packit Service 4684c1
* Safe renegotiation::
Packit Service 4684c1
* OCSP status request::
Packit Service 4684c1
* SRTP::
Packit Service 4684c1
* False Start::
Packit Service 4684c1
* Application Layer Protocol Negotiation (ALPN)::
Packit Service 4684c1
* Extensions and Supplemental Data::
Packit Service 4684c1
@end menu
Packit Service 4684c1
Packit Service 4684c1
@node Maximum fragment length negotiation
Packit Service 4684c1
@subsection Maximum fragment length negotiation
Packit Service 4684c1
@cindex TLS extensions
Packit Service 4684c1
@cindex maximum fragment length
Packit Service 4684c1
Packit Service 4684c1
This extension allows a @acronym{TLS} implementation to negotiate a
Packit Service 4684c1
smaller value for record packet maximum length. This extension may be
Packit Service 4684c1
useful to clients with constrained capabilities. The functions shown
Packit Service 4684c1
below can be used to control this extension.
Packit Service 4684c1
Packit Service 4684c1
@showfuncB{gnutls_record_get_max_size,gnutls_record_set_max_size}
Packit Service 4684c1
Packit Service 4684c1
@node Server name indication
Packit Service 4684c1
@subsection Server name indication
Packit Service 4684c1
@anchor{serverind}
Packit Service 4684c1
@cindex TLS extensions
Packit Service 4684c1
@cindex server name indication
Packit Service 4684c1
Packit Service 4684c1
A common problem in @acronym{HTTPS} servers is the fact that the
Packit Service 4684c1
@acronym{TLS} protocol is not aware of the hostname that a client
Packit Service 4684c1
connects to, when the handshake procedure begins. For that reason the
Packit Service 4684c1
@acronym{TLS} server has no way to know which certificate to send.
Packit Service 4684c1
Packit Service 4684c1
This extension solves that problem within the @acronym{TLS} protocol,
Packit Service 4684c1
and allows a client to send the HTTP hostname before the handshake
Packit Service 4684c1
begins within the first handshake packet.  The functions
Packit Service 4684c1
@funcref{gnutls_server_name_set} and @funcref{gnutls_server_name_get} can be
Packit Service 4684c1
used to enable this extension, or to retrieve the name sent by a
Packit Service 4684c1
client.
Packit Service 4684c1
Packit Service 4684c1
@showfuncB{gnutls_server_name_set,gnutls_server_name_get}
Packit Service 4684c1
Packit Service 4684c1
@node Session tickets
Packit Service 4684c1
@subsection Session tickets
Packit Service 4684c1
@cindex TLS extensions
Packit Service 4684c1
@cindex session tickets
Packit Service 4684c1
@cindex tickets
Packit Service 4684c1
Packit Service 4684c1
To resume a TLS session, the server normally stores session parameters.  This
Packit Service 4684c1
complicates deployment, and can be avoided by delegating the storage
Packit Service 4684c1
to the client. Because session parameters are sensitive they are encrypted
Packit Service 4684c1
and authenticated with a key only known to the server and then sent to the
Packit Service 4684c1
client. The Session Tickets extension is described in RFC 5077 @xcite{TLSTKT}.
Packit Service 4684c1
Packit Service 4684c1
A disadvantage of session tickets is that they eliminate the effects of
Packit Service 4684c1
forward secrecy when a server uses the same key for long time. That is,
Packit Service 4684c1
the secrecy of all sessions on a server using tickets depends on the ticket
Packit Service 4684c1
key being kept secret. For that reason server keys should be rotated and discarded
Packit Service 4684c1
regularly.
Packit Service 4684c1
Packit Service 4684c1
Since version 3.1.3 GnuTLS clients transparently support session tickets,
Packit Service 4684c1
unless forward secrecy is explicitly requested (with the PFS priority string).
Packit Service 4684c1
Packit Service 4684c1
Under TLS 1.3 session tickets are mandatory for session resumption, and they
Packit Service 4684c1
do not share the forward secrecy concerns as with TLS 1.2 or earlier.
Packit Service 4684c1
Packit Service 4684c1
@node HeartBeat
Packit Service 4684c1
@subsection HeartBeat
Packit Service 4684c1
@cindex TLS extensions
Packit Service 4684c1
@cindex heartbeat
Packit Service 4684c1
Packit Service 4684c1
This is a TLS extension that allows to ping and receive confirmation from the peer,
Packit Service 4684c1
and is described in @xcite{RFC6520}. The extension is disabled by default and
Packit Service 4684c1
@funcref{gnutls_heartbeat_enable} can be used to enable it. A policy
Packit Service 4684c1
may be negotiated to only allow sending heartbeat messages or sending and receiving.
Packit Service 4684c1
The current session policy can be checked with @funcref{gnutls_heartbeat_allowed}.
Packit Service 4684c1
The requests coming from the peer result to @code{GNUTLS_@-E_@-HEARTBEAT_@-PING_@-RECEIVED}
Packit Service 4684c1
being returned from the receive function. Ping requests to peer can be send via
Packit Service 4684c1
@funcref{gnutls_heartbeat_ping}.
Packit Service 4684c1
Packit Service 4684c1
@showfuncB{gnutls_heartbeat_allowed,gnutls_heartbeat_enable}
Packit Service 4684c1
Packit Service 4684c1
@showfuncD{gnutls_heartbeat_ping,gnutls_heartbeat_pong,gnutls_heartbeat_set_timeouts,gnutls_heartbeat_get_timeout}
Packit Service 4684c1
Packit Service 4684c1
@node Safe renegotiation
Packit Service 4684c1
@subsection Safe renegotiation
Packit Service 4684c1
@cindex renegotiation
Packit Service 4684c1
@cindex safe renegotiation
Packit Service 4684c1
Packit Service 4684c1
TLS gives the option to two communicating parties to renegotiate
Packit Service 4684c1
and update their security parameters. One useful example of this feature
Packit Service 4684c1
was for a client to initially connect using anonymous negotiation to a
Packit Service 4684c1
server, and the renegotiate using some authenticated ciphersuite. This occurred
Packit Service 4684c1
to avoid having the client sending its credentials in the clear.
Packit Service 4684c1
Packit Service 4684c1
However this renegotiation, as initially designed would not ensure that
Packit Service 4684c1
the party one is renegotiating is the same as the one in the initial negotiation.
Packit Service 4684c1
For example one server could forward all renegotiation traffic to an other
Packit Service 4684c1
server who will see this traffic as an initial negotiation attempt.
Packit Service 4684c1
Packit Service 4684c1
This might be seen as a valid design decision, but it seems it was
Packit Service 4684c1
not widely known or understood, thus today some application protocols use the TLS
Packit Service 4684c1
renegotiation feature in a manner that enables a malicious server to insert
Packit Service 4684c1
content of his choice in the beginning of a TLS session.
Packit Service 4684c1
Packit Service 4684c1
The most prominent vulnerability was with HTTPS. There servers request
Packit Service 4684c1
a renegotiation to enforce an anonymous user to use a certificate in order
Packit Service 4684c1
to access certain parts of a web site.  The
Packit Service 4684c1
attack works by having the attacker simulate a client and connect to a
Packit Service 4684c1
server, with server-only authentication, and send some data intended
Packit Service 4684c1
to cause harm.  The server will then require renegotiation from him
Packit Service 4684c1
in order to perform the request.
Packit Service 4684c1
When the proper client attempts to contact the server,
Packit Service 4684c1
the attacker hijacks that connection and forwards traffic to
Packit Service 4684c1
the initial server that requested renegotiation.  The
Packit Service 4684c1
attacker will not be able to read the data exchanged between the
Packit Service 4684c1
client and the server.  However, the server will (incorrectly) assume
Packit Service 4684c1
that the initial request sent by the attacker was sent by the now authenticated
Packit Service 4684c1
client.  The result is a prefix plain-text injection attack.
Packit Service 4684c1
Packit Service 4684c1
The above is just one example.  Other vulnerabilities exists that do
Packit Service 4684c1
not rely on the TLS renegotiation to change the client's authenticated
Packit Service 4684c1
status (either TLS or application layer).
Packit Service 4684c1
Packit Service 4684c1
While fixing these application protocols and implementations would be
Packit Service 4684c1
one natural reaction, an extension to TLS has been designed that
Packit Service 4684c1
cryptographically binds together any renegotiated handshakes with the
Packit Service 4684c1
initial negotiation.  When the extension is used, the attack is
Packit Service 4684c1
detected and the session can be terminated.  The extension is
Packit Service 4684c1
specified in @xcite{RFC5746}.
Packit Service 4684c1
Packit Service 4684c1
GnuTLS supports the safe renegotiation extension.  The default
Packit Service 4684c1
behavior is as follows.  Clients will attempt to negotiate the safe
Packit Service 4684c1
renegotiation extension when talking to servers.  Servers will accept
Packit Service 4684c1
the extension when presented by clients.  Clients and servers will
Packit Service 4684c1
permit an initial handshake to complete even when the other side does
Packit Service 4684c1
not support the safe renegotiation extension.  Clients and servers
Packit Service 4684c1
will refuse renegotiation attempts when the extension has not been
Packit Service 4684c1
negotiated.
Packit Service 4684c1
Packit Service 4684c1
Note that permitting clients to connect to servers when the safe
Packit Service 4684c1
renegotiation extension is not enabled, is open up for attacks.
Packit Service 4684c1
Changing this default behavior would prevent interoperability against
Packit Service 4684c1
the majority of deployed servers out there.  We will reconsider this
Packit Service 4684c1
default behavior in the future when more servers have been upgraded.
Packit Service 4684c1
Note that it is easy to configure clients to always require the safe
Packit Service 4684c1
renegotiation extension from servers.
Packit Service 4684c1
Packit Service 4684c1
To modify the default behavior, we have introduced some new priority
Packit Service 4684c1
strings (see @ref{Priority Strings}).
Packit Service 4684c1
The @code{%UNSAFE_RENEGOTIATION} priority string permits
Packit Service 4684c1
(re-)handshakes even when the safe renegotiation extension was not
Packit Service 4684c1
negotiated. The default behavior is @code{%PARTIAL_RENEGOTIATION} that will
Packit Service 4684c1
prevent renegotiation with clients and servers not supporting the
Packit Service 4684c1
extension. This is secure for servers but leaves clients vulnerable
Packit Service 4684c1
to some attacks, but this is a trade-off between security and compatibility
Packit Service 4684c1
with old servers. The @code{%SAFE_RENEGOTIATION} priority string makes
Packit Service 4684c1
clients and servers require the extension for every handshake. The latter
Packit Service 4684c1
is the most secure option for clients, at the cost of not being able
Packit Service 4684c1
to connect to legacy servers. Servers will also deny clients that
Packit Service 4684c1
do not support the extension from connecting.
Packit Service 4684c1
Packit Service 4684c1
It is possible to disable use of the extension completely, in both
Packit Service 4684c1
clients and servers, by using the @code{%DISABLE_SAFE_RENEGOTIATION}
Packit Service 4684c1
priority string however we strongly recommend you to only do this for
Packit Service 4684c1
debugging and test purposes.
Packit Service 4684c1
Packit Service 4684c1
The default values if the flags above are not specified are:
Packit Service 4684c1
@table @code
Packit Service 4684c1
Packit Service 4684c1
@item Server:
Packit Service 4684c1
%PARTIAL_RENEGOTIATION
Packit Service 4684c1
Packit Service 4684c1
@item Client:
Packit Service 4684c1
%PARTIAL_RENEGOTIATION
Packit Service 4684c1
Packit Service 4684c1
@end table
Packit Service 4684c1
Packit Service 4684c1
For applications we have introduced a new API related to safe
Packit Service 4684c1
renegotiation.  The @funcref{gnutls_safe_renegotiation_status} function is
Packit Service 4684c1
used to check if the extension has been negotiated on a session, and
Packit Service 4684c1
can be used both by clients and servers.
Packit Service 4684c1
Packit Service 4684c1
@node OCSP status request
Packit Service 4684c1
@subsection OCSP status request
Packit Service 4684c1
@cindex OCSP status request
Packit Service 4684c1
@cindex Certificate status request
Packit Service 4684c1
Packit Service 4684c1
The Online Certificate Status Protocol (OCSP) is a protocol that allows the
Packit Service 4684c1
client to verify the server certificate for revocation without messing with
Packit Service 4684c1
certificate revocation lists. Its drawback is that it requires the client
Packit Service 4684c1
to connect to the server's CA OCSP server and request the status of the
Packit Service 4684c1
certificate. This extension however, enables a TLS server to include
Packit Service 4684c1
its CA OCSP server response in the handshake. That is an HTTPS server
Packit Service 4684c1
may periodically run @code{ocsptool} (see @ref{ocsptool Invocation}) to obtain
Packit Service 4684c1
its certificate revocation status and serve it to the clients. That
Packit Service 4684c1
way a client avoids an additional connection to the OCSP server.
Packit Service 4684c1
Packit Service 4684c1
See @ref{OCSP stapling} for further information.
Packit Service 4684c1
Packit Service 4684c1
Since version 3.1.3 GnuTLS clients transparently support the certificate status
Packit Service 4684c1
request.
Packit Service 4684c1
Packit Service 4684c1
@node SRTP
Packit Service 4684c1
@subsection SRTP
Packit Service 4684c1
@cindex SRTP
Packit Service 4684c1
@cindex Secure RTP
Packit Service 4684c1
Packit Service 4684c1
The TLS protocol was extended in @xcite{RFC5764} to provide keying material to the
Packit Service 4684c1
Secure RTP (SRTP) protocol. The SRTP protocol provides an encapsulation of encrypted
Packit Service 4684c1
data that is optimized for voice data. With the SRTP TLS extension two peers can
Packit Service 4684c1
negotiate keys using TLS or DTLS and obtain keying material for use with SRTP. The
Packit Service 4684c1
available SRTP profiles are listed below.
Packit Service 4684c1
Packit Service 4684c1
@showenumdesc{gnutls_srtp_profile_t,Supported SRTP profiles}
Packit Service 4684c1
Packit Service 4684c1
To enable use the following functions.
Packit Service 4684c1
Packit Service 4684c1
@showfuncB{gnutls_srtp_set_profile,gnutls_srtp_set_profile_direct}
Packit Service 4684c1
Packit Service 4684c1
To obtain the negotiated keys use the function below.
Packit Service 4684c1
Packit Service 4684c1
@showfuncdesc{gnutls_srtp_get_keys}
Packit Service 4684c1
Packit Service 4684c1
Other helper functions are listed below.
Packit Service 4684c1
Packit Service 4684c1
@showfuncC{gnutls_srtp_get_selected_profile,gnutls_srtp_get_profile_name,gnutls_srtp_get_profile_id}
Packit Service 4684c1
Packit Service 4684c1
@node False Start
Packit Service 4684c1
@subsection False Start
Packit Service 4684c1
@cindex False Start
Packit Service 4684c1
@cindex TLS False Start
Packit Service 4684c1
Packit Service 4684c1
The TLS protocol was extended in @xcite{RFC7918} to allow the client
Packit Service 4684c1
to send data to server in a single round trip. This change however operates on the borderline
Packit Service 4684c1
of the TLS protocol security guarantees and should be used for the cases where the reduced
Packit Service 4684c1
latency outperforms the risk of an adversary intercepting the transferred data. In GnuTLS
Packit Service 4684c1
applications can use the @acronym{GNUTLS_ENABLE_FALSE_START} as option to @funcref{gnutls_init}
Packit Service 4684c1
to request an early return of the @funcref{gnutls_handshake} function. After that early
Packit Service 4684c1
return the application is expected to transfer any data to be piggybacked on the last handshake
Packit Service 4684c1
message.
Packit Service 4684c1
Packit Service 4684c1
After handshake's early termination, the application is expected to transmit
Packit Service 4684c1
data using @funcref{gnutls_record_send}, and call @funcref{gnutls_record_recv} on
Packit Service 4684c1
any received data as soon, to ensure that handshake completes timely. That is, especially
Packit Service 4684c1
relevant for applications which set an explicit time limit for the handshake process
Packit Service 4684c1
via @funcref{gnutls_handshake_set_timeout}.
Packit Service 4684c1
Packit Service 4684c1
Note however, that the API ensures that the early return will not happen
Packit Service 4684c1
if the false start requirements are not satisfied. That is, on ciphersuites which are not
Packit Service 4684c1
whitelisted for false start or on insufficient key sizes, the handshake
Packit Service 4684c1
process will complete properly (i.e., no early return). To verify that false start was used you
Packit Service 4684c1
may use @funcref{gnutls_session_get_flags} and check for the @acronym{GNUTLS_SFLAGS_FALSE_START}
Packit Service 4684c1
flag. For GnuTLS the false start is whitelisted for the following
Packit Service 4684c1
key exchange methods (see @xcite{RFC7918} for rationale)
Packit Service 4684c1
@itemize
Packit Service 4684c1
@item DHE
Packit Service 4684c1
@item ECDHE
Packit Service 4684c1
@end itemize
Packit Service 4684c1
but only when the negotiated parameters exceed @code{GNUTLS_SEC_PARAM_HIGH}
Packit Service 4684c1
--see @ref{tab:key-sizes}, and when under (D)TLS 1.2 or later.
Packit Service 4684c1
Packit Service 4684c1
@node Application Layer Protocol Negotiation (ALPN)
Packit Service 4684c1
@subsection Application Layer Protocol Negotiation (ALPN)
Packit Service 4684c1
@cindex ALPN
Packit Service 4684c1
@cindex Application Layer Protocol Negotiation
Packit Service 4684c1
Packit Service 4684c1
The TLS protocol was extended in @code{RFC7301}
Packit Service 4684c1
to provide the application layer a method of
Packit Service 4684c1
negotiating the application protocol version. This allows for negotiation
Packit Service 4684c1
of the application protocol during the TLS handshake, thus reducing
Packit Service 4684c1
round-trips. The application protocol is described by an opaque
Packit Service 4684c1
string. To enable, use the following functions.
Packit Service 4684c1
Packit Service 4684c1
@showfuncB{gnutls_alpn_set_protocols,gnutls_alpn_get_selected_protocol}
Packit Service 4684c1
Packit Service 4684c1
Note that these functions are intended to be used with protocols that are
Packit Service 4684c1
registered in the Application Layer Protocol Negotiation IANA registry. While
Packit Service 4684c1
you can use them for other protocols (at the risk of collisions), it is preferable
Packit Service 4684c1
to register them.
Packit Service 4684c1
Packit Service 4684c1
@node Extensions and Supplemental Data
Packit Service 4684c1
@subsection Extensions and Supplemental Data
Packit Service 4684c1
@cindex Supplemental data
Packit Service 4684c1
Packit Service 4684c1
It is possible to transfer supplemental data during the TLS handshake, following
Packit Service 4684c1
@xcite{RFC4680}. This is for "custom" protocol modifications for applications which
Packit Service 4684c1
may want to transfer additional data (e.g. additional authentication messages). Such
Packit Service 4684c1
an exchange requires a custom extension to be registered.
Packit Service 4684c1
The provided API for this functionality is low-level and described in @ref{TLS Hello Extension Handling}.
Packit Service 4684c1
Packit Service 4684c1
@include sec-tls-app.texi
Packit Service 4684c1
Packit Service 4684c1
@node On SSL 2 and older protocols
Packit Service 4684c1
@section On SSL 2 and older protocols
Packit Service 4684c1
@cindex SSL 2
Packit Service 4684c1
Packit Service 4684c1
One of the initial decisions in the @acronym{GnuTLS} development was
Packit Service 4684c1
to implement the known security protocols for the transport layer.
Packit Service 4684c1
Initially @acronym{TLS} 1.0 was implemented since it was the latest at
Packit Service 4684c1
that time, and was considered to be the most advanced in security
Packit Service 4684c1
properties.  Later the @acronym{SSL} 3.0 protocol was implemented
Packit Service 4684c1
since it is still the only protocol supported by several servers and
Packit Service 4684c1
there are no serious security vulnerabilities known.
Packit Service 4684c1
Packit Service 4684c1
One question that may arise is why we didn't implement @acronym{SSL}
Packit Service 4684c1
2.0 in the library.  There are several reasons, most important being
Packit Service 4684c1
that it has serious security flaws, unacceptable for a modern security
Packit Service 4684c1
library.  Other than that, this protocol is barely used by anyone
Packit Service 4684c1
these days since it has been deprecated since 1996.  The security
Packit Service 4684c1
problems in @acronym{SSL} 2.0 include:
Packit Service 4684c1
Packit Service 4684c1
@itemize
Packit Service 4684c1
Packit Service 4684c1
@item Message integrity compromised.
Packit Service 4684c1
The @acronym{SSLv2} message authentication uses the MD5 function, and
Packit Service 4684c1
is insecure.
Packit Service 4684c1
Packit Service 4684c1
@item Man-in-the-middle attack.
Packit Service 4684c1
There is no protection of the handshake in @acronym{SSLv2}, which
Packit Service 4684c1
permits a man-in-the-middle attack.
Packit Service 4684c1
Packit Service 4684c1
@item Truncation attack.
Packit Service 4684c1
@acronym{SSLv2} relies on TCP FIN to close the session, so the
Packit Service 4684c1
attacker can forge a TCP FIN, and the peer cannot tell if it was a
Packit Service 4684c1
legitimate end of data or not.
Packit Service 4684c1
Packit Service 4684c1
@item Weak message integrity for export ciphers.
Packit Service 4684c1
The cryptographic keys in @acronym{SSLv2} are used for both message
Packit Service 4684c1
authentication and encryption, so if weak encryption schemes are
Packit Service 4684c1
negotiated (say 40-bit keys) the message authentication code uses the
Packit Service 4684c1
same weak key, which isn't necessary.
Packit Service 4684c1
Packit Service 4684c1
@end itemize
Packit Service 4684c1
Packit Service 4684c1
@cindex PCT
Packit Service 4684c1
Other protocols such as Microsoft's @acronym{PCT} 1 and @acronym{PCT}
Packit Service 4684c1
2 were not implemented because they were also abandoned and deprecated
Packit Service 4684c1
by @acronym{SSL} 3.0 and later @acronym{TLS} 1.0.
Packit Service 4684c1
Packit Service 4684c1