Post

Deep Dive into HTTPS A Comprehensive Guide

Deep Dive into HTTPS A Comprehensive Guide

Deep Dive into HTTPS: A Comprehensive Guide

Introduction

Hypertext Transfer Protocol Secure (HTTPS) is the backbone of secure internet communication. This comprehensive guide explores how HTTPS works, its key components, and why it’s crucial for modern web security.

Architecture Overview

1
2
3
4
5
6
7
8
9
10
┌─────────────┐                                              ┌─────────────┐
│             │         1. Initial Connection                │             │
│   Client    │─────────────────────────────────────────────▶│   Server    │
│  (Browser)  │                                              │  (Website)  │
│             │         2. TLS Handshake                     │             │
│             │◀ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ▶│             │
│             │                                              │             │
│             │         3. Secure Data Exchange              │             │
│             │◀━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━▶│             │
└─────────────┘                                              └─────────────┘

Key Features of HTTPS

1. Encryption

  • Protects data in transit
  • Prevents eavesdropping
  • Ensures confidentiality

2. Authentication

1
2
3
4
5
6
7
8
┌──────────────┐     ┌───────────────┐     ┌──────────────┐
│   Website    │     │  Certificate   │     │    Client    │
│   Server     │────▶│   Authority    │────▶│   Browser    │
└──────────────┘     └───────────────┘     └──────────────┘
      │                      ▲                     │
      │                      │                     │
      └──────────────────────┴─────────────────────┘
           Certificate Verification Chain

3. Data Integrity

1
2
3
4
Original Data ──▶ Hash Function ──▶ Digital Signature
     │                                    │
     │                                    │
     └────────────────▶ Compare ◀────────┘

TLS Handshake Process (TLS 1.2)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
                                CLIENT                                                                  SERVER
                                  │                                                                      │
                                  │                           TCP (SYN)                                  │
                                  │─────────────────────────────────────────────────────────────────────▶│
                                  │                         TCP (SYN + ACK)                             │
                                  │◀─────────────────────────────────────────────────────────────────────│
                                  │                           TCP (ACK)                                  │
                                  │─────────────────────────────────────────────────────────────────────▶│
                                  │                                                                      │
Client Takes a random value a,    │                                                                      │
prime (p) and n                   │       Client Hello (TLS Version, Cypher suite, A)                   │    Client Takes a random value b,
(n,p from standards)              │─────────────────────────────────────────────────────────────────────▶│    takes p,n from cypher suite
A=n^a mod p                       │                                                                      │    B=n^b mod p
                                  │                                                                      │    Generate Pub, Priv Keys
                                  │        Server Hello (Pub key, Signature, B)                         │
                                  │◀─────────────────────────────────────────────────────────────────────│
                                  │                                                                      │
Client generates Pre master       │                         Encrypted PMS                               │
secret (PMS) and encrypt with     │─────────────────────────────────────────────────────────────────────▶│    Decrypt Encrypted PMS using
server's public key.              │                                                                      │    priv key.
                                  │                                                                      │
master_secret = PRF(PMS,          │                                                                      │    master_secret = PRF(PMS,
"master secret", a + B)           │   Client and server derives master secret by themselves which is     │    "master secret", A + b)
                                  │           used as the symmetri key (session key)                     │
                                  │                                                                      │
                                  │      Client finish (Includes the hash of previous handshakes)       │
Client verifies the hash with     │─────────────────────────────────────────────────────────────────────▶│    Server verifies the hash with
the expected hash                 │      Server finish (Includes the hash of previous handshakes)       │    the expected hash
                                  │◀─────────────────────────────────────────────────────────────────────│
                                  │                                                                      │
                                  │           Symmetric key encrypted communcation starts                │
                                  │◀────────────────────────────────────────────────────────────────────▶│

Cipher Suite Components

A modern HTTPS cipher suite consists of multiple cryptographic algorithms working together:

1
2
3
4
5
6
7
┌──────────┐ ┌─────────┐ ┌───────────────┐ ┌────────────────┐ ┌──────────┐
│   Key    │ │         │ │     Bulk      │ │    Message     │ │ Elliptic │
│ Exchange │ │Signature│ │  Encryption   │ │Authentication  │ │  Curve   │
├──────────┤ ├─────────┤ ├───────────────┤ ├────────────────┤ ├──────────┤
│  ECDHE   │ │  ECDSA  │ │  AES_256_GCM │ │    SHA384     │ │   P384   │
└──────────┘ └─────────┘ └───────────────┘ └────────────────┘ └──────────┘
└─────────────────────────── Cipher Suite ────────────────────────────────┘

