惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
U
Unit 42
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
G
Google Developers Blog
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
Jina AI
Jina AI
量子位
宝玉的分享
宝玉的分享
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
美团技术团队
The Hacker News
The Hacker News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tailwind CSS Blog
博客园 - 司徒正美
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Vercel News
Vercel News
Martin Fowler
Martin Fowler
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Forbes - Security
Forbes - Security
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
P
Privacy International News Feed
G
GRAHAM CLULEY
The Last Watchdog
The Last Watchdog
C
Cyber Attacks, Cyber Crime and Cyber Security
AI
AI
V2EX - 技术
V2EX - 技术

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Rebuilding TLS, Part 4- Certificate, Trust, and MITM Protection
Dmytro Huz · 2026-04-27 · via DEV Community

This article is part of my Rebuilding TLS from Scratch series. The full code and runnable walkthrough are available on GitHub.

A secure connection to the wrong server is still a broken connection.

That sentence looks strange at first. If traffic is encrypted, if nobody can read it, if nobody can modify it, then what is still missing?

The missing piece is identity.

In the previous parts of this series, we slowly moved from a plain TCP connection to something that started to look like a real secure channel. First, we added encryption. Then we added integrity. Then we stopped using fixed shared keys and introduced a handshake with X25519 and HKDF, so the client and server could derive fresh session keys for every connection.

That was a big step forward, but it was still not enough.

The client could now create a strong encrypted channel, but it still had no reliable way to know who it had created that channel with. It could be the real server. It could also be an attacker sitting in the middle, performing a separate key exchange with the client and another one with the real server.

In this post we will discuss why key exchange is not the same as authentication, why certificates exist, how certificate chains work, and how I added a simplified certificate-based authentication layer to my small TLS-like protocol.

By the end, the protocol will finally move from:

“I have an encrypted channel with whoever answered.”

to:

“I have an encrypted channel with the server that proved its identity.”

That is the moment where this toy protocol starts to feel much closer to real TLS.

The Problem We Still Had After Key Exchange

At the end of Part 3, the protocol already had a real handshake.

The client and server exchanged ephemeral X25519 public keys. They used the resulting shared secret as input to HKDF. From that, they derived separate keys for client-to-server and server-to-client traffic. Then they used those keys to protect application data with AES-GCM.

That is already much better than hardcoding a shared key into both programs.

A hardcoded key has many problems. If someone gets it once, every connection using that key is compromised. If you want to rotate it, you need to update both sides. If two clients use the same key, one compromised client can affect other connections. It is simple for a demo, but it is not a good model for a real secure protocol.

X25519 and HKDF solved a different problem. They allowed the client and server to create fresh session keys for every connection without sending the actual secret over the network.

But there was still a hole.

The client received a public key from “the server,” but it had no way to know whether that public key really belonged to the server. The protocol could protect traffic after the handshake, but the handshake itself was not authenticated.

That means a man-in-the-middle could sit between the client and server and do this:

Client  <---- key exchange ---->  Attacker  <---- key exchange ---->  Server

Enter fullscreen mode Exit fullscreen mode

From the client’s point of view, everything looks fine. It completed a key exchange and derived keys.

From the server’s point of view, everything also looks fine. It completed a key exchange and derived keys.

But the attacker is in the middle of both secure channels.

This is the uncomfortable lesson:

A secure key exchange with an unauthenticated peer can still give you a secure channel to the attacker.

That is why Part 4 exists.

Encryption Is Not the Same as Trust

It is easy to mix these ideas together because HTTPS makes them feel like one thing.

When we open a website over HTTPS, we usually think:

The connection is encrypted, so it is secure.

But real TLS gives us several properties at the same time. Encryption is only one of them.

A useful way to separate the ideas is this:

Encryption answers:
Can outsiders read the data?

Integrity answers:
Can outsiders modify the data without being detected?

Key exchange answers:
Can both sides create fresh session keys?

Authentication answers:
Do I know who is on the other side?

Enter fullscreen mode Exit fullscreen mode

Before Part 4, our protocol had the first three. It did not have the fourth.

That distinction matters because an attacker does not always need to break encryption. Sometimes the attacker only needs to become the endpoint that you encrypt to.

If the client encrypts data to the attacker’s key, the encryption still works. The math is not broken. AES-GCM still protects the records. HKDF still derives keys. X25519 still creates a shared secret.

