📘 Tutorial 10: Application-Layer Security and HTTPS

COMP347 (Revision 10) | TrustOpen University

📑 Table of Contents

🎯 Learning Objectives

Upon completion of this expanded tutorial, students will be able to:

🔭 Overview

Application-layer security is paramount in modern networking, as applications handle sensitive user data and are exposed to sophisticated adversaries. This tutorial provides a rigorous, university‑level examination of the security mechanisms that protect application communications, with a primary focus on HTTPS and its underlying TLS protocol.

We begin with formal security models, including the Dolev‑Yao adversary and the CIA triad. We then dissect TLS 1.3, the current standard, detailing the handshake, key exchange, and record protocol. A comparison with TLS 1.2 highlights the security improvements (removal of weak ciphers, perfect forward secrecy by default). We explore the PKI ecosystem, including certificate validation, the role of CAs, and the emergence of Certificate Transparency to detect mis‑issuance. We then shift to web application security, covering the OWASP Top 10 vulnerabilities and their mitigations, including security headers like CSP, HSTS, and X‑Frame‑Options. Finally, we examine historical attacks (BEAST, POODLE, Heartbleed) and the lessons learned.


1. Security Fundamentals – Formal Models

1.1 CIA Triad and the Dolev‑Yao Model

The Dolev‑Yao model formalises the adversary's capabilities: the attacker can intercept, replay, drop, and fabricate messages, but cannot break cryptographic primitives (i.e., the attacker cannot decrypt without the key). This model underpins the security proofs of TLS.

1.2 Security Mechanisms


2. TLS Protocol – In‑Depth

2.1 TLS 1.3 Handshake (Full 1‑RTT)

Client Server | | |--- ClientHello ----->| | (key_share, sig_algs)| | | |<-- ServerHello ------| | (key_share) | |<-- EncryptedExtensions| |<-- Certificate ------| |<-- CertificateVerify | |<-- Finished --------| | | |--- Finished -------->| | | |--- Application Data--| |<-- Application Data--|

Messages explained:

2.2 Key Schedule

TLS 1.3 uses the HKDF (HMAC‑based Extract‑and‑Expand) key derivation function based on the negotiated hash (e.g., SHA‑256). The steps:

  1. Early Secret: derived from the pre‑shared key (PSK) if used, or a fixed null value.
  2. Handshake Secret: derived from the (EC)DHE shared secret.
  3. Master Secret: derived from the handshake secret.
  4. Traffic Keys: derived from the master secret for application data encryption.

Each stage produces separate keys for client‑to‑server and server‑to‑client traffic, ensuring forward secrecy (the handshake keys are independent of session keys).

2.3 Record Protocol

The record protocol encapsulates application data and control messages. In TLS 1.3, it uses AEAD (Authenticated Encryption with Associated Data) modes like AES‑GCM or ChaCha20‑Poly1305. The record header includes the content type (always 23 for application data), the version (0x0304 for TLS 1.3), and the length. The payload is encrypted and authenticated in one pass.


3. TLS 1.3 vs TLS 1.2 – Detailed Comparison

FeatureTLS 1.2TLS 1.3
Handshake latency2 RTT (full) or 1 RTT (with session resumption)1 RTT (full) or 0‑RTT (with resumption)
Key exchangeRSA, DH, ECDH (static or ephemeral)Ephemeral Diffie‑Hellman (ECDHE) only – mandatory PFS
Signature algorithmsRSA, DSA, ECDSARSA‑PSS, ECDSA, Ed25519
Record encryptionMAC + CBC or AEADAEAD only (e.g., AES‑GCM)
Cipher suitesMany, including weak (RC4, 3DES)Limited to AEAD, with no weak ciphers
CompressionSupported (but disabled)Removed
RenegotiationSupportedRemoved
Session resumptionSession IDs or ticketsPSK with (EC)DHE or 0‑RTT

3.1 0‑RTT Resumption

0‑RTT allows a client to send application data in the first flight (ClientHello) if it has a PSK from a previous session. However, 0‑RTT is vulnerable to replay attacks; therefore, it is only safe for idempotent requests (e.g., GET). The server must implement replay detection (e.g., using a cache of tickets).


4. HTTPS and TLS Termination

4.1 HTTPS vs HTTP

HTTPS is HTTP over TLS. It uses port 443 by default. The security benefits include confidentiality, integrity, and server authentication. Browsers enforce HTTPS for many features (geolocation, service workers) and mark HTTP sites as "Not Secure".

4.2 TLS Termination Architectures


5. Public Key Infrastructure and Certificates

5.1 Certificate Chain and Validation

An X.509 certificate contains the subject (domain), public key, validity period, and the issuer (CA). The chain of trust: Root CA → Intermediate CA → Server certificate. Validation steps:

  1. Check validity period.
  2. Check signature against the issuer's public key (recursively up to a trusted root).
  3. Check revocation via CRL or OCSP.
  4. Check hostname (subjectAltName or CN).
  5. Check key usage and extended key usage.

5.2 Certificate Transparency (CT)

CT (RFC 6962) is a system where CAs must publicly log all issued certificates. Browsers require certificates to have a Signed Certificate Timestamp (SCT) from a trusted log. This prevents CAs from issuing certificates without public oversight, mitigating mis‑issuance and man‑in‑the‑middle attacks.

5.3 Let's Encrypt and ACME

Let's Encrypt provides free, automated certificates using the ACME (Automated Certificate Management Environment) protocol. ACME uses challenges (HTTP‑01, DNS‑01, TLS‑ALPN‑01) to prove domain ownership, enabling auto‑renewal (certificates valid for 90 days).


6. Web Application Security – OWASP Top 10

6.1 Top Vulnerabilities (2021)

#CategoryMitigation
A01Broken Access ControlEnforce least privilege, proper session management
A02Cryptographic FailuresUse TLS, strong cipher suites, secure key storage
A03Injection (SQL, XSS)Parameterised queries, output encoding, CSP
A04Insecure DesignSecure by design, threat modelling
A05Security MisconfigurationHardening, minimal config, automated scanning
A06Vulnerable & Outdated ComponentsRegular updates, dependency scanning
A07Identification & Authentication FailuresStrong passwords, MFA, rate limiting
A08Software & Data Integrity FailuresSigned builds, integrity checks
A09Security Logging & Monitoring FailuresComprehensive logging, incident response
A10Server‑Side Request Forgery (SSRF)Validate and sanitise URLs, restrict outbound

7. Security Headers and Best Practices

7.1 HTTP Security Headers

7.2 TLS Configuration Best Practices


8. Cryptographic Attacks and Mitigations

8.1 Historic Attacks

AttackDescriptionMitigation
BEAST (2011)Exploits CBC mode in TLS 1.0; allows plaintext recoveryUse TLS 1.2+ with AEAD; disable CBC
POODLE (2014)Padding oracle attack on SSLv3Disable SSLv3
Heartbleed (2014)Buffer over‑read in OpenSSL; leaks memoryPatch OpenSSL; use heartbleed‑free versions
DROWN (2016)Cross‑protocol attack on RSA using SSLv2Disable SSLv2; use ephemeral key exchange
Logjam (2015)Downgrade attack on Diffie‑Hellman with weak parametersUse strong DHE groups (≥2048 bits); prefer ECDHE
Sweet32 (2016)Birthday attack on 64‑bit block ciphers (3DES)Disable 3DES; use AES

8.2 Modern Countermeasures


📝 Quiz: Tutorial 10

Q1: In the Dolev‑Yao model, what is the attacker assumed to be capable of?

Answer

Intercepting, replaying, dropping, and fabricating messages, but cannot break cryptographic primitives.

Q2: What is the main purpose of the CertificateVerify message in TLS 1.3?

Answer

It contains a digital signature over the handshake transcript, proving the server's possession of the private key.

Q3: Which key exchange mechanism is mandatory in TLS 1.3?

Answer

Ephemeral Diffie‑Hellman (ECDHE) – providing perfect forward secrecy.

Q4: What is the primary security concern with 0‑RTT in TLS 1.3?

Answer

Replay attacks; the server must implement replay detection for non‑idempotent requests.

Q5: What is the role of Certificate Transparency?

Answer

It requires CAs to publicly log all issued certificates, allowing detection of fraudulent or mis‑issued certificates.

Q6: How does HSTS improve security?

Answer

It instructs the browser to only connect over HTTPS for a specified period, preventing SSL stripping and downgrade attacks.

Q7: What does the Content‑Security‑Policy (CSP) header do?

Answer

It restricts the sources from which resources (scripts, images, etc.) can be loaded, preventing XSS and data injection.

Q8: Which cryptographic attack exploited the CBC mode in TLS 1.0?

Answer

The BEAST attack.

Q9: What is the difference between CRL and OCSP for certificate revocation checking?

Answer

CRL is a periodically‑published list; OCSP is a real‑time query to a designated responder, providing more timely revocation information.

Q10: In TLS termination at a load balancer, where is the private key stored?

Answer

On the load balancer; the traffic to the origin server may be unencrypted, introducing a security risk if the network is not trusted.

Q11: What is the purpose of the `X‑Frame‑Options` header?

Answer

It prevents clickjacking by controlling whether the page can be embedded in frames (DENY, SAMEORIGIN).

Q12: Why was SSLv3 deprecated?

Answer

Due to the POODLE attack, which exploited a padding oracle vulnerability.


✏️ Exercises: Tutorial 10

Exercise 1 – TLS Handshake Analysis

Describe the steps in a TLS 1.3 full handshake, including the cryptographic computations.

Sample Solution

ClientHello (key_share) → ServerHello (key_share, certificate, certificate_verify) → Finished messages. The shared secret is derived via ECDHE; handshake transcript is hashed; HKDF derives traffic keys; Finished messages authenticate the handshake.

Exercise 2 – Certificate Validation

A browser receives a certificate with a valid signature but for a domain that doesn't match. What happens?

Sample Solution

The browser shows a security warning. The connection may be encrypted, but the server identity is not verified, making it vulnerable to MITM attacks.

Exercise 3 – Security Header Configuration

Write the HTTP response headers for a website that wants to enforce HTTPS, prevent framing, and restrict scripts to its own domain.

Sample Solution

Strict‑Transport‑Security: max‑age=31536000; includeSubDomains
X‑Frame‑Options: DENY
Content‑Security‑Policy: default‑src 'self'; script‑src 'self'

Exercise 4 – Attack Mitigation

Your server supports TLS 1.0 and 3DES. Which attacks are you vulnerable to and how would you fix them?

Sample Solution

Vulnerable to BEAST (TLS 1.0), POODLE (if SSLv3 enabled), and Sweet32 (3DES). Fix: disable TLS 1.0 and 1.1, disable SSLv3, disable 3DES, and use only TLS 1.2/1.3 with AEAD ciphers (AES‑GCM, ChaCha20).

Exercise 5 – CSRF Protection

Explain how a CSRF token works and where it should be placed.

Sample Solution

The server generates a random token per session (or per form) and embeds it in the HTML form or as a custom header. When the client submits the request, the token is sent back; the server verifies it. This ensures that the request originated from the legitimate site, not from a malicious third‑party.

Exercise 6 – Heartbleed Explanation

What was the Heartbleed bug and how was it exploited?

Sample Solution

Heartbleed was a buffer over‑read vulnerability in OpenSSL's heartbeat extension. An attacker could send a heartbeat request with a length longer than the actual data, causing the server to return up to 64KB of memory contents, potentially leaking private keys, session data, and passwords. It was fixed by patching OpenSSL and re‑issuing certificates.


📚 Homework: Tutorial 10

Homework 1 – TLS 1.3 Performance vs Security

Benchmark the performance of TLS 1.3 vs TLS 1.2 for a web server under load. Measure connection establishment time (full handshake and session resumption) and throughput. Analyse the impact of 0‑RTT on latency.

Guidance

Use `openssl s_time` or `wrk` with TLS support.

Homework 2 – Certificate Transparency Analysis

Investigate a recently issued certificate using a CT log (e.g., crt.sh). Check the SCTs and the log inclusion proof. Write a report on how CT prevents MITM attacks.

Guidance

Pick a common domain; inspect the certificate's SCTs and verify the signatures using CT tools.

Homework 3 – OWASP Top 10 Vulnerability Assessment

Perform a vulnerability assessment on a test web application (e.g., OWASP WebGoat) using OWASP ZAP. Identify at least five vulnerabilities and propose specific fixes for each.

Guidance

Focus on authentication, injection, and misconfiguration issues.

Homework 4 – HSTS Preload Submission

Prepare a domain for HSTS preload submission. List the requirements (valid HTTPS, HSTS header with max‑age ≥ 1 year, includeSubDomains, preload). Document the process and test with the HSTS preload check.

Guidance

Follow the hstspreload.org checklist.

Homework 5 – mTLS Implementation

Design a mutual TLS authentication scheme for a microservices architecture. Describe how certificates are issued, distributed, and renewed. Discuss the trade‑offs between mTLS and JWT for service‑to‑service authentication.

Guidance

Include certificate lifecycle management using a PKI (e.g., Vault) and the use of SPIFFE identities.


📌 Summary

This expanded tutorial has provided a comprehensive, university‑level examination of application‑layer security and HTTPS. Key takeaways:

Understanding these concepts is crucial for building secure networked applications and for staying ahead of evolving threats.