foreseen

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

identity-manager.cpp (1073B)


      1 #include "../include/identity-manager.hpp"
      2 
      3 #include <unistd.h>
      4 
      5 #include <filesystem>
      6 #include <string>
      7 
      8 #include "../include/utils.hpp"
      9 #include "../vendor/uri.hpp"
     10 
     11 Identity IdentityManager::getIdentityForURI(uri destination) {
     12     if (destination.get_scheme() != "gemini") {
     13         return Identity{"", ""};
     14     }
     15 
     16     namespace fs = std::filesystem;
     17     fs::path certDir = fs::path(getHome()) / ".foreseen";
     18     std::string host = destination.get_host();
     19     std::string name = host;
     20     if (destination.get_port() && destination.get_port() != 1965) {
     21         name += ":" + std::to_string(destination.get_port());
     22     }
     23     fs::path dir = certDir / name;
     24 
     25     try {
     26         if (fs::exists(dir / "client.crt") && fs::exists(dir / "client.key")) {
     27             return Identity{(dir / "client.key").string(),
     28                             (dir / "client.crt").string()};
     29         }
     30     } catch (const fs::filesystem_error& e) {
     31         // this can happen if the domain is stupidly long.
     32         // in such cases, there are bigger issues.
     33     }
     34     return Identity{"", ""};
     35 }