The problem is not the cryptography. The problem is that the client trusted the wrong public key.

So the next question becomes simple:

How does the client know that the server’s handshake key belongs to the real server?

This is where certificates enter the story.

What Certificates Actually Add

A certificate is not magic. It is also not just a random file that makes browsers happy.

At a practical level, a certificate connects an identity to a public key.

For example, a server certificate says something like:

This public key belongs to this server identity.

Enter fullscreen mode Exit fullscreen mode

But the client should not just believe that statement because the server said so. Anyone can generate a key pair and create a file that claims to be example.com.

So certificates are signed.

That means another key, usually belonging to a Certificate Authority, signs the certificate data. The client can then verify the signature using the Certificate Authority’s public key.

In the real Web PKI, this usually forms a chain:

Root CA
  signs
Intermediate CA
  signs
Server Certificate

Enter fullscreen mode Exit fullscreen mode

The root certificate is already trusted by the client’s system or browser. The server sends its certificate chain during the handshake. The client verifies each signature in the chain until it reaches a trusted root.

In my simplified implementation for Part 4, I use the same conceptual model:

Root CA
  ↓
Intermediate CA
  ↓
Server Certificate

Enter fullscreen mode Exit fullscreen mode

The point is not to recreate all of Web PKI. The point is to make the trust chain visible.

The client does not trust the server certificate because the server sent it. The client trusts it because it can verify that the certificate was signed through a chain that ends at a trusted root.

Now the client has something it did not have before:

A public identity key that is connected to the server certificate and can be verified through a certificate chain.

But there is still one more important step.

Why the Server Must Sign the Handshake

A certificate chain proves that a certificate is valid.

It does not automatically prove that the server currently speaking in this connection owns the private key for that certificate.

That difference is important.

If the server only sends a certificate chain, an attacker could potentially copy that public certificate chain and send it to the client. Public certificates are public. They are not secrets.

So the server must prove ownership of the corresponding private key.

In real TLS, this is done with a handshake signature. In TLS 1.3, the server signs data derived from the handshake transcript. This binds the server’s authenticated identity to the exact handshake that is happening now.

In my simplified Part 4 implementation, I use the same core idea, but in a smaller form.

The server has two different types of keys:

Long-term identity key
= connected to the server certificate

Ephemeral X25519 key
= used only for this connection’s key exchange

Enter fullscreen mode Exit fullscreen mode

The server sends its ephemeral X25519 public key, its certificate chain, and a signature over the handshake data.

The client verifies three things:

1. Is the certificate chain valid?

2. Does the server certificate contain the expected identity key?

3. Did the server sign this handshake using the private key that matches the certificate?

Enter fullscreen mode Exit fullscreen mode

This is the key conceptual step.

The ephemeral X25519 key gives us fresh session keys. The certificate gives us identity. The signature connects both worlds together.

Without that signature, the certificate and the key exchange are two separate facts.

With the signature, the server says:

I own the private key for this certificate, and I am binding that identity to this ephemeral key exchange.

That is what stops the man-in-the-middle from silently replacing the handshake key.

The Architecture of Part 4

After Part 4, the handshake looks roughly like this:

Client
  |
  |  ClientHello
  |  ephemeral X25519 public key
  |
  v
Server
  |
  |  ServerHello
  |  ephemeral X25519 public key
  |  certificate chain
  |  handshake signature
  |
  v
Client

Enter fullscreen mode Exit fullscreen mode

Then both sides derive the shared secret using X25519:

client private key + server public key
server private key + client public key

Enter fullscreen mode Exit fullscreen mode

Both sides arrive at the same shared secret without sending that secret over the network.

Then HKDF turns that shared secret into actual session keys.

Then AES-GCM protects the application records.

The important change is that the client no longer accepts the server’s ephemeral public key blindly. It checks whether the authenticated server signed the handshake.

The complete shape now looks like this:

Certificate chain
  proves server identity

Handshake signature
  binds server identity to the ephemeral key exchange

X25519
  creates a fresh shared secret

HKDF
  derives directional session keys

AES-GCM
  protects application records

Enter fullscreen mode Exit fullscreen mode

This is still a simplified protocol, but the main pieces now line up with the real TLS story much better.

What We Built in Code

