KeyStream password communication
Simple encrypt messages with plain KeyStream used as password.
This commit is contained in:
parent
4dd26f6044
commit
35fe9f49db
5 changed files with 107 additions and 22 deletions
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"algo": "cryptonight", // cryptonight (default) or cryptonight-lite
|
||||
"user-agent": "", // custom user-agent
|
||||
"av": 0, // algorithm variation, 0 auto select
|
||||
"background": false, // true to run the miner in the background
|
||||
"colors": true, // false to disable colored output
|
||||
|
@ -17,14 +18,10 @@
|
|||
"threads": null, // number of miner threads
|
||||
"pools": [
|
||||
{
|
||||
"url": "pool.minemonero.pro:5555", // URL of mining server
|
||||
"user": "", // username for mining server
|
||||
"pass": "x", // password for mining server
|
||||
"keepalive": true, // send keepalived for prevent timeout (need pool support)
|
||||
"nicehash": false // enable nicehash/xmrig-proxy support
|
||||
},
|
||||
{
|
||||
"url": "pool.minemonero.pro:5555@localhost:8080",// URL of mining server with localhost proxy (example)
|
||||
"url": "pool.minemonero.pro:3333", // --------------- URL of mining server
|
||||
/* "url": "pool.minemonero.pro:443@localhost:8080",*/ // --------------- URL of mining server over HTTP (CONNECT) proxy
|
||||
/* "url": "pool.minemonero.pro:7777#secret_keystream",*/ // URL of mining xmrig-proxy with encrypted support
|
||||
/* "url": "pool.minemonero.pro:8080#secret_keystream@localhost:8080",*/ // URL of mining xmrig-proxy with encrypted support over HTTP (CONNECT) proxy
|
||||
"user": "", // username for mining server
|
||||
"pass": "x", // password for mining server
|
||||
"keepalive": true, // send keepalived for prevent timeout (need pool support)
|
||||
|
|
|
@ -55,6 +55,8 @@ int64_t Client::m_sequence = 1;
|
|||
|
||||
Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||
m_quiet(false),
|
||||
m_keystream(),
|
||||
m_encrypted(false),
|
||||
m_agent(agent),
|
||||
m_listener(listener),
|
||||
m_id(id),
|
||||
|
@ -68,6 +70,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
|
|||
{
|
||||
memset(m_ip, 0, sizeof(m_ip));
|
||||
memset(&m_hints, 0, sizeof(m_hints));
|
||||
memset(m_keystream, 0, sizeof(m_keystream));
|
||||
|
||||
m_resolver.data = this;
|
||||
|
||||
|
@ -128,6 +131,16 @@ void Client::setUrl(const Url *url)
|
|||
return;
|
||||
}
|
||||
|
||||
if (url->hasKeystream())
|
||||
{
|
||||
url->copyKeystream(m_keystream, sizeof(m_keystream));
|
||||
m_encrypted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_encrypted = false;
|
||||
}
|
||||
|
||||
m_url = url;
|
||||
}
|
||||
|
||||
|
@ -271,7 +284,7 @@ int Client::resolve(const char *host)
|
|||
}
|
||||
|
||||
|
||||
int64_t Client::send(size_t size)
|
||||
int64_t Client::send(size_t size, const bool encrypted)
|
||||
{
|
||||
LOG_DEBUG("[%s:%u] send (%d bytes): \"%s\"", m_url.host(), m_url.port(), size, m_sendBuf);
|
||||
if ((state() != ConnectedState && state() != ProxingState) || !uv_is_writable(m_stream)) {
|
||||
|
@ -279,6 +292,22 @@ int64_t Client::send(size_t size)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(encrypted && m_encrypted)
|
||||
{
|
||||
// Encrypt
|
||||
for(size_t i = 0; i < std::min(size, sizeof(m_keystream)); ++i)
|
||||
{
|
||||
m_sendBuf[i] ^= m_keystream[i];
|
||||
}
|
||||
|
||||
char * send_encr_hex = static_cast<char*>(malloc(size * 2 + 1));
|
||||
memset(send_encr_hex, 0, size * 2 + 1);
|
||||
Job::toHex((const unsigned char*)m_sendBuf, size, send_encr_hex);
|
||||
send_encr_hex[size * 2] = '\0';
|
||||
LOG_DEBUG("[%s:%u] send encr. (%d bytes): \"0x%s\"", m_url.host(), m_url.port(), size, send_encr_hex);
|
||||
free(send_encr_hex);
|
||||
}
|
||||
|
||||
uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size);
|
||||
|
||||
if (uv_try_write(m_stream, &buf, 1) < 0) {
|
||||
|
@ -341,7 +370,7 @@ void Client::prelogin()
|
|||
m_sendBuf[size + 1] = '\0';
|
||||
|
||||
LOG_DEBUG("Prelogin send (%d bytes): \"%s\"", size, m_sendBuf);
|
||||
send (size + 1);
|
||||
send (size + 1, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -631,6 +660,21 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
|||
char* start = buf->base;
|
||||
size_t remaining = client->m_recvBufPos;
|
||||
|
||||
if(client->m_encrypted)
|
||||
{
|
||||
char * read_encr_hex = static_cast<char*>(malloc(nread * 2 + 1));
|
||||
memset(read_encr_hex, 0, nread * 2 + 1);
|
||||
Job::toHex((const unsigned char*)start, nread, read_encr_hex);
|
||||
LOG_DEBUG("[%s] read encr. (%d bytes): \"0x%s\"", client->m_ip, nread, read_encr_hex);
|
||||
free(read_encr_hex);
|
||||
|
||||
// DeEncrypt
|
||||
for(int i = 0; i < (int)nread; ++i)
|
||||
{
|
||||
start[i] ^= client->m_keystream[i];
|
||||
}
|
||||
}
|
||||
|
||||
while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) {
|
||||
end++;
|
||||
size_t len = end - start;
|
||||
|
|
|
@ -79,7 +79,7 @@ private:
|
|||
bool parseJob(const rapidjson::Value ¶ms, int *code);
|
||||
bool parseLogin(const rapidjson::Value &result, int *code);
|
||||
int resolve(const char *host);
|
||||
int64_t send(size_t size);
|
||||
int64_t send(size_t size, const bool encrypted = true);
|
||||
void close();
|
||||
void connect(struct sockaddr *addr);
|
||||
void prelogin();
|
||||
|
@ -106,6 +106,8 @@ private:
|
|||
char m_ip[17];
|
||||
char m_rpcId[64];
|
||||
char m_sendBuf[768];
|
||||
char m_keystream[sizeof(m_sendBuf)];
|
||||
bool m_encrypted;
|
||||
const char *m_agent;
|
||||
IClientListener *m_listener;
|
||||
int m_id;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
#include "net/Url.h"
|
||||
|
@ -43,7 +44,8 @@ Url::Url() :
|
|||
m_user(nullptr),
|
||||
m_port(kDefaultPort),
|
||||
m_proxy_host(nullptr),
|
||||
m_proxy_port(kDefaultProxyPort)
|
||||
m_proxy_port(kDefaultProxyPort),
|
||||
m_keystream(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -67,7 +69,8 @@ Url::Url(const char *url) :
|
|||
m_user(nullptr),
|
||||
m_port(kDefaultPort),
|
||||
m_proxy_host(nullptr),
|
||||
m_proxy_port (kDefaultProxyPort)
|
||||
m_proxy_port(kDefaultProxyPort),
|
||||
m_keystream(nullptr)
|
||||
{
|
||||
parse(url);
|
||||
}
|
||||
|
@ -80,7 +83,8 @@ Url::Url(const char *host, uint16_t port, const char *user, const char *password
|
|||
m_user(user ? strdup(user) : nullptr),
|
||||
m_port(port),
|
||||
m_proxy_host(nullptr),
|
||||
m_proxy_port (kDefaultProxyPort)
|
||||
m_proxy_port(kDefaultProxyPort),
|
||||
m_keystream(nullptr)
|
||||
{
|
||||
m_host = strdup(host);
|
||||
}
|
||||
|
@ -91,9 +95,10 @@ Url::~Url()
|
|||
free(m_host);
|
||||
free(m_password);
|
||||
free(m_user);
|
||||
free(m_proxy_host);
|
||||
free(m_keystream);
|
||||
}
|
||||
|
||||
|
||||
bool Url::parse(const char *url)
|
||||
{
|
||||
const char *p = strstr(url, "://");
|
||||
|
@ -123,6 +128,23 @@ bool Url::parse(const char *url)
|
|||
m_host[size - 1] = '\0';
|
||||
|
||||
const char* proxy = strchr(port, '@');
|
||||
const char* keystream = strchr(port, '#');
|
||||
if(keystream)
|
||||
{
|
||||
++keystream;
|
||||
if(!proxy)
|
||||
{
|
||||
m_keystream = strdup(keystream);
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t keystreamsize = proxy - keystream;
|
||||
m_keystream = static_cast<char*>(malloc (keystreamsize + 1));
|
||||
m_keystream[keystreamsize] = '\0';
|
||||
memcpy(m_keystream, keystream, keystreamsize);
|
||||
}
|
||||
}
|
||||
|
||||
m_port = (uint16_t) strtol(port, nullptr, 10);
|
||||
if (!proxy) {
|
||||
m_port = (uint16_t) strtol(port, nullptr, 10);
|
||||
|
@ -203,6 +225,14 @@ void Url::setUser(const char *user)
|
|||
m_user = strdup(user);
|
||||
}
|
||||
|
||||
void Url::copyKeystream(char *keystreamDest, const size_t keystreamLen) const
|
||||
{
|
||||
if(hasKeystream())
|
||||
{
|
||||
memset(keystreamDest, 1, keystreamLen);
|
||||
memcpy(keystreamDest, m_keystream, std::min(keystreamLen, strlen(m_keystream)));
|
||||
}
|
||||
}
|
||||
|
||||
Url &Url::operator=(const Url *other)
|
||||
{
|
||||
|
@ -227,5 +257,14 @@ Url &Url::operator=(const Url *other)
|
|||
setPassword(other->m_password);
|
||||
setUser(other->m_user);
|
||||
|
||||
free (m_keystream);
|
||||
if(other->m_keystream)
|
||||
{
|
||||
m_keystream = strdup (other->m_keystream);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_keystream = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
inline bool isKeepAlive() const { return m_keepAlive; }
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return m_host && m_port > 0; }
|
||||
inline bool hasKeystream() const { return m_keystream; }
|
||||
inline const char *host() const { return isProxyed() ? proxyHost() : finalHost(); }
|
||||
inline const char *password() const { return m_password ? m_password : kDefaultPassword; }
|
||||
inline const char *user() const { return m_user ? m_user : kDefaultUser; }
|
||||
|
@ -61,6 +62,7 @@ public:
|
|||
void applyExceptions();
|
||||
void setPassword(const char *password);
|
||||
void setUser(const char *user);
|
||||
void copyKeystream(char *keystreamDest, const size_t keystreamLen) const;
|
||||
|
||||
Url &operator=(const Url *other);
|
||||
|
||||
|
@ -73,6 +75,7 @@ private:
|
|||
uint16_t m_port;
|
||||
char* m_proxy_host;
|
||||
uint16_t m_proxy_port;
|
||||
char* m_keystream;
|
||||
};
|
||||
|
||||
#endif /* __URL_H__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue