Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Samyak05/TLS-Handshake-Linux-Namespaces

Repository files navigation

πŸ” TLS & Mutual TLS (mTLS) Analysis over Layer-3 Routing using Linux Network Namespaces

Linux Networking TLS


πŸš€ Motivation

This project was built to deeply understand how TCP and TLS operate over a routed Layer-3 network.

Instead of using physical hardware, Linux network namespaces were used to simulate:

  • Isolated network nodes (client, router, server)
  • Two different IP subnets
  • IP forwarding across a software router
  • Real packet-level protocol behavior

The objective was to analyze:

  • TCP 3-way handshake
  • TLS 1.2 handshake workflow
  • Certificate exchange in plaintext
  • Encryption boundary after ChangeCipherSpec
  • TTL decrement across a router (Layer-3 proof)

This project was later extended to include Mutual TLS (mTLS) to demonstrate two-way authentication, where both client and server verify each other's identity using certificates.

This project provides a hands-on, packet-level understanding of secure communication mechanisms used in modern distributed systems and zero-trust architectures.


πŸ—Ί Network Topology

Topology

Addressing Scheme

Namespace Interface IP Subnet
red (Client) 10.0.1.2 10.0.1.0/24
router 10.0.1.1 / 10.0.2.1 Two connected subnets
blue (Server) 10.0.2.2 10.0.2.0/24
  • Default gateway (red): 10.0.1.1
  • Default gateway (blue): 10.0.2.1
  • IP forwarding enabled in router namespace

🧰 Requirements

  • Ubuntu 22.04 (or compatible Linux system)
  • iproute2
  • OpenSSL
  • tcpdump
  • Wireshark (host machine)

βš™οΈ Setup Instructions

πŸ” Generate Certificates

./generate_certs.sh

🌐 Create Namespaces and Routing

sudo ./setup.sh

πŸ”Ž Verify Connectivity

sudo ip netns exec red ping 10.0.2.2

Expected observation:

  • Successful ping replies
  • TTL decreases from 64 β†’ 63 (proof of router traversal)

🧹 Cleanup

sudo ./cleanup.sh

πŸ” TLS Handshake Execution & Packet Capture (TLS 1.2)

This section demonstrates capturing and analyzing the TLS handshake at packet level in a clean, linear workflow.

πŸ›  Step 1 β€” Start Packet Capture (Router)

sudo ip netns exec router tcpdump -i any port 4433 -w tls_capture.pcap

Keep this running.


πŸ” Step 2 β€” Start TLS Server (blue namespace)

(Open a new terminal)

sudo ip netns exec blue openssl s_server \
 -accept 4433 \
 -cert /certs/server.crt \
 -key /certs/server.key \
 -tls1_2

Expected output:

ACCEPT

πŸ”— Step 3 β€” Start TLS Client (red namespace)

(Open another terminal)

sudo ip netns exec red openssl s_client \
 -connect 10.0.2.2:4433 \
 -CAfile /certs/ca.crt \
 -tls1_2

This initiates the TLS handshake.


πŸ›‘ Step 4 β€” Stop Packet Capture

Press:

Ctrl + C

in the tcpdump terminal.


πŸ‘€ Step 5 β€” Analyze in Wireshark

Open the generated .pcap file in Wireshark.


πŸ” Recommended Filters

tls
tcp.port == 4433

πŸ”Ž Key Observations (TLS)

  • TCP 3-way handshake occurs before TLS begins
  • TLS handshake messages visible:
    • ClientHello
    • ServerHello
    • Certificate
    • ServerHelloDone
    • ClientKeyExchange
  • Encryption starts after ChangeCipherSpec
  • Subsequent packets appear as:
    TLS Application Data
    

πŸ” Mutual TLS (mTLS) Execution & Packet Capture

This section demonstrates mutual authentication where both client and server verify each other using certificates.

πŸ›  Step 1 β€” Start Packet Capture (Router)

sudo ip netns exec router tcpdump -i any port 4433 -w mtls_capture.pcap

Keep this running.


πŸ” Step 2 β€” Start mTLS Server (blue namespace)

