commit 53e51a977079b3779305182374fe4d935ced4de8
parent 61eb66e26df66623ffcf4c55dbff929d378b3c67
Author: Andrew Laack <andrew@laack.co>
Date: Fri, 25 Sep 2026 18:46:10 -0500
Basic scaffolding for identity management.
Diffstat:
9 files changed, 67 insertions(+), 14 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,25 +1,25 @@
build:
- g++ -g src/main.cpp src/quote.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/cache.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp src/heading.cpp -lssl -lcrypto -lncursesw -o browser.out
+ g++ -g src/main.cpp src/identity-manager.cpp src/quote.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/cache.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp src/heading.cpp -lssl -lcrypto -lncursesw -o browser.out
install:
- g++ -Ofast src/main.cpp src/quote.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/cache.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp src/heading.cpp -lssl -lcrypto -lncursesw -o browser.out
+ g++ -Ofast src/main.cpp src/identity-manager.cpp src/quote.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/cache.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp src/heading.cpp -lssl -lcrypto -lncursesw -o browser.out
cp browser.out /usr/local/bin/gem-browser
clean:
echo "Not implemented"
browser-test:
- g++ tests/browser-test.cpp src/quote.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/plaintext.cpp src/browser.cpp src/link.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
+ g++ tests/browser-test.cpp src/quote.cpp src/identity-manager.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/plaintext.cpp src/browser.cpp src/link.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
./test.out
rm test.out
fetch-test:
- g++ tests/fetch-test.cpp src/quote.cpp src/list-item.cpp src/link.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/site.cpp src/plaintext.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
+ g++ tests/fetch-test.cpp src/quote.cpp src/identity-manager.cpp src/list-item.cpp src/link.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/site.cpp src/plaintext.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
./test.out
rm test.out
pure-test:
- g++ tests/pure-test.cpp src/quote.cpp src/list-item.cpp src/link.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/site.cpp src/plaintext.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
+ g++ tests/pure-test.cpp src/quote.cpp src/list-item.cpp src/identity-manager.cpp src/link.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/site.cpp src/plaintext.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
./test.out
rm test.out
diff --git a/TODO.txt b/TODO.txt
@@ -11,7 +11,6 @@
- way to show where links go
- text search
- character encoding options
-- don't line break on preformatted text...
- should reset y value when switching between some tabs
- persistent memory sometimes though.
- perhaps on the basis of a page? sort of wonder about that though; like should this be stored in browser and then perhaps
@@ -33,3 +32,6 @@
- different color lines
- would be nice for link lines to vary depending on if they've been visited in history
- horizontal scroll when lines are too long?
+- make unordered list items indent correctly
+ - first line is normal, subsequent lines should have 2 spaces prefixing them
+- show prompt for inputs from metaline.
diff --git a/include/browser.hpp b/include/browser.hpp
@@ -6,6 +6,7 @@
#include <unordered_map>
#include <vector>
#include "line.hpp"
+#include "identity-manager.hpp"
#include "site.hpp"
#include "cache.hpp"
#include "link.hpp"
@@ -16,6 +17,7 @@ const int THREAD_NUM = 4;
class Browser {
private:
+ 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/gemini-client.hpp b/include/gemini-client.hpp
@@ -4,7 +4,7 @@
#include "link.hpp"
class GeminiClient {
- Site* getNetworkedSite(Link link);
+ Site* getNetworkedSite(Link link, std::string crtPath, std::string keyPath);
public:
- Site* fetchSite(Link link);
+ Site* fetchSite(Link link, std::string crtPath = "", std::string keyPath = "");
};
diff --git a/include/identity-manager.hpp b/include/identity-manager.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <string>
+#include <unordered_map>
+#include "../vendor/uri.hpp"
+
+struct Identity {
+ std::string keyPath = "";
+ std::string crtPath = "";
+};
+
+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/src/browser.cpp b/src/browser.cpp
@@ -6,6 +6,7 @@
#include "../include/site.hpp"
#include "../include/gemini-client.hpp"
#include "../include/utils.hpp"
+#include "../include/identity-manager.hpp"
#include <cstddef>
#include <cstdlib>
#include <optional>
@@ -113,7 +114,8 @@ void Browser::goToSite(std::string url, bool addToHistory, bool refresh) {
}
if(site == nullptr) {
- site = client.fetchSite(*destination);
+ Identity id = identityManager.getIdentityForURI(destination->getLinkDestination());
+ site = client.fetchSite(*destination, id.crtPath, id.keyPath);
}
if(site == nullptr || site->getUnreachable()) {
@@ -216,7 +218,7 @@ std::vector<Line*> Browser::toLines(Site* site) {
}
-Browser::Browser() : threads(THREAD_NUM), done(THREAD_NUM) {
+Browser::Browser() : threads(THREAD_NUM), done(THREAD_NUM){
currentSite = nullptr;
visitedCache = new Cache{};
preFetchCache = new Cache{};
diff --git a/src/gemini-client.cpp b/src/gemini-client.cpp
@@ -1,3 +1,4 @@
+#include <filesystem>
#include <iostream>
#include <stdexcept>
#include <sys/socket.h>
@@ -11,7 +12,7 @@
#include <string>
#include <poll.h>
-Site* GeminiClient::getNetworkedSite(Link link) {
+Site* GeminiClient::getNetworkedSite(Link link, std::string crtPath, std::string keyPath) {
std::string host = link.getLinkDestination().get_host();
std::string req = link.getLinkDestination().to_string() + "\r\n";
@@ -22,6 +23,17 @@ Site* GeminiClient::getNetworkedSite(Link link) {
}
SSL_CTX* ctx = SSL_CTX_new(TLS_client_method());
+
+
+ if(crtPath != "" && keyPath != "") {
+ if (SSL_CTX_use_certificate_file(ctx, crtPath.c_str(), SSL_FILETYPE_PEM) <= 0 ||
+ SSL_CTX_use_PrivateKey_file(ctx, keyPath.c_str(), SSL_FILETYPE_PEM) <= 0 ||
+ !SSL_CTX_check_private_key(ctx)) {
+ SSL_CTX_free(ctx);
+ return nullptr;
+ }
+ }
+
BIO* bio = BIO_new_ssl_connect(ctx);
SSL* ssl;
@@ -87,13 +99,13 @@ Site* GeminiClient::getNetworkedSite(Link link) {
}
-Site* GeminiClient::fetchSite(Link link) {
+Site* GeminiClient::fetchSite(Link link, std::string crtPath, std::string keyPath) {
std::string destination = link.getLinkDestination().to_string();
// TODO: Actually handle uris
if(isPrefixed(destination, "gemini://")) {
try {
- return getNetworkedSite(link);
+ return getNetworkedSite(link, crtPath, keyPath);
} catch (...) {
auto* unreach = new Site{"", ""};
unreach->setUnreachable();
diff --git a/src/identity-manager.cpp b/src/identity-manager.cpp
@@ -0,0 +1,16 @@
+#include <string>
+#include <unordered_map>
+#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"};
+}
+
+Identity IdentityManager::getIdentityForURI(uri destination) {
+ // TODO: Implement this.
+ return Identity{"",""};
+}
+
+
diff --git a/src/main.cpp b/src/main.cpp
@@ -4,6 +4,7 @@
#include <cassert>
#include <cstddef>
#include <filesystem>
+#include <iostream>
#include <ncurses.h>
#include <string>
#include <unctrl.h>
@@ -452,7 +453,6 @@ int main(int argc, char** argv) {
refresh();
-
input = getch();
}