mirror of
https://git.wownero.com/wownero/wownero-puddle.git
synced 2024-08-15 01:03:20 +00:00
add network validation
This commit is contained in:
parent
b8c62a0378
commit
c9ba3a8428
3 changed files with 58 additions and 20 deletions
22
src/pool.c
22
src/pool.c
|
@ -253,6 +253,7 @@ static pthread_mutex_t mutex_clients = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static FILE *fd_log;
|
static FILE *fd_log;
|
||||||
static unsigned char sec_view[32];
|
static unsigned char sec_view[32];
|
||||||
static unsigned char pub_spend[32];
|
static unsigned char pub_spend[32];
|
||||||
|
static uint8_t nettype;
|
||||||
|
|
||||||
#ifdef HAVE_RX
|
#ifdef HAVE_RX
|
||||||
extern void rx_stop_mining();
|
extern void rx_stop_mining();
|
||||||
|
@ -1622,9 +1623,6 @@ rpc_on_view_key(const char* data, rpc_callback_t *callback)
|
||||||
const char *vk = json_object_get_string(key);
|
const char *vk = json_object_get_string(key);
|
||||||
hex_to_bin(vk, strlen(vk), &sec_view[0], 32);
|
hex_to_bin(vk, strlen(vk), &sec_view[0], 32);
|
||||||
json_object_put(root);
|
json_object_put(root);
|
||||||
|
|
||||||
uint64_t prefix;
|
|
||||||
parse_address(config.pool_wallet, &prefix, &pub_spend[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -2087,12 +2085,17 @@ client_on_login(json_object *message, client_t *client)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *address = json_object_get_string(login);
|
const char *address = json_object_get_string(login);
|
||||||
uint64_t prefix;
|
uint8_t nt;
|
||||||
parse_address(address, &prefix, NULL);
|
if (parse_address(address, NULL, &nt, NULL))
|
||||||
if (prefix != MAINNET_ADDRESS_PREFIX && prefix != TESTNET_ADDRESS_PREFIX)
|
|
||||||
{
|
{
|
||||||
send_validation_error(client,
|
send_validation_error(client,
|
||||||
"login only main wallet addresses are supported");
|
"Invalid address");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (nt != nettype)
|
||||||
|
{
|
||||||
|
send_validation_error(client,
|
||||||
|
"Invalid address network type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2790,6 +2793,11 @@ read_config(const char *config_file)
|
||||||
log_fatal("No pool wallet supplied. Aborting.");
|
log_fatal("No pool wallet supplied. Aborting.");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
if (parse_address(config.pool_wallet, NULL, &nettype, &pub_spend[0]))
|
||||||
|
{
|
||||||
|
log_fatal("Invalid pool wallet");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
if (!config.wallet_rpc_host[0] || config.wallet_rpc_port == 0)
|
if (!config.wallet_rpc_host[0] || config.wallet_rpc_port == 0)
|
||||||
{
|
{
|
||||||
log_fatal("Both wallet-rpc-host and wallet-rpc-port need setting. "
|
log_fatal("Both wallet-rpc-host and wallet-rpc-port need setting. "
|
||||||
|
|
46
src/xmr.cpp
46
src/xmr.cpp
|
@ -45,6 +45,7 @@ developers.
|
||||||
#include "cryptonote_basic/difficulty.h"
|
#include "cryptonote_basic/difficulty.h"
|
||||||
#include "crypto/crypto.h"
|
#include "crypto/crypto.h"
|
||||||
#include "crypto/hash.h"
|
#include "crypto/hash.h"
|
||||||
|
#include "cryptonote_config.h"
|
||||||
#include "serialization/binary_utils.h"
|
#include "serialization/binary_utils.h"
|
||||||
#include "ringct/rctSigs.h"
|
#include "ringct/rctSigs.h"
|
||||||
#include "common/base58.h"
|
#include "common/base58.h"
|
||||||
|
@ -56,6 +57,33 @@ developers.
|
||||||
using namespace epee::string_tools;
|
using namespace epee::string_tools;
|
||||||
using namespace cryptonote;
|
using namespace cryptonote;
|
||||||
using namespace crypto;
|
using namespace crypto;
|
||||||
|
using namespace config;
|
||||||
|
|
||||||
|
static int nettype_from_prefix(uint8_t *nettype, uint64_t prefix)
|
||||||
|
{
|
||||||
|
static const struct { cryptonote::network_type type; uint64_t prefix; } nettype_prefix[] = {
|
||||||
|
{ MAINNET, CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX },
|
||||||
|
{ MAINNET, CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX },
|
||||||
|
{ MAINNET, CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX },
|
||||||
|
{ TESTNET, testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX },
|
||||||
|
{ TESTNET, testnet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX },
|
||||||
|
{ TESTNET, testnet::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX },
|
||||||
|
{ STAGENET, stagenet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX },
|
||||||
|
{ STAGENET, stagenet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX },
|
||||||
|
{ STAGENET, stagenet::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX }
|
||||||
|
};
|
||||||
|
int rv = XMR_MISMATCH_ERROR;
|
||||||
|
for (auto ntp : nettype_prefix)
|
||||||
|
{
|
||||||
|
if (ntp.prefix == prefix)
|
||||||
|
{
|
||||||
|
rv = XMR_NO_ERROR;
|
||||||
|
*nettype = ntp.type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
int get_hashing_blob(const unsigned char *input, const size_t in_size,
|
int get_hashing_blob(const unsigned char *input, const size_t in_size,
|
||||||
unsigned char **output, size_t *out_size)
|
unsigned char **output, size_t *out_size)
|
||||||
|
@ -75,23 +103,25 @@ int get_hashing_blob(const unsigned char *input, const size_t in_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_address(const char *input, uint64_t *prefix,
|
int parse_address(const char *input, uint64_t *prefix,
|
||||||
unsigned char *pub_spend)
|
uint8_t *nettype, unsigned char *pub_spend)
|
||||||
{
|
{
|
||||||
uint64_t tag;
|
uint64_t tag;
|
||||||
std::string decoded;
|
std::string decoded;
|
||||||
bool rv = tools::base58::decode_addr(input, tag, decoded);
|
if (!tools::base58::decode_addr(input, tag, decoded))
|
||||||
if (rv)
|
return XMR_PARSE_ERROR;
|
||||||
{
|
if (prefix)
|
||||||
*prefix = tag;
|
*prefix = tag;
|
||||||
if (pub_spend != NULL)
|
if (nettype && nettype_from_prefix(nettype, tag))
|
||||||
|
return XMR_MISMATCH_ERROR;
|
||||||
|
if (pub_spend)
|
||||||
{
|
{
|
||||||
account_public_address address;
|
account_public_address address;
|
||||||
::serialization::parse_binary(decoded, address);
|
if (!::serialization::parse_binary(decoded, address))
|
||||||
|
return XMR_PARSE_ERROR;
|
||||||
public_key S = address.m_spend_public_key;
|
public_key S = address.m_spend_public_key;
|
||||||
memcpy(pub_spend, &S, 32);
|
memcpy(pub_spend, &S, 32);
|
||||||
}
|
}
|
||||||
}
|
return XMR_NO_ERROR;
|
||||||
return rv ? XMR_NO_ERROR : XMR_PARSE_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_block_hash(const unsigned char *input, const size_t in_size,
|
int get_block_hash(const unsigned char *input, const size_t in_size,
|
||||||
|
|
|
@ -53,7 +53,7 @@ enum xmr_error
|
||||||
int get_hashing_blob(const unsigned char *input, const size_t in_size,
|
int get_hashing_blob(const unsigned char *input, const size_t in_size,
|
||||||
unsigned char **output, size_t *out_size);
|
unsigned char **output, size_t *out_size);
|
||||||
int parse_address(const char *input, uint64_t *prefix,
|
int parse_address(const char *input, uint64_t *prefix,
|
||||||
unsigned char *pub_spend);
|
uint8_t *nettype, unsigned char *pub_spend);
|
||||||
int get_block_hash(const unsigned char *input, const size_t in_size,
|
int get_block_hash(const unsigned char *input, const size_t in_size,
|
||||||
unsigned char *output);
|
unsigned char *output);
|
||||||
void get_hash(const unsigned char *input, const size_t in_size,
|
void get_hash(const unsigned char *input, const size_t in_size,
|
||||||
|
|
Loading…
Reference in a new issue