Sitemap

Why Every Developer Should Understand PKI (And How It Actually Works)

5 min readSep 11, 2025

--

That little lock icon in your browser? It’s doing way more heavy lifting than you think.

You’re building your first serious web app or mobile app. Maybe it’s a side project that handles payments, or perhaps you’re integrating with some third-party APIs at work. Everything’s going smoothly until you start dealing with authentication, and suddenly you’re drowning in acronyms: SSL, TLS, JWT, OAuth, certificates, keys…

Sound familiar, right? I’ve been there.. and the worst part is that most explanations of Public Key Infrastructure (PKI) either treat you like you’re five years old or assume you already have a PhD in cryptography :)

Let me tell you what I wish someone had told me when I first encountered this challenge in my app development journey.

The Real Problem PKI Solves

Forget the textbook definitions for a moment. Here’s the actual problem… every time your code talks to another service over the internet, you’re basically shouting across a crowded room. Anyone can listen in, anyone can pretend to be someone else, and anyone can mess with your message before it reaches its destination.

PKI is the solution that makes sure:

  1. You’re actually talking to who you think you’re talking to
  2. Nobody else can read your private conversations
  3. Your messages haven’t been tampered with

That’s it. Everything else is just implementation details.

Your First Real Encounter With PKI

You’ve probably used PKI without realizing it. Ever generate SSH keys to connect to a server?

ssh-keygen -t rsa -b 4096
ssh-copy-id user@myappserver.xyz

Yes, you just used public key cryptography. That key pair you generated? The public key sits on your server saying “this person is allowed in,” and your private key proves you’re actually that person. No passwords flying around the network, no shared secrets to manage.

But SSH is just PKI with training wheels. The real complexity comes when you need to scale this across the entire internet.

The Certificate Authority Game

Here’s where things get interesting (or a bit scary). When you visit https://github.com, how does your browser know it's really GitHub and not some imposter?

The answer is Certificate Authorities (CAs). These are companies that browsers trust by default — think DigiCert, Let’s Encrypt, or VeriSign. When GitHub wants to prove their identity, they ask one of these CAs to vouch for them.

The CA essentially says: “Yeah, I checked. This public key really belongs to GitHub. Here’s my digital signature to prove I said that.” Your browser sees this signature, recognizes the CA, and decides to trust GitHub.

Here’s the wild part: there are about 100 root CAs that your browser trusts by default. Each one of them could theoretically impersonate any website on the internet. Sleep well tonight.

PKI in Your Daily Development Life

Here are the places you’re definitely going to face at some point in your coding journey:

API Authentication with JWT

If you’ve ever implemented “Sign in with Google” or similar OAuth flows, you’ve used PKI. When Google sends you back a JWT token, it’s signed with their private key. Your app verifies it using their public key:

import jwt
from cryptography import x509
# Get Google's public key from their well-known endpoint
google_cert = get_google_certificate()
public_key = google_cert.public_key()
# Verify the token came from Google
try:
decoded = jwt.decode(token, public_key, algorithms=['RS256'])
# Token is valid and definitely came from Google
except jwt.InvalidTokenError:
# Someone's trying to trick you
pass

Microservices Security

Working with microservices? You’ll probably encounter mutual TLS (mTLS) where every service has its own certificate and they all verify each other. It’s like everyone having their own ID card in a high-security building.

Database Connections

Many production databases require SSL connections with client certificates. That connection string with all the certificate paths? That’s PKI making sure your app is allowed to connect and that nobody’s eavesdropping on your queries.

The Tools You Actually Need to Know

Skip the theory for now and focus on these practical tools:

OpenSSL: The Swiss Army knife of certificates. You’ll use it to generate keys, create certificate signing requests, and debug SSL issues. Learn the basics — trust me, you’ll need them.

Let’s Encrypt + Certbot: Free, automated certificate management. If you’re running any web service, this should be your first stop for HTTPS certificates.

Your cloud provider’s certificate manager: AWS Certificate Manager, Google Cloud SSL certificates, etc. These handle most of the complexity for you.

When PKI Goes Wrong (And It Will)

Here’s what nobody tells you: PKI breaks. A lot. And when it does, the error messages are cryptic and unhelpful. Here are the scenarios you’ll definitely encounter:

Certificate Expired: Someone forgot to renew a certificate. The fix is usually simple, but finding which certificate expired can be a nightmare.

Chain of Trust Issues: The certificate is valid, but your system can’t verify it because it’s missing intermediate certificates. This one will drive you crazy.

Hostname Mismatches: The certificate is for api.example.com but you're connecting to legacy-api.example.com. Simple problem, not-so-simple to debug.

Time Sync Problems: Certificates have validity periods, and if your server’s clock is wrong, valid certificates appear expired. Yes, this happens more than you’d think.

The Modern Reality

PKI isn’t going anywhere. If anything, it’s becoming more important. Zero-trust networks assume every connection needs to be verified. Kubernetes service meshes use mTLS by default. Even your IoT devices are getting certificates.

The good news? The tooling is getting much better. Certificate management that used to require dedicated teams can now be automated. Let’s Encrypt democratized SSL certificates. Cloud providers handle most of the complexity.

The bad news? You still need to understand how it works when things go sideways.

My Advice for Devs

Start with understanding what certificates actually are and why they exist. Once that clicks, get your hands dirty with the tools you’ll actually use. OpenSSL might seem intimidating at first, but learning just the basic commands will save you hours of debugging later. Same goes for whatever certificate management your platform provides — whether that’s AWS Certificate Manager, Kubernetes cert-manager, or something else entirely.

Here’s something I wish I’d done earlier: set up a throwaway environment and deliberately break SSL connections. Mess with expired certificates, try connecting with the wrong hostname, use self-signed certs where you shouldn’t. It sounds masochistic, but there’s no better way to learn how to fix these issues when they inevitably happen in production.

Most importantly, remember that PKI is just a tool, not some mystical black box. It solves real problems, but it also creates new ones. You don’t need to understand every cryptographic detail to build secure systems. Focus on building things that work easily and dive deeper into the theory when you actually need it.

--

--

Dr. Mohammadreza Ashouri
Dr. Mohammadreza Ashouri

Written by Dr. Mohammadreza Ashouri

Mo has a Ph.D. in Compter Science. Mo specializes in Backend Programming and Security. He works as a cyber security researcher at Bytescan.net