Goal

This part covers how public keys travel between people: exporting and importing them, using keyservers safely, and how the Web of Trust verifies identity without a central authority.

Prerequisites: Week 3b (Encryption & Signatures)

This is Part 3 of 4 - Covers key distribution, keyservers, and web of trust.


1. Public Key Distribution and Import

Export Your Public Key

# Export in ASCII armor (shareable format)
gpg --armor --export [email protected] > alice-public-key.asc

# View the exported key
cat alice-public-key.asc

Output:

-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBGcYexamplePublicKeyDataHere...
=ABCD
-----END PGP PUBLIC KEY BLOCK-----

Where to Publish Your Public Key

Options:

  1. Personal website - https://example.com/pgp-key.asc
  2. Keyserver (see next section)
  3. GitHub - Add to profile README
  4. Email signature - Include fingerprint
  5. Business card - QR code of fingerprint
  6. Social media bio - Link to key

Example website publication:

<!-- On your About page -->
<h2>GPG Public Key</h2>
<p>Fingerprint: <code>ABCD 1234 ABCD 1234 ABCD 1234 ABCD 1234</code></p>
<p><a href="/alice-public-key.asc">Download Public Key</a></p>

Import Someone’s Public Key

# Import from file
gpg --import bobs-public-key.asc

# Output:
gpg: key XYZ789: public key "Bob Cypherpunk <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Verify Imported Key Fingerprint

Always verify fingerprints.

# Check Bob's key fingerprint
gpg --fingerprint [email protected]

# Output:
pub   rsa4096 2025-09-01 [SC]
      XYZ7 89AB XYZ7 89AB XYZ7 89AB XYZ7 89AB XYZ7 89AB
uid           [ unknown] Bob Cypherpunk <[email protected]>

Verification process:

  1. Get Bob’s fingerprint through trusted channel (in person, phone call, his website)
  2. Compare with imported key fingerprint
  3. If match: Trust the key
  4. If mismatch: DELETE the key immediately (potential MITM attack)

Example secure verification:

# You're on phone with Bob
You: "I imported your key. Can you read your fingerprint?"
Bob: "X Y Z 7 8 9 A B..."
You: [Compares with gpg --fingerprint output]
You: "Confirmed! I'll sign your key now."

2. The Keyserver Ecosystem

What Are Keyservers?

Public keyservers store GPG public keys for discovery and distribution.

Popular keyservers:

  • keys.openpgp.org (modern, privacy-focused)
  • keyserver.ubuntu.com (Ubuntu default)
  • pgp.mit.edu (classic, legacy)

How they work:

Alice uploads public key → Keyserver → Bob searches for Alice → Downloads key

Uploading Your Key to Keyserver

# Upload to keys.openpgp.org
gpg --keyserver keys.openpgp.org --send-keys ABCD1234

# Upload to Ubuntu keyserver
gpg --keyserver keyserver.ubuntu.com --send-keys ABCD1234

--send-keys uploads the key, but keys.openpgp.org won’t publish your email (so nobody can look you up by it) until you verify it. To start that check, run gpg --export [email protected] | curl -T - https://keys.openpgp.org and open the verification link it prints, or upload the file at https://keys.openpgp.org/upload.

What gets uploaded:

  • Public key
  • User IDs (name, email; keys.openpgp.org publishes them only after email verification)
  • Signatures on your key (keys.openpgp.org strips third-party signatures unless you attest them)

What stays private:

  • Private key (never leaves your system)
  • Passphrase

Searching for Keys

# NOTE: keys.openpgp.org (Hagrid) does NOT support keyword/index --search-keys —
# it only does exact lookups by verified email, key ID, or fingerprint. Use a
# classic SKS-style keyserver for name/keyword searches:

# Search by email
gpg --keyserver keyserver.ubuntu.com --search-keys [email protected]

# Search by name
gpg --keyserver keyserver.ubuntu.com --search-keys "Alice Cypherpunk"

# Search by full fingerprint (never an 8-char short key ID, which is forgeable:
# anyone can generate a key with the same short ID)
gpg --keyserver keyserver.ubuntu.com --search-keys 0x<FULL-40-HEX-FINGERPRINT>

Refreshing Keys from Keyserver

# Update all keys in your keyring
gpg --keyserver keys.openpgp.org --refresh-keys

# Update specific key
gpg --keyserver keys.openpgp.org --refresh-keys [email protected]

# keys.openpgp.org carries revocations and expiry updates, but not
# third-party signatures. To pull in web-of-trust signatures, refresh
# from an SKS-style server:
gpg --keyserver keyserver.ubuntu.com --refresh-keys

Why refresh:

  • Gets updated expiration dates
  • Downloads new signatures (only from SKS-style servers such as keyserver.ubuntu.com)
  • Gets revocation certificates (if key compromised)

Pros and Cons of Keyservers

Pros:

  • Easy public key distribution
  • No need for manual key exchange
  • Automatically propagate updates
  • Standard part of GPG ecosystem

