From: Maxim Mamontov Date: Sat, 18 Dec 2010 14:01:33 +0000 (+0200) Subject: У клієнтському класі модуля rlm_stg методи шифрування винесені як X-Git-Tag: 2.407-rc3~271 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/9ff5d2bf8c72ad82b68761b920475ac8175791c6 У клієнтському класі модуля rlm_stg методи шифрування винесені як звичайні функції --- diff --git a/projects/rlm_stg/stg_client.cpp b/projects/rlm_stg/stg_client.cpp index 75d443ad..834f19c4 100644 --- a/projects/rlm_stg/stg_client.cpp +++ b/projects/rlm_stg/stg_client.cpp @@ -39,6 +39,10 @@ using namespace std; +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); +void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); +void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -66,7 +70,9 @@ outerAddr.sin_family = AF_INET; outerAddr.sin_port = htons(port); outerAddr.sin_addr.s_addr = *(uint32_t *)he->h_addr; -InitEncrypt(); +InitEncrypt(&ctx, password); + +PrepareNet(); } //----------------------------------------------------------------------------- STG_CLIENT::~STG_CLIENT() @@ -79,15 +85,6 @@ uint32_t STG_CLIENT::GetFramedIP() const return framedIP; } //----------------------------------------------------------------------------- -inline -void STG_CLIENT::InitEncrypt() -{ -unsigned char keyL[RAD_PASSWORD_LEN]; -memset(keyL, 0, RAD_PASSWORD_LEN); -strncpy((char *)keyL, password.c_str(), RAD_PASSWORD_LEN); -Blowfish_Init(&ctx, keyL, RAD_PASSWORD_LEN); -} -//----------------------------------------------------------------------------- int STG_CLIENT::PrepareNet() { if (localPort != 0) @@ -106,16 +103,6 @@ if (localPort != 0) return 0; } //----------------------------------------------------------------------------- -int STG_CLIENT::Start() -{ -return PrepareNet(); -} -//----------------------------------------------------------------------------- -int STG_CLIENT::Stop() -{ -return 0; -} -//----------------------------------------------------------------------------- string STG_CLIENT::GetUserPassword() const { return userPassword; @@ -125,7 +112,7 @@ int STG_CLIENT::Send(const RAD_PACKET & packet) { char buf[RAD_MAX_PACKET_LEN]; -Encrypt(buf, (char *)&packet, sizeof(RAD_PACKET) / 8); +Encrypt(&ctx, buf, (char *)&packet, sizeof(RAD_PACKET) / 8); int res = sendto(sock, buf, sizeof(RAD_PACKET), 0, (struct sockaddr *)&outerAddr, sizeof(outerAddr)); @@ -150,7 +137,7 @@ if (res == -1) return -1; } -Decrypt((char *)packet, buf, res / 8); +Decrypt(&ctx, (char *)packet, buf, res / 8); return 0; } @@ -274,23 +261,34 @@ if (packet.packetType != RAD_ACCEPT_PACKET) return 0; } //----------------------------------------------------------------------------- -void STG_CLIENT::Encrypt(char * dst, const char * src, int len8) +inline +void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) { // len8 - длина в 8-ми байтовых блоках if (dst != src) memcpy(dst, src, len8 * 8); for (int i = 0; i < len8; i++) - Blowfish_Encrypt(&ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4)); + Blowfish_Encrypt(ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4)); } //----------------------------------------------------------------------------- -void STG_CLIENT::Decrypt(char * dst, const char * src, int len8) +inline +void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) { // len8 - длина в 8-ми байтовых блоках if (dst != src) memcpy(dst, src, len8 * 8); for (int i = 0; i < len8; i++) - Blowfish_Decrypt(&ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4)); + Blowfish_Decrypt(ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4)); +} +//----------------------------------------------------------------------------- +inline +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) +{ +unsigned char keyL[RAD_PASSWORD_LEN]; +memset(keyL, 0, RAD_PASSWORD_LEN); +strncpy((char *)keyL, password.c_str(), RAD_PASSWORD_LEN); +Blowfish_Init(ctx, keyL, RAD_PASSWORD_LEN); } //----------------------------------------------------------------------------- diff --git a/projects/rlm_stg/stg_client.h b/projects/rlm_stg/stg_client.h index 253b262f..4b684968 100644 --- a/projects/rlm_stg/stg_client.h +++ b/projects/rlm_stg/stg_client.h @@ -44,9 +44,6 @@ public: STG_CLIENT(const std::string & host, uint16_t port, uint16_t lp, const std::string & pass); ~STG_CLIENT(); - int Start(); - int Stop(); - std::string GetUserPassword() const; int Authorize(const std::string & login, const std::string & svc); @@ -74,10 +71,6 @@ private: int PrepareNet(); - void InitEncrypt(); - void Encrypt(char * dst, const char * src, int len8); - void Decrypt(char * dst, const char * src, int len8); - int Request(RAD_PACKET * packet, const std::string & login, const std::string & svc, uint8_t packetType); int RecvData(RAD_PACKET * packet);