mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Store DHParams in sqlite.
This commit is contained in:
@@ -56,12 +56,11 @@ const char *WalletDBInit[] = {
|
||||
Comment TEXT \
|
||||
);",
|
||||
|
||||
// XXX Don't really need this.
|
||||
// We should generate communication identity per launch.
|
||||
// Validation id is provided via rpc or stored in config.
|
||||
"CREATE TABLE NodeIdentity ( \
|
||||
PublicKey CHARACTER(53), \
|
||||
PrivateKey CHARACTER(52) \
|
||||
PrivateKey CHARACTER(52), \
|
||||
Dh512 TEXT, \
|
||||
Dh1024 TEXT \
|
||||
);",
|
||||
|
||||
// Miscellaneous persistent information
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/mem_fn.hpp>
|
||||
//#include <boost/log/trivial.hpp>
|
||||
#include <openssl/dh.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Config.h"
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::asio::ip;
|
||||
@@ -16,33 +17,7 @@ using namespace boost::asio::ip;
|
||||
// Generate DH for SSL connection.
|
||||
static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
|
||||
{
|
||||
// We don't care if for export.
|
||||
static DH* sdh512 = 0;
|
||||
static DH* sdh1024 = 0;
|
||||
|
||||
if (!sdh512 && 512 == iKeyLength)
|
||||
{
|
||||
int iCodes;
|
||||
|
||||
do {
|
||||
sdh512 = DH_generate_parameters(512, DH_GENERATOR_5, NULL, NULL);
|
||||
iCodes = 0;
|
||||
DH_check(sdh512, &iCodes);
|
||||
} while (iCodes & (DH_CHECK_P_NOT_PRIME|DH_CHECK_P_NOT_SAFE_PRIME|DH_UNABLE_TO_CHECK_GENERATOR|DH_NOT_SUITABLE_GENERATOR));
|
||||
}
|
||||
|
||||
if (!sdh1024 && 512 != iKeyLength)
|
||||
{
|
||||
int iCodes;
|
||||
|
||||
do {
|
||||
sdh1024 = DH_generate_parameters(1024, DH_GENERATOR_5, NULL, NULL);
|
||||
iCodes = 0;
|
||||
DH_check(sdh1024, &iCodes);
|
||||
} while (iCodes & (DH_CHECK_P_NOT_PRIME|DH_CHECK_P_NOT_SAFE_PRIME|DH_UNABLE_TO_CHECK_GENERATOR|DH_NOT_SUITABLE_GENERATOR));
|
||||
}
|
||||
|
||||
return 512 == iKeyLength ? sdh512 : sdh1024;
|
||||
return 512 == iKeyLength ? theApp->getWallet().getDh512() : theApp->getWallet().getDh1024();
|
||||
}
|
||||
|
||||
PeerDoor::PeerDoor(boost::asio::io_service& io_service) :
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "Ledger.h"
|
||||
#include "NewcoinAddress.h"
|
||||
#include "Application.h"
|
||||
#include "utils.h"
|
||||
|
||||
// TEMPORARY
|
||||
#ifndef CHECK_NEW_FAMILIES
|
||||
@@ -381,6 +382,14 @@ bool Wallet::nodeIdentityLoad()
|
||||
mNodePublicKey.setNodePublic(strPublicKey);
|
||||
mNodePrivateKey.setNodePrivate(strPrivateKey);
|
||||
|
||||
std::string strDh512, strDh1024;
|
||||
|
||||
db->getStr("Dh512", strDh512);
|
||||
db->getStr("Dh1024", strDh1024);
|
||||
|
||||
mDh512 = DH_der_load_hex(strDh512);
|
||||
mDh1024 = DH_der_load_hex(strDh1024);
|
||||
|
||||
db->endIterRows();
|
||||
bSuccess = true;
|
||||
}
|
||||
@@ -390,6 +399,8 @@ bool Wallet::nodeIdentityLoad()
|
||||
|
||||
// Create and store a network identity.
|
||||
bool Wallet::nodeIdentityCreate() {
|
||||
std::cerr << "NodeIdentity: Creating." << std::endl;
|
||||
|
||||
//
|
||||
// Generate the public and private key
|
||||
//
|
||||
@@ -403,7 +414,14 @@ bool Wallet::nodeIdentityCreate() {
|
||||
nodePublicKey.setNodePublic(key.GetPubKey());
|
||||
nodePrivateKey.setNodePrivate(key.GetSecret());
|
||||
|
||||
std::cerr << "NodeIdentity: Created." << std::endl;
|
||||
std::string strDh512, strDh1024;
|
||||
|
||||
DH_der_gen_hex(strDh512, 512); // Using hex as db->escape in insufficient.
|
||||
#if 1
|
||||
strDh1024 = strDh512; // For testing and most cases 512 is fine.
|
||||
#else
|
||||
DH_der_gen_hex(strDh1024, 1024);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Store the node information
|
||||
@@ -411,11 +429,15 @@ bool Wallet::nodeIdentityCreate() {
|
||||
Database* db = theApp->getWalletDB()->getDB();
|
||||
|
||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||
db->executeSQL(str(boost::format("INSERT INTO NodeIdentity (PublicKey,PrivateKey) VALUES (%s,%s);")
|
||||
db->executeSQL(str(boost::format("INSERT INTO NodeIdentity (PublicKey,PrivateKey,Dh512,Dh1024) VALUES (%s,%s,%s,%s);")
|
||||
% db->escape(nodePublicKey.humanNodePublic())
|
||||
% db->escape(nodePrivateKey.humanNodePrivate())));
|
||||
% db->escape(nodePrivateKey.humanNodePrivate())
|
||||
% db->escape(strDh512)
|
||||
% db->escape(strDh1024)));
|
||||
// XXX Check error result.
|
||||
|
||||
std::cerr << "NodeIdentity: Created." << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "openssl/ec.h"
|
||||
#include "openssl/dh.h"
|
||||
|
||||
#include "../json/value.h"
|
||||
|
||||
@@ -31,6 +32,8 @@ protected:
|
||||
|
||||
NewcoinAddress mNodePublicKey;
|
||||
NewcoinAddress mNodePrivateKey;
|
||||
DH* mDh512;
|
||||
DH* mDh1024;
|
||||
|
||||
std::map<NewcoinAddress, LocalAccountFamily::pointer> mFamilies;
|
||||
std::map<NewcoinAddress, LocalAccount::pointer> mAccounts;
|
||||
@@ -50,8 +53,10 @@ public:
|
||||
// - Maintain peer connectivity through validation and peer management.
|
||||
void start();
|
||||
|
||||
NewcoinAddress& getNodePublic() { return mNodePublicKey; }
|
||||
NewcoinAddress& getNodePrivate() { return mNodePrivateKey; }
|
||||
NewcoinAddress& getNodePublic() { return mNodePublicKey; }
|
||||
NewcoinAddress& getNodePrivate() { return mNodePrivateKey; }
|
||||
DH* getDh512() { return DHparams_dup(mDh512); }
|
||||
DH* getDh1024() { return DHparams_dup(mDh1024); }
|
||||
|
||||
NewcoinAddress addFamily(const std::string& passPhrase, bool lock);
|
||||
NewcoinAddress addFamily(const NewcoinAddress& familySeed, bool lock);
|
||||
|
||||
Reference in New Issue
Block a user