Cons:

  • No identity verification - Anyone can upload key with any name/email
  • Spam problem - Keys can be polluted with fake signatures
  • Privacy leak - Your email and social graph become public
  • Can’t delete keys - On SKS-style servers, once uploaded, permanent (keys.openpgp.org lets you remove your identity information)
  • Certificate flooding attacks - Attackers add millions of signatures, making key unusable

Modern best practice:

  • Use keys.openpgp.org (has email verification, prevents abuse)
  • Publish key on personal website too
  • Always verify fingerprints out-of-band
  • Consider not using keyservers for privacy-sensitive identities

Alternative: Web Key Directory (WKD)

Modern, privacy-preserving key distribution:

# Keys hosted on your own domain
# Example: https://example.com/.well-known/openpgpkey/

Advantages:

  • You control your keys
  • No third-party keyserver
  • Domain-verified (key at [email protected] hosted on example.com)
  • Privacy-respecting

Implementation beyond this course, but worth knowing about.


3. Web of Trust: Decentralized Identity Verification

The Problem: How to Trust Public Keys

Scenario:

  • You download Bob’s public key from keyserver
  • Key says “Bob Smith [email protected]”
  • How do you know this is the REAL Bob?

Without verification:

  • Could be attacker’s key pretending to be Bob
  • Man-in-the-middle attack
  • You encrypt to fake Bob → Attacker reads message

The Web of Trust Solution

Trust comes from relationships between people instead of a central authority.

You trust Alice → Alice met Bob in person and signed his key
  → You can trust Bob's key (transitively through Alice)

Key signing:

  • Alice verifies Bob’s identity in person
  • Alice signs Bob’s key with her private key
  • Alice’s signature says “I verified this key belongs to Bob”
  • Anyone who trusts Alice as an introducer will see Bob’s key as valid

Signing Someone’s Key

Prerequisites:

  1. Met person in person OR verified via multiple channels
  2. Verified government ID (if high-trust scenario)
  3. Verified key fingerprint

Process:

# 1. Import their key
gpg --import bobs-key.asc

# 2. Verify fingerprint (in person or phone)
gpg --fingerprint [email protected]

# 3. Sign their key
gpg --sign-key [email protected]

# Prompts:
# - Confirm you've verified identity
# - Enter your passphrase
# - Sign at different trust levels

# 4. Export signed key back to them
gpg --armor --export [email protected] > bobs-key-signed-by-alice.asc

# 5. Bob imports your signature
# (Bob's key now has your signature, strengthening web of trust)

Trust Levels

When editing trust:

gpg --edit-key [email protected]
> trust

Trust levels:

  1. Unknown - No opinion
  2. None - Don’t trust this person to verify others
  3. Marginal - Somewhat trust (need 3 marginal signatures to trust a key)
  4. Full - Fully trust (1 full signature enough to trust a key)
  5. Ultimate - Your own key

Example web of trust:

You (ultimate trust)
  ↓ (you set Alice's owner-trust to FULL)
Alice
  ↓ (Alice signed)
Bob   ← Bob's key is VALID
  ↓ (Bob signed)
Carol ← valid ONLY if you ALSO set Bob's owner-trust to full or marginal
        (gpg --edit-key bob → trust → 4 or 3)

A signature makes a key valid; only owner-trust you assign lets that key’s own signatures count. With GnuPG’s defaults, one fully trusted signature or three marginal ones make a key valid (completes-needed 1, marginals-needed 3), and the chain stops at max-cert-depth (default 5).

Key Signing Parties

In-person events where people verify identities and sign keys.

How it works:

  1. Everyone brings government ID and key fingerprint printouts
  2. Form a circle, verify each person’s ID and fingerprint
  3. Everyone goes home and signs all keys they verified
  4. Send each signed key back to its owner, encrypted to their verified email, and let them decide whether to publish it (keys.openpgp.org will not carry third-party signatures; SKS-style servers such as keyserver.ubuntu.com will)
  5. Web of trust grows stronger

Remote alternative:

  • Video call with ID verification
  • Voice verification of fingerprints
  • Lower trust level, but better than nothing

Web of Trust vs TOFU (Trust On First Use)

Web of Trust:

  • Distributed trust model
  • Requires social interaction (key signing)
  • Strong security if done right
  • Complex for beginners

TOFU (like SSH):

  • Trust first key you see
  • Warn if key changes
  • Simpler, but vulnerable to initial MITM

Modern GPG supports both models.


Up Next

Week 3d covers key management (rotation, revocation, backup), email encryption setup, and modern alternatives like age.


Key Takeaways

  • Export/import keys using ASCII armor for portability
  • Keyservers enable discovery but have privacy trade-offs
  • keys.openpgp.org is the modern, privacy-focused choice
  • Always verify fingerprints through a separate trusted channel
  • Web of Trust builds decentralized identity verification through key signing
  • Trust levels decide whose signatures count toward a key’s validity
  • Key signing parties strengthen the web of trust through in-person verification