Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

HTTPS, SSH and email security

Concise, exam-focused notes on HTTPS, SSH and email security: definitions, handshake steps, key formulas, worked examples, common mistakes and likely exam questions.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

HTTPS, SSH and email security protect confidentiality, integrity and authentication on the Internet. Engineers use these protocols when building web servers, remote-access services and mail systems so users and services can communicate safely over untrusted networks.

Key ideas

  • Authentication: verifying the identity of a peer (server, client or signer).

  • Confidentiality: ensuring only authorized parties can read the data (encryption).

  • HTTPS: HTTP over TLS. It means the HTTP application protocol runs over a secure channel established by the Transport Layer Security (TLS) protocol. TLS provides confidentiality, integrity and server (and optionally client) authentication.

    • TLS: protocol that performs a handshake to authenticate peers and establish shared session keys, then uses the TLS Record Protocol to send encrypted data. TLS versions: TLS 1.0/1.1 (obsolete), TLS 1.2 (widely used), TLS 1.3 (modern, reduced round-trips and stronger defaults; removes static RSA key exchange in favor of (EC)DHE and uses an HKDF-based key schedule).
    • SSL: older protocol family; name remains in common speech but TLS replaced SSL. SSL 3.0 is insecure.
    • X.509 certificate: a digitally signed data structure that binds a public key to an identity (subject) and is issued by a Certificate Authority (CA). It contains: subject name, issuer name, subject public key, validity period, signature algorithm and the CA's signature.
    • Certificate chain: sequence of certificates from the server's certificate up to a trusted root CA. The browser verifies the chain by checking signatures and validity. HTTP Strict Transport Security (HSTS) lets a site signal browsers to always use HTTPS, mitigating downgrade/stripping attacks.
    • TLS handshake (basic outline for TLS 1.2; draw and label messages left-to-right between Client and Server): Include CertificateRequest and client Certificate/CertificateVerify messages when client authentication is used.
      1. ClientHello (client random, supported ciphersuites, extensions)
      2. ServerHello (server random, chosen ciphersuite)
      3. ServerCertificate (server's X.509 cert)
      4. ServerKeyExchange (if needed, e.g. DHE parameters)
      5. ServerHelloDone
      6. ClientKeyExchange (e.g. RSA-encrypted pre-master or DH public value)
      7. ChangeCipherSpec, Finished messages both sides using derived keys
      • Draw two vertical lines labelled Client and Server, arrows for each message with the names above.
  • SSH: Secure Shell, a protocol for secure remote login and command execution. SSH provides an authenticated and encrypted channel over an insecure network.

    • Host key: a long-term public/private key pair that identifies a server. Clients store known host keys to detect changes (and possible MitM attacks).
    • SSH key exchange commonly uses Diffie–Hellman to agree a shared secret and then authenticates the server by signing the exchange with the host key. Modern SSH commonly uses curve25519-based ECDH; client authentication then follows (e.g., public key or password).
    • Common components: SSH client (user machine, program providing remote shell), SSH server (daemon), utilities: ssh, scp, sftp.
  • Email transport and message security:

    • SMTP: Simple Mail Transfer Protocol, used by Mail Transfer Agents (MTAs) to forward mail. Clients (Mail User Agents, MUAs) send mail to an MTA.
    • STARTTLS and SMTPS: ways to secure SMTP. STARTTLS is a command to upgrade an existing plaintext SMTP connection to TLS. SMTPS is using TLS from the beginning (implicit TLS) on a dedicated port. Common ports: 25 (MTA-to-MTA, opportunistic STARTTLS), 587 (mail submission with STARTTLS), 465 (implicit TLS for submissions).
    • S/MIME: Secure/Multipurpose Internet Mail Extensions — uses X.509 certificates to sign and/or encrypt email messages. Provides end-to-end message-level confidentiality and signatures.
    • PGP / OpenPGP: uses a web-of-trust model and public-key cryptography to sign and encrypt messages; keys are user-managed rather than CA-signed.
    • SPF (Sender Policy Framework): DNS record listing which hosts are allowed to send mail for a domain; helps prevent sender address forgery.
    • DKIM (DomainKeys Identified Mail): signed headers and body using a domain's private key; receiving server checks signature with public key published in DNS.
    • DMARC: a policy layer that lets domain owners tell receivers how to handle messages failing SPF/DKIM and requests reports.

Formulas

HMAC(K, m) = H((K ⊕ opad) || H((K ⊕ ipad) || m)) — H is the hash function (e.g. SHA-256), K is the key (if shorter than block-size pad with zeros; if longer than block-size, replace K with H(K) first), ipad/opad are constants; result is a MAC.

s = m^d mod n — RSA signature generation (m is the message representative, d private exponent, n modulus). Units: dimensionless integers; applies when message is represented as integer in [0, n-1].

m = s^e mod n — RSA signature verification (e public exponent). Same units.

S = g^{ab} mod p — Diffie–Hellman shared secret for primes p, generator g and private exponents a,b. Units: integers modulo p.

master_secret = PRF(pre_master_secret, "master secret", ClientHello.random || ServerHello.random)[0..47] — TLS 1.0/1.1/1.2 conceptual formula (PRF depends on version); produces 48 bytes. Verify exact PRF construction for the TLS version used. Note: TLS 1.3 uses HKDF and a different key schedule; this formula does not apply to TLS 1.3.

Note: For syntax to remember: ssh command: ssh user@host ; scp: scp file user@host:/path ; sftp: sftp user@host ; OpenSSL s_client: openssl s_client -connect host:443 -servername host to inspect TLS.

Worked examples

  1. RSA signature example (small numbers for exam demonstration):

    • Given: n = 33 (3·11), e = 3, φ(n) = (3-1)(11-1) = 20. Find d such that 3·d ≡ 1 (mod 20) → d = 7.
    • Message representative m = 4.
    • Signature s = m^d mod n = 4^7 mod 33.
      • 4^2 = 16
      • 4^4 = 16^2 = 256 ≡ 25 (mod 33)
      • 4^7 = 4^4 · 4^2 · 4 = 25 · 16 · 4 = 1600 ≡ 16 (mod 33)
    • Verify: m' = s^e mod n = 16^3 mod 33 = (16^2)·16 = 256·16 ≡ 25·16 = 400 ≡ 4 (mod 33) = m. Signature valid.
  2. Diffie–Hellman numeric trace (small prime):

    • Choose p = 23, g = 5. Alice private a = 6, Bob private b = 15.
    • Alice public A = g^a mod p = 5^6 mod 23. Compute: 5^2=2, 5^4=4, 5^6=5^4·5^2 = 4·2 = 8 -> A = 8.
    • Bob public B = 5^15 mod 23. Compute via exponents: 5^8=16, 5^4=4, 5^2=2, 5^1=5 ⇒ 5^15 = 5^8·5^4·5^2·5 = 16·4·2·5 ≡ 19 -> B = 19.
    • Shared secret computed by Alice: S = B^a mod p = 19^6 mod 23 -> compute 19^2=16, 19^4=3, 19^6=3·16=48≡2. Bob computes A^b = 8^15 mod 23 -> also ≡ 2. Shared secret S = 2.
  3. TLS server certificate verification (exam-style steps):

    • Given a server certificate and chain, list steps you do to verify it:
      1. Check certificate validity period (notBefore ≤ now ≤ notAfter).
      2. Check certificate signature: verify issuer's signature using issuer's public key (repeat up chain).
      3. Ensure the chain ends in a root CA trusted by the client (root CA certificate present in trust store).
      4. Check certificate revocation (CRL or OCSP) if required by policy.
      5. Verify that the certificate subject matches the server name (the Subject Alternative Name DNSName must match; CN is ignored if SAN is present). If all pass, trust the server's public key for TLS.

Common mistakes

  • Thinking HTTPS encrypts DNS or all metadata; standard HTTPS protects HTTP payload and headers inside TLS, but DNS and IP addresses are visible (unless you use DoH/DoT and TLS 1.3’s Encrypted Client Hello (ECH), which encrypts the SNI; deployment is not yet universal).
  • In SSH, ignoring host key warnings and accepting changed host keys without verification (this defeats MitM detection).
  • In email security, assuming STARTTLS guarantees end-to-end encryption; STARTTLS protects transport only and can be downgraded unless MTA enforces TLS (e.g., via MTA-STS or DANE for SMTP).
  • Mixing up DKIM (signs messages) and SPF (authorizes senders) and DMARC (policy for failures).

For your exam

Kinds of questions:

  • Definitions: define TLS, HTTPS, X.509 certificate, SSH host key, S/MIME, DKIM, SPF, DMARC.
  • Short notes: TLS handshake steps, SSH key exchange, STARTTLS vs SMTPS, how DKIM works.
  • Derivations/algorithms: trace RSA sign/verify with small numbers, Diffie–Hellman exchange.
  • Numericals: compute RSA signature with small primes, compute DH shared secret, compute HMAC with simplified hash.
  • Diagrams: draw TLS handshake (Client and Server vertical lines, arrows for ClientHello, ServerHello, Certificate, KeyExchange, Finished).

What full-marks answers include:

  • Precise definitions with bolded term, required fields (e.g., what an X.509 cert contains), and assumptions.
  • For handshakes: correct ordered messages, brief note of what each message carries (e.g., random nonces, public values, certs, Finished MAC).
  • For numericals: state formulas used, show arithmetic steps, keep mod operations clear, and final value.
  • For security policy questions: explain threat model (MitM, replay), what the protocol protects and limitations.

Quick check

  1. What does DKIM sign — the SMTP envelope or the message headers and body?
  2. In SSH, what should you do if a host key for a server changes unexpectedly?
  3. Which TLS version removed the RSA key-exchange that sent the pre-master encrypted with server RSA, and why?

Answers: 1) Message headers and body (not SMTP envelope). 2) Stop and verify the change out-of-band (do not accept the new key blindly). 3) TLS 1.3 removed RSA key-exchange in favor of (EC)DHE to provide forward secrecy and remove reliance on long-term private key confidentiality.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?