blob: 1fcac367df6d2ee468ca3f7ea2bcf634a030379e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#ifndef CRYPTOR_H
#define CRYPTOR_H
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#ifdef WIN32
#include <windows.h>
#else
#include <termios.h>
#include <unistd.h>
#endif // WIN32
#include "mbedtls/cipher.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/entropy.h"
#include "Socket.h"
#define DEF_PASSWD_LENGTH 50
#define AES_BLOCK_LENGTH 16
#define KEYCHAIN_FILE ".compasskeychain"
#define PASSWORD_PROMPT "ComPASS Password: "
#define PASSWORD_CONF "Confirm Password: "
#define PASSWORD_ERROR "Passwords do not match..."
struct PasswordSpec {
PasswordSpec() { // Default Values
ml = DEF_PASSWD_LENGTH;
ns = nc = nn = false;
}
int ml; // max length
bool ns; // no special chars
bool nc; // no caps
bool nn; // no numeric chars
};
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 std::string createRandomPassword(PasswordSpec spec);
static void rekey();
private:
static bool haveKey;
static unsigned char key[AES_BLOCK_LENGTH];
static void sha256(std::string str);
static void generateRandom(void *output, size_t size);
static std::string readPassword(bool confirm);
static std::string readPassword();
static void assembleKey(bool confirm);
static void assembleKey();
static std::string promptPassword(bool confirm);
};
#endif // CRYPTOR_H
|