upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/db.cpp b/src/db.cpp
index 6f9461b..405a3db 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -872,9 +872,9 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
872 } 872 }
873 if (!fHaveStoredHDCoinType) 873 if (!fHaveStoredHDCoinType)
874 { 874 {
875 nHDCoinType = HD_BIP44_COIN_TYPE_BITFLASH_PROVISIONAL; 875 nHDCoinType = HD_BIP44_COIN_TYPE_BITFLASH;
876 printf("LoadWallet: deterministic seed has no BIP44 coin type metadata; " 876 printf("LoadWallet: deterministic seed has no BIP44 coin type metadata; "
877 "using provisional Bitflash coin type %u\n", nHDCoinType); 877 "using Bitflash coin type %u\n", nHDCoinType);
878 } 878 }
879 } 879 }
880 else 880 else
@@ -883,7 +883,7 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
883 nHDNext = 0; 883 nHDNext = 0;
884 nHDReceiveNext = 0; 884 nHDReceiveNext = 0;
885 nHDChangeNext = 0; 885 nHDChangeNext = 0;
886 nHDCoinType = HD_BIP44_COIN_TYPE_BITFLASH_PROVISIONAL; 886 nHDCoinType = HD_BIP44_COIN_TYPE_BITFLASH;
887 } 887 }
888 888
889 // fGenerateBitcoins and nMineMode only mean anything together, and a 889 // fGenerateBitcoins and nMineMode only mean anything together, and a
@@ -1396,6 +1396,13 @@ static bool EncryptPrivateKeyForWallet(const CKeyingMaterial& vchMasterKey,
1396 return true; 1396 return true;
1397} 1397}
1398 1398
1399static void SecureClearBytes(vector<unsigned char>& vch)
1400{
1401 if (!vch.empty())
1402 OPENSSL_cleanse(&vch[0], vch.size());
1403 vch.clear();
1404}
1405
1399bool EncryptWallet(const string& strPassphrase, string& strBackupRet, string& strErrorRet) 1406bool EncryptWallet(const string& strPassphrase, string& strBackupRet, string& strErrorRet)
1400{ 1407{
1401 strBackupRet.clear(); 1408 strBackupRet.clear();
@@ -1415,6 +1422,7 @@ bool EncryptWallet(const string& strPassphrase, string& strBackupRet, string& st
1415 map<vector<unsigned char>, CPrivKey> mapPlainKeys; 1422 map<vector<unsigned char>, CPrivKey> mapPlainKeys;
1416 vector<unsigned char> vchPlainHDMaster; 1423 vector<unsigned char> vchPlainHDMaster;
1417 vector<unsigned char> vchPlainHDChainCode; 1424 vector<unsigned char> vchPlainHDChainCode;
1425 bool fHadHDSeed = false;
1418 unsigned int nHDNextSnapshot = 0; 1426 unsigned int nHDNextSnapshot = 0;
1419 { 1427 {
1420 CRITICAL_BLOCK(cs_mapKeys) 1428 CRITICAL_BLOCK(cs_mapKeys)
@@ -1425,6 +1433,7 @@ bool EncryptWallet(const string& strPassphrase, string& strBackupRet, string& st
1425 { 1433 {
1426 vchPlainHDMaster = vchHDMaster; 1434 vchPlainHDMaster = vchHDMaster;
1427 vchPlainHDChainCode = vchHDChainCode; 1435 vchPlainHDChainCode = vchHDChainCode;
1436 fHadHDSeed = !vchPlainHDMaster.empty() || !vchPlainHDChainCode.empty();
1428 nHDNextSnapshot = nHDNext; 1437 nHDNextSnapshot = nHDNext;
1429 } 1438 }
1430 } 1439 }
@@ -1475,11 +1484,13 @@ bool EncryptWallet(const string& strPassphrase, string& strBackupRet, string& st
1475 1484
1476 vector<unsigned char> vchCryptedHDMasterNew; 1485 vector<unsigned char> vchCryptedHDMasterNew;
1477 vector<unsigned char> vchCryptedHDChainCodeNew; 1486 vector<unsigned char> vchCryptedHDChainCodeNew;
1478 if (!vchPlainHDMaster.empty() || !vchPlainHDChainCode.empty()) 1487 if (fHadHDSeed)
1479 { 1488 {
1480 if (vchPlainHDMaster.size() != 32 || vchPlainHDChainCode.size() != 32) 1489 if (vchPlainHDMaster.size() != 32 || vchPlainHDChainCode.size() != 32)
1481 { 1490 {
1482 strErrorRet = "wallet has an incomplete HD seed"; 1491 strErrorRet = "wallet has an incomplete HD seed";
1492 SecureClearBytes(vchPlainHDMaster);
1493 SecureClearBytes(vchPlainHDChainCode);
1483 return false; 1494 return false;
1484 } 1495 }
1485 if (!EncryptSecret(vchMasterKey, vchPlainHDMaster, 1496 if (!EncryptSecret(vchMasterKey, vchPlainHDMaster,
@@ -1488,8 +1499,12 @@ bool EncryptWallet(const string& strPassphrase, string& strBackupRet, string& st
1488 WalletSecretIV("hdchaincode"), vchCryptedHDChainCodeNew)) 1499 WalletSecretIV("hdchaincode"), vchCryptedHDChainCodeNew))
1489 { 1500 {
1490 strErrorRet = "could not encrypt the HD seed"; 1501 strErrorRet = "could not encrypt the HD seed";
1502 SecureClearBytes(vchPlainHDMaster);
1503 SecureClearBytes(vchPlainHDChainCode);
1491 return false; 1504 return false;
1492 } 1505 }
1506 SecureClearBytes(vchPlainHDMaster);
1507 SecureClearBytes(vchPlainHDChainCode);
1493 } 1508 }
1494 1509
1495 vector<pair<int64, vector<unsigned char> > > vNewPool; 1510 vector<pair<int64, vector<unsigned char> > > vNewPool;
@@ -1498,7 +1513,7 @@ bool EncryptWallet(const string& strPassphrase, string& strBackupRet, string& st
1498 for (int i = 0; i < KEYPOOL_SIZE; i++) 1513 for (int i = 0; i < KEYPOOL_SIZE; i++)
1499 { 1514 {
1500 CKey key; 1515 CKey key;
1501 if (!vchPlainHDMaster.empty()) 1516 if (fHadHDSeed)
1502 { 1517 {
1503 string strDeriveError; 1518 string strDeriveError;
1504 if (!DeriveHDKey(nHDNextNew, key, strDeriveError)) 1519 if (!DeriveHDKey(nHDNextNew, key, strDeriveError))