For this part, I added a small certificate infrastructure to the project.

The implementation generates a simple hierarchy:

Root CA
Intermediate CA
Server Certificate

Enter fullscreen mode Exit fullscreen mode

The server uses the server certificate and private key as its long-term identity. During the handshake, it still creates a fresh ephemeral X25519 key pair for the current connection.

That distinction matters.

The long-term certificate key is not used to encrypt application data. It is used to prove identity.

The ephemeral X25519 key is not used as identity. It is used to create a fresh shared secret for this connection.

This separation is one of the most important design ideas in modern TLS. Long-term keys authenticate. Ephemeral keys protect the session.

The simplified Part 4 flow is:

1. Client creates an ephemeral X25519 key pair.

2. Client sends its public key.

3. Server creates an ephemeral X25519 key pair.

4. Server sends:
   - its ephemeral public key
   - certificate chain
   - signature over handshake data

5. Client verifies the certificate chain.

6. Client verifies the handshake signature.

7. Both sides derive the shared secret with X25519.

8. Both sides derive session keys with HKDF.

9. Application data is protected with AES-GCM.

Enter fullscreen mode Exit fullscreen mode

The full code is in the GitHub repository:

https://github.com/DmytroHuzz/rebuilding_tls

The full technical walkthrough is here:

https://dmytrohuzz.github.io/rebuilding_tls/part_4/walkthrough/walkthrough.html

I intentionally keep the article focused on the protocol idea rather than pasting the whole implementation here. Long code blocks inside an article often create an illusion of depth, but they usually make the article harder to read.

The repository is the right place for the full implementation. The article is the right place for the explanation.

What This Still Is Not

This is not real TLS.

That sentence is important.

This project is an educational reconstruction of some core TLS ideas. It is not a library. It is not a production protocol. It is not something that should protect real traffic.

Real TLS has many more details and much stronger guarantees around the handshake. For example, real TLS 1.3 binds the handshake with a transcript hash. It supports negotiation, extensions, certificate validation rules, revocation mechanisms, session resumption, alerts, many edge cases, and years of hardening against attacks that are easy to miss when building a small protocol.

My version is intentionally smaller.

It is useful because it makes the main ideas visible:

Why encryption alone is not enough.

Why integrity must be added.

Why fixed keys are weak.

Why key exchange gives fresh session keys.

Why key exchange is still not authentication.

Why certificates exist.

Why the server must sign the handshake.

Why TLS has the shape it has.

Enter fullscreen mode Exit fullscreen mode

That is the real goal of this series.

Not to replace TLS, but to make TLS less mysterious.

Try It Yourself

The project is public and runnable.

The main repository is here:

https://github.com/DmytroHuzz/rebuilding_tls

The Part 4 walkthrough is here:

https://dmytrohuzz.github.io/rebuilding_tls/part_4/walkthrough/walkthrough.html

The complete series landing page is here:

https://www.dmytrohuz.com/p/rebuilding-tls-from-scratch-my-complete

If you want to understand the path from the beginning, I recommend reading the series in order. Each part fixes one problem and reveals the next one.

Part 1 starts with encryption. Part 2 adds integrity. Part 3 adds key exchange and session keys. Part 4 adds authentication through certificates and a handshake signature.

That sequence matters because it shows why TLS is not just “encryption.” It is a stack of answers to different problems.

Summary

Before Part 4, the protocol could create an encrypted channel, but it could not prove who was on the other side.

That is a serious problem.

Encryption protects data from being read. Integrity protects data from being modified. Key exchange creates fresh session keys. But authentication tells the client whether it is talking to the real server or to an attacker in the middle.

In Part 4, I added that missing authentication layer.

The client now verifies a certificate chain and checks a handshake signature. The server uses a long-term identity key to authenticate itself, while still using an ephemeral X25519 key for the actual key exchange. HKDF derives session keys, and AES-GCM protects application data.

The result is still not real TLS, but it now has the core shape:

authenticated handshake
fresh session keys
protected records

Enter fullscreen mode Exit fullscreen mode

And that is the point of this whole series.

TLS is hard to understand when you only look at the final protocol. There are too many details, too many names, too many moving parts.

But when you rebuild it step by step, each piece starts to make sense.

You first feel the problem.

Then you add the missing mechanism.

Then you see why the real protocol looks the way it does.