TLS and DTLS: A Tale of Two Protocols Kenny Paterson: Information Security Group
TLS and DTLS: A Tale of Two Protocols Kenny Paterson: Information Security Group
Kenny Paterson
2
TLS Overview
• SSL = Secure Sockets Layer.
– Developed by Netscape
– SSLv3 still widely supported
• TLS = Transport Layer Security.
– IETF-standardised version of SSL.
– TLS 1.0=SSLv3 with minor tweaks, RFC 2246 (1999).
– TLS 1.1=TLS 1.0 + tweaks, RFC 4346 (2006).
– TLS 1.2=TLS 1.1 + more tweaks, RFC 5246 (2008).
• SSL/TLS provides security ‘at TCP layer’.
– Runs over TCP, using TCP to provide reliable, end-to-end
transport.
– Widely deployed in Web browsers and servers to support
‘secure e-commerce’ over HTTP.
3
TLS Protocol Architecture
Change
Handshake Alert HTTP,
Cipher
Protocol Protocol other apps
Spec
Protocol
Record Protocol
TCP
4
TLS Record Protocol
• TLS Record Protocol provides:
– Data origin authentication and integrity using a MAC.
– Confidentiality using a symmetric encryption
algorithm.
– Anti-replay using sequence numbers protected by
the MAC.
• Keys for the algorithms are supplied by the TLS
Handshake Protocol.
– A complex protocol which we will henceforth ignore.
5
TLS Record Protocol: MAC-Encode-Encrypt
SQN + Payload
other data
MAC
Encrypt
Header Ciphertext
6
TLS Record Processing
1. Decrypt;
2. Remove padding;
3. Check MAC on header data, sequence number and
plaintext.
7
Outline
8
DTLS Overview
• DTLS = Datagram Transport Layer Security.
– A tweak to TLS.
– Runs over UDP, using UDP to provide end-to-end transport.
– Becoming more widely used, e.g. Cisco VPN products.
• Some modifications to TLS are needed to handle unreliable
nature of UDP.
– Allow for retransmission of handshake messages.
– Allow out-of-order arrival of messages.
• Use explicit sequence numbers rather than implicit sequence numbers and keep
a sliding window of received messages.
– Tolerance of errors during decryption, but no error messages and
no session termination.
• Versions:
– DTLS 1.0, based on TLS 1.1, RFC 4347 (2006).
– DTLS 1.2, based on TLS 1.2, RFC 6347 (2012).
9
DTLS Protocol Architecture
Change
Handshake Alert HTTP,
Cipher
Protocol Protocol other apps
Spec
Protocol
UDP
10
CBC Mode in TLS and DTLS
12
Attacking Predictable IVs
Pb
eK
C0 C1
14
Attacking Predictable IVs
Pb P0⊕C0⊕C1
eK eK
C0 C1 C2
15
Attacking Predictable IVs
Pb P0⊕C0⊕C1
eK eK
C0 C1 C2
17
Preventing Predictable IVs
(source: Wikipedia)
21
TLS Record Protocol: Padding
SQN + Payload
other data
MAC
Encrypt
Header Ciphertext
22
TLS Record Protocol Padding
23
SSL/TLS Record Protocol Padding
• Security?
24
Handling Padding During Decryption
26
Attack Based on Distinguishable Errors
27
Attack Based on Distinguishable Errors
Check
Valid/Invalid
padding of P
Ct-1 Ct
dK dK
Pt-1 Pt
30
Padding Oracle Attack for TLS
C
Rt-1 Ct
Revealing value of
dK(Ct) in last byte
here (R ⊕ 00 )
dK dK
Recovering true
plaintext byte here
Ct-1 ⊕ R ⊕ 00
Pt-1 Pt
Eventually produces
valid pad 00 here
31
Padding Oracle Attack for TLS
R Ct Revealing value of
dK(Ct) in second last
byte here (R ⊕ 01 )
dK dK
Eventually produces
valid pattern 01 01 here
32
Padding Oracle Attack for TLS
33
TLS Padding Oracles In Practice?
34
TLS Padding Oracles In Practice?
Good news (for the attacker):
• The error messages arising in TLS 1.0 are
different:
– bad_record_mac
– decryption_failed
Bad news:
• But they are encrypted, so cannot be seen by
the attacker.
• And an error of either type is fatal, leading to
the TLS session being terminated.
35
TLS Padding Oracles In Practice?
Canvel et al. [CHVV03] :
• But a MAC failure error message is likely to
appear on the network later than a padding
failure error message.
– Because MAC only checked if padding fails.
• So timing the appearance of error messages
can give us the required padding oracle.
• Because the errors are fatal, the attacker can
only learn one byte of plaintext, and then with
probability 1/256.
36
OpenSSL and Padding Oracles
37
Preventing Padding Oracle Attacks
38
Outline
39
Breaking DTLS in OpenSSL
41
Breaking DTLS in OpenSSL
Attack Heartbeat
packet packet
Heartbeat
response
Heartbeat
response
44
Experimental Results
46
Impact – OpenSSL
OpenSSL Security Advisory [04 Jan 2012]
======================================
DTLS Plaintext Recovery Attack (CVE-2011-4108)
==============================================
Nadhem Alfardan and Kenny Paterson have discovered an extension of the
Vaudenay padding oracle attack on CBC mode encryption which enables an
efficient plaintext recovery attack against the OpenSSL implementation of DTLS.
Their attack exploits timing differences arising during decryption processing. A
research paper describing this attack can be found at http://www.isg.rhul.ac.uk/
~kp/dtls.pdf
GNUTLS-SA-2012-1 (CVE-2012-0390)
48
Impact!
49
Outline
50
Back to TLS
Practical
attacks
exist!!! eK eK
C0 C1 C2
53
A Positive Security Result for TLS
Secure in
the LHAE
model eK eK eK
C0 C1 C2 C3
54
A New Attack [PRS11]
K
C C K
Byte 13 is hex
No 134 1316
for ‘19’
eK eK
C0 C1 C2
Byte 12 is hex
C0 = C0 ⊕ 0012104 Yes 123 1216
for ‘18’
C = C0 C1 eK eK
C0 C1 C2
56
MAC length t = 80, block length n = 128
No 034 1316
eK eK Decrypts
fine to No
C0 C1 C2
C = C0 C1 eK eK
C0 C1 C2
57
MAC length t = 80, block length n = 128
No 034 1316
eK eK Decrypts
fine to No
C0 C1 C2
eK eK
C0 C1 C2
59
Where Does the Attack apply?
Attack applies!
eK eK
C0 C1 C2
60
Characteristics of the Attack
61
Consequences of the Attack
62
Outline
63
Authenticated Encryption (AE)
Security
C <- E( K, M1 ) M <- Dec( C ) C <- E( K, M0 )
Ret C Ret M Ret C
Ret !
M0 , M1 C M0 , M1 C
64
Length-hiding Authenticated
Encryption (LHAE) Security
C1 <- E( K, L, M1 ) M <- Dec( C ) C1 <- E( K, L, M1 )
C0 <- E( K, L, M0 ) Ret M C0 <- E( K, L, M0 ) Ret !
If C0 = !or C1 = ! If C0 = !or C1 = !
Ret ! Ret !
Ret C1 Ret C0
C
C
L,
M0,
M1
L,
M0,
M1
eK eK eK
C0 C1 C2 C3
No 134 1316
eK eK
C0 C1 C2
67
Collision-Resistant Decryption Security
This is exactly the gap between INT-PTXT and INT-CTXT
INT-CTXT INT-PTXT + CRD
No 034 1316
eK eK
C0 C1 C2
eK eK eK
C0 C1 C2 C3 69
Updated Security Analyses of MEE in TLS
Encode
In(security)
Restric2ons
Tag
must
fill
exactly
IND-‐CPA
+
Easy
extension
to
[K00]
Concatena2on
one
block;
random
INT-‐CTXT
IVs
[Rogaway/Dai/Moeller
Dis2nguishing
aUack/
Chained
IVs;
chosen
2002];
Any
plaintext
recovery
plaintexts
[Duong-‐Rizzo
2011]
aUack
Dis2nct
error
Plaintext
recovery
[V02]/[CHVV03]
TLS
padding
messages/2ming
aUack
side
channel
Minimal-‐length
Secure
channel
padding
only;
[MT10]
Any
func%on
(construc2ve
crypto
uniform
errors;
framework
)
random
IVs
Practical
attacks
exist eK eK
C0 C1 C2
Secure in
our LHAE
model eK eK eK
C0 C1 C2 C3
71
Outline
72
TLS and Complexity
• TLS is now part of the “critical infrastructure” of
the Internet, but we still don’t fully understand its
security.
• TLS continues to evolve and get more complex.
– DTLS.
– TLS extensions.
– New ciphersuites; PSK, GCM, ECC,…
– TLS Handshake Protocol options.
– Renegotiation/resumption.
– Ad hoc design proposals are rife on TLS mailing list.
• But complexity is the enemy of security.
73
Lessons Learned
• MAC-Encode-Encrypt is hard to implement securely and
hard to analyse.
– Maybe there are still some surprises in store!?
• Ignore theoretical attacks at your peril!
– Rogaway’s 1995 observation was largely ignored until a “real”
attack was presented in 2011.
– Attacks tend to improve with age.
• Desire to support legacy and backwards compatibility
hampers the adoption of better cryptographic
alternatives.
• TLS is late 20th century technology.
– Tried and trusted?
– Or obsolete, and a moving target as a consequence?
74
Literature
75