Example cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384_P384

Diffie-Hellman Key Exchange

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
┌─────────────┐                                   ┌─────────────┐
│    Alice    │                                   │     Bob     │
└─────────────┘                                   └─────────────┘
      │                                                │
      │ Private key a                  Private key b   │
      │                                                │
      │        Public Key A = g^a mod p               │
      │───────────────────────────────────────────────▶│
      │                                                │
      │        Public Key B = g^b mod p               │
      │◀───────────────────────────────────────────────│
      │                                                │
      │ Shared Secret = B^a mod p   Shared Secret = A^b mod p
      │                                                │
      │         Both arrive at same secret            │
      └────────────────────┬─────────────────────────┘
                          │
                    Secure Channel

Example Calculation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Given:
- Prime modulus p = 23
- Primitive root g = 5
- Alice's private key a = 6
- Bob's private key b = 15

Alice's public key (A):
A = g^a mod p = 5^6 mod 23 = 8

Bob's public key (B):
B = g^b mod p = 5^15 mod 23 = 19

Shared Secret:
For Alice: s = B^a mod p = 19^6 mod 23 = 2
For Bob:   s = A^b mod p = 8^15 mod 23 = 2

Security Layers in HTTPS

1
2
3
4
5
6
7
8
9
┌─────────────────────────────────────────────┐
│              Application Layer              │
├─────────────────────────────────────────────┤
│                HTTP Protocol                │
├─────────────────────────────────────────────┤
│             TLS/SSL Protocol                │
├─────────────────────────────────────────────┤
│             Transport Layer                 │
└─────────────────────────────────────────────┘

Benefits of HTTPS

1. Security Benefits

1
2
3
4
5
6
7
┌─────────────┐
│   HTTPS     │
├─────────────┤
│ Encryption  │──▶ Protects sensitive data
│ Auth        │──▶ Verifies website identity
│ Integrity   │──▶ Prevents tampering
└─────────────┘

2. SEO and Trust Benefits

1
2
3
4
5
6
7
8
┌─────────────────────┐
│    HTTPS Benefits   │
├─────────────────────┤
│ ✓ Better Rankings   │
│ ✓ User Trust       │
│ ✓ Conversion Rates │
│ ✓ Security Badge   │
└─────────────────────┘

Implementation Best Practices

1. Certificate Management

1
2
3
4
5
6
7
8
9
10
11
12
13
┌────────────────────┐
│ Certificate Cycle  │
│                    │
│    Generation      │
│        ↓          │
│    Validation     │
│        ↓          │
│   Installation    │
│        ↓          │
│    Monitoring     │
│        ↓          │
│     Renewal       │
└────────────────────┘

2. Security Headers

1
2
3
4
5
6
7
8
# Example Security Headers
{
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
    'X-Content-Type-Options': 'nosniff',
    'X-Frame-Options': 'DENY',
    'X-XSS-Protection': '1; mode=block',
    'Content-Security-Policy': "default-src 'self'"
}

Common Vulnerabilities and Mitigations

1
2
3
4
5
6
7
8
┌────────────────────┬────────────────────────────┐
│    Vulnerability   │         Mitigation         │
├────────────────────┼────────────────────────────┤
│ SSL Stripping      │ HSTS Implementation        │
│ Weak Ciphers      │ Strong Cipher Suite        │
│ Expired Certs     │ Auto-renewal               │
│ Protocol Downgrade│ TLS 1.2+ Only             │
└────────────────────┴────────────────────────────┘

Performance Optimization

1
2
3
4
5
6
7
8
┌─────────────────────────┐
│ Performance Techniques  │
├─────────────────────────┤
│ ✓ OCSP Stapling        │
│ ✓ Session Resumption   │
│ ✓ HTTP/2 Support       │
│ ✓ CDN Integration      │
└─────────────────────────┘

Conclusion

HTTPS has become indispensable for modern web security, providing:

  • Encrypted communication
  • Server authentication
  • Data integrity
  • User trust and confidence

References

  1. IETF TLS 1.2 Specification
  2. OWASP HTTPS Best Practices
  3. Mozilla SSL Configuration Generator
This post is licensed under CC BY 4.0 by the author.