CNComputer Networks

Block E · Topics 22–24

Security

The internet was built by people who trusted each other, and every protocol in this section is a retrofit. Understanding which specific trust assumption each one repairs is how you answer these questions well.

22

Cryptography basics

symmetricasymmetrichashingkey exchangeforward secrecy
The four properties

Every crypto question is really asking which of these you need. Confidentiality — nobody else can read it. Integrity — nobody changed it. Authentication — it's really from who it claims. Non-repudiation — they can't later deny sending it. Different primitives give different subsets, and mixing them up is the classic error.

SymmetricAsymmetric
KeysOne shared secret for both encrypt and decryptA public/private pair
SpeedFast — hardware accelerated (AES-NI)~1000× slower
Problem it hasKey distribution — how do you share the secret over an untrusted network?Too slow for bulk data
ExamplesAES-256-GCM, ChaCha20-Poly1305RSA, ECDSA, Ed25519, ECDH
Used forEncrypting the actual trafficKey exchange and signatures
Why TLS uses both — the answer to a very common question

Asymmetric crypto solves key distribution but is far too slow for a video stream. Symmetric crypto is fast but can't bootstrap a shared secret over a hostile network. So TLS is a hybrid: use asymmetric operations once, during the handshake, to authenticate the server and agree a symmetric session key — then encrypt all the actual data symmetrically. Best of both, and the asymmetric cost is paid once per connection rather than per byte.

Hashing, MACs and signatures

PrimitiveGivesNeedsNote
Hash (SHA-256)Integrity onlyNothingOne-way, fixed output, avalanche effect. An attacker who can change the data can change the hash too — so a bare hash proves nothing about origin.
MAC / HMACIntegrity + authenticationA shared secretBoth parties can produce it, so it gives no non-repudiation.
Digital signatureIntegrity + authentication + non-repudiationA private keySign with the private key, verify with the public. Only the holder could have produced it.
Password hash (bcrypt, Argon2)Storage safetyA saltDeliberately slow. Using SHA-256 for passwords is a vulnerability: it's fast, so it's cheap to brute-force.

Diffie-Hellman and forward secrecy

The magic trick: two parties agree a shared secret over a public channel,
and an eavesdropper who saw EVERYTHING cannot compute it.

  public:  g, p
  Alice picks secret a, sends g^a mod p
  Bob   picks secret b, sends g^b mod p
  Alice computes (g^b)^a = g^ab
  Bob   computes (g^a)^b = g^ab      ← same shared secret
  Eve saw g, p, g^a, g^b — and computing a from g^a is the
  discrete logarithm problem, which is computationally infeasible.

Plain DH gives no authentication — Eve can do DH separately with each
side and sit in the middle. That is why TLS SIGNS the exchange with a
certificate: DH gives secrecy, the certificate gives identity.
Forward secrecy, explained the way that lands

With old RSA key exchange, the client encrypted the session key with the server's public key. So an attacker who recorded years of traffic and later stole the server's private key could decrypt all of it, retroactively.

With ephemeral Diffie-Hellman (ECDHE), a fresh key pair is generated per session and thrown away afterwards. The long-term certificate key only signs the exchange; it never encrypts the session key. So stealing it tomorrow lets an attacker impersonate the server going forward, but does not decrypt anything recorded in the past. That's why TLS 1.3 removed static RSA key exchange entirely and mandates ephemeral exchange.

23

TLS & PKI

handshakecertificateschain of trustSNI
Why it exists

HTTP is plaintext, and anyone on the path — your ISP, the coffee shop router, a compromised backbone — can read and modify it. TLS provides confidentiality, integrity and server authentication, and that last one is the hard part: encryption is useless if you've encrypted your traffic to an attacker.

Client Server ClientHello — TLS version, cipher suites, random, SNI hostname, and a DH key_share guessed up front ServerHello — chosen cipher, server random, its key_share {Certificate + chain} {CertificateVerify — signs the transcript} {Finished} ← braces = already encrypted client verifies the chain, checks the hostname, derives the same session keys from both key_shares {Finished} + encrypted application data 1 round trip total (TLS 1.2 needed 2) TLS 1.3's trick: the client GUESSES a key-exchange group and sends its key_share immediately. If the guess is right — it usually is — no extra round trip is needed to negotiate one.
TLS 1.3 in one round trip. It also removed static RSA key exchange, so every session now has forward secrecy by construction.

What a certificate is, and the chain of trust

A certificate binds an IDENTITY to a PUBLIC KEY, signed by a CA.
  subject          CN / SAN: example.com, www.example.com
  public key       the server's
  validity         not-before / not-after
  issuer           who signed it
  signature        the CA's signature over all of the above

Chain:
  example.com  ← signed by →  Intermediate CA  ← signed by →  Root CA
                                                               ↑
                                          in your OS/browser trust store,
                                          SELF-SIGNED, trusted by decree

The client walks the chain up to a root it already trusts. Roots are kept
offline; intermediates do the day-to-day signing, so a compromised
intermediate can be revoked without replacing every device's trust store.

Validation is not just "is the signature valid". The client must also check:
  · the hostname matches a SAN entry (CN alone is deprecated)
  · it is within its validity period  ← why clock skew breaks HTTPS
  · it is not revoked (CRL, or OCSP — in practice OCSP stapling, because
    live OCSP lookups were slow and leaked browsing history)
  · the chain terminates at a trusted root
  · signature algorithms are still acceptable (SHA-1 is not)
