Skip to content

TLS and encryption: which threat each one stops

Two kinds of encryption, two different threats

Section titled “Two kinds of encryption, two different threats”

Data is in one of two places. It is in transit when it crosses a network between two machines, and at rest when it is stored on a disk, in a database or in a backup. Encryption protects each place against a different person, and the commonest mistake is to treat one as if it covered the other.

Mental model. Encryption in transit protects against someone who can see the wire. Encryption at rest protects against someone who can take the medium. Neither one protects against someone who is let in by the application, because the application has to read the plain data to do its job.

In transit: what TLS gives, and where it ends

Section titled “In transit: what TLS gives, and where it ends”

The TLS handshakes lesson counted what a secure connection costs in round trips. This lesson is about what the connection gives. RFC 8446 lists three properties of a TLS channel.

  • Authentication. The server side is always authenticated, and the client side is optionally authenticated.
  • Confidentiality. The data sent after the channel is established is visible only to the endpoints. TLS does not hide the length of the data.
  • Integrity. The data sent over the channel cannot be modified by attackers without detection.

OWASP’s TLS cheat sheet words the same thing as protection against attackers reading the traffic and against its modification, and recommends TLS 1.3 by default, with TLS 1.2 only if compatibility needs it. It says TLS 1.0 and 1.1 are formally deprecated and must be disabled. It also recommends HTTP Strict Transport Security, which instructs the browser to always request the site over HTTPS.

Three limits matter for a system design.

The protection stops at the end of the connection. RFC 8446 promises confidentiality between the endpoints of the channel. If a load balancer ends the TLS connection and passes the request on in plain HTTP, the first hop is protected and the second is not: it is a different connection and needs its own protection. OWASP adds that TLS provides no protection for the data once it has reached the requesting system.

TLS does not say what the caller may do. The server is authenticated, and the client usually is not. A request that arrives over a perfectly secure channel from an unknown client is still an unknown client. Who the client is, and what it may do, are the questions of the first lesson.

Early data can be replayed. RFC 8446 warns that for 0-RTT data there are no guarantees of non-replay between connections, and that this data is not forward secret. The TLS handshakes lesson covers what that means for a request that changes something.

A typical TLS connection authenticates the server. Mutual TLS (mTLS) also authenticates the client, with a client certificate and a proof that the client holds its private key. It is a way to answer “which service is calling” without a password between two internal services. OWASP lists the cost: significant administrative overhead for certificate management, which is why it recommends considering it for high-value applications. A certificate says who the caller is. Whether that service may perform the operation is still an authorization decision.

Encryption at rest can be done at several layers. OWASP’s cryptographic storage guidance names the application, the database (for instance transparent data encryption), the file system and the hardware. Which layer is right depends on the threat model, and its example is the one to remember: encryption at the hardware level is effective at protecting against the physical theft of the server, and gives no protection if an attacker compromises the server remotely.

The reason is simple once you ask who holds the key. A running database decrypts data for every request it accepts. A person who steals the disk has the ciphertext and not the key. A person who steals the application’s credentials asks the database, and the database answers in plain text. OWASP says applications should be designed to stay secure even if cryptographic controls fail, with additional layers around any encrypted data and strong access control.

So encryption at rest is a precise tool.

Threat In transit (TLS) At rest What does stop it
Someone reads packets on the network Stops it Does nothing TLS
Someone alters a request on the way Detects it Does nothing TLS
A disk or a backup is stolen Does nothing Stops it, if the key is not with it Encryption at rest
A signed-in user asks for another user’s record Does nothing Does nothing An authorization check
An attacker holds the application’s credentials Does nothing Does nothing Least privilege, short-lived credentials

The last two rows are the ones that surprise people. No amount of encryption makes a wrong answer safe when the application is the one giving it.

