Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/build-openbsd.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ Dash Core includes a GUI built with the cross-platform Qt Framework. To compile
pkg_add qt5
```

###### libqrencode

The GUI can encode addresses in a QR Code. To build in QR support for the GUI, install `libqrencode`. Skip if not using the GUI or don't want QR code functionality.
```bash
pkg_add libqrencode
```
---

#### Notifications
###### ZeroMQ

Dash Core can provide notifications via ZeroMQ. If the package is installed, support will be compiled in.
```bash
pkg_add zeromq
```

## Building Dash Core

**Important**: Use `gmake` (the non-GNU `make` will exit with an error).
Expand Down
6 changes: 4 additions & 2 deletions doc/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ it will use a special cookie file for authentication. The cookie is generated wi
content when the daemon starts, and deleted when it exits. Read access to this file
controls who can access it through RPC.

By default the cookie is stored in the data directory, but it's location can be overridden
with the option '-rpccookiefile'.
By default the cookie is stored in the data directory, but its location can be
overridden with the option `-rpccookiefile`. Default file permissions for the
cookie are "owner" (i.e. user read/writeable) via default application-wide file
umask of `0077`, but these can be overridden with the `-rpccookieperms` option.

This allows for running dashd without having to do any manual configuration.

Expand Down
1 change: 1 addition & 0 deletions src/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Checks: '
-*,
bitcoin-*,
bugprone-argument-comment,
bugprone-move-forwarding-reference,
bugprone-use-after-move,
bugprone-lambda-function-name,
misc-unused-using-decls,
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ FUZZ_SUITE_LD_COMMON += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif

if ENABLE_FUZZ_BINARY
test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS) $(EVENT_CFLAGS)
test_fuzz_fuzz_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fuzz_fuzz_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_fuzz_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS) $(PTHREAD_FLAGS)
Expand Down
3 changes: 0 additions & 3 deletions src/bech32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace

typedef std::vector<uint8_t> data;

/** The Bech32 and Bech32m checksum size */
constexpr size_t CHECKSUM_SIZE = 6;

/** The Bech32 and Bech32m character set for encoding. */
const char* CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";

Expand Down
3 changes: 3 additions & 0 deletions src/bech32.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
namespace bech32
{

/** The Bech32 and Bech32m checksum size */
constexpr size_t CHECKSUM_SIZE = 6;

enum class Encoding {
INVALID, //!< Failed decoding

Expand Down
37 changes: 35 additions & 2 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,41 @@ static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, co
// 2. port in -rpcconnect (ie following : in ipv4 or ]: in ipv6)
// 3. default port for chain
uint16_t port{BaseParams().RPCPort()};
SplitHostPort(gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host);
port = static_cast<uint16_t>(gArgs.GetIntArg("-rpcport", port));
{
uint16_t rpcconnect_port{0};
const std::string rpcconnect_str = gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT);
if (!SplitHostPort(rpcconnect_str, rpcconnect_port, host)) {
// Uses argument provided as-is
// (rather than value parsed)
// to aid the user in troubleshooting
throw std::runtime_error(strprintf("Invalid port provided in -rpcconnect: %s", rpcconnect_str));
} else {
if (rpcconnect_port != 0) {
// Use the valid port provided in rpcconnect
port = rpcconnect_port;
} // else, no port was provided in rpcconnect (continue using default one)
}

if (std::optional<std::string> rpcport_arg = gArgs.GetArg("-rpcport")) {
// -rpcport was specified
const uint16_t rpcport_int{ToIntegral<uint16_t>(rpcport_arg.value()).value_or(0)};
if (rpcport_int == 0) {
// Uses argument provided as-is
// (rather than value parsed)
// to aid the user in troubleshooting
throw std::runtime_error(strprintf("Invalid port provided in -rpcport: %s", rpcport_arg.value()));
}

// Use the valid port provided
port = rpcport_int;

// If there was a valid port provided in rpcconnect,
// rpcconnect_port is non-zero.
if (rpcconnect_port != 0) {
tfm::format(std::cerr, "Warning: Port specified in both -rpcconnect and -rpcport. Using -rpcport %u\n", port);
}
}
}

// Obtain event base
raii_event_base base = obtain_event_base();
Expand Down
18 changes: 4 additions & 14 deletions src/clientversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#endif

#include <clientversion.h>
#include <util/string.h>
#include <util/translation.h>

#include <tinyformat.h>

#include <sstream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -67,19 +67,9 @@ std::string FormatFullVersion()
*/
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
{
std::ostringstream ss;
ss << "/";
ss << name << ":" << FormatVersion(nClientVersion);
if (!comments.empty())
{
std::vector<std::string>::const_iterator it(comments.begin());
ss << "(" << *it;
for(++it; it != comments.end(); ++it)
ss << "; " << *it;
ss << ")";
}
ss << "/";
return ss.str();
std::string comments_str;
if (!comments.empty()) comments_str = strprintf("(%s)", Join(comments, "; "));
return strprintf("/%s:%s%s/", name, FormatVersion(nClientVersion), comments_str);
}

std::string CopyrightHolders(const std::string& strPrefix, unsigned int nStartYear, unsigned int nEndYear)
Expand Down
19 changes: 17 additions & 2 deletions src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <netaddress.h>
#include <rpc/protocol.h>
#include <rpc/server.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/time.h>
Expand All @@ -20,6 +22,7 @@
#include <iterator>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
Expand Down Expand Up @@ -281,8 +284,20 @@ static bool InitRPCAuthentication()
{
if (gArgs.GetArg("-rpcpassword", "") == "")
{
LogPrintf("Using random cookie authentication.\n");
if (!GenerateAuthCookie(&strRPCUserColonPass)) {
LogInfo("Using random cookie authentication.\n");

std::optional<fs::perms> cookie_perms{std::nullopt};
auto cookie_perms_arg{gArgs.GetArg("-rpccookieperms")};
if (cookie_perms_arg) {
auto perm_opt = InterpretPermString(*cookie_perms_arg);
if (!perm_opt) {
LogInfo("Invalid -rpccookieperms=%s; must be one of 'owner', 'group', or 'all'.\n", *cookie_perms_arg);
return false;
}
cookie_perms = *perm_opt;
}

if (!GenerateAuthCookie(&strRPCUserColonPass, cookie_perms)) {
return false;
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-rpcbind=<addr>[:port]", "Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., all addresses)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);
argsman.AddArg("-rpcdoccheck", strprintf("Throw a non-fatal error at runtime if the documentation for an RPC is incorrect (default: %u)", DEFAULT_RPC_DOC_CHECK), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
argsman.AddArg("-rpccookiefile=<loc>", "Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir)", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpccookieperms=<readable-by>", strprintf("Set permissions on the RPC auth cookie file so that it is readable by [owner|group|all] (default: owner [via umask 0077])"), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcexternaluser=<users>", "List of comma-separated usernames for JSON-RPC external connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
argsman.AddArg("-rpcexternalworkqueue=<n>", strprintf("Set the depth of the work queue to service external RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
argsman.AddArg("-rpcpassword=<pw>", "Password for JSON-RPC connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
Expand Down
6 changes: 0 additions & 6 deletions src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ void CKey::MakeNewKey(bool fCompressedIn) {
fCompressed = fCompressedIn;
}

bool CKey::Negate()
{
assert(keydata);
return secp256k1_ec_seckey_negate(secp256k1_context_sign, keydata->data());
}

CPrivKey CKey::GetPrivKey() const {
assert(keydata);
CPrivKey seckey;
Expand Down
3 changes: 0 additions & 3 deletions src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ class CKey
//! Generate a new private key using a cryptographic PRNG.
void MakeNewKey(bool fCompressed);

//! Negate private key
bool Negate();

/**
* Convert the private key to a CPrivKey (serialized OpenSSL private key data).
* This is expensive.
Expand Down
21 changes: 15 additions & 6 deletions src/rpc/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

#include <rpc/request.h>

#include <util/fs.h>

#include <common/args.h>
#include <logging.h>
#include <random.h>
#include <rpc/protocol.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/strencodings.h>

Expand Down Expand Up @@ -83,7 +82,7 @@ static fs::path GetAuthCookieFile(bool temp=false)

static bool g_generated_cookie = false;

bool GenerateAuthCookie(std::string *cookie_out)
bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie_perms)
{
const size_t COOKIE_SIZE = 32;
unsigned char rand_pwd[COOKIE_SIZE];
Expand All @@ -97,19 +96,29 @@ bool GenerateAuthCookie(std::string *cookie_out)
fs::path filepath_tmp = GetAuthCookieFile(true);
file.open(filepath_tmp);
if (!file.is_open()) {
LogPrintf("Unable to open cookie authentication file %s for writing\n", fs::PathToString(filepath_tmp));
LogInfo("Unable to open cookie authentication file %s for writing\n", fs::PathToString(filepath_tmp));
return false;
}
file << cookie;
file.close();

fs::path filepath = GetAuthCookieFile(false);
if (!RenameOver(filepath_tmp, filepath)) {
LogPrintf("Unable to rename cookie authentication file %s to %s\n", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
LogInfo("Unable to rename cookie authentication file %s to %s\n", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
return false;
}
if (cookie_perms) {
std::error_code code;
fs::permissions(filepath, cookie_perms.value(), fs::perm_options::replace, code);
if (code) {
LogInfo("Unable to set permissions on cookie authentication file %s\n", fs::PathToString(filepath_tmp));
return false;
}
}

g_generated_cookie = true;
LogPrintf("Generated RPC authentication cookie %s\n", fs::PathToString(filepath));
LogInfo("Generated RPC authentication cookie %s\n", fs::PathToString(filepath));
LogInfo("Permissions used for cookie: %s\n", PermsToSymbolicString(fs::status(filepath).permissions()));

if (cookie_out)
*cookie_out = cookie;
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@

#include <context.h>

#include <optional>
#include <string>

#include <univalue.h>
#include <util/fs.h>

UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);
UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id);
std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id);
UniValue JSONRPCError(int code, const std::string& message);

/** Generate a new RPC authentication cookie and write it to disk */
bool GenerateAuthCookie(std::string *cookie_out);
bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie_perms=std::nullopt);
/** Read the RPC authentication cookie from disk */
bool GetAuthCookie(std::string *cookie_out);
/** Delete RPC authentication cookie from disk */
Expand Down
5 changes: 3 additions & 2 deletions src/test/fuzz/bech32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ FUZZ_TARGET(bech32)
std::vector<unsigned char> input;
ConvertBits<8, 5, true>([&](unsigned char c) { input.push_back(c); }, buffer.begin(), buffer.end());

if (input.size() + 3 + 6 <= 90) {
// If it's possible to encode input in Bech32(m) without exceeding the 90-character limit:
// Input data part + 3 characters for the HRP and separator (bc1) + the checksum characters
if (input.size() + 3 + bech32::CHECKSUM_SIZE <= bech32::CharLimit::BECH32) {
// If it's possible to encode input in Bech32(m) without exceeding the bech32-character limit:
for (auto encoding : {bech32::Encoding::BECH32, bech32::Encoding::BECH32M}) {
const std::string encoded = bech32::Encode(encoding, "bc", input);
assert(!encoded.empty());
Expand Down
10 changes: 0 additions & 10 deletions src/test/fuzz/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ FUZZ_TARGET(key, .init = initialize_key)
assert(copied_key == key);
}

{
CKey negated_key = key;
negated_key.Negate();
assert(negated_key.IsValid());
assert(!(negated_key == key));

negated_key.Negate();
assert(negated_key == key);
}

const uint256 random_uint256 = Hash(buffer);

{
Expand Down
31 changes: 0 additions & 31 deletions src/test/key_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,37 +200,6 @@ BOOST_AUTO_TEST_CASE(key_signature_tests)
BOOST_CHECK(found_small);
}

BOOST_AUTO_TEST_CASE(key_key_negation)
{
// create a dummy hash for signature comparison
unsigned char rnd[8];
std::string str = "Bitcoin key verification\n";
GetRandBytes(rnd);
uint256 hash{Hash(str, rnd)};

// import the static test key
CKey key = DecodeSecret(strSecret1C);

// create a signature
std::vector<unsigned char> vch_sig;
std::vector<unsigned char> vch_sig_cmp;
key.Sign(hash, vch_sig);

// negate the key twice
BOOST_CHECK(key.GetPubKey().data()[0] == 0x03);
key.Negate();
// after the first negation, the signature must be different
key.Sign(hash, vch_sig_cmp);
BOOST_CHECK(vch_sig_cmp != vch_sig);
BOOST_CHECK(key.GetPubKey().data()[0] == 0x02);
key.Negate();
// after the second negation, we should have the original key and thus the
// same signature
key.Sign(hash, vch_sig_cmp);
BOOST_CHECK(vch_sig_cmp == vch_sig);
BOOST_CHECK(key.GetPubKey().data()[0] == 0x03);
}

static CPubKey UnserializePubkey(const std::vector<uint8_t>& data)
{
DataStream stream{};
Expand Down
Loading
Loading