Bulletproof Tls Guide 20240531 b127
Bulletproof Tls Guide 20240531 b127
TLS Guide
Ivan Ristić
Bulletproof TLS Guide
by Ivan Ristić
Version 2023.1 (build 127), published in May 2024.
Copyright © 2023 Feisty Duck Limited. All rights reserved.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or
by any means, without the prior permission in writing of the publisher.
The author and publisher have taken care in preparation of this book, but make no expressed or implied warranty of any kind
and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in con-
nection with or arising out of the use of the information or programs contained herein.
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
1. Configuration Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Private Keys and Certificates 1
Use Strong Private Keys 1
Secure Your Private Keys 1
Choose the Right Certification Authority 3
Prevent Certificate Warnings 4
Control Key and Certificate Sharing 4
Think Chains, Not Certificates 5
Deploy Certification Authority Authorization 5
Automate Certificate Renewal 5
Use Certificate Transparency Monitoring 6
Configuration 6
Use Secure Protocols 6
Use Forward Secrecy 7
Use a Strong Key Exchange 8
Prioritize the Best Cipher Suites 8
Use Secure Cipher Suites 8
Ensure Ticket Keys Are Rotated 10
Mitigate Known Problems 11
Supporting Legacy Platforms 11
HTTP and Application Security 12
Encrypt Everything 12
Secure Cookies 13
Use Strict Transport Security 14
Deploy Content Security Policy 15
Disable Caching 15
Be Aware of Issues with HTTP Compression 15
Understand and Acknowledge Third-Party Trust 16
iii
Performance 16
Don’t Use Too Much Security 16
Enable Session Resumption 17
Optimize Connection Management 17
Enable Caching of Nonsensitive Content 18
Use Fast Cryptographic Primitives 18
Validate and Monitor 19
iv
Preface
Our journey to achieving good network transport security has been long and fraught with
difficulties. In the 1990s—when this story began with the early versions of SSL and the
Netscape browser—the main challenges were lack of good encryption standards, restric-
tions on the export of cryptography, and insufficiently powerful computer chips. It took us a
good three decades to work through these problems. During that period, a few things im-
proved. The export restrictions went away and computers became faster. A few other things
became worse, chiefly because the web platform continued to evolve organically without
sufficient thought given to security.
But we collectively kept chipping away at the problems, eventually figuring out what secure
network protocols should look like and what kind of security we’d like to have. We figured
out that we don’t have to configure each and every server individually and that we can in-
stead rely on the secure and sane defaults now available. We also figured out that we don’t
need to manually rotate every single certificate and that automation can achieve much bet-
ter results with far less time and effort.
At some point, the threads of our progress started to converge, and there is now a feeling
that transport security is within our reach. Your reach. Things are significantly better, but
we’re not quite there just yet. The field remains complex and filled with many moving parts
that need to be accounted for. Some assembly is required.
The guide that’s in front of you has been designed to get you over the finish line. If you fol-
low the assembly instructions specified herein, you will be able to deploy TLS and PKI with
confidence. Yes, there will still be things you’ll need to figure out, but the path should at
least be predictable and easy to follow.
I have been involved with SSL/TLS and PKI in some form since the early days, but especial-
ly in the last two decades, focusing my efforts on what I sometimes like to call the last mile
of transport security. My work consisted chiefly of researching the field and communicating
my findings in various forms.
For example, SSL Labs, one of my earlier projects, provided free assessments of SSL/TLS and
PKI configuration and ended up being fairly successful. It happened to be right there when
v
the world decided to start caring about such things, roughly around the time of Heartbleed.
(Look it up.) In the end, SSL Labs helped improve the security of millions of web sites, and
I’m very happy with that. These days, you’re probably better off taking a look at my follow-
up project, Hardenize, which helps with problems related to a wider range of network and
security standards.
Most of what I learned has been recorded in my book Bulletproof TLS and PKI, which I’ve
been continuously writing and publishing for about a decade now. You should definitely
read it if you’re involved with computer security, software development, or system adminis-
tration. But even if you don’t have time for that, this guide will tell you everything you need
to know. In fact, this guide has been taken directly from my book and published stand-alone
for the very purpose of being easily available to a large audience.
—Ivan Ristić
vi Preface
1 Configuration Guide
Private Keys and Certificates
Private keys are the cornerstone of TLS security, but also one of the easier things to get
right. These days, CAs aren’t allowed to issue certificates against weak keys. But despite fre-
quent focus on key sizes, the weakest link is usually key management, or the job of keeping
the private keys private. We’ll touch upon that in this section. Equally important are certifi-
cates, which build upon the keys with important metadata, such as the permission to asso-
ciate a certificate with a particular domain name.
1
gest that the most successful attacks bypass encryption rather than break it. If someone can
break into your server and steal your private key or otherwise compel you to disclose the
key, why would they bother with brute-force attacks against cryptography?
Keep your private keys private
Treat your private keys as an important asset, restricting access to the smallest possi-
ble group of employees while still keeping the arrangements practical. Some CAs of-
fer to generate private keys for you, but they should know better. The hint is in the
name: private keys should stay private, without exception.
Think about random number generation
The security of encryption keys depends on the quality of the random number gener-
ator (RNG) of the computer on which the keys are generated. Keys are often created
on servers right after their installation and rebooting, but at that point the server
might not have sufficient entropy to generate a strong key. It’s better to generate all
your keys in one (offline) location, where you can ensure that a strong RNG is in
place.
Password protect your keys
Your keys should have a passphrase on them from the moment they are created. This
helps reduce the attack surface if your backup system is compromised. It also helps
prevent leakage of the key material when copying keys from one computer to another
(directly or using USB sticks); it’s getting increasingly difficult to safely delete data
from modern file systems.
Don’t share keys among unrelated servers and applications
Sharing keys is dangerous: if one system is broken into, its compromised key could be
used to attack other systems that use the same key, even if they use different certifi-
cates. Different keys allow you to establish strong internal access controls, giving ac-
cess to the keys only to those who need them.
Change keys regularly
Treat private keys as a liability. Keep track of when the keys were created to ensure
they don’t remain in use for too long. You must change them after a security incident
and when a key member of your staff leaves, and you should change them when ob-
taining a new certificate. When you generate a new key, you remove the old key as an
attack vector. This is especially true for systems that do not use or support forward
secrecy. In this case, your key can be used to decrypt all previous communications, if
your adversary has recorded them. By deleting the key safely, you ensure that it can’t
be used against you.
Your default should be to generate a new private key with every certificate renewal.
Systems with valuable assets that do not use forward secrecy (which is not advisable)
should have their keys changed at least quarterly.
CAA is a very useful addition to the defense arsenal. Even a policy that allows many CAs is
helpful as a way of reducing the attack surface, compared to the default, which allows all
CAs. Deploying CAA may be difficult in complex environments because a policy set on the
apex domain name applies to all subdomains.
Configuration
When it comes to protocol configuration, your choices are likely to be influenced by a com-
bination of security, interoperability, and regulatory requirements. In the ideal world, focus-
ing on security alone, you would allow only TLS 1.3 and disable all other protocol versions.
But that works only in well-understood environments; although modern browsers support
TLS 1.3, many other products and tools still don’t.
When it comes to TLS 1.2, you should rely on cipher suites that provide strong key ex-
change, forward secrecy, and AEAD (authenticated encryption with associated data) encryp-
tion of 128 bits. Use AES and ChaCha20 encryption algorithms. Your configuration can
continue to utilize non-AEAD suites, but only to support very old clients, if that’s necessary.
Don’t use anything else unless you’re a cryptographer and know what you’re doing.
The preceding recommendations, translated to specific TLS 1.2 suites, yields the following:
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
TLS_DHE_RSA_WITH_AES_128_CBC_SHA
TLS_DHE_RSA_WITH_AES_256_CBC_SHA
TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
This configuration is designed with both security and performance in mind. It supports
both ECDSA and RSA keys, with priority given to the former, which is faster. It also in-
cludes more suites than strictly necessary in order to support a wider range of clients.
If you’re using OpenSSL, the following configuration is exactly the same but uses the non-
standard suite names that OpenSSL will understand:
ECDHE-ECDSA-AES128-GCM-SHA256
ECDHE-ECDSA-CHACHA20-POLY1305
ECDHE-ECDSA-AES256-GCM-SHA384
ECDHE-ECDSA-AES128-SHA
ECDHE-ECDSA-AES256-SHA
ECDHE-ECDSA-AES128-SHA256
ECDHE-ECDSA-AES256-SHA384
I recommend that you always configure OpenSSL with an explicit list of desired suites, as
indicated earlier. This approach is the simplest and provides great visibility into exactly what
is enabled. With OpenSSL, it’s also possible to use the legacy, keyword-based configuration
approach, but that leads to opaque configurations that are difficult to understand and often
end up doing the wrong thing.
Note
If you have to resort to using some of these weak encryption components in pro-
duction, consider splitting your systems into those that are well-configured and
those that are intended to serve your legacy clients. Structuring your deployments
like that will help you minimize the risk.
Encrypt Everything
There is no longer any excuse not to encrypt everything by default. A long time ago there
was—maybe—but not any longer. The first barrier fell with the increase of CPU power,
Secure Cookies
In HTTP, cookies are a weak link and need additional attention. You could have a web site
that is 100% encrypted and yet remains insecure because of how its cookies are configured.
Browsers have been working hard to eliminate this problem, but they’ll need your help.
Mark cookies secure
Depending on the user agent, cookies may by default span both HTTP and HTTPS
contexts, which is why they need to be explicitly marked as secure to disable trans-
mission over insecure channels.
Mark cookies as HttpOnly
If a web site uses cookies that need not be accessed from the browser itself, they
should be marked as HttpOnly. This is a defense-in-depth technique that aims to
minimize the attack surface.
Use cookie name prefixes
Cookie prefixes are a new security measure that is now supported by browsers and
being added to the main cookie specification (RFC 6265bis). Cookies with names
that start with prefixes __Host- and __Secure- are given special powers that address a
variety of problems that existed for years. All cookies should be transitioned to use
these prefixes.
For best results, consider adding cryptographic integrity validation or even encryption to
your cookies. These techniques are useful with cookies that include application data. En-
cryption can help if the data inadvertently includes something that the user doesn’t already
know. Integrity validation will prevent tampering. With these kinds of cookies, it’s also a
good practice to bond the cookies to the context in which they were issued—for example, to
the user account to which they were issued.
Secure Cookies 13
Use Strict Transport Security
For proper security of the transport layer, you must indicate your preference for encrypted
content. HTTP Strict Transport Security (HSTS) is a standard that allows web sites to request
strict handling of encryption. Web sites signal their policies via an HTTP response header
for enforcement in compliant browsers. Once HSTS is deployed, compliant browsers will
switch to always using TLS when communicating with the web site. This addresses a num-
ber of issues that are otherwise difficult to enforce: (1) users who have plaintext bookmarks
and follow plaintext links, (2) insecure cookies, (3) HTTPS stripping attacks, and (4) mixed-
content issues within the same site.
In addition, and perhaps more importantly, HSTS fixes handling of invalid certificates.
Without HSTS, when browsers encounter invalid certificates, they allow their users to pro-
ceed to the site. Many users can’t differentiate between attacks and configuration issues and
decide to proceed, which makes them susceptible to active network attacks. With HSTS,
certificate validation failures are final and can’t be bypassed. That brings TLS back to how it
should have been implemented in the first place.
All web sites should deploy HSTS to fix legacy browser issues in how encryption is handled.
In fact, deploying HSTS is probably the single most important improvement you can make.
The following configuration enables HSTS on the current domain and all subdomains, with
a policy duration of one full year:
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
For best results, consider adding your properties to the HSTS preload list. With that,
browsers and other clients can ship with a full list of encryption-properties, which means
that even first access to those sites can enforce encryption.
Warning
Unless you have full control over your infrastructure, it’s best to deploy HSTS in-
crementally, starting with a short policy duration (e.g., 300 seconds) and no
preloading. The fact that HSTS has a memory effect, combined with its potential
effect on subdomains, can lead to problems in complex environments. With incre-
mental deployments, problems are discovered while they’re still easy to fix. Request
preloading as the last deployment step, and after you activate sufficiently long poli-
cy duration.
HSTS is not the only technology that can help with enforcing encryption. Although much
more recent and with a lot of catching up to do, there are also the HTTPS DNS resource
records, which build on the DNS infrastructure to carry various metadata, including signal-
ing of support for encryption.
Disable Caching
Encryption at the network level prevents both passive and active network attacks, but TLS
doesn’t actually provide full end-to-end encryption. Both sides involved in the communica-
tion have access to the plaintext. Caching is commonly used with HTTP to improve perfor-
mance, so, for example, browsers may choose to store plaintext data in persistent storage.
Intermediate proxy services (e.g., content delivery networks) may choose to not only cache
sensitive data, but even share it with other users in some situations when incorrect configu-
ration is involved.
With the increase of cloud-based application delivery platforms and content delivery net-
works, it’s never been more important to very carefully mark all sensitive content as private.
The most secure option is to indicate that the content is private and that it must not be
cached:
Cache-Control: private, no-store
With this setting, neither intermediate devices nor browsers will be allowed to cache the
served content.
Performance
Everybody worries about security, but they worry about performance even more. What use
is a secure service that people can’t or don’t want to use? Properly configured, TLS is plenty
fast. With little effort, the performance will be good enough. In some cases, it’s even possible
to deploy TLS with virtually no performance overhead. In this section, we’ll look at how you
can achieve best-in-class performance with some additional effort.
If you have a content delivery network in place and want to utilize its caching abilities, indi-
cate that the content is public:
Cache-Control: public
In both situations, you can use other HTTP caching configuration options to control how
the caching is to be done.
1 There is also the Expect-CT HTTP response header, which was designed to support early opt-in into CT before this technology became de facto
required. With Expect-CT reporting, it’s possible to get a full certificate chain that’s not CT compliant. Although this feature is very useful, it is
most likely that Expect-CT will be deprecated, now that pre-CT public certificates have all expired.