diff --git a/README.md b/README.md index d2df1f4..10ce335 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ usage decently. [gemini]: https://gemini.circumlunar.space/ [amfora]: https://github.com/makeworld-the-better-one/amfora -If you are interested in Gemini and looking for a client, I recommend trying a -graphical one like the excellent [Lagrange][lagrange] or [Kristall][kristall], -or Amfora if you're feeling more at home in the terminal. Bebop won't attempt -to support every feature other clients might have. +If you are interested in Gemini and looking for a desktop/laptop client, I +recommend trying a graphical one like the excellent [Lagrange][lagrange] or +[Kristall][kristall], or Amfora if you're feeling more at home in the terminal. +Bebop won't attempt to support every feature other clients might have. [lagrange]: https://git.skyjake.fi/skyjake/lagrange [kristall]: https://kristall.random-projects.net/ diff --git a/bebop/__main__.py b/bebop/__main__.py index 360a45c..9c7c8d2 100644 --- a/bebop/__main__.py +++ b/bebop/__main__.py @@ -1,7 +1,9 @@ import argparse +import os from bebop.browser import Browser -from bebop.tofu import load_cert_stash +from bebop.fs import get_user_data_path +from bebop.tofu import load_cert_stash, save_cert_stash def main(): @@ -14,8 +16,16 @@ def main(): else: start_url = None - cert_stash = load_cert_stash("/tmp/stash") - Browser(cert_stash).run(start_url=start_url) + user_data_path = get_user_data_path() + if not user_data_path.exists(): + user_data_path.mkdir() + + cert_stash_path = user_data_path / "known_hosts.txt" + cert_stash = load_cert_stash(cert_stash_path) + try: + Browser(cert_stash).run(start_url=start_url) + finally: + save_cert_stash(cert_stash, cert_stash_path) main() diff --git a/bebop/tofu.py b/bebop/tofu.py index 1ab8080..df0419b 100644 --- a/bebop/tofu.py +++ b/bebop/tofu.py @@ -42,6 +42,20 @@ def load_cert_stash(stash_path): return stash +def save_cert_stash(stash, stash_path): + """Save the certificate stash.""" + try: + with open(stash_path, "wt") as stash_file: + for name, entry in stash.values(): + algo, fingerprint, timestamp, is_permanent = entry + if not is_permanent: + continue + entry_line = f"{name} {algo} {fingerprint} {timestamp}\n" + stash_path.write(entry_line) + except (OSError, ValueError): + pass + + class CertStatus(Enum): """Value returned by validate_cert.""" # Cert is valid: proceed.