summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2024-10-25 03:34:18 -0400
committerMalfurious <m@lfurio.us>2024-10-25 03:34:18 -0400
commita86c2daf3d9958c838c55950a53b4a1d6d99f3d1 (patch)
tree80660a9a058033f475c49cc71c4f18ae7cca14ac
parent512aa4c77b3dc0d72db713a9215ff65a98a99ec3 (diff)
parent8455d3e9256bff8d4f74b3606347522ea6c381ca (diff)
downloadcompass-a86c2daf3d9958c838c55950a53b4a1d6d99f3d1.tar.gz
compass-a86c2daf3d9958c838c55950a53b4a1d6d99f3d1.zip
Merge branch 'remove-network'
* remove-network: Remove remote-host and port options Remove Socket class
-rw-r--r--CMakeLists.txt1
-rw-r--r--Compass.cpp20
-rw-r--r--Cryptor.cpp70
-rw-r--r--Cryptor.h7
-rw-r--r--Help.cpp4
-rw-r--r--Keychain.cpp15
-rw-r--r--Keychain.h6
-rw-r--r--Options.cpp32
-rw-r--r--Options.h2
-rw-r--r--Socket.cpp46
-rw-r--r--Socket.h29
11 files changed, 42 insertions, 190 deletions
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/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 9db2bdc..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);
@@ -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) {
+std::string Cryptor::loadAndDecrypt(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..6afe6f2 100644
--- a/Cryptor.h
+++ b/Cryptor.h
@@ -5,6 +5,7 @@
#include <string>
#include <fstream>
#include <vector>
+#include <cstring>
#ifdef WIN32
#include <windows.h>
@@ -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
@@ -43,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 <username> 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 <password> Used to specify a password value for new or updated credentials" << std::endl;
- std::cout << "-rh <address> Used to specify a remote host to connect to if keychain is on another machine" << std::endl;
- std::cout << "-pt <port> Port on remote host to connect to" << std::endl;
- std::cout << "-dr <path> Directory to look for, or put, keychain in. If -rh is set, this refers to the remote machine" << std::endl;
+ std::cout << "-dr <path> Directory to look for, or put, keychain in" << std::endl;
std::cout << "-cn <number> Used to disambiguate credentials if lookups return more than one" << std::endl;
std::cout << "-ml <length> 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<std::string, std::vector<Credential> > credentials; // map from service name (string) onto list of credentials for that service (vector<Credential>)
- 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<std::string> 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
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 <string>
-#include <cstring>
-
-#ifdef WIN32
-#else
-#include <sys/socket.h>
-#include <netdb.h>
-#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