ConceptPoint
SNIServer Name Indication — the client says which hostname it wants in the clear, so one IP can host many HTTPS sites. It's the main metadata leak in TLS: an observer learns which site you visited even though the content is encrypted. Encrypted Client Hello (ECH) is the fix being deployed.
mTLSMutual TLS — the client presents a certificate too. Standard for service-to-service authentication inside a mesh, where you don't want to rely on network location as identity.
HSTSA header telling the browser "only ever use HTTPS for this domain". Defeats SSL-stripping downgrade attacks, which otherwise work because the very first request is plain HTTP.
Certificate TransparencyPublic append-only logs of every issued certificate, so a domain owner can detect mis-issuance. A structural fix for "any of hundreds of CAs can vouch for your domain".
Self-signedEncryption without identity. Fine for internal use with pinning; a browser warning otherwise, and clicking through it defeats the whole point.
Say this

"TLS is hybrid: asymmetric crypto once in the handshake to authenticate the server and agree a session key, then fast symmetric encryption for the data. In 1.3 that's one round trip, because the client guesses a key-exchange group and sends its key share immediately. Authentication comes from the certificate chain — the client walks it up to a root in its trust store and, crucially, also checks the hostname, validity dates and revocation. And 1.3 mandates ephemeral key exchange, so stealing the server's private key later doesn't decrypt recorded traffic — that's forward secrecy."

24

Attacks & defences

SYN floodDDoSMITMspoofingfirewalls
The pattern

Almost every network attack exploits one of three original design assumptions: that the source address is honest, that anyone on the path is trustworthy, or that peers behave in good faith. Name which assumption an attack breaks and the defence follows.

AttackMechanismDefence
SYN floodSend SYNs with spoofed sources and never complete the handshake. Each half-open connection consumes a slot in the backlog queue until legitimate clients can't connect.SYN cookies — encode the connection state into the sequence number itself, so no memory is allocated until the final ACK proves the client is real. Plus backlog tuning and rate limiting.
Volumetric DDoSOverwhelm bandwidth from many sourcesAbsorb it with scale (CDN/scrubbing provider), anycast to spread it geographically, blackhole or rate-limit upstream. You cannot solve this at the origin.
Amplification / reflectionSend a small spoofed query to a service with a big reply (DNS, NTP, memcached) using the victim's address as the source. A 60-byte request can yield a 4,000-byte response — ~70× amplification.BCP 38 ingress filtering at ISPs so spoofed sources can't leave a network; don't run open resolvers; rate-limit responses.
ARP spoofingARP has no authentication — claim to be the gateway and become a local man-in-the-middleDynamic ARP inspection, DHCP snooping, port security — plus TLS, which makes reading the traffic useless
DNS cache poisoningRace a forged response to a resolver so it caches a wrong addressSource-port and query-ID randomisation (the post-Kaminsky fix), DNSSEC for signed answers, DoT/DoH for an encrypted channel
MITM / SSL strippingDowngrade an HTTPS link to HTTP, since the first request is usually plain HTTPHSTS plus the preload list, so the browser never sends that first plaintext request
IP spoofingForge the source addressIngress filtering; and don't authenticate on IP address alone. Note TCP resists it somewhat — you must guess the sequence number, which is why random ISNs matter.
Session hijackingSteal a session cookie via XSS or an open networkHttpOnly, Secure, SameSite, TLS everywhere, rotate the session ID on privilege change
BGP hijackAnnounce someone else's prefix and attract their trafficRPKI route origin validation, prefix filtering, monitoring. Structurally still an open problem.
SlowlorisOpen many connections and send headers extremely slowly, exhausting worker slots with almost no bandwidthHeader/body timeouts, connection limits per IP, event-driven servers rather than thread-per-connection

Firewalls and VPNs

TypeInspectsTradeoff
Packet filter (stateless)IPs, ports, flags — each packet aloneFast; can't tell a reply from an unsolicited packet
StatefulConnection state, so replies to your own outbound traffic are allowed automaticallyThe normal choice; costs memory per connection
Application / WAFFull HTTP — paths, payloads, SQL-injection patternsCatches application attacks; adds latency; needs tuning, and false positives break real users
Next-gen / IDS-IPSPlus identity, TLS inspection, threat feedsPowerful; TLS inspection means decrypting your own users' traffic, which is a real privacy and risk decision

A VPN creates an encrypted tunnel so traffic traverses an untrusted network as if it were on a trusted one — remote access to a corporate network, or site-to-site links. Two clarifications worth making unprompted: a commercial "privacy VPN" doesn't give anonymity, it moves the trust from your ISP to the VPN provider, who can see everything your ISP could. And a VPN is irrelevant to end-to-end encryption you already have — HTTPS is already encrypted before the tunnel gets it.

The defence-in-depth framing

No single control is sufficient, and interviewers like hearing the layers named: ingress filtering at the ISP, anycast and scrubbing for volume, a stateful firewall and security groups at the perimeter, TLS everywhere so path access is worthless, authentication that doesn't trust the network (mTLS or tokens rather than IP allow-lists), rate limiting per identity, and monitoring so you find out from your own alerts rather than from customers. Assume the network is hostile — that assumption is what zero-trust architecture formalises.

Say this

"A SYN flood works because the server allocates state on the first packet of the handshake, and the source can be spoofed. SYN cookies fix it by encoding the state into the sequence number so nothing is allocated until the final ACK proves the client is real. Amplification is the same spoofing weakness pointed outward — a small forged DNS query producing a large reply at the victim — and the real fix is ingress filtering at ISPs so spoofed sources can't leave a network in the first place. The general lesson is that IP's source address was never authenticated, and most network attacks are a consequence of that one decision."