-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeepass.h
More file actions
133 lines (98 loc) · 3.35 KB
/
keepass.h
File metadata and controls
133 lines (98 loc) · 3.35 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) 2014 The Darkcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef _KEEPASS_H_
#define _KEEPASS_H_
#define KEEPASS_CRYPTO_KEY_SIZE 32
#define KEEPASS_CRYPTO_BLOCK_SIZE 16
#define KEEPASS_KEEPASSHTTP_HOST "localhost"
#define KEEPASS_KEEPASSHTTP_PORT 19855
#include <string>
#include <vector>
#include <map>
#include "json/json_spirit_value.h"
#include "allocators.h"
class CKeePassIntegrator {
bool bIsActive;
unsigned int nPort;
SecureString sKeyBase64;
SecureString sKey;
SecureString sUrl;
//SecureString sSubmitUrl;
std::string sKeePassId;
std::string sKeePassEntryName;
class CKeePassRequest {
json_spirit::Object requestObj;
std::string sType;
std::string sIV;
SecureString sKey;
void init();
public:
void addStrParameter(std::string sName, std::string sValue); // Regular
void addStrParameter(std::string sName, SecureString sValue); // Encrypt
std::string getJson();
CKeePassRequest(SecureString sKey, std::string sType)
{
this->sKey = sKey;
this->sType = sType;
init();
};
};
class CKeePassEntry {
SecureString uuid;
SecureString name;
SecureString login;
SecureString password;
public:
CKeePassEntry(SecureString uuid, SecureString name, SecureString login, SecureString password) :
uuid(uuid), name(name), login(login), password(password) {
}
SecureString getUuid() {
return uuid;
}
SecureString getName() {
return name;
}
SecureString getLogin() {
return login;
}
SecureString getPassword() {
return password;
}
};
class CKeePassResponse {
bool bSuccess;
std::string sType;
std::string sIV;
SecureString sKey;
void parseResponse(std::string sResponse);
public:
json_spirit::Object responseObj;
CKeePassResponse(SecureString sKey, std::string sResponse) {
this->sKey = sKey;
parseResponse(sResponse);
}
bool getSuccess() {
return bSuccess;
}
SecureString getSecureStr(std::string sName);
std::string getStr(std::string sName);
std::vector<CKeePassEntry> getEntries();
SecureString decrypt(std::string sValue); // DecodeBase64 and decrypt arbitrary string value
};
static SecureString generateRandomKey(size_t nSize);
static std::string constructHTTPPost(const std::string& strMsg, const std::map<std::string,std::string>& mapRequestHeaders);
void doHTTPPost(const std::string& sRequest, int& nStatus, std::string& sResponse);
void rpcTestAssociation(bool bTriggerUnlock);
std::vector<CKeePassEntry> rpcGetLogins();
void rpcSetLogin(const SecureString& strWalletPass, const SecureString& sEntryId);
public:
CKeePassIntegrator();
void init();
static SecureString generateKeePassKey();
void rpcAssociate(std::string& sId, SecureString& sKeyBase64);
SecureString retrievePassphrase();
void updatePassphrase(const SecureString& sWalletPassphrase);
};
extern CKeePassIntegrator keePassInt;
#endif