From 9ff5d2bf8c72ad82b68761b920475ac8175791c6 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 18 Dec 2010 16:01:33 +0200 Subject: [PATCH] =?utf8?q?=D0=A3=20=D0=BA=D0=BB=D1=96=D1=94=D0=BD=D1=82?= =?utf8?q?=D1=81=D1=8C=D0=BA=D0=BE=D0=BC=D1=83=20=D0=BA=D0=BB=D0=B0=D1=81?= =?utf8?q?=D1=96=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20rlm=5Fstg=20?= =?utf8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B8=20=D1=88=D0=B8=D1=84=D1=80?= =?utf8?q?=D1=83=D0=B2=D0=B0=D0=BD=D0=BD=D1=8F=20=D0=B2=D0=B8=D0=BD=D0=B5?= =?utf8?q?=D1=81=D0=B5=D0=BD=D1=96=20=D1=8F=D0=BA=20=D0=B7=D0=B2=D0=B8?= =?utf8?q?=D1=87=D0=B0=D0=B9=D0=BD=D1=96=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?utf8?q?=D1=96=D1=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/rlm_stg/stg_client.cpp | 50 ++++++++++++++++----------------- projects/rlm_stg/stg_client.h | 7 ----- 2 files changed, 24 insertions(+), 33 deletions(-) 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); -- 2.44.2