sudo ip netns exec blue openssl s_server \
 -accept 4433 \
 -cert /certs/server.crt \
 -key /certs/server.key \
 -CAfile /certs/ca.crt \
 -Verify 1 \
 -tls1_2

πŸ”— Step 3 β€” Start mTLS Client (SUCCESS CASE)

sudo ip netns exec red openssl s_client \
 -connect 10.0.2.2:4433 \
 -cert /certs/client.crt \
 -key /certs/client.key \
 -CAfile /certs/ca.crt \
 -tls1_2

Expected result:

  • Handshake succeeds
  • Client and server authenticate each other

❌ Step 4 β€” Negative Test (Without Client Certificate)

sudo ip netns exec red openssl s_client \
 -connect 10.0.2.2:4433 \
 -CAfile /certs/ca.crt

Expected result:

  • Handshake fails
  • Server rejects client

πŸ›‘ Step 5 β€” Stop Packet Capture

Press:

Ctrl + C

in the tcpdump terminal.


πŸ‘€ Step 6 β€” Analyze in Wireshark

Open the generated .pcap file in Wireshark.


πŸ” Recommended Filters

tls
tcp.port == 4433

πŸ”Ž Key Observations (mTLS)

  • Server sends Certificate Request
  • Client responds with its Certificate
  • Client proves identity using Certificate Verify
  • Mutual authentication is established
  • Without client certificate β†’ handshake failure

πŸ” Encryption Boundary

After ChangeCipherSpec, Wireshark shows:

TLS Application Data

This applies to both TLS and mTLS, indicating the transition from asymmetric to symmetric encryption.


🌐 Layer-3 Routing Proof

Initial TTL: 64
Observed TTL: 63


πŸ”„ TLS vs mTLS Comparison

Feature TLS mTLS
Server Authentication βœ… βœ…
Client Authentication ❌ βœ…
Certificate Exchange One-way Two-way
Security Level High Very High
Use Cases HTTPS Zero Trust, Microservices

πŸ“ Project Structure

network_namespaces/
β”‚
β”œβ”€β”€ blue_namespace/
β”‚ β”œβ”€β”€ server.crt
β”‚ β”œβ”€β”€ server.key
β”‚ └── ca.crt
β”‚
β”œβ”€β”€ red_namespace/
β”‚ β”œβ”€β”€ client.crt
β”‚ β”œβ”€β”€ client.key
β”‚ └── ca.crt
β”‚
β”œβ”€β”€ ca/
β”‚ β”œβ”€β”€ ca.crt
β”‚ └── ca.key
β”‚
β”œβ”€β”€ diagrams/
β”‚ └── topology.png
β”‚
β”œβ”€β”€ screenshots/
β”‚
β”œβ”€β”€ report/
β”‚ └── report.pdf
β”‚
β”œβ”€β”€ setup.sh
β”œβ”€β”€ cleanup.sh
β”œβ”€β”€ generate_certs.sh
β”œβ”€β”€ README.md
β”œβ”€β”€ tls_capture.pcap
└── mtls_capture.pcap

⚠ Security Disclaimer

Self-signed certificates are used for educational purposes only.


πŸŽ“ Learning Outcomes

  • Layer-3 routing using namespaces
  • TCP handshake understanding
  • TLS 1.2 internals
  • Mutual TLS (mTLS) authentication
  • Certificate Authority (CA) concepts
  • Packet-level analysis with Wireshark

πŸ”— Lecture Source: Network Namespaces - Session 1

https://nitkeduin-my.sharepoint.com/:v:/g/personal/tahiliani_nitk_edu_in/EZsxo6VafiBIn3ybNUNOYPYBJ9Oe7nvBMFc81vTTC-FhtQ?e=b16yGn


πŸ‘¨β€πŸ’» Author

Samyak Gedam
National Institute of Technology Surathkal, Karnataka
Built as part of first task in mini-project course during my 2nd Semester.

About

Simulating Layer-3 routing using Linux network namespaces and performing packet-level TCP & TLS handshakes for analysis using Wireshark.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /