2021-04-20 21:33:02 +02:00
|
|
|
// Copyright (c) 2014-2020 The Dash Core developers
|
2014-12-26 12:53:29 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#ifndef BITCOIN_KEEPASS_H
|
|
|
|
#define BITCOIN_KEEPASS_H
|
2014-12-26 12:53:29 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <support/allocators/secure.h>
|
2014-12-26 12:53:29 +01:00
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
#include <univalue.h>
|
2016-08-12 07:39:43 +02:00
|
|
|
|
2016-08-23 13:27:04 +02:00
|
|
|
class CKeePassIntegrator;
|
|
|
|
|
2016-08-12 07:39:43 +02:00
|
|
|
static const unsigned int DEFAULT_KEEPASS_HTTP_PORT = 19455;
|
2016-08-23 13:27:04 +02:00
|
|
|
|
|
|
|
extern CKeePassIntegrator keePassInt;
|
2014-12-26 12:53:29 +01:00
|
|
|
|
|
|
|
class CKeePassIntegrator {
|
2016-08-23 13:27:04 +02:00
|
|
|
private:
|
|
|
|
static const int KEEPASS_CRYPTO_KEY_SIZE = 32;
|
|
|
|
static const int KEEPASS_CRYPTO_BLOCK_SIZE = 16;
|
|
|
|
static const int KEEPASS_HTTP_CONNECT_TIMEOUT = 30;
|
|
|
|
static const char* KEEPASS_HTTP_HOST;
|
2014-12-26 12:53:29 +01:00
|
|
|
|
|
|
|
bool bIsActive;
|
|
|
|
unsigned int nPort;
|
|
|
|
SecureString sKeyBase64;
|
|
|
|
SecureString sKey;
|
|
|
|
SecureString sUrl;
|
|
|
|
//SecureString sSubmitUrl;
|
2016-08-23 13:27:04 +02:00
|
|
|
std::string strKeePassId;
|
|
|
|
std::string strKeePassEntryName;
|
2014-12-26 12:53:29 +01:00
|
|
|
|
|
|
|
class CKeePassRequest {
|
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
UniValue requestObj;
|
2016-08-23 13:27:04 +02:00
|
|
|
std::string strType;
|
|
|
|
std::string strIV;
|
2014-12-26 12:53:29 +01:00
|
|
|
SecureString sKey;
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
|
public:
|
2018-02-12 13:49:00 +01:00
|
|
|
void addStrParameter(const std::string& strName, const std::string& strValue); // Regular
|
|
|
|
void addStrParameter(const std::string& strName, const SecureString& sValue); // Encrypt
|
2014-12-26 12:53:29 +01:00
|
|
|
std::string getJson();
|
|
|
|
|
2018-02-12 13:49:00 +01:00
|
|
|
CKeePassRequest(const SecureString& sKey, const std::string& strType)
|
2014-12-26 12:53:29 +01:00
|
|
|
{
|
|
|
|
this->sKey = sKey;
|
2016-08-23 13:27:04 +02:00
|
|
|
this->strType = strType;
|
2014-12-26 12:53:29 +01:00
|
|
|
init();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CKeePassEntry {
|
|
|
|
|
2016-08-23 13:27:04 +02:00
|
|
|
SecureString sUuid;
|
|
|
|
SecureString sName;
|
|
|
|
SecureString sLogin;
|
|
|
|
SecureString sPassword;
|
2014-12-26 12:53:29 +01:00
|
|
|
|
|
|
|
public:
|
2018-02-12 13:49:00 +01:00
|
|
|
CKeePassEntry(const SecureString& sUuid, const SecureString& sName, const SecureString& sLogin, const SecureString& sPassword) :
|
2016-08-23 13:27:04 +02:00
|
|
|
sUuid(sUuid), sName(sName), sLogin(sLogin), sPassword(sPassword) {
|
2014-12-26 12:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SecureString getUuid() {
|
2016-08-23 13:27:04 +02:00
|
|
|
return sUuid;
|
2014-12-26 12:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SecureString getName() {
|
2016-08-23 13:27:04 +02:00
|
|
|
return sName;
|
2014-12-26 12:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SecureString getLogin() {
|
2016-08-23 13:27:04 +02:00
|
|
|
return sLogin;
|
2014-12-26 12:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SecureString getPassword() {
|
2016-08-23 13:27:04 +02:00
|
|
|
return sPassword;
|
2014-12-26 12:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CKeePassResponse {
|
|
|
|
|
|
|
|
bool bSuccess;
|
2016-08-23 13:27:04 +02:00
|
|
|
std::string strType;
|
|
|
|
std::string strIV;
|
2014-12-26 12:53:29 +01:00
|
|
|
SecureString sKey;
|
|
|
|
|
2018-02-12 13:49:00 +01:00
|
|
|
void parseResponse(const std::string& strResponse);
|
2014-12-26 12:53:29 +01:00
|
|
|
|
|
|
|
public:
|
2016-02-02 16:28:56 +01:00
|
|
|
UniValue responseObj;
|
2018-02-12 13:49:00 +01:00
|
|
|
CKeePassResponse(const SecureString& sKey, const std::string& strResponse) {
|
2014-12-26 12:53:29 +01:00
|
|
|
this->sKey = sKey;
|
2016-08-23 13:27:04 +02:00
|
|
|
parseResponse(strResponse);
|
2014-12-26 12:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool getSuccess() {
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2018-02-12 13:49:00 +01:00
|
|
|
SecureString getSecureStr(const std::string& strName);
|
|
|
|
std::string getStr(const std::string& strName);
|
2014-12-26 12:53:29 +01:00
|
|
|
std::vector<CKeePassEntry> getEntries();
|
|
|
|
|
2018-02-12 13:49:00 +01:00
|
|
|
SecureString decrypt(const std::string& strValue); // DecodeBase64 and decrypt arbitrary string value
|
2014-12-26 12:53:29 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static SecureString generateRandomKey(size_t nSize);
|
|
|
|
static std::string constructHTTPPost(const std::string& strMsg, const std::map<std::string,std::string>& mapRequestHeaders);
|
2018-02-12 13:49:00 +01:00
|
|
|
void doHTTPPost(const std::string& strRequest, int& nStatusRet, std::string& strResponseRet);
|
2014-12-26 12:53:29 +01:00
|
|
|
void rpcTestAssociation(bool bTriggerUnlock);
|
|
|
|
std::vector<CKeePassEntry> rpcGetLogins();
|
2016-08-23 13:27:04 +02:00
|
|
|
void rpcSetLogin(const SecureString& sWalletPass, const SecureString& sEntryId);
|
2014-12-26 12:53:29 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
CKeePassIntegrator();
|
|
|
|
void init();
|
|
|
|
static SecureString generateKeePassKey();
|
2018-02-12 13:49:00 +01:00
|
|
|
void rpcAssociate(std::string& strIdRet, SecureString& sKeyBase64Ret);
|
2014-12-26 12:53:29 +01:00
|
|
|
SecureString retrievePassphrase();
|
|
|
|
void updatePassphrase(const SecureString& sWalletPassphrase);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#endif // BITCOIN_KEEPASS_H
|