Skip to content

Commit 05e27c6

Browse files
committed
Merge pull request #3332
5094f8d Split off rpc_wallet_tests (Wladimir J. van der Laan) 829c920 Move CCryptoKeyStore to crypter.cpp (Wladimir J. van der Laan) ae6ea5a Update build-unix.md to mention --disable-wallet (Wladimir J. van der Laan) 4f9e993 Add --disable-wallet option to build system (Wladimir J. van der Laan) d004d72 Move CAddrDB frrom db to net (Wladimir J. van der Laan) 48ba56c Delimit code with #ifdef ENABLE_WALLET (Wladimir J. van der Laan) 991685d Move getinfo to rpcnet.cpp (Wladimir J. van der Laan) bbb0936 Move HelpExample* from rpcwallet to rpcserver (Wladimir J. van der Laan)
2 parents fbbed19 + 5094f8d commit 05e27c6

23 files changed

+687
-537
lines changed

configure.ac

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ AM_MAINTAINER_MODE([enable])
3737
dnl make the compilation flags quiet unless V=1 is used
3838
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
3939

40+
# Enable wallet
41+
AC_ARG_ENABLE([wallet],
42+
[AS_HELP_STRING([--enable-wallet],
43+
[enable wallet (default is yes)])],
44+
[enable_wallet=$enableval],
45+
[enable_wallet=yes])
46+
4047
AC_ARG_WITH([miniupnpc],
4148
[AS_HELP_STRING([--with-miniupnpc],
4249
[enable UPNP (default is yes if libminiupnpc is found)])],
@@ -362,8 +369,10 @@ AC_TRY_COMPILE([#include <sys/socket.h>],
362369
[ AC_MSG_RESULT(no)]
363370
)
364371

365-
dnl Check for libdb_cxx
366-
BITCOIN_FIND_BDB48
372+
if test x$enable_wallet != xno; then
373+
dnl Check for libdb_cxx only if wallet enabled
374+
BITCOIN_FIND_BDB48
375+
fi
367376

368377
dnl Check for libminiupnpc (optional)
369378
if test x$use_upnp != xno; then
@@ -593,6 +602,20 @@ if test "x$use_ccache" != "xno"; then
593602
AC_MSG_RESULT($use_ccache)
594603
fi
595604

605+
dnl enable wallet
606+
AC_MSG_CHECKING([if wallet should be enabled])
607+
if test x$enable_wallet != xno; then
608+
AC_MSG_RESULT(yes)
609+
AC_DEFINE_UNQUOTED([ENABLE_WALLET],[1],[Define to 1 to enable wallet functions])
610+
611+
else
612+
AC_MSG_RESULT(no)
613+
614+
if test "x$use_qt" != "xno"; then
615+
AC_MSG_ERROR([Cannot currently build Qt GUI with wallet disabled. Use --without-qt.])
616+
fi
617+
fi
618+
596619
dnl enable ipv6 support
597620
AC_MSG_CHECKING([if ipv6 should be enabled])
598621
if test x$have_ipv6 = xno; then
@@ -705,6 +728,7 @@ fi
705728

706729
AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
707730
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
731+
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet == xyes])
708732
AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
709733
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov == xyes])
710734
AM_CONDITIONAL([USE_COMPARISON_TOOL],[test x$use_comparison_tool != xno])

doc/build-unix.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Dependencies
2222
Library Purpose Description
2323
------- ------- -----------
2424
libssl SSL Support Secure communications
25-
libdb4.8 Berkeley DB Blockchain & wallet storage
25+
libdb4.8 Berkeley DB Wallet storage
2626
libboost Boost C++ Library
2727
miniupnpc UPnP Support Optional firewall-jumping support
2828
qt GUI GUI toolkit
@@ -178,3 +178,12 @@ Hardening enables the following features:
178178
RW- R-- RW-
179179

180180
The STK RW- means that the stack is readable and writeable but not executable.
181+
182+
Disable-wallet mode
183+
--------------------
184+
When the intention is to run only a P2P node without a wallet, bitcoin may be compiled in
185+
disable-wallet mode with:
186+
187+
./configure --disable-wallet
188+
189+
In this case there is no dependency on Berkeley DB 4.8.

src/Makefile.am

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ AM_CPPFLAGS += -I$(top_srcdir)/src/leveldb/helpers/memenv \
44
-I$(builddir)
55

66
noinst_LIBRARIES = libbitcoin_server.a libbitcoin_common.a libbitcoin_cli.a
7+
if ENABLE_WALLET
8+
noinst_LIBRARIES += libbitcoin_wallet.a
9+
endif
710

811
bin_PROGRAMS = bitcoind bitcoin-cli
912

@@ -33,14 +36,37 @@ obj/build.h: FORCE
3336
$(abs_top_srcdir)
3437
version.o: obj/build.h
3538

36-
libbitcoin_server_a_SOURCES = addrman.cpp alert.cpp \
39+
libbitcoin_server_a_SOURCES = \
40+
addrman.cpp \
41+
alert.cpp \
3742
rpcserver.cpp \
3843
bloom.cpp \
39-
chainparams.cpp checkpoints.cpp coins.cpp crypter.cpp db.cpp \
40-
init.cpp keystore.cpp leveldbwrapper.cpp main.cpp miner.cpp \
41-
net.cpp noui.cpp rpcblockchain.cpp rpcdump.cpp \
42-
rpcmining.cpp rpcnet.cpp rpcrawtransaction.cpp rpcwallet.cpp \
43-
txdb.cpp txmempool.cpp wallet.cpp walletdb.cpp $(JSON_H) \
44+
chainparams.cpp \
45+
checkpoints.cpp \
46+
coins.cpp \
47+
init.cpp \
48+
keystore.cpp \
49+
leveldbwrapper.cpp \
50+
main.cpp \
51+
net.cpp \
52+
noui.cpp \
53+
rpcblockchain.cpp \
54+
rpcnet.cpp \
55+
rpcrawtransaction.cpp \
56+
txdb.cpp \
57+
txmempool.cpp \
58+
$(JSON_H) \
59+
$(BITCOIN_CORE_H)
60+
61+
libbitcoin_wallet_a_SOURCES = \
62+
db.cpp \
63+
crypter.cpp \
64+
miner.cpp \
65+
rpcdump.cpp \
66+
rpcmining.cpp \
67+
rpcwallet.cpp \
68+
wallet.cpp \
69+
walletdb.cpp \
4470
$(BITCOIN_CORE_H)
4571

4672
libbitcoin_common_a_SOURCES = \
@@ -68,6 +94,9 @@ nodist_libbitcoin_common_a_SOURCES = $(top_srcdir)/src/obj/build.h
6894
# bitcoind binary #
6995
bitcoind_LDADD = libbitcoin_server.a libbitcoin_cli.a libbitcoin_common.a leveldb/libleveldb.a leveldb/libmemenv.a \
7096
$(BOOST_LIBS)
97+
if ENABLE_WALLET
98+
bitcoind_LDADD += libbitcoin_wallet.a
99+
endif
71100
bitcoind_SOURCES = bitcoind.cpp
72101
#
73102

src/Makefile.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ AM_CPPFLAGS = $(INCLUDES) \
66
AM_LDFLAGS = $(PTHREAD_CFLAGS)
77

88
LIBBITCOIN_SERVER=$(top_builddir)/src/libbitcoin_server.a
9+
LIBBITCOIN_WALLET=$(top_builddir)/src/libbitcoin_wallet.a
910
LIBBITCOIN_COMMON=$(top_builddir)/src/libbitcoin_common.a
1011
LIBBITCOIN_CLI=$(top_builddir)/src/libbitcoin_cli.a
1112
LIBLEVELDB=$(top_builddir)/src/leveldb/libleveldb.a

src/crypter.cpp

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
#include "crypter.h"
66

7+
#include "script.h"
8+
79
#include <string>
810
#include <vector>
9-
11+
#include <boost/foreach.hpp>
1012
#include <openssl/aes.h>
1113
#include <openssl/evp.h>
1214

@@ -117,3 +119,156 @@ bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned
117119
return false;
118120
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext));
119121
}
122+
123+
bool CCryptoKeyStore::SetCrypted()
124+
{
125+
LOCK(cs_KeyStore);
126+
if (fUseCrypto)
127+
return true;
128+
if (!mapKeys.empty())
129+
return false;
130+
fUseCrypto = true;
131+
return true;
132+
}
133+
134+
bool CCryptoKeyStore::Lock()
135+
{
136+
if (!SetCrypted())
137+
return false;
138+
139+
{
140+
LOCK(cs_KeyStore);
141+
vMasterKey.clear();
142+
}
143+
144+
NotifyStatusChanged(this);
145+
return true;
146+
}
147+
148+
bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
149+
{
150+
{
151+
LOCK(cs_KeyStore);
152+
if (!SetCrypted())
153+
return false;
154+
155+
CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
156+
for (; mi != mapCryptedKeys.end(); ++mi)
157+
{
158+
const CPubKey &vchPubKey = (*mi).second.first;
159+
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
160+
CKeyingMaterial vchSecret;
161+
if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
162+
return false;
163+
if (vchSecret.size() != 32)
164+
return false;
165+
CKey key;
166+
key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed());
167+
if (key.GetPubKey() == vchPubKey)
168+
break;
169+
return false;
170+
}
171+
vMasterKey = vMasterKeyIn;
172+
}
173+
NotifyStatusChanged(this);
174+
return true;
175+
}
176+
177+
bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
178+
{
179+
{
180+
LOCK(cs_KeyStore);
181+
if (!IsCrypted())
182+
return CBasicKeyStore::AddKeyPubKey(key, pubkey);
183+
184+
if (IsLocked())
185+
return false;
186+
187+
std::vector<unsigned char> vchCryptedSecret;
188+
CKeyingMaterial vchSecret(key.begin(), key.end());
189+
if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret))
190+
return false;
191+
192+
if (!AddCryptedKey(pubkey, vchCryptedSecret))
193+
return false;
194+
}
195+
return true;
196+
}
197+
198+
199+
bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
200+
{
201+
{
202+
LOCK(cs_KeyStore);
203+
if (!SetCrypted())
204+
return false;
205+
206+
mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
207+
}
208+
return true;
209+
}
210+
211+
bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const
212+
{
213+
{
214+
LOCK(cs_KeyStore);
215+
if (!IsCrypted())
216+
return CBasicKeyStore::GetKey(address, keyOut);
217+
218+
CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
219+
if (mi != mapCryptedKeys.end())
220+
{
221+
const CPubKey &vchPubKey = (*mi).second.first;
222+
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
223+
CKeyingMaterial vchSecret;
224+
if (!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
225+
return false;
226+
if (vchSecret.size() != 32)
227+
return false;
228+
keyOut.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed());
229+
return true;
230+
}
231+
}
232+
return false;
233+
}
234+
235+
bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
236+
{
237+
{
238+
LOCK(cs_KeyStore);
239+
if (!IsCrypted())
240+
return CKeyStore::GetPubKey(address, vchPubKeyOut);
241+
242+
CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
243+
if (mi != mapCryptedKeys.end())
244+
{
245+
vchPubKeyOut = (*mi).second.first;
246+
return true;
247+
}
248+
}
249+
return false;
250+
}
251+
252+
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
253+
{
254+
{
255+
LOCK(cs_KeyStore);
256+
if (!mapCryptedKeys.empty() || IsCrypted())
257+
return false;
258+
259+
fUseCrypto = true;
260+
BOOST_FOREACH(KeyMap::value_type& mKey, mapKeys)
261+
{
262+
const CKey &key = mKey.second;
263+
CPubKey vchPubKey = key.GetPubKey();
264+
CKeyingMaterial vchSecret(key.begin(), key.end());
265+
std::vector<unsigned char> vchCryptedSecret;
266+
if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret))
267+
return false;
268+
if (!AddCryptedKey(vchPubKey, vchCryptedSecret))
269+
return false;
270+
}
271+
mapKeys.clear();
272+
}
273+
return true;
274+
}

0 commit comments

Comments
 (0)