tofu: add save_cert_stash
This commit is contained in:
parent
0b79bd9e9e
commit
e517df7836
|
@ -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/
|
||||
|
|
|
@ -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")
|
||||
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()
|
||||
|
|
|
@ -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.
|
||||
|
|
Reference in a new issue