Перейти к содержимому
Skip to content
← All articles

SSL Pinning: What It Is and When to Use It

What Is SSL Pinning?

SSL pinning (also called certificate pinning or public key pinning) is a security technique where an application is configured to accept only specific certificates or public keys when connecting to a server, rather than trusting any certificate signed by a trusted Certificate Authority (CA).

In standard TLS, trust is hierarchical: your browser or operating system trusts a set of root CAs (~150 on most systems), and any certificate signed by these CAs (or their intermediates) is accepted. This is convenient but creates a large attack surface. If any single CA is compromised, attackers can issue valid certificates for any domain.

Pinning reduces this attack surface by hardcoding the expected certificate or public key into the application. If the server presents a different certificate — even one signed by a trusted CA — the connection is refused.

Why Pinning Exists

The standard CA trust model has known weaknesses:

Pinning protects against all of these scenarios by making the application independently verify the server's identity, regardless of the CA chain.

What Can Be Pinned

There are several pinning strategies, each with different trade-offs:

Pin TargetWhat Is PinnedFlexibilitySecurity
Leaf certificateExact server certificateLow — breaks on every renewalHighest
Public keyServer's public key (SPKI hash)Medium — survives certificate renewal if key is reusedHigh
Intermediate CAIssuing CA's certificateHigh — any certificate from that CA worksMedium
Root CARoot CA's certificateHighest — any chain to that root worksLowest (of pinning options)

Public key pinning is the most common choice — it provides strong security while surviving certificate renewals, as long as you generate new certificates with the same key pair or pin backup keys.

Implementation Methods

HTTP Public Key Pinning (HPKP) — Deprecated

HPKP was a browser-based pinning mechanism via HTTP headers:

Public-Key-Pins:
  pin-sha256="base64+primary==";
  pin-sha256="base64+backup==";
  max-age=5184000;
  includeSubDomains;
  report-uri="https://example.com/hpkp-report"

HPKP was deprecated in 2018 and removed from Chrome 72. The reasons: risk of bricking websites if pins were misconfigured (permanent denial of service), difficulty of key rotation, and the rise of Certificate Transparency as an alternative.

Mobile App Pinning

Pinning is most common in mobile applications where you control the client:

// Android — OkHttp certificate pinning
CertificatePinner pinner = new CertificatePinner.Builder()
    .add("api.example.com",
         "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
    .add("api.example.com",
         "sha256/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=") // backup
    .build();

OkHttpClient client = new OkHttpClient.Builder()
    .certificatePinner(pinner)
    .build();
// iOS — URLSession with pinning delegate
func urlSession(_ session: URLSession,
    didReceive challenge: URLAuthenticationChallenge,
    completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {

    guard let serverTrust = challenge.protectionSpace.serverTrust,
          let certificate = SecTrustGetCertificateAtChain(serverTrust, 0) else {
        completionHandler(.cancelAuthenticationChallenge, nil)
        return
    }

    let serverKey = SecCertificateCopyKey(certificate)
    // Compare with pinned key hash...
}

Certificate Transparency (CT) as Alternative

Certificate Transparency requires CAs to log every issued certificate to public, auditable logs. Browsers verify that certificates appear in CT logs. This does not prevent misissuance but makes it detectable — any fraudulent certificate becomes publicly visible. Since 2018, Chrome requires all new certificates to be CT-logged.

When to Use Pinning

Pinning is appropriate when:

Pinning is generally NOT appropriate for:

Risks and Pitfalls

Best Practices

Conclusion

SSL pinning is a powerful security technique that narrows the trust model beyond CA hierarchies. It is most effective for mobile apps and internal services where you control both endpoints. However, it introduces operational complexity — misconfigured pins can cause outages worse than the attacks they prevent. Use pinning when the threat model justifies it, always pin backup keys, and combine with Certificate Transparency monitoring for comprehensive certificate security.

Check your website right now

Check now →
More articles: SSL/TLS
SSL/TLS
TLS Handshake Explained: Step-by-Step Guide to Secure Connections
16.03.2026 · 10 views
SSL/TLS
Certificate Transparency Logs: Detecting Rogue Certificates and Monitoring Your Domain
16.03.2026 · 14 views
SSL/TLS
How to Check a Website's SSL Certificate: Step-by-Step Guide
12.03.2026 · 12 views
SSL/TLS
SSL/TLS Certificates: How HTTPS Works
10.03.2025 · 13 views