From 6285b4d8b283fb38112ec04b1cc570a8c0c9844b Mon Sep 17 00:00:00 2001 From: Malfurious Date: Thu, 24 Oct 2024 08:44:36 -0400 Subject: Remove Socket class The remote socket functionality was only stub code, never fully implemented. A network architecture for compass keychains is no longer a design goal, so the dead code is removed. Signed-off-by: Malfurious --- CMakeLists.txt | 1 - Cryptor.cpp | 66 ++++++++++++++++------------------------------------------ Cryptor.h | 3 +-- Socket.cpp | 46 ---------------------------------------- Socket.h | 29 -------------------------- 5 files changed, 19 insertions(+), 126 deletions(-) delete mode 100644 Socket.cpp delete mode 100644 Socket.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e0fd0a8..263cd58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ add_executable(compass Help.cpp Keychain.cpp Options.cpp - Socket.cpp ) target_link_libraries(compass mbedtls) diff --git a/Cryptor.cpp b/Cryptor.cpp index 9db2bdc..1cce31e 100644 --- a/Cryptor.cpp +++ b/Cryptor.cpp @@ -61,62 +61,32 @@ void Cryptor::encryptAndSave(std::string remoteHost, std::string port, std::stri delete[] encCipher; delete[] ciphertext; - if (remoteHost == "") { - if (directory[directory.size() - 1] != '/') { - directory += "/"; - } - directory += KEYCHAIN_FILE; - std::ofstream f(directory.c_str()); - f << _encIV << std::endl; - f << _encCipher << std::endl; - f.close(); - } else { - Socket s; - std::string err = ""; - s.conn(remoteHost, port); - s.sendline("store"); - s.sendline(directory); - s.sendline(_encIV); - s.sendline(_encCipher); - err = s.readline(); - s.clo(); - if (err != "OK") { - throw 1; - } + if (directory[directory.size() - 1] != '/') { + directory += "/"; } + directory += KEYCHAIN_FILE; + std::ofstream f(directory.c_str()); + f << _encIV << std::endl; + f << _encCipher << std::endl; + f.close(); } std::string Cryptor::loadAndDecrypt(std::string remoteHost, std::string port, std::string directory) { // Load Data std::string encIV, encCipher; - if (remoteHost == "") { - if (directory[directory.size() - 1] != '/') { - directory += "/"; - } - directory += KEYCHAIN_FILE; - std::ifstream f(directory.c_str()); - if (!f.good()) { - f.close(); - throw 1; - } - f >> encIV; - f >> encCipher; + + if (directory[directory.size() - 1] != '/') { + directory += "/"; + } + directory += KEYCHAIN_FILE; + std::ifstream f(directory.c_str()); + if (!f.good()) { f.close(); - } else { - Socket s; - std::string err = ""; - s.conn(remoteHost, port); - s.sendline("fetch"); - s.sendline(directory); - err = s.readline(); - if (err != "OK") { - s.clo(); - throw 1; - } - encIV = s.readline(); - encCipher = s.readline(); - s.clo(); + throw 1; } + f >> encIV; + f >> encCipher; + f.close(); // Decode data unsigned char *ciphertext = new unsigned char[encCipher.size() / 2]; diff --git a/Cryptor.h b/Cryptor.h index f1448b0..94af673 100644 --- a/Cryptor.h +++ b/Cryptor.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef WIN32 #include @@ -18,8 +19,6 @@ #include "mbedtls/entropy.h" #include "mbedtls/sha256.h" -#include "Socket.h" - #define DEF_PASSWD_LENGTH 50 #define AES_BLOCK_LENGTH 16 diff --git a/Socket.cpp b/Socket.cpp deleted file mode 100644 index c90a607..0000000 --- a/Socket.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "Socket.h" - -Socket::Socket() { - /*memset(&hostInfo, 0, sizeof(hostInfo)); - hostInfo.ai_family = AF_UNSPEC; - hostInfo.ai_socktype = SOCK_STREAM;*/ -} - -Socket::~Socket() { - /*freeaddrinfo(hostInfoList); - clo();*/ -} - -void Socket::conn(std::string host, std::string port) { - throw 1; - /*int status; - status = getaddrinfo(host.c_str(), port.c_str(), &hostInfo, &hostInfoList); - if (status) throw 1; - - sockid = socket(hostInfoList->ai_family, hostInfoList->ai_socktype, hostInfoList->ai_protocol); - if (sockid == -1) throw 1; - - status = connect(sockid, hostInfoList->ai_addr, hostInfoList->ai_addrlen); - if (status) throw 1;*/ -} - -void Socket::sendline(std::string line) { - throw 1; - /*ssize_t bytesSent; - - do { - int len = line.size(); - bytesSent = send(sockid, line.c_str(), len, 0); - - line = line.substr(bytesSent, line.size() - bytesSent); - } while (line.size() > 0); - - send(sockid, "\n", 1, 0); // add \n*/ -} - -std::string Socket::readline() { - throw 1; -} - -void Socket::clo() { -} diff --git a/Socket.h b/Socket.h deleted file mode 100644 index 86b6478..0000000 --- a/Socket.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SOCKET_H -#define SOCKET_H - -#include -#include - -#ifdef WIN32 -#else -#include -#include -#endif // WIN32 - -class Socket { -public: - Socket(); - virtual ~Socket(); - - void conn(std::string host, std::string port); - void sendline(std::string line); - std::string readline(); - void clo(); - -private: - /*int sockid; - addrinfo hostInfo; - addrinfo* hostInfoList;*/ -}; - -#endif // SOCKET_H -- cgit v1.2.3 From 8455d3e9256bff8d4f74b3606347522ea6c381ca Mon Sep 17 00:00:00 2001 From: Malfurious Date: Thu, 24 Oct 2024 13:06:13 -0400 Subject: Remove remote-host and port options Support for remote keychains is removed, so also remove the associated command-line options. Signed-off-by: Malfurious --- Compass.cpp | 20 ++++++++++---------- Cryptor.cpp | 4 ++-- Cryptor.h | 4 ++-- Help.cpp | 4 +--- Keychain.cpp | 15 ++++++--------- Keychain.h | 6 ++---- Options.cpp | 32 -------------------------------- Options.h | 2 -- 8 files changed, 23 insertions(+), 64 deletions(-) diff --git a/Compass.cpp b/Compass.cpp index 9a27d55..dd0bbaf 100644 --- a/Compass.cpp +++ b/Compass.cpp @@ -215,7 +215,7 @@ void Compass::initialize() { } void Compass::create(std::string service) { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); Credential c; if (opt.user != "" && opt.pass != "") @@ -238,13 +238,13 @@ void Compass::create(std::string service) { } void Compass::walk() { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); kc->walk(); delete kc; } void Compass::rekey() { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); Cryptor::rekey(); std::cout << "Enter a new master password for your keychain... (CTRL-C to abort)" << std::endl; @@ -253,7 +253,7 @@ void Compass::rekey() { } void Compass::get(std::string service) { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); Credential c; if (opt.cn != -1) @@ -278,7 +278,7 @@ void Compass::get(std::string service) { } void Compass::_delete(std::string service) { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); bool b; if (opt.cn != -1) @@ -300,7 +300,7 @@ void Compass::_delete(std::string service) { } void Compass::show(std::string service, bool like) { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); if (service == "") kc->show(); @@ -319,7 +319,7 @@ void Compass::random() { } void Compass::markReset(std::string service) { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); int i; if (service == "") @@ -335,7 +335,7 @@ void Compass::markReset(std::string service) { } void Compass::checkReset(std::string service) { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); int i; if (service == "") @@ -349,7 +349,7 @@ void Compass::checkReset(std::string service) { } void Compass::ruser(std::string service) { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); Credential c; if (opt.user == "") { @@ -376,7 +376,7 @@ void Compass::ruser(std::string service) { } void Compass::rpass(std::string service) { - Keychain* kc = Keychain::loadKeychain(opt.rh, opt.pt, opt.dr); + Keychain* kc = Keychain::loadKeychain(opt.dr); Credential c; if (opt.pass == "") { diff --git a/Cryptor.cpp b/Cryptor.cpp index 1cce31e..0d2dd71 100644 --- a/Cryptor.cpp +++ b/Cryptor.cpp @@ -25,7 +25,7 @@ static void fromHex(void *output, const char *input) { } } -void Cryptor::encryptAndSave(std::string remoteHost, std::string port, std::string directory, std::string payload) { +void Cryptor::encryptAndSave(std::string directory, std::string payload) { // Key if (!haveKey) { assembleKey(true); @@ -71,7 +71,7 @@ void Cryptor::encryptAndSave(std::string remoteHost, std::string port, std::stri f.close(); } -std::string Cryptor::loadAndDecrypt(std::string remoteHost, std::string port, std::string directory) { +std::string Cryptor::loadAndDecrypt(std::string directory) { // Load Data std::string encIV, encCipher; diff --git a/Cryptor.h b/Cryptor.h index 94af673..6afe6f2 100644 --- a/Cryptor.h +++ b/Cryptor.h @@ -42,8 +42,8 @@ struct PasswordSpec { class Cryptor { public: - static void encryptAndSave(std::string remoteHost, std::string port, std::string directory, std::string payload); - static std::string loadAndDecrypt(std::string remoteHost, std::string port, std::string directory); + static void encryptAndSave(std::string directory, std::string payload); + static std::string loadAndDecrypt(std::string directory); static std::string createRandomPassword(PasswordSpec spec); static void rekey(); diff --git a/Help.cpp b/Help.cpp index a8739be..d0ee0c0 100644 --- a/Help.cpp +++ b/Help.cpp @@ -52,9 +52,7 @@ void Help::dispGeneral() { std::cout << "-user Used to disambiguate credentials if lookups return more than one" << std::endl; std::cout << " Also used to specify a username value for new or updated credentials" << std::endl; std::cout << "-pass Used to specify a password value for new or updated credentials" << std::endl; - std::cout << "-rh
Used to specify a remote host to connect to if keychain is on another machine" << std::endl; - std::cout << "-pt Port on remote host to connect to" << std::endl; - std::cout << "-dr Directory to look for, or put, keychain in. If -rh is set, this refers to the remote machine" << std::endl; + std::cout << "-dr Directory to look for, or put, keychain in" << std::endl; std::cout << "-cn Used to disambiguate credentials if lookups return more than one" << std::endl; std::cout << "-ml Password Gen Option: max-length for generated string" << std::endl; std::cout << "-ns Password Gen Option: set this if no special chars should be used" << std::endl; diff --git a/Keychain.cpp b/Keychain.cpp index 8e017eb..8f0880d 100644 --- a/Keychain.cpp +++ b/Keychain.cpp @@ -1,8 +1,6 @@ #include "Keychain.h" -Keychain::Keychain(std::string remoteHost, std::string port, std::string directory) { - this->remoteHost = remoteHost; - this->port = port; +Keychain::Keychain(std::string directory) { this->directory = directory; } @@ -10,15 +8,14 @@ Keychain::~Keychain() { } Keychain* Keychain::newKeychain(std::string directory) { - Keychain* kc = new Keychain("", "", directory); - return kc; + return new Keychain(directory); } -Keychain* Keychain::loadKeychain(std::string remoteHost, std::string port, std::string directory) { - std::string data = Cryptor::loadAndDecrypt(remoteHost, port, directory); +Keychain* Keychain::loadKeychain(std::string directory) { + std::string data = Cryptor::loadAndDecrypt(directory); std::istringstream datstr(data); - Keychain* kc = new Keychain(remoteHost, port, directory); + Keychain* kc = new Keychain(directory); int kcSize, servSize; datstr >> kcSize; @@ -86,7 +83,7 @@ void Keychain::saveKeychain() { } } - Cryptor::encryptAndSave(remoteHost, port, directory, datstr.str()); + Cryptor::encryptAndSave(directory, datstr.str()); } void Keychain::walk() { // Don't call this, it's just for debuging purposes and prints out plaintext passwords! diff --git a/Keychain.h b/Keychain.h index 8219424..de0d760 100644 --- a/Keychain.h +++ b/Keychain.h @@ -23,12 +23,12 @@ struct Credential { class Keychain { public: // Structors - Keychain(std::string remoteHost, std::string port, std::string directory); + Keychain(std::string directory); virtual ~Keychain(); // Open/close static Keychain* newKeychain(std::string directory); - static Keychain* loadKeychain(std::string remoteHost, std::string port, std::string directory); + static Keychain* loadKeychain(std::string directory); void saveKeychain(); // Info/Debug @@ -80,8 +80,6 @@ public: private: std::map > credentials; // map from service name (string) onto list of credentials for that service (vector) - std::string remoteHost; - std::string port; std::string directory; // Reset Credentials diff --git a/Options.cpp b/Options.cpp index 34b1e66..acfb803 100644 --- a/Options.cpp +++ b/Options.cpp @@ -7,8 +7,6 @@ Options::Options() { user = ""; pass = ""; - rh = ""; - pt = "3041"; dr = cwd; cn = -1; ml = DEF_PASSWD_LENGTH; @@ -39,7 +37,6 @@ void Options::checkString(std::string str) { } void Options::parseArgv(int start, int argc, char* argv[]) { - bool setPort = false; bool setGenMod = false; std::vector args = loadOptionsFile(start, argc, argv); @@ -71,29 +68,6 @@ void Options::parseArgv(int start, int argc, char* argv[]) { checkString(pass); } - else if (opt == "-rh") { - i++; - if (i >= args.size()) { - std::cerr << "Warning: remote-host: value is missing." << std::endl; - i--; - continue; - } - rh = std::string(args[i]); - checkString(rh); - } - - else if (opt == "-pt") { - i++; - if (i >= args.size()) { - std::cerr << "Warning: port: value is missing." << std::endl; - i--; - continue; - } - pt = std::string(args[i]); - checkString(pt); - setPort = true; - } - else if (opt == "-dr") { i++; if (i >= args.size()) { @@ -180,12 +154,6 @@ void Options::parseArgv(int start, int argc, char* argv[]) { std::cerr << "Notice: unrecognized option: " << opt << std::endl; } - if (rh != "") - std::cout << "Notice: using remote-host: " << rh << std::endl; - - if (setPort && rh == "") - std::cerr << "Notice: setting remote port without setting remote host." << std::endl; - if (setGenMod && pass != "") std::cerr << "Notice: setting generator modifiers and explicitly setting a password. Explicit password takes precedence." << std::endl; } diff --git a/Options.h b/Options.h index a813fa4..9440964 100644 --- a/Options.h +++ b/Options.h @@ -24,8 +24,6 @@ public: // Options std::string user; std::string pass; - std::string rh; // remote host - std::string pt; // TCP port std::string dr; // directory int cn; // credential number int ml; // max length -- cgit v1.2.3