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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#ifndef KEYCHAIN_H
#define KEYCHAIN_H
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <sstream>
#include "Cryptor.h"
struct Credential {
Credential() {
username = password = "";
reset = false;
}
std::string username;
std::string password;
bool reset;
};
class Keychain {
public:
// Structors
Keychain(std::string remoteHost, std::string port, 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);
void saveKeychain();
// Info/Debug
void walk();
int getServiceCount(std::string service);
// Create
Credential create(std::string service, std::string username, std::string password);
Credential create(std::string service, std::string username, PasswordSpec spec);
Credential create(std::string service, std::string password);
Credential create(std::string service, PasswordSpec spec);
// Delete
bool _delete(std::string service);
bool _delete(std::string service, std::string username);
bool _delete(std::string service, int cn);
// Show
void show();
void show1(std::string service);
void showlike(std::string service);
// Get
Credential get(std::string service);
Credential get(std::string service, std::string username);
Credential get(std::string service, int cn);
// Mark Reset
int markResetAll();
int markResetOne(std::string service);
// Check Reset
int checkResetAll();
int checkResetOne(std::string service);
// Reset Username
Credential ruser(std::string service, std::string username);
Credential ruser(std::string service);
Credential ruser(std::string service, std::string username, int cn);
Credential ruser(std::string service, int cn);
// Reset Password
Credential rpass(std::string service, std::string password);
Credential rpass(std::string service, PasswordSpec spec);
Credential rpass(std::string service, std::string password, std::string username);
Credential rpass(std::string service, PasswordSpec spec, std::string username);
Credential rpass(std::string service, std::string password, int cn);
Credential rpass(std::string service, PasswordSpec spec, int cn);
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
Credential resetUsername(std::string service, std::string username, int cn);
Credential resetPassword(std::string service, std::string password, int cn);
std::vector<Credential> getCreds(std::string service);
int getCredsUsernameCount(std::vector<Credential> creds, std::string username);
Credential getCredByUsername(std::vector<Credential> creds, std::string username);
int getPosByUsername(std::vector<Credential> creds, std::string username);
void printServiceCreds(std::vector<Credential> creds);
void promptConfirm();
std::vector<std::string> getServicesLike(std::string service);
PasswordSpec getUsernameSpec();
};
#endif // KEYCHAIN_H
|