logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

Gemini-TOFU.gmi (4126B)


  1. I will have more to say about Gemini in the future, but for now, I wanted to write up some details about one thing in particular: the trust-on-first-use algorithm I implemented for my client, gmni. I think you should implement this algorithm, too!
  2. => /gmni.gmi gmni: A gemini client
  3. First of all, it's important to note that the Gemini specification explicitly mentions TOFU and the role of self-signed certificates: they are the norm in Geminiland, and if your client does not support them then you're going to be unable to browse many sites. However, the exact details are left up to the implementation.
  4. ## Client recommendations
  5. First, on startup, it finds the known_hosts file. For my client, this is `~/.local/share/gmni/known_hosts` (the exact path is adjusted as necessary per the XDG basedirs specification). Each line of this file represents a known host, and each host has four fields separated by spaces, in this order:
  6. * Hostname (e.g. gemini.circumlunar.space)
  7. * Fingerprint algorithm (e.g. SHA-512)
  8. * Fingerprint, in hexadecimal, with ':' between each octet (e.g. 55:01:D8...)
  9. If a known_hosts entry is encountered with a hashing algorithm you don't understand, it is disregarded.
  10. Then, when processing a request and deciding whether or not to trust its certificate, take the following steps:
  11. 1. Compute the certificate's fingerprint. Use the entire certificate (in OpenSSL terms, `X509_digest` will do this), not just the public key.†
  12. 2. Look up the known_hosts record for this hostname. If one is found, and the fingerprint does not match, the trust state is UNTRUSTED, GOTO 4. If found, and the fingerprint matches, the trust state is TRUSTED, GOTO 6.
  13. 3. The trust state is UNKNOWN. GOTO 4.
  14. 4. Display information about the certficate and its trust state to the user, and prompt them to choose an action, from the following options:
  15. * If INVALID, the user's choices are ABORT or TRUST_TEMPORARY.
  16. * If UNKNOWN, the user's choices are ABORT, TRUST_TEMPORARY, or TRUST_ALWAYS.
  17. * If UNTRUSTED, abort the request and display a diagnostic message. The user must manually edit the known_hosts file to correct the issue.
  18. 5. Complete the requested action:
  19. * If ABORT, terminate the request.
  20. * If TRUST_TEMPORARY, update the session's list of known hosts.
  21. * If TRUST_ALWAYS, append a record to the known_hosts file and update the session's list of known hosts.
  22. 6. Allow the request to proceed.
  23. † Rationale: this fingerprint matches the output of `openssl x509 -sha512 -fingerprint`.
  24. If the trust state is UNKNOWN, instead of requring user input to proceed, the implementation MAY proceed with the request IF the UI displays that a new certificate was trusted and provides a means to review the certificate and revoke that trust.
  25. Note that being signed by a certificate authority in the system trust store is not considered meaningful to this algorithm. Such a cert is TOFU'd all the same.
  26. That's it! If you have feedback on this approach, please send me an email.
  27. => mailto:sir@cmpwn.com Send me an email
  28. My implementation doesn't *entirely* match this behavior, but it's close and I'll finish it up before 1.0. If you want to read the code, here it is:
  29. => https://git.sr.ht/~sircmpwn/gmni/tree/master/src/tofu.c src/tofu.c
  30. ## Server recommendations
  31. You should use a self-signed certificate, and you should not use a certificate signed by one of the mainstream certificate authorities. We don't need to carry along the legacy CA cabal into our brave new Gemini future.
  32. You should also set the certificate expiration into the far future, hundreds of years from now, and move certificates from server to server to keep the trust state intact. Think how SSH host keys work.
  33. Finally, if you're writing a Gemini server, you should not burden your users with certificate maintenance at all. Generate a self-signed certificate for each host you intend to service on startup. Certificate maintenance is annoying and error prone, and because we use TOFU, we don't have to make the user do it.
  34. See also:
  35. => gemini://makeworld.gq/gemlog/2020-07-03-tofu-rec.gmi TOFU Recommendations on makeworld.qq