The key decides whether encryption at rest does anything. OWASP says encryption keys should be stored in a separate location from the data they encrypt, so that an attacker who reaches only one of them, through directory traversal or SQL injection for instance, cannot read the data. It describes the usual structure, envelope encryption: a data encryption key encrypts the data, a key-encrypting key encrypts that key, and the key-encrypting key is kept on another system. The encrypted data key can sit next to the data, and it is useless without the key above it. OWASP also notes that where the two cannot be kept apart, as in a simple shared environment, the approach is of limited value.

It lists reasons to rotate a key: a suspected compromise, the end of its planned lifetime, the limits of the encryption mode, and a vulnerability found in the algorithm. For the algorithm itself it recommends AES with authenticated modes such as GCM, and it advises against inventing your own. The best protection, it adds, is not to store the sensitive information at all.

Four controls, twelve statements. Each statement describes one of them: authentication, authorization, encryption in transit or encryption at rest. Sort them, and read the reason for each line you got wrong.

Challenge

Which control is it?

Four different controls are easy to mix up: authentication, authorization, encryption in transit and encryption at rest. Each statement below describes what exactly one of them does. Put it under that control.

Sorting needs JavaScript.

Categories

Authentication
Proves who the caller is.
Authorization
Decides what an identified caller may do.
Encryption in transit
Protects data while it crosses a network.
Encryption at rest
Protects data stored on a disk or in a backup.
  1. Line 1 of 12The service compares the password in the login request with what it has stored, and creates a session.
  2. Line 2 of 12Each internal service presents a certificate, and the server checks which service it is talking to.
  3. Line 3 of 12After the password, the login page asks for a code from the person’s phone.
  4. Line 4 of 12The service refuses to show order 523 to a signed-in user who does not own it.
  5. Line 5 of 12A token that only allows reading orders is refused with a 403 when it tries to create one.
  6. Line 6 of 12A new endpoint refuses everyone until someone adds a rule that allows a role.
  7. Line 7 of 12Someone on the café’s Wi-Fi sees only unreadable bytes between the browser and the server.
  8. Line 8 of 12A request changed on its way to the server is detected and the connection is dropped.
  9. Line 9 of 12A header tells the browser to always use HTTPS for the site.
  10. Line 10 of 12A backup tape that is lost in the post is unreadable without the key.
  11. Line 11 of 12The key that encrypts the data is itself encrypted by another key, held on another system.
  12. Line 12 of 12A server’s disk is removed from the data centre, and its contents cannot be read elsewhere.

Check your answers at least once before looking at the answers.

What happens if the database is encrypted and the application’s password leaks?

Section titled “What happens if the database is encrypted and the application’s password leaks?”

Say the disks are encrypted at rest and every connection uses TLS. An attacker gets the application’s database password from a configuration file. They connect from their own machine over a valid TLS connection and run a query. The database authenticates them with the password, the disk key is held by the database server as always, and the query returns plain rows.

Both encryptions did what they promise. TLS protected the connection between the attacker and the database, which is a connection they were entitled to open with that password. The disk encryption protected the disk, which they never touched. What was missing were least privilege, so that the password reached only the tables the application needs, and a way to find out that it had left the building. The data was protected from the thief of the disk and not from the holder of the key.

  • TLS gives a connection server authentication (client authentication optionally), confidentiality between its two endpoints, and integrity. It does not hide the length of the data, and it does not protect data after it has reached an endpoint.
  • If a proxy ends the TLS connection, the next hop is a separate connection that needs its own protection.
  • Mutual TLS lets the server authenticate the client with a certificate, at the cost of managing certificates. It says who is calling, not what they may do.
  • Encryption at rest protects against the theft of a disk or a backup, if the key is kept apart from the data. It does not protect against a caller the application serves, or against a leaked credential.
  • Keys belong in a separate place, in a hierarchy where a key-encrypting key protects the data key, and they are rotated on a compromise or at the end of their life.

Next: secrets and least privilege, and what a leaked credential can reach.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.