2016-02-02 16:28:56 +01:00
|
|
|
// Copyright (c) 2014-2016 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.
|
|
|
|
|
|
|
|
#ifndef _KEEPASS_H_
|
|
|
|
#define _KEEPASS_H_
|
|
|
|
|
2016-08-12 07:39:43 +02: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:
|
2016-08-23 13:27:04 +02:00
|
|
|
void addStrParameter(std::string strName, std::string strValue); // Regular
|
|
|
|
void addStrParameter(std::string strName, SecureString sValue); // Encrypt
|
2014-12-26 12:53:29 +01:00
|
|
|
std::string getJson();
|
|
|
|
|
2016-08-23 13:27:04 +02:00
|
|
|
CKeePassRequest(SecureString sKey, 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:
|
2016-08-23 13:27:04 +02:00
|
|
|
CKeePassEntry(SecureString sUuid, SecureString sName, SecureString sLogin, SecureString sPassword) :
|
|
|
|
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;
|
|
|
|
|
2016-08-23 13:27:04 +02:00
|
|
|
void parseResponse(std::string strResponse);
|
2014-12-26 12:53:29 +01:00
|
|
|
|
|
|
|
public:
|
2016-02-02 16:28:56 +01:00
|
|
|
UniValue responseObj;
|
2016-08-23 13:27:04 +02:00
|
|
|
CKeePassResponse(SecureString sKey, 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;
|
|
|
|
}
|
|
|
|
|
2016-08-23 13:27:04 +02:00
|
|
|
SecureString getSecureStr(std::string strName);
|
|
|
|
std::string getStr(std::string strName);
|
2014-12-26 12:53:29 +01:00
|
|
|
std::vector<CKeePassEntry> getEntries();
|
|
|
|
|
2016-08-23 13:27:04 +02:00
|
|
|
SecureString decrypt(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);
|
2016-08-23 13:27:04 +02:00
|
|
|
void doHTTPPost(const std::string& strRequest, int& nStatus, std::string& strResponse);
|
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();
|
2016-08-23 13:27:04 +02:00
|
|
|
void rpcAssociate(std::string& strId, SecureString& sKeyBase64);
|
2014-12-26 12:53:29 +01:00
|
|
|
SecureString retrievePassphrase();
|
|
|
|
void updatePassphrase(const SecureString& sWalletPassphrase);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
#endif
|