← Concepts

阅读中文版本

TLS

TLS encrypts and authenticates data in transit, using certificates and a handshake to derive session keys. It protects network hops, not endpoints or data at rest.

security

Definition

Transport Layer Security is a cryptographic protocol that provides confidentiality, integrity, and server authentication for data moving between two endpoints. It negotiates algorithms during a handshake, validates an X.509 certificate chain, and derives symmetric keys used to protect every record.

Context and scope

TLS underpins HTTPS, API traffic, database connections, and service-to-service calls. Modern deployments use TLS 1.3, automate certificate renewal, and pair transport encryption with encryption at rest and HSTS.

Common misconceptions

  • A browser padlock proves the site is trustworthy rather than merely encrypted to the certificate subject
  • TLS protects data after it is decrypted or stored on disk

Anti-patterns

  • Disabling certificate verification in production clients to work around a misconfiguration
  • Terminating TLS at a proxy and forwarding plaintext across an untrusted internal network

Related concepts

Related examples

Authoritative source

https://www.rfc-editor.org/rfc/rfc8446

How TLS works

TLS runs above TCP and below application protocols such as HTTP. During the handshake it authenticates the server with an X.509 certificate, negotiates a cipher suite, and derives symmetric session keys. TLS 1.3 shortens the handshake to one round trip, mandates forward secrecy through ephemeral Diffie-Hellman, and encrypts most handshake metadata. After the handshake, records are protected with AEAD ciphers such as AES-GCM or ChaCha20-Poly1305.

When to use it

Use TLS on every network hop that carries credentials, personal data, or commands: public HTTPS, API calls, database connections, message brokers, and service-to-service traffic inside a private network. Mutual TLS adds client certificates when the server must authenticate callers. TLS protects data in transit, so pair it with encryption at rest for stored data and with HSTS so browsers never fall back to plain HTTP.

Trade-offs

Handshakes cost latency and CPU, especially with large certificate chains or many short-lived connections; session resumption and keep-alive amortize that cost. Certificate issuance and renewal are operational risks because an expired certificate causes an outage. Terminating TLS at a load balancer simplifies certificate management but leaves the internal hop unencrypted unless you re-encrypt. Deep packet inspection and some debugging tools stop working. Compared with a private network alone, TLS adds authenticated encryption but not access control.

Example

openssl s_client -connect api.example.com:443 -servername api.example.com -tls1_3

Check that the negotiated protocol is TLS 1.3, the certificate chain validates, and the hostname matches. In Node.js, https.createServer({ cert, key }, app) serves traffic with the same guarantees. Never disable certificate verification in production clients.

A padlock means the connection is encrypted to the certificate’s subject, not that the site is trustworthy. TLS does not protect data after it is decrypted, does not replace authentication or authorization, and does not hide the destination IP address. HSTS prevents protocol downgrade after the first visit, while CSP and CORS address different browser threats.