Skip to content
uencoder

TLS Pinning

TLS certificate pinning embeds the expected certificate public key or hash in the client and rejects all other certificates, preventing man-in-the-middle attacks (including forged certificates issued by legitimate CAs).

Purpose

To prevent man-in-the-middle attacks by adversaries holding legitimate CA certificates (e.g., governments or compromised CAs).

Mechanism

The client preconfigures the SPKI hash (pin) of the server certificate. During the TLS handshake it compares the server certificate with the pin and refuses the connection on mismatch. Types: SPKI pin, certificate-chain pin. Common in mobile apps; browsers rarely pin because certificate rotation is hard.

Use cases

  • Mobile app API MITM defense
  • IoT device communication
  • High-security API clients
  • Inter-service communication

Examples

  • Input
    pin: sha256/SPKI=abc...
    Output
    Reject on certificate mismatch

    Public key pinning

Common errors

Expired pins without updates cause connection failures
Provide backup pins and a rotation policy

Related terms

References