1 of 64

Basic Cryptography & HTTPS

CSE 598 Advanced Security of the Web

Fish Wang

Fall 2026

2 of 64

Cryptography

  • Cryptography provides the building-blocks to achieve communication security

​

  • Communication security includes
    • Privacy/confidentiality
    • Authentication
    • Integrity
    • Non-repudiation

3 of 64

Applying Cryptography

Cleartext

Encryption

Ciphertext

A7&QK#L<

Decryption

Key

Key

4 of 64

What Will A Hacker Think?

  • Is the crypto secure?
    • Is it strong enough (in theory)?
    • Is the implementation secure? Are there weaknesses?
    • Is the user using the crypto securely?

​

  • Can I recover the plaintext?
  • Can I recover the key?

​

5 of 64

Cryptanalysis

  • Cryptanalysis attempts to discover the key or the plaintext of an encrypted message
  • Types of attack
    • Ciphertext only

Given C1=E_K(P1), C2=E_K(P2), … derive P1, P2, … or K

    • Known plaintext

Given P1, C1=E_K(P1), P2, C2=E_K(P2), … derive K or an algorithm to obtain Pi+1 from Ci+1 = E_K(Pi+1)

    • Chosen plaintext

Given P1, C1=E_K(P1), P2, C2=E_K(P2), … where the attacker chooses P1, P2, …, derive K or an algorithm to obtain Pi+1 from Ci+1=E_K(Pi+1)

6 of 64

Security of a Cryptosystem

  • One-time pad is perfectly secure (Shannon)

​

​

​

​

  • You cannot decipher the ciphertext without knowing the key
  • OTP is the foundation of many modern cryptos

Plaintext

Key

Operation

Ciphertext

3 0 0 8 1 2 3 7 2 1 8 3

1 9 4 6 8 0 3 1 9 4 5 3

+

4 9 4 14 9 2 6 8 11 5 13 6

7 of 64

More on OTP

  • What problems may an OTP have?

​

​

  • Keys must be random enough
  • Keys must be long enough
  • Keys can only be used once

8 of 64

Security of a Cryptosystem

  • Crypto algorithms can be computationally secure
    • The cost of breaking the encryption exceeds the value of the encrypted information
    • The time required to break the cipher exceeds the useful lifetime of the information
  • Cost and time are difficult to estimate
  • Exhaustive key space search (brute-force)

If trying all possible keys requires ten billion years with the most powerful computer, then the algorithm can be considered secure

9 of 64

In The Real World…

https://xkcd.com/538/

10 of 64

Crypto Algorithms

  • Symmetric algorithms (single-key, secret-key)
    • Encryption/decryption keys (K) are the same

​

  • Asymmetric algorithms (public-key)
    • Two different keys (K1 and K2)
    • Impossible to calculate one key from the other
    • Encryption is done with one key, and decryption must be done with the other

11 of 64

Crypto Algorithms

  • Random number generators
    • Random number generators (using physical phenomena)
    • Pseudorandom number generators (using an initial seed and an algorithm)

4541995603……………128393314541995603………….128393314541....

A sequence of numbers with an extremely long period.

12 of 64

Crypto Algorithms

  • One-way hash functions
    • Take a variable-length input and generate a fixed-length input
    • Transform the input data irreversibly
    • … in a way that is as similar as possible to a random function
    • The transformation can be parameterized/customized using a secret key K

13 of 64

Crypto Algorithms

  • One-way hash functions
    • Cannot change the message without changing the hash
    • Cannot pre-compute the whole hash space (pre-image resistance)
    • Cannot find a (previously unknown) message that generates a specific hash (second pre-image resistance)
    • Cannot find two messages with the same hash (collision resistance)

14 of 64

Examples

  • Symmetric algorithms
    • DES (broken)
    • AES
    • RC4 (broken)
  • Asymmetric algorithms
    • Diffie-Hellman
    • RSA
    • Elliptic curve
  • One-way hash functions
    • MD4 (broken)
    • MD5 (broken)
    • SHA1 (broken)
    • SHA-256

MD4: d36183e60baff473fe3eaff527445f23

MD5: b62ba115efc8e9dc0509fc81d2b3facd

SHA1: 447c96527e26351b9452951abea9460b951cc81d

SHA-256: 23ae442892c1b454376f6d471534a59d49000da0c80ae5ff92b51f6238ab57f4

15 of 64

Secure Communication

  • Goals
    • Confidentiality
    • Authentication
    • Integrity
    • Non-repudiation
  • Threat model
    • Can intercept
    • Can repeat
    • Can modify
    • Cannot break the crypto

