foreseen

A text-based gemini browser with prefetching.
git clone git://git.laack.co/foreseen.git
Log | Files | Refs | README | LICENSE

commit 2ff3222900b5f8429d175fcbff736ea935678a17
parent 69af76a184c2c6dfd81ffd2562f6082c3baa10cb
Author: Andrew Laack <andrew@laack.co>
Date:   Fri, 25 Sep 2026 20:05:42 -0500

Very basic auth where certs are sent on the basis of domains.

Diffstat:
Minclude/browser.hpp | 2+-
Minclude/identity-manager.hpp | 4----
Minclude/utils.hpp | 2++
Msrc/identity-manager.cpp | 34+++++++++++++++++++++++++---------
Msrc/main.cpp | 1-
Msrc/utils.cpp | 15+++++++++++++++
6 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/include/browser.hpp b/include/browser.hpp @@ -17,7 +17,7 @@ const int THREAD_NUM = 4; class Browser { private: - IdentityManager identityManager = IdentityManager{""}; + IdentityManager identityManager = IdentityManager{}; std::vector<std::thread> threads; std::vector<std::atomic<bool>> done; std::unordered_map<std::string, int> previousStatusCodes; diff --git a/include/identity-manager.hpp b/include/identity-manager.hpp @@ -10,10 +10,6 @@ struct Identity { }; class IdentityManager { - private: - // We want to search based on path first then domain. - std::unordered_map<std::string, Identity> lookup; public: - IdentityManager(std::string configurationPath); Identity getIdentityForURI(uri destination); }; diff --git a/include/utils.hpp b/include/utils.hpp @@ -1,5 +1,6 @@ #pragma once #include <optional> +#include <filesystem> #include <string> #include <vector> #include "line.hpp" @@ -28,3 +29,4 @@ std::vector<std::pair<std::string, TextRender>> breakLines(std::vector<std::pair // This will over-write the existing file, if relevant. This will not create directories for you. void writeStringToFile(std::string toWrite, std::string filePath); std::string encodeAsFilename(uri link); +std::filesystem::path getHome(); diff --git a/src/identity-manager.cpp b/src/identity-manager.cpp @@ -1,16 +1,32 @@ +#include <algorithm> +#include <cstdlib> +#include <filesystem> +#include <iostream> +#include <stdexcept> #include <string> -#include <unordered_map> +#include <unistd.h> #include "../vendor/uri.hpp" #include "../include/identity-manager.hpp" - -IdentityManager::IdentityManager(std::string configurationPath) { - // TODO: Implement this. - // lookup["bbs.geminispace.org"] = Identity{"/home/andrew/client.key", "/home/andrew/client.crt"}; -} +#include "../include/utils.hpp" Identity IdentityManager::getIdentityForURI(uri destination) { - // TODO: Implement this. - return Identity{"",""}; -} + if(destination.get_scheme() != "gemini") { + return Identity{"", ""}; + } + namespace fs = std::filesystem; + fs::path certDir = fs::path(getHome()) / ".gb"; + std::string host = destination.get_host(); + std::string name = host; + if (destination.get_port() && destination.get_port() != 1965) { + name += ":" + std::to_string(destination.get_port()); + } + fs::path dir = certDir / name; + + if (fs::exists(dir / "client.crt") && fs::exists(dir / "client.key")) { + return Identity{(dir / "client.key").string(), (dir / "client.crt").string()}; + } + + return Identity{"", ""}; +} diff --git a/src/main.cpp b/src/main.cpp @@ -325,7 +325,6 @@ std::string handleUserInput(DrawState ds) { int main(int argc, char** argv) { - Browser* bPtr = new Browser{}; Browser& b = *bPtr; diff --git a/src/utils.cpp b/src/utils.cpp @@ -251,3 +251,18 @@ std::string encodeAsFilename(uri link) { std::string cleaned = std::regex_replace(base, std::regex("[^[:alnum:]._-]"), "_"); return cleaned; } + +std::filesystem::path getHome() +{ + std::string home = std::getenv("HOME"); + if (home == "") { + throw std::runtime_error{"$HOME not set."}; + } + if(!std::filesystem::exists(home)) { + throw std::runtime_error{"$HOME directory doesn't exist..."}; + } + + return home; +} + +