X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/2c1686d0b3dee0f327cda1b55ac7e42b21446416..0f7d406b3da99019403e76e7ca7686c14a583b3f:/projects/stargazer/plugins/other/radius/radius.cpp diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 4dd18c46..9c5ab1db 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -27,6 +27,7 @@ */ #include +#include #include #include "radius.h" @@ -34,6 +35,10 @@ extern volatile const time_t stgTime; +void InitEncrypt(BLOWFISH_CTX * ctx, const string & password); +void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); +void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -157,6 +162,7 @@ RADIUS::RADIUS() store(NULL), sock(-1) { +InitEncrypt(&ctx, ""); } //----------------------------------------------------------------------------- void RADIUS::SetUsers(USERS * u) @@ -208,14 +214,6 @@ uint16_t RADIUS::GetStopPosition() const return 20; } //----------------------------------------------------------------------------- -void RADIUS::SetUserNotifier(user_iter) -{ -} -//----------------------------------------------------------------------------- -void RADIUS::UnSetUserNotifier(user_iter) -{ -} -//----------------------------------------------------------------------------- int RADIUS::PrepareNet() { sock = socket(AF_INET, SOCK_DGRAM, 0); @@ -595,34 +593,6 @@ packet->packetType = RAD_ACCEPT_PACKET; return 0; } //----------------------------------------------------------------------------- -void RADIUS::InitEncrypt(BLOWFISH_CTX * ctx, const 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); -} -//----------------------------------------------------------------------------- -void RADIUS::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)); -} -//----------------------------------------------------------------------------- -void RADIUS::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)); -} -//----------------------------------------------------------------------------- void RADIUS::PrintServices(const list & svcs) { for_each(svcs.begin(), svcs.end(), Printer()); @@ -679,3 +649,34 @@ if (res == 0) // Timeout return true; } +//----------------------------------------------------------------------------- +inline +void InitEncrypt(BLOWFISH_CTX * ctx, const 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); +} +//----------------------------------------------------------------------------- +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)); +} +//----------------------------------------------------------------------------- +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)); +}