stratum: precheck addresses are valid base58

This commit is contained in:
Tanguy Pruvot 2018-05-01 15:03:59 +02:00
parent b517afb571
commit 1bfec2be32
3 changed files with 22 additions and 1 deletions

View file

@ -96,3 +96,19 @@ bool base58_decode(const char *input, char *output)
return true;
}
bool is_base58(char *input)
{
// All alphanumeric characters except "0", "O", "I" and "l"
size_t i=0, len = strlen(input);
char *c = input;
while (i < len) {
bool isdigit = (c[i] >= '1' && c[i] <= '9');
bool isalpha = (c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z');
if (!isdigit && !isalpha) return false;
if (c[i] == 'I' || c[i] == 'O' || c[i] == 'l') return false;
i++;
}
return true;
}

View file

@ -256,8 +256,12 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params)
CommonUnlock(&g_db_mutex);
}
bool is_bad_address = !is_base58(client->username);
// when auto exchange is disabled, only authorize good wallet address...
if (!g_autoexchange && !client_validate_user_address(client)) {
if (!g_autoexchange && !client_validate_user_address(client))
is_bad_address = true;
if (is_bad_address) {
clientlog(client, "bad mining address %s", client->username);
client_send_result(client, "false");

View file

@ -74,6 +74,7 @@ string merkle_with_first(vector<string> steps, string f);
//////////////////////////////////////////////////////////////////////////
bool base58_decode(const char *input, char *output);
bool is_base58(char *input);
void base64_encode(char *base64, const char *normal);
void base64_decode(char *normal, const char *base64);