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
1 change: 1 addition & 0 deletions src/Blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define DIGIBYTECORE_BLOB_H


#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
Expand Down
23 changes: 21 additions & 2 deletions src/DigiByteCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@
using jsonrpc::Client;
using jsonrpc::JSONRPC_CLIENT_V1;

/**
* URL-encode a string for safe use in HTTP basic auth URLs.
* Characters like /, +, =, @ in RPC passwords would otherwise
* break the URL parsing in jsonrpc::HttpClient.
*/
static std::string urlEncode(const std::string& value) {
std::string encoded;
for (unsigned char c : value) {
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
encoded += c;
} else {
char buf[4];
snprintf(buf, sizeof(buf), "%%%02X", c);
encoded += buf;
}
}
return encoded;
}

using jsonrpc::HttpClient;
using jsonrpc::JsonRpcException;

Expand Down Expand Up @@ -90,8 +109,8 @@ void DigiByteCore::makeConnection() {
//see if core is online and config if valid
try {
httpClient.reset(new jsonrpc::HttpClient(
"http://" + config.getString("rpcuser") + ":" +
config.getString("rpcpassword") + "@" +
"http://" + urlEncode(config.getString("rpcuser")) + ":" +
urlEncode(config.getString("rpcpassword")) + "@" +
config.getString("rpcbind", "127.0.0.1") + ":" +
std::to_string(_useAssetPort ? config.getInteger("rpcassetport", 14024) : config.getInteger("rpcport", 14022))));
client.reset(new jsonrpc::Client(*httpClient, jsonrpc::JSONRPC_CLIENT_V1));
Expand Down