Alice

Bob

Eve

16 of 64

Communication Using Symmetric Cryptography

  • Alice and Bob agree on a crypto system (e.g., AES)
  • Alice and Bob agree on a secret key K
  • Alice encrypts a message using K and then sends it to Bob�C = E_K(M)
  • Bob decrypts the message using K�M = D_K(C)

17 of 64

Properties

  • Pros
    • Confidentiality: Eve cannot access M without knowing K
    • Authentication (weak): only who knows K can participate in the communication
    • Integrity (weak): if the message C is modified, it will decrypt to gibberish
  • Cons
    • Key distribution is critical, and requires out-of-band communication
    • If key is compromised, Eve can impersonate both Alice and Bob
    • The number of keys increases with the number of parties
    • Cannot be used to prove that the message was sent specifically by one of the involved parties

18 of 64

Key Distribution Center (KDC)

  • A KDC manages and distributes secret keys

​

    • Alice shares a secret key Ka with the KDC
    • Bob shares a (different) secret key Kb with the same KDC
    • Alice tells the KDC that she wants to talk to Bob
    • The KDC generates a temporary secret key (session key) Kt
    • The KDC sends E_Ka(Kt) to Alice and E_Kb(Kt) to Bob
    • Alice and Bob communicate using Kt

19 of 64

Properties

  • Pros
    • Limited number of keys
    • Kt validity is limited to a session

​

  • Cons
    • The KDC is a single point of failure: If compromised, the whole system is compromised
    • Requires constant availability of the KDC

20 of 64

Communication Using Asymmetric Cryptography

  • Alice and Bob agree on a public-key cryptosystem (e.g., RSA)
  • Bob sends his public key PKb to Alice
  • Alice encrypts a message with Bob’s public key and sends it to Bob
  • Bob decrypts the message using his private key SKb

21 of 64

Properties

  • Pros
    • Key distribution: Public keys can be sent using in-band channels
    • Confidentiality: Eve must know Bob’s private key to decrypt the message
    • Integrity (weak): any modification of the message would be revealed when decrypting
  • Cons
    • No authentication: anybody can send a message to Bob pretending to be Alice
    • Alice can deny having sent the message

22 of 64

Communication Using Asymmetric Cryptography

A better version!

    • Alice and Bob agree on a public-key cryptosystem
    • Alice and Bob exchange their public keys (PKa, PKb)
    • Alice encrypts a message with her private key SKa and then with Bob’s public key PKb
    • Alice sends the message to Bob
    • Bob decrypts the message with his private key and then with Alice’s public key

23 of 64

Properties

  • Pros
    • Confidentiality: Eve needs Bob’s private key to decrypt the message
    • Integrity: message tampering is detected during the decryption process
    • Authentication: Alice is the only one who can encrypt with her private key (Note: this process is called “signing”)
    • Non-repudiation: Bob can prove to a third party that Alice is the originator of the message
  • Cons
    • Vulnerable to man-in-the-middle attacks

24 of 64

Diffie-Hellman Key Exchange

  • Alice and Bob negotiate a private key (a long integer) without sending the private key (or its encrypted form) over the wire!

​

  • Alice and Bob agree on public parameters
    • p = 23, g = 5 (p is a prime and g is a primitive root modulo p)
  • Alice picks a secret key a = 4 and sends the public key A to Bob
    • A = g ^ a mod p = 5 ^ 4 mod 23 = 4
  • Bob picks a secret key b = 3 and sends the public key B to Alice
    • B = g ^ b mod p = 5 ^ 3 mod 23 = 10

​

24

25 of 64

Diffie-Hellman Key Exchange (Cont’d)

  • Alice combines Bob’s public key B with her secret key a to derive the secret s_a
    • s_a = B ^ a mod p = 10 ^ 4 mod 23 = 18
  • Bob combines Alice’s public key A with his secret key b to derive the secret s_b
    • s_b = A ^ b mod p = 4 ^ 3 mod 23 = 18

​

  • s_a = s_b, which is the shared secret s
    • Most importantly, s = 18 never appeared anywhere in communication, so attackers cannot steal it by wiretapping!

​

25

26 of 64

Man-in-the-middle Attack

  • Alice sends to Bob her public key PKa
  • Eve intercepts the message and sends her own public key PKe to
  • Bob, who now believes PKe to be Pka (associated with Alice)
  • Bob sends to Alice his public key PKb
  • Eve intercepts the message and sends her own public key PKe to Alice, who now believes PKe to be PKb (associated with Bob)
  • Alice sends to Bob a message encrypted with Eve’s public key thinking she’s encrypting it with Bob’s public key
  • Eve intercepts the message, decrypts it with her own secret key, re-encrypts it with Bob’s public key, and forwards it to Bob
  • The same applies to messages from Bob to Alice

27 of 64

Public-key Certificates

  • Used to associate an identity (e.g., Alice and Bob) with a public key
  • The association is guaranteed by a trusted third party, the Certification Authority (CA)
  • The CA owns a public key and a private key PKca, SKca
  • The CA creates a self-signed certificate that is distributed through many channels to avoid interception
  • The CA signs certificates containing an identity and the corresponding public key after having verified the identity of the requester
  • Certificates are made available in public databases

28 of 64

X.509 Certificate

  • Version
  • Serial Number
  • Signature Algorithm
  • Issuer (CA)
  • Validity (to, from)
  • Subject (End-entity)
  • Subject Public Key Info
  • Extensions

​

CA Signature

29 of 64

Communication Using Certificates

  • Both Alice and Bob have the CA self-signed certificate
  • When Alice wants to send a message to Bob
    • She retrieves Bob’s certificate from a public database
    • She verifies the CA’s signature on Bob’s certificate
    • She extracts Bob’s public key
    • She uses the Bob’s public key and her own secret key to encrypt the message

30 of 64

Communication Using Certificates

  • When Bob receives the message
    • He retrieves Alice’s certificate from a public database
    • He verifies the CA’s signature on Alice’s certificate
    • He extracts Alice’s public key
    • He uses his own private key to decrypt the message and Alice’s public key to verify the signature

31 of 64

Communication Using Certificates

Request for Bob’s certificate

PKa

PKb

PKb

PKca

PKca

Request for Alice’s certificate

SKa

SKb

Alice

Bob

E_PKb(E_SKa(M))

PKa

Directory

32 of 64

Certifying Certification Authorities

  • Public Key Infrastructure (PKI)

Alice

Bob

Root CA

CA1

CA2

CA11

CA111

CA21

CA22

CA221

33 of 64

Conclusions

  • Cryptography provides the building blocks for secure communication
  • Algorithms
    • Symmetric algorithms
    • Public-key algorithms
    • Hash functions
    • Random number generators
  • Cryptographic protocols use crypto algorithms to provide
    • Confidentiality
    • Integrity
    • Authentication
    • Non repudiation

34 of 64

Imagine an attacker in a coffee shop

​

​

​

​

  • An attacker on the network can read, drop, delay, replay, and replace packets.
  • The attacker can also redirect DNS responses and even advertise a fake access point.
  • How does the browser reach the intended website safely?

​

34

35 of 64

HTTPS

35

PKb

PKb

SKb

Alice

Bob.com

E_PKb(M)

CA

Request for Bob.com’s certificate

Request for a CA-signed certificate

PKca

PKca

36 of 64

An HTTPS URL

  • https:// requests a secure connection to the host.
  • The client checks the server identity uses the hostname in the URL.
  • Default port: 443 (any other ports will also work)
  • The encrypted HTTP request contains the path and query.
    • So attackers can’t know what you are browsing! (really?)

36

37 of 64

HTTP & HTTPS

  • HTTPS is an encryption conduit with raw HTTP data inside
    • SSL -> TLS (Transport Layer Security)
    • HTTP/1.1 over TLS over TCP over IP.
    • HTTP/2 over TLS over TCP over IP.
    • HTTP/3 over QUIC over UDP over IP.
      • QUIC uses TLS 1.3 handshake and key establishment

​

    • HTTP applications usually do not directly deal with TLS or QUIC; we have libraries and APIs for that!

​

  • We focus on HTTP/1.1 + TLS for the rest of this lecture.

37

38 of 64

What HTTPS aims to protect

  • Confidentiality

Prevent attackers from reading the HTTP content.

  • Integrity

Detect any changes to encrypted HTTP content.

  • Server authentication

Connect to the server for the requested host name.

​

38

39 of 64

Establishing the encrypted conduit

  • Resolve the hostname.
  • Create a TCP connection.
  • Negotiate TLS parameters.
  • Authenticate the server.
  • Derive symmetric traffic keys.
  • Send HTTP GET (encrypted).

​

  • Receive HTTP response (encrypted)
  • Decrypt and process.
  • …

​

​

  • Receives a TCP connection.
  • Negotiate TLS parameters.
  • (Optional) authenticate the client.
  • Derive symmetric traffic keys.
  • Receive HTTP GET (encrypted)
  • Decrypt and process.
  • Send HTTP response (encrypted).
  • …

39

40 of 64

Establishing the encrypted conduit

  • Resolve the hostname.
  • Create a TCP connection.
  • Negotiate TLS parameters.
  • Authenticate the server.
  • Derive symmetric traffic keys.
  • Send HTTP GET (encrypted).

​

  • Receive HTTP response (encrypted)
  • Decrypt and process.
  • …

​

​

  • Receives a TCP connection.
  • Negotiate TLS parameters.
  • (Optional) authenticate the client.
  • Derive symmetric traffic keys.
  • Receive HTTP GET (encrypted)
  • Decrypt and process.
  • Send HTTP response (encrypted).
  • …

40

TLS Handshake

41 of 64

TLS 1.3 handshake

  • Client → Server: ClientHello with supported versions and key share
  • Server → Client: ServerHello with selected parameters and key share
  • Server → Client: EncryptedExtensions, Certificate, CertificateVerify, Finished
  • Client → Server: Finished

​

41

42 of 64

TLS certificate

  • Server must send a (leaf) certificate, typically also with the necessary intermediate certificates
    • Why intermediate certificates?

​

  • The leaf certificate contains
    • Common name, purposes, the public key, and many other properties

​

  • The client must
    • Verify that the common name matches the requested host name
    • Verify the validity and expiration date
    • Verify the purpose

42

43 of 64

What can attackers learn about a TLS connection?

  • Let’s see!

​

  • ClientHello, ServerHello
  • Traffic metadata (packet sizes and timing)
  • Server name
  • TLS 1.2
    • The certificate is in plain text
  • TLS 1.3
    • The certificate is encrypted

43

44 of 64

Multiple hosts on one IP

  • HTTP/1.1 uses “host” to differentiate between HTTP hosts
    • But it is not transferred until the connection is established
  • SNI: Server Name Indication
    • Tells server which host name the client talks to
    • Part of ClientHello
    • Exposes host name to attackers
    • Q: Why must SNI be part of the initial message in TLS?

​

  • Encrypted ClientHello (ECH) allows encrypted SNI

44

45 of 64

Ephemeral key exchange

  • Later versions of TLS 1.2 and TLS 1.3 uses Diffie-Hellman encryption to schedule encryption keys for each TLS session
    • Q: Why doesn’t server just send client a new encryption key after they establish the public key encryption?

​

  • Forward secrecy
    • Even if the server’s private key is leaked at one point in the future, attackers should not be able to break the communication
    • DH-based key exchange guarantees that the real symmetric key never appears anywhere in traffic (even after decryption)

45

46 of 64

Optimizations: Round Trip Time

  • HTTPS means a lot of work must be done before the first HTTP request is sent
    • Extra work both uses CPU time and introduces network latency
    • How can we reduce the latency (time to first byte)?

​

  • 0-RTT
    • Implemented by the PSK extension and Early Data extension in TLS 1.3
    • After initial TLS connection, the server issues a session ticket (a new pre-shared key)
    • For future connections, the client sends ClientHello, the session ticket, together with HTTP request encrypted using the PSK
    • Any problems?

46

47 of 64

HTTPS Failures

47

48 of 64

What can fail in HTTPS?

  • Using bad certificates
    • Fake or illegitimate certificates
    • Broken certificate verification
  • Using weak crypto keys
    • Traffic decryption and re-encryption
  • Leaking data without breaking crypto
    • Mixed content
    • Downgrade attack
    • Software security issues
    • Side channels

48

49 of 64

Attack scenarios

  • Man-in-the-middle

A middle box decrypting the traffic, examining or manipulating the traffic, and encrypting the traffic again before relaying

  • Eavesdropping

Decrypts the traffic offline�Detects and terminates the connection if anything “bad” is seen�The attacker defines what is bad

  • Downgrading

​

​

49

50 of 64

Fake or illegitimate certificates

  • Weak, compromised, or illegal CA
    • CA getting compromised by attackers
    • CA improperly issues certificates without proper verification (or no verification at all)
    • CA root certificates using extremely weak public keys
    • CA leaks private keys for their root certificates

​

50

51 of 64

How to defend?

  • Certification Authority Authorization (CAA) DNS records
    • RFC 8659
    • A domain name can specify which CAs can issue certificates for it
  • Regular auditing of CA
  • Near real-time monitoring of certificate issuance
    • Certificate Transparency: public, append-only logs of issued certificates
  • Extremely high stake
    • Browsers stop trusting all certs issued by a bad CA, which loses business
  • Certificate revocation
  • Researchers keep finding new and astonishing failure modes

51

52 of 64

Fake or illegitimate certificates

  • Leaking the private key of a certificate
    • Less impactful than leaking the private key of a CA root certificate
    • Weak private key used in private certificates

​

​

52

53 of 64

How to defend?

  • Protect the private key of your certificate
  • Shorter certificate lifetimes
    • All publicly trusted TLS certs issued after 3/15/2026 have a maximum validity of 200 days (100 days in 2027, 47 days in 2029)
    • Forces automated renewal and management�… which turns certificate security into system security…
  • Certificate revocation
    • Problems:�Timely certificate revocation check increases latency�Asynchronous revocation checks require client update and increases the window of exposure to bad certs

53

54 of 64

How to defend?

  • Public key pinning (HPKP, HTTP PKP)
    • Websites can pin one or a few public keys that they accept in browsers
    • Problems:�Lost keys and misconfiguration will lock users out for a long time�Attackers who successfully pinning a website against a bad cert will create long-lasting damage (this is also why backdooring cryptography is a very bad idea)

54

55 of 64

Broken certificate verification

  • Proper cert verification is actually difficult to (correctly) implement
    • Writing software is hard
    • The verification logic have many corner cases and nuances

​

55

56 of 64

SSL stripping

  • The victim first opens an http:// URL or follows an insecure link.
  • A network attacker intercepts HTTP and blocks the upgrade to HTTPS.
  • The victim may continue using HTTP while the attacker talks to the real site over HTTPS.
  • The TLS session to the real site can be secure while the victim’s connection remains exposed to the attacker.

​

56

57 of 64

How to defend?

  • Type “https://” yourself!
  • Modern browsers default to https://
  • Be aware of http:// URLs
  • HSTS (HTTP Strict Transport Security)
    • A list of domain names in modern browsers that must be served via HTTPS
    • Can be specified in HTTP headers or preloaded in browsers

57

58 of 64

Protocol downgrade attacks

  • Modern TLS versions are significantly more secure than earlier versions
  • Attackers can prevent clients from communicating with servers using modern TLS versions, forcing them to use earlier versions with weaker crypto
  • POODLE (2014): Forcing SSL 3.0 in HTTPS and enabling MITM
    • This is why supporting obsolete protocols and implementations creates security risks

58

59 of 64

Software security issues

  • TLS must be handled by more code, which increases the attack surface
    • “Code is liability!” --- Yan Shoshitaishvili
    • Heartbleed (2014): An OpenSSL bug that allows heap data leak
    • TLStorm / nanoSSL (CVE-2022-22805): A software bug during TLS record reassembly causing a pre-authentication heap overflow

59

60 of 64

CRIME and BREACH: Compression side channels

  • CRIME: Compression Ratio Info-leak Made Easy
    • Chosen plain-text attack
    • Q: Do we compress then encrypt, or encrypt then compress?
    • The same substring appeared multiple times will be compressed to one instance
    • A third-party attacker who can control part of the HTTP page or header content (even just a short string) can observe if that string already appears in the page content by observing the change of the encrypted HTTPS request or response size

​

60

61 of 64

Similar side channels

  • File sizes
    • A large file will still be large post encryption
  • Timing
    • Certain endpoints reliably take multiple seconds before responding

​

  • HTTPS does not eliminate side channels

61

62 of 64

Mixed content

  • HTTP resources in an HTTPS page can still be tampered with by attackers
    • … which allows attackers to hijack JavaScript served over HTTP, which will run under the HTTPS page’s context
    • Q: Does CORS help? Why or why not?

​

  • How to defend?
    • Modern browsers apply mixed-content rules to reduce the risk

62

63 of 64

Mixed content in applications

  • Ordinary software also heavily rely on HTTP and HTTPS for background traffic
    • Even worse, you don’t usually see what URLs they access or what protocols they use
    • CVE-2026-120422: Sogou Pinyin retrieves configuration via HTTP, which was hijacked by government-associated attackers in China to deliver malware

63

64 of 64

CDN & HTTPS

  • Browser → CDN: CDN sends a certificate to the browser.

The certificate is either issued by the CDN or provided by the owner of the website

  • CDN → Origin: The connection might be in HTTP!

Many attacks are conducted by hijacking HTTP connections between CDN and the original hosts

​

64