feature: Encrypt for server address
This commit is contained in:
@@ -58,8 +58,7 @@ typedef void* LPVOID, * HANDLE;
|
|||||||
#define CancelIo(p) close(reinterpret_cast<intptr_t>(p))
|
#define CancelIo(p) close(reinterpret_cast<intptr_t>(p))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include "ip_enc.h"
|
||||||
#include <vector>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
@@ -352,10 +351,16 @@ public:
|
|||||||
int FlagLen() const {
|
int FlagLen() const {
|
||||||
return strlen(szFlag);
|
return strlen(szFlag);
|
||||||
}
|
}
|
||||||
const char* ServerIP()const {
|
const char* ServerIP(){
|
||||||
|
if (bEncrypt) {
|
||||||
|
Decrypt();
|
||||||
|
}
|
||||||
return szServerIP;
|
return szServerIP;
|
||||||
}
|
}
|
||||||
int ServerPort()const {
|
int ServerPort() {
|
||||||
|
if (bEncrypt) {
|
||||||
|
Decrypt();
|
||||||
|
}
|
||||||
return atoi(szPort);
|
return atoi(szPort);
|
||||||
}
|
}
|
||||||
int ClientType()const {
|
int ClientType()const {
|
||||||
@@ -372,8 +377,24 @@ public:
|
|||||||
|
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
bool IsValid()const {
|
void Encrypt() {
|
||||||
return strlen(szServerIP) != 0 && atoi(szPort) > 0;
|
if (!bEncrypt){
|
||||||
|
bEncrypt = true;
|
||||||
|
StreamCipher cipher(0x12345678);
|
||||||
|
cipher.process((uint8_t*)szServerIP, sizeof(szServerIP));
|
||||||
|
cipher.process((uint8_t*)szPort, sizeof(szPort));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Decrypt() {
|
||||||
|
if (bEncrypt) {
|
||||||
|
bEncrypt = false;
|
||||||
|
StreamCipher cipher(0x12345678);
|
||||||
|
cipher.process((uint8_t*)szServerIP, sizeof(szServerIP));
|
||||||
|
cipher.process((uint8_t*)szPort, sizeof(szPort));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool IsValid() {
|
||||||
|
return strlen(ServerIP()) != 0 && ServerPort() > 0;
|
||||||
}
|
}
|
||||||
int Size() const {
|
int Size() const {
|
||||||
return sizeof(CONNECT_ADDRESS);
|
return sizeof(CONNECT_ADDRESS);
|
||||||
|
|||||||
33
common/ip_enc.h
Normal file
33
common/ip_enc.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Encode for IP and Port.
|
||||||
|
// provided by ChatGPT.
|
||||||
|
class StreamCipher {
|
||||||
|
private:
|
||||||
|
uint32_t state;
|
||||||
|
|
||||||
|
// <20><EFBFBD><F2B5A5B7><EFBFBD><EFBFBD><EFBFBD>α<EFBFBD><CEB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
uint8_t prngNext() {
|
||||||
|
// <20><><EFBFBD>ӣ<EFBFBD>xorshift32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
state ^= (state << 13);
|
||||||
|
state ^= (state >> 17);
|
||||||
|
state ^= (state << 5);
|
||||||
|
// <20>ٻ<EFBFBD><D9BB><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ķ<F2B5A5B5><C4B7><EFBFBD><EFBFBD>Ա任
|
||||||
|
uint8_t out = (state & 0xFF) ^ ((state >> 8) & 0xFF);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
StreamCipher(uint32_t key) : state(key) {}
|
||||||
|
|
||||||
|
// <20><><EFBFBD>ܽ<EFBFBD><DCBD>ܣ<EFBFBD><DCA3>Գƣ<D4B3><C6A3><EFBFBD><EFBFBD>Ȳ<EFBFBD><C8B2>䣩
|
||||||
|
void process(uint8_t* data, size_t len) {
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
data[i] ^= prngNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -151,6 +151,7 @@ void CBuildDlg::OnBnClickedOk()
|
|||||||
SAFE_DELETE_ARRAY(szBuffer);
|
SAFE_DELETE_ARRAY(szBuffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
g_ConnectAddress.Encrypt();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// <20><><EFBFBD>±<EFBFBD>ʶ
|
// <20><><EFBFBD>±<EFBFBD>ʶ
|
||||||
|
|||||||
Reference in New Issue
Block a user