π Module 04: SSL/TLS, Certificate Authorities & PKI
Core Focus: Symmetric vs Asymmetric Encryption, TLS 1.2 vs TLS 1.3 Handshake Packet Flows, Certificate Authorities (CA) & PKI Hierarchy, Step-by-Step Local Certificate Validation (Root Store, Digital Signatures, Chain of Trust, OCSP/CRL), Forward Secrecy (PFS), and Mutual TLS (mTLS) in Banking/Juspay Infrastructure.
π Table of Contents
- Cryptography Fundamentals for Networks
- Public Key Infrastructure (PKI) & Certificate Authorities
- How Your Computer Validates a Certificate Locally
- The SSL/TLS Handshake Deep Dive
- Mutual TLS (mTLS) in Payment Systems
- Juspay & Payment Systems Real-World Context
- High-Yield Interview Questions & Verbatim Answers
1. Cryptography Fundamentals for Networks
Security over the internet requires solving three distinct challenges:
- Confidentiality (Privacy): Eavesdroppers cannot read data $\implies$ Encryption.
- Integrity (Tamper-Proof): Data cannot be altered in transit $\implies$ Hashing / HMAC.
- Authentication (Identity): Proof of who you are talking to $\implies$ Digital Signatures & Certificates.
1.1 Symmetric vs Asymmetric Encryption
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SYMMETRIC vs ASYMMETRIC ENCRYPTION β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β SYMMETRIC ENCRYPTION (Single Shared Key): β
β - Same key used to encrypt and decrypt. β
β - Algorithms: **AES-256-GCM**, **ChaCha20-Poly1305**. β
β - Properties: Blazingly fast (hardware accelerated via CPU AES-NI instructions). β
β - Challenge: Key distribution problem (how do you securely share the secret key?). β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β ASYMMETRIC ENCRYPTION (Public / Private Key Pair): β
β - Mathematical pair: Public Key (shared openly), Private Key (kept strictly secret). β
β - Data encrypted with Public Key can ONLY be decrypted by corresponding Private Key. β
β - Algorithms: **RSA (2048/4096-bit)**, **ECC / ECDSA (256-bit)**, **Diffie-Hellman**.β
β - Properties: Computationally expensive (~1000x slower than AES). β
β - Primary Use: Key exchange & digital signatures during the initial handshake. β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ[!IMPORTANT] Hybrid Encryption (The Best of Both Worlds):
HTTPS does not encrypt website data with RSA/ECC. It uses Asymmetric Cryptography for 1 second during the handshake to authenticate and negotiate a temporary shared Symmetric Session Key, and then uses AES-GCM (Symmetric) to encrypt all actual HTTP traffic.
1.2 Cryptographic Hashes & Digital Signatures
- Cryptographic Hash (SHA-256): One-way mathematical function producing a fixed-size 256-bit fingerprint. Any 1-bit change produces a drastically different hash (avalanche effect).
- Digital Signature:
- The signer computes: $\text{Hash} = \text{SHA-256}(\text{Data})$.
- The signer encrypts the hash using their Private Key: $$\text{Digital Signature} = \text{Encrypt}_{\text{PrivateKey}}(\text{Hash})$$
- Anyone holding the signer's Public Key can decrypt the signature to reveal the expected hash and compare it with the independently computed hash of the data. If they match, authenticity and integrity are proven.
1.3 Forward Secrecy (PFS β Perfect Forward Secrecy)
- The Danger of Static RSA Key Exchange: In legacy TLS, the client encrypted the pre-master secret with the server's public RSA key. If an adversary recorded years of encrypted traffic and eventually stole the server's private key, they could decrypt all past historical traffic!
- PFS via Ephemeral Diffie-Hellman (ECDHE):
- Generates a fresh, temporary key pair for every single session.
- Even if the server's permanent private key is compromised in the future, past recorded sessions cannot be decrypted.
- TLS 1.3 bans static RSA key exchange and mandates Ephemeral Diffie-Hellman.
2. Public Key Infrastructure (PKI) & Certificate Authorities
How does a browser know that the public key received from api.juspay.in genuinely belongs to Juspay and not an adversary performing a Man-in-the-Middle (MitM) attack? Certificate Authorities (CAs) solve this.
2.1 The Chain of Trust
THE PKI CHAIN OF TRUST
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ROOT CA CERTIFICATE (e.g., DigiCert Global Root CA) β
β - Self-Signed with Root CA Private Key β
β - Pre-installed inside OS / Browser "Root Trust Store" β
ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ
β Signs Intermediate Cert
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INTERMEDIATE CA CERTIFICATE (e.g., DigiCert TLS RSA CA) β
β - Signed by Root CA Private Key β
β - Issued to protect the offline Root CA private key β
ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ
β Signs End-Entity Cert
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LEAF / END-ENTITY CERTIFICATE (api.juspay.in) β
β - Contains: Domain Name, Juspay Public Key, Validity β
β - Signed by Intermediate CA Private Key β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ[!NOTE] Why Intermediate CAs?
Root CA private keys are stored on air-gapped Hardware Security Modules (HSMs) in high-security vaults. If a Root CA key were compromised, all certificates on the internet would be invalidated. Intermediate CAs handle day-to-day issuance; if an intermediate CA is compromised, only that intermediate is revoked without affecting the Root CA.
2.2 Structure of an X.509 Certificate
An X.509 certificate contains:
- Subject: Entity being certified (
CN=api.juspay.in,O=Juspay Technologies Pvt Ltd). - Subject Alternative Name (SAN): List of valid hostnames (
api.juspay.in,*.juspay.in). - Subject Public Key Info: Algorithm (e.g., RSA 2048-bit or ECC P-256) and the actual Public Key.
- Issuer: Name of issuing CA (
DigiCert Global G2 TLS CA). - Validity Period:
NotBefore: Aug 01 2026,NotAfter: Aug 01 2027(Max lifetime is currently 398 days). - Digital Signature: Signature generated by the Issuer CA's private key over the certificate fields.
3. How Your Computer Validates a Certificate Locally
This is one of the most frequently asked questions in high-bar interviews.
LOCAL CERTIFICATE VALIDATION FLOW
[ Server sends Certificate Chain: Leaf Cert + Intermediate Cert ]
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β Step 1: Validate Chain to Root Store β
β Does the Root CA exist in local OS Store?β
ββββββββββββββββββββββ¬ββββββββββββββββββββββ
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β Step 2: Cryptographic Signature Check β
β Decrypt signature using Issuer Public Keyβ
β Compare with computed SHA-256 hash. β
ββββββββββββββββββββββ¬ββββββββββββββββββββββ
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β Step 3: Domain Name Matching (SAN) β
β Does requested URL match Cert SAN list? β
ββββββββββββββββββββββ¬ββββββββββββββββββββββ
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β Step 4: Validity & Expiration Check β
β Current Time between NotBefore & NotAfterβ
ββββββββββββββββββββββ¬ββββββββββββββββββββββ
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β Step 5: Revocation Check (OCSP Stapling) β
β Has the certificate been revoked? β
ββββββββββββββββββββββ¬ββββββββββββββββββββββ
βΌ
[ TRUST VERIFIED! Proceed ]3.1 The 5-Step Local Verification Algorithm
- Step 1: Locate the Root CA in the Local Trust Store:
- Operating Systems (Windows Certificate Manager
certmgr.msc, macOS Keychain, Linux/etc/ssl/certs) and browsers (Mozilla Firefox) ship with a hardcoded Trust Store containing ~150 vetted Root CA certificates and their public keys. - The computer matches the Root CA name in the certificate chain against its pre-installed Root Store.
- Operating Systems (Windows Certificate Manager
- Step 2: Cryptographic Signature Verification (Walking Up the Chain):
- Verifying Leaf Cert: The computer takes the Intermediate CA's Public Key and uses it to decrypt the Digital Signature on the Leaf Certificate. It hashes the Leaf Certificate body using SHA-256. If
Decrypted_Signature == Computed_Hash, the Leaf Cert is authentic! - Verifying Intermediate Cert: The computer takes the Root CA's pre-installed Public Key (from local storage) and verifies the Intermediate CA's signature.
- Verifying Leaf Cert: The computer takes the Intermediate CA's Public Key and uses it to decrypt the Digital Signature on the Leaf Certificate. It hashes the Leaf Certificate body using SHA-256. If
- Step 3: Domain Name Matching:
- The browser inspects the Subject Alternative Name (SAN) field in the Leaf Certificate.
- If user typed
api.juspay.in, the SAN must containapi.juspay.inor*.juspay.in. If not, browser showsERR_CERT_COMMON_NAME_INVALID.
- Step 4: Date & Expiration Verification:
- The computer reads its local system clock. It verifies that: $$\text{NotBefore} \le \text{Current Time} \le \text{NotAfter}$$
- If system clock is incorrect (e.g., set to year 2010), valid certificates will fail with
NET::ERR_CERT_DATE_INVALID.
- Step 5: Revocation Status Check:
- Checks if the certificate was revoked before its expiration date (e.g., due to compromised private key).
3.2 Digital Signature Verification Math
SERVER SENDS: [ Certificate Body ] + [ Digital Signature (Encrypted Hash) ]
β β
βΌ βΌ
[ SHA-256 Hashing ] [ Decrypt with CA Public Key ]
β β
βΌ βΌ
Hash Value 'H1' Hash Value 'H2'
β β
βββββββββββββΊ H1 == H2 ? βββββββββββ
β
βββββββββββββββββ΄ββββββββββββββββ
βΌ βΌ
[ TRUE ] [ FALSE ]
Cert is Authentic TAMPERED / INVALID!3.3 Revocation Checking: CRL vs OCSP vs OCSP Stapling
| Mechanism | How It Works | Latency / Privacy Issue | Production Status |
|---|---|---|---|
| CRL (Certificate Revocation List) | CA periodically publishes a signed list of revoked serial numbers. Client downloads entire list. | Huge file download (megabytes); high latency; stale lists. | Legacy / Deprecated |
| OCSP (Online Certificate Status Protocol) | Client sends real-time HTTP request to CA server for specific cert serial number. | Privacy Leak (CA learns every site user visits) + extra network round-trip. | Fallback only |
| OCSP Stapling (Modern Standard) | Server periodically queries CA OCSP responder, caches the time-stamped CA response, and "staples" it directly to the TLS Handshake. | Zero latency for client; 100% privacy preserved. | Industry Standard |
4. The SSL/TLS Handshake Deep Dive
4.1 TLS 1.2 Handshake (2 RTT Overhead)
CLIENT SERVER
β βββ 1. ClientHello (TLS Version, Supported Ciphers, Random_C) βββ> β
β β
β <ββ 2. ServerHello (Selected Cipher, Random_S) βββββββββββββββββββ β
β <ββ 3. Certificate (Leaf + Intermediate Chain) βββββββββββββββββββ β
β <ββ 4. ServerKeyExchange (ECDHE Public Parameter + CA Signature) β β
β <ββ 5. ServerHelloDone βββββββββββββββββββββββββββββββββββββββββββ β
β β
β [Client Validates Certificate locally against Root Store] β
β βββ 6. ClientKeyExchange (ECDHE Public Parameter) βββββββββββββββ> β
β βββ 7. ChangeCipherSpec + Finished (Encrypted Hash of Handshake) β> β
β β
β [Both compute: Master Secret = KDF(Random_C, Random_S, ECDHE_Secret)]β
β <ββ 8. ChangeCipherSpec + Finished βββββββββββββββββββββββββββββββ β
β β
βΌ [SECURE SYMMETRIC CHANNEL ESTABLISHED (AES-256-GCM)] βΌ
β βββ 9. Encrypted Application Data (HTTP POST /payment) ββββββββββ> β4.2 TLS 1.3 Handshake (Optimized 1 RTT)
TLS 1.3 (RFC 8446) overhauled the handshake to reduce connection setup time by 50% and eliminate legacy insecure ciphers:
CLIENT SERVER
β βββ 1. ClientHello ββββββββββββββββββββββββββββββββββββββββββββββ> β
β - Supported Ciphers (AES-GCM, ChaCha20) β
β - Key Share (Client's ECDHE Public Key sent immediately!) β
β β
β <ββ 2. ServerHello (Server's ECDHE Key Share) ββββββββββββββββββββ β
β <ββ 3. [ENCRYPTED] Certificate + OCSP Staple βββββββββββββββββββββ β
β <ββ 4. [ENCRYPTED] Finished ββββββββββββββββββββββββββββββββββββββ β
β β
β βββ 5. Finished + First HTTP Application Data (POST /payment) βββ> β- Key Difference: In TLS 1.3, the client guesses the key exchange algorithm and sends its Diffie-Hellman key share in the first message (
ClientHello), allowing encryption to begin immediately after 1 RTT.
5. Mutual TLS (mTLS) in Payment Systems
Standard TLS provides One-Way Authentication (Client verifies Server identity, but Server accepts connections from anyone).
In Mutual TLS (mTLS), both parties authenticate each other using certificates.
mTLS AUTHENTICATION FLOW
[ Juspay Payment Core ] <βββββββββββββββββββββββββ> [ HDFC Bank UPI Gateway ]
β β
βββββ 1. Server Certificate (HDFC proves identity) βββ€
β β
βββββ 2. Client Certificate (Juspay proves identity) β€
β β
βΌ βΌ
[ Verified & Encrypted Direct Inter-Banking Tunnel via Private CA ]Why mTLS is Mandatory in Payments:
- API Keys and Bearer tokens can be leaked, stolen, or logged in plaintext proxy logs.
- mTLS requires a cryptographic private key stored in an HSM or secure enclave. Even if an attacker intercepts network packets, they cannot impersonate the client without the private key.
6. Juspay & Payment Systems Real-World Context
ββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Security Standard / Requirement β Implementation Detail at Juspay Scale β
ββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β **PCI-DSS Level 1 Compliance** β TLS 1.2+ mandatory; SSLv3, TLS 1.0, TLS 1.1 strictly β
β β disabled. Deprecated ciphers (RC4, 3DES, CBC) banned. β
ββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β **Card Data Environment (CDE)** β Raw credit card numbers (PAN) are encrypted via AES-256β
β β and replaced with surrogate Tokens inside an HSM vault.β
ββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β **Certificate Pinning in SDKs** β Mobile SDKs (Android/iOS) pin Juspay's Intermediate β
β β Public Key to block local proxy inspection (Charles). β
ββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ7. High-Yield Interview Questions & Verbatim Answers
Q1: "How does your computer validate an SSL/TLS Certificate locally when you visit a website?"
Spoken Answer:
*"When the server presents its certificate chain (Leaf $\rightarrow$ Intermediate $\rightarrow$ Root), my computer performs a 5-step local verification:
- Root Store Lookup: It matches the Root CA in the chain against its local operating system / browser Root Trust Store.
- Digital Signature Verification: Starting from the trusted Root CA, it uses the CA's public key to decrypt the digital signature on the intermediate certificate and verifies the computed SHA-256 hash. It repeats this step down to the leaf certificate using the intermediate CA's public key.
- Domain Matching: It verifies that the requested domain name matches the Subject Alternative Name (SAN) field.
- Validity Window: It compares the system clock against the
NotBeforeandNotAftertimestamps.- Revocation Check: It checks if the certificate has been revoked via OCSP Stapling or CRL.
If all checks pass, the identity is authenticated and session keys are derived."*
Q2: "Why do we use both Symmetric and Asymmetric encryption in HTTPS instead of just one?"
Spoken Answer:
*"We use both because each solves what the other lacks:
- Asymmetric Encryption (RSA/ECC) solves the key distribution problemβit allows two parties who have never met to authenticate identities and establish a shared secret over an untrusted network. However, it is computationally expensive (~1000x slower).
- Symmetric Encryption (AES-256-GCM) is blazingly fast and hardware-accelerated, but requires both parties to already share a secret key.
Therefore, HTTPS uses Hybrid Encryption: asymmetric crypto is used for only 1 RTT during the initial handshake to authenticate and negotiate a temporary session key, after which symmetric crypto encrypts all high-volume HTTP data."*
Q3: "What is Perfect Forward Secrecy (PFS) and why is it important?"
Spoken Answer:
*"Perfect Forward Secrecy is a property of cryptographic key exchange protocols (like Ephemeral Diffie-Hellman, ECDHE) where a unique, temporary session key is generated for every individual session.Without PFS (such as in static RSA key exchange), if an adversary records encrypted network traffic for years and eventually compromises the server's long-term private key, they can decrypt all historical recorded communications. With PFS, compromising the server's private key does not compromise past session keys, keeping historical data secure."*
Q4: "What is Mutual TLS (mTLS) and where is it used in banking architectures?"
Spoken Answer:
*"In standard TLS, authentication is one-way: the client validates the server's identity. In Mutual TLS (mTLS), both the client and the server present X.509 digital certificates to authenticate each other.It is heavily used in Banking APIs, UPI Switches, and Payment Gateways (like Juspay) for B2B server-to-server communication. It guarantees that only pre-approved partner servers with valid private keys can invoke sensitive financial endpoints, mitigating credential leakage and Man-in-the-Middle attacks."*