<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/certificate-pinning---the-most-important-security-measure-for-network-traffic-in-your-app-25apqcm92" -->

---
title: Certificate Pinning - The MOST Important Security...
description: Certificate pinning on Android is explained from first principles: how HTTPS trust normally works via OS-baked certificate authorities, why that trust chain...
canonical: https://daily.dev/posts/certificate-pinning---the-most-important-security-measure-for-network-traffic-in-your-app-25apqcm92
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Certificate Pinning - The MOST Important Security Measure for Network Traffic In Your App | daily.dev
og:description: Certificate pinning on Android is explained from first principles: how HTTPS trust normally works via OS-baked certificate authorities, why that trust chain...
og:url: https://daily.dev/posts/certificate-pinning---the-most-important-security-measure-for-network-traffic-in-your-app-25apqcm92
og:image: https://api.daily.dev/og/posts/25APQcm92.png
og:image:alt: Certificate Pinning - The MOST Important Security Measure for Network Traffic In Your App
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Certificate Pinning - The MOST Important Security Measure for Network Traffic In Your App

**[Philipp Lackner](https://daily.dev/sources/philipplackner)** · 21 min read · 0 upvotes · 0 comments

## Summary

Certificate pinning on Android is explained from first principles: how HTTPS trust normally works via OS-baked certificate authorities, why that trust chain can be undermined if a CA is compromised or a malicious CA is added to a device, and how pinning a server's public key hash inside the app closes that gap. The video walks through implementing a network security config XML file in Android Studio, defining base and domain configs, generating SHA-256 public key hashes via OpenSSL, and setting an expiration date as a safety fallback in case keys get accidentally rotated. It stresses that pinning is only appropriate for security-critical apps like banking, fintech, password managers, or health apps, since misconfiguration can lock users out until a new app update propagates, and closes with a plug for the creator's mentoring program.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=hGdI7aKtVxI>

## Questions this post answers

### How do I implement certificate pinning on Android using the network security config?

Create an XML resource file named network_security_config.xml with a domain-config block specifying the domain, includeSubdomains, and a pin-set containing SHA-256 hashes of the server's public key, then link it in the AndroidManifest.xml via android:networkSecurityConfig on the application tag. Pin the public key hash, not the full certificate, since certificates change on renewal but keys can remain stable.

_Developers hardening banking or health apps can find implementation walkthroughs like this through daily.dev._

### Why should certificate pinning use the public key hash instead of hashing the entire certificate?

Certificates are typically renewed every 90 days and their content changes on renewal, so hashing the full certificate would break the app after every renewal. Hashing just the public key works because the key pair can be configured to stay the same across renewals, though this requires explicit server configuration since defaults like Let's Encrypt normally rotate keys too.

_Teams deciding how to configure TLS renewal without breaking pinned mobile clients can track this kind of guidance on daily.dev._

### What is the risk of setting a pin expiration date too far in the future or forgetting to update it in certificate pinning?

An expiration date acts as a fallback so that if a public/private key pair is accidentally rotated and breaks the pinned certificate set, the app stops enforcing pinning after that date and traffic resumes instead of staying permanently broken. However, developers must keep pushing app updates with later expiration dates, or pinning enforcement silently lapses even when the original pins are still valid.

_Anyone maintaining pinned certificates across app releases can follow practical safeguards like this via daily.dev._

## Similar posts on daily.dev

- [Why Certificate Pinning Alone Won’t Stop Modern MITM Attacks](https://daily.dev/posts/why-certificate-pinning-alone-won-t-stop-modern-mitm-attacks-ly2ys6iwc) · ProAndroidDev · 0 upvotes · 0 comments
- [Securing Secrets in Android: From API Keys to Production-Grade Defense](https://daily.dev/posts/securing-secrets-in-android-from-api-keys-to-production-grade-defense-jxwjjpdsh) · ProAndroidDev · 0 upvotes · 0 comments
- [Securing Legacy Android Apps: Modern Encryption Practices](https://daily.dev/posts/securing-legacy-android-apps-modern-encryption-practices-odsmhlmnq) · The New Stack · 0 upvotes · 0 comments

---

Tags: [#security](https://daily.dev/tags/security), [#android](https://daily.dev/tags/android)

[View this post on daily.dev](https://daily.dev/posts/certificate-pinning---the-most-important-security-measure-for-network-traffic-in-your-app-25apqcm92)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Certificate Pinning - The MOST Important Security Measure for Network Traffic In Your App","url":"https://daily.dev/posts/certificate-pinning---the-most-important-security-measure-for-network-traffic-in-your-app-25apqcm92","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/certificate-pinning---the-most-important-security-measure-for-network-traffic-in-your-app-25apqcm92"},"datePublished":"2026-09-13T11:21:54.741Z","dateModified":"2026-09-13T11:22:21.316Z","description":"Certificate pinning on Android is explained from first principles: how HTTPS trust normally works via OS-baked certificate authorities, why that trust chain...","image":"https://i.ytimg.com/vi/hGdI7aKtVxI/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/hGdI7aKtVxI/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Philipp Lackner","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Philipp Lackner","logo":"https://media.daily.dev/image/upload/s--WOEWUbRT--/f_auto/v1725038407/logos/philipplackner","url":"https://daily.dev/sources/philipplackner"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/certificate-pinning---the-most-important-security-measure-for-network-traffic-in-your-app-25apqcm92","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"security,android","timeRequired":"PT21M","video":{"@type":"VideoObject","name":"Certificate Pinning - The MOST Important Security Measure for Network Traffic In Your App","description":"Certificate pinning on Android is explained from first principles: how HTTPS trust normally works via OS-baked certificate authorities, why that trust chain...","thumbnailUrl":"https://i.ytimg.com/vi/hGdI7aKtVxI/sddefault.jpg","uploadDate":"2026-09-13T11:21:54.741Z","duration":"PT21M","url":"https://api.daily.dev/r/25APQcm92","embedUrl":"https://www.youtube.com/embed/hGdI7aKtVxI"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Philipp Lackner","item":"https://daily.dev/sources/philipplackner"},{"@type":"ListItem","position":3,"name":"Certificate Pinning - The MOST Important Security Measure for Network Traffic In Your App"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/certificate-pinning---the-most-important-security-measure-for-network-traffic-in-your-app-25apqcm92#faq","mainEntity":[{"@type":"Question","name":"How do I implement certificate pinning on Android using the network security config?","acceptedAnswer":{"@type":"Answer","text":"Create an XML resource file named network_security_config.xml with a domain-config block specifying the domain, includeSubdomains, and a pin-set containing SHA-256 hashes of the server's public key, then link it in the AndroidManifest.xml via android:networkSecurityConfig on the application tag. Pin the public key hash, not the full certificate, since certificates change on renewal but keys can remain stable. Developers hardening banking or health apps can find implementation walkthroughs like this through daily.dev."}},{"@type":"Question","name":"Why should certificate pinning use the public key hash instead of hashing the entire certificate?","acceptedAnswer":{"@type":"Answer","text":"Certificates are typically renewed every 90 days and their content changes on renewal, so hashing the full certificate would break the app after every renewal. Hashing just the public key works because the key pair can be configured to stay the same across renewals, though this requires explicit server configuration since defaults like Let's Encrypt normally rotate keys too. Teams deciding how to configure TLS renewal without breaking pinned mobile clients can track this kind of guidance on daily.dev."}},{"@type":"Question","name":"What is the risk of setting a pin expiration date too far in the future or forgetting to update it in certificate pinning?","acceptedAnswer":{"@type":"Answer","text":"An expiration date acts as a fallback so that if a public/private key pair is accidentally rotated and breaks the pinned certificate set, the app stops enforcing pinning after that date and traffic resumes instead of staying permanently broken. However, developers must keep pushing app updates with later expiration dates, or pinning enforcement silently lapses even when the original pins are still valid. Anyone maintaining pinned certificates across app releases can follow practical safeguards like this via daily.dev."}}]}
```

