From f43738eae59a7cde24a2d9afcb2fc22de92600e8 Mon Sep 17 00:00:00 2001 From: Detroit Date: Mon, 4 Nov 2019 15:35:23 +0100 Subject: [PATCH] Changed encryption method from AES to OTP. --- README.md | 1 - app.ahk | 2 +- src/labels/labels.ahk | 14 +++---- src/lib/AES.ahk | 92 ------------------------------------------- src/lib/OTP.ahk | 25 ++++++++++++ 5 files changed, 32 insertions(+), 102 deletions(-) delete mode 100644 src/lib/AES.ahk create mode 100644 src/lib/OTP.ahk diff --git a/README.md b/README.md index a967644..3b5708e 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,6 @@ The content of this repository is bound by the following license(s): - The computer software Retro Multi Manager and its associated source code is licensed under the [GNU General Public License v3.0](https://github.com/DetroitApps/RetroMultiManager/blob/master/LICENSE) license. - The license doesn't apply for Library files - [SB_SetProgress]( https://autohotkey.com/board/topic/34593-stdlib-sb-setprogress/ ) by derRaphael ([EUPL v1.0](https://spdx.org/licenses/EUPL-1.0.html)) - - [AES](https://gist.github.com/jNizM/79aa6a4b8ec428bf780f) by [jNizM]( https://gist.github.com/jNizM ) - [i18n-autohotkey](https://github.com/iammael/i18n-autohotkey) by [IAmMael](https://github.com/iammael/) ([MIT](https://github.com/iammael/i18n-autohotkey/blob/master/LICENSE)) - Icon made by [monkik](https://www.flaticon.com/authors/monkik) from [www.flaticon.com](http://www.flaticon.com/) diff --git a/app.ahk b/app.ahk index eb2a8de..a668444 100644 --- a/app.ahk +++ b/app.ahk @@ -16,7 +16,7 @@ CoordMode, Mouse, Window #Include src\class\accounts.ahk #Include src\class\logger.ahk #Include src\class\settings.ahk -#Include src\lib\AES.ahk +#Include src\lib\OTP.ahk #Include src\lib\i18n.ahk ;---------------------------------------- diff --git a/src/labels/labels.ahk b/src/labels/labels.ahk index e8fc709..cd469ad 100644 --- a/src/labels/labels.ahk +++ b/src/labels/labels.ahk @@ -59,11 +59,8 @@ LoadProfile: break If (Encrypt = 1) { - username := AES.Decrypt(username, MasterPassword, 256) - ;msgbox, %username% - username := RegExReplace(username, "[^[:ascii:]]") ;clean weird characters when decoding - password := AES.Decrypt(password, MasterPassword, 256) - password := RegExReplace(password, "[^[:ascii:]]") + username := XOR_String_Minus(username, MasterPassword) + password := XOR_String_Minus(password, MasterPassword) } ArrayAccounts[A_Index] := New Account(username, password, nickname, characterClass, isActive, playerSlot, serverSlot) If Settings.GuiStatus @@ -83,7 +80,7 @@ LoadProfile: SaveProfile: FileCreateDir, Profiles profileIniPath := A_WorkingDir . "\Profiles\profile" . SelectProfile . ".ini" - file := FileOpen(profileIniPath, "w") + file := FileOpen(profileIniPath, "w", "UTF-16") If (file = 0) { MsgBox,, % Translate("Error"), % "[" A_LastError "]" Translate("ErrorSaveProfile", profileIniPath) "." @@ -96,11 +93,12 @@ SaveProfile: username := InputUsername%A_Index% If (CheckEncryption = 1) - username := AES.Encrypt(username, MasterPassword, 256) + username := XOR_String_Plus(username, MasterPassword) file.WriteLine("Username" . A_Index . "=" . username) password := InputPassword%A_Index% If (CheckEncryption = 1) - password := AES.Encrypt(password, MasterPassword, 256) + password := XOR_String_Plus(password, MasterPassword) + Logger.Write(username) file.WriteLine("Password" . A_Index . "=" . password) file.WriteLine("Nickname" . A_Index . "=" . InputNickname%A_Index%) file.WriteLine("Class" . A_Index . "=" . SelectClass%A_Index%) diff --git a/src/lib/AES.ahk b/src/lib/AES.ahk deleted file mode 100644 index 415bae4..0000000 --- a/src/lib/AES.ahk +++ /dev/null @@ -1,92 +0,0 @@ -/* - AES Encryption lib - Author: https://gist.github.com/jNizM/79aa6a4b8ec428bf780f -*/ - -Class AES -{ - Encrypt(string, password, alg) - { - len := this.StrPutVar(string, str_buf, 0, "UTF-16") - this.Crypt(str_buf, len, password, alg, 1) - return this.b64Encode(str_buf, len) - } - Decrypt(string, password, alg) - { - len := this.b64Decode(string, encr_Buf) - sLen := this.Crypt(encr_Buf, len, password, alg, 0) - sLen /= 2 - return StrGet(&encr_Buf, sLen, "UTF-16") - } - - Crypt(ByRef encr_Buf, ByRef Buf_Len, password, ALG_ID, CryptMode := 1) - { - ; WinCrypt.h - static MS_ENH_RSA_AES_PROV := "Microsoft Enhanced RSA and AES Cryptographic Provider" - static PROV_RSA_AES := 24 - static CRYPT_VERIFYCONTEXT := 0xF0000000 - static CALG_SHA1 := 0x00008004 - static CALG_SHA_256 := 0x0000800c - static CALG_SHA_384 := 0x0000800d - static CALG_SHA_512 := 0x0000800e - static CALG_AES_128 := 0x0000660e ; KEY_LENGHT := 0x80 ; (128) - static CALG_AES_192 := 0x0000660f ; KEY_LENGHT := 0xC0 ; (192) - static CALG_AES_256 := 0x00006610 ; KEY_LENGHT := 0x100 ; (256) - static KP_BLOCKLEN := 8 - - if !(DllCall("advapi32.dll\CryptAcquireContext", "Ptr*", hProv, "Ptr", 0, "Ptr", 0, "Uint", PROV_RSA_AES, "UInt", CRYPT_VERIFYCONTEXT)) - MsgBox % "*CryptAcquireContext (" DllCall("kernel32.dll\GetLastError") ")" - - if !(DllCall("advapi32.dll\CryptCreateHash", "Ptr", hProv, "Uint", CALG_SHA1, "Ptr", 0, "Uint", 0, "Ptr*", hHash)) - MsgBox % "*CryptCreateHash (" DllCall("kernel32.dll\GetLastError") ")" - - passLen := this.StrPutVar(password, passBuf, 0, "UTF-16") - if !(DllCall("advapi32.dll\CryptHashData", "Ptr", hHash, "Ptr", &passBuf, "Uint", passLen, "Uint", 0)) - MsgBox % "*CryptHashData (" DllCall("kernel32.dll\GetLastError") ")" - - if !(DllCall("advapi32.dll\CryptDeriveKey", "Ptr", hProv, "Uint", CALG_AES_%ALG_ID%, "Ptr", hHash, "Uint", (ALG_ID << 0x10), "Ptr*", hKey)) ; KEY_LENGHT << 0x10 - MsgBox % "*CryptDeriveKey (" DllCall("kernel32.dll\GetLastError") ")" - - if !(DllCall("advapi32.dll\CryptGetKeyParam", "Ptr", hKey, "Uint", KP_BLOCKLEN, "Uint*", BlockLen, "Uint*", 4, "Uint", 0)) - MsgBox % "*CryptGetKeyParam (" DllCall("kernel32.dll\GetLastError") ")" - BlockLen /= 8 - - if (CryptMode) - DllCall("advapi32.dll\CryptEncrypt", "Ptr", hKey, "Ptr", 0, "Uint", 1, "Uint", 0, "Ptr", &encr_Buf, "Uint*", Buf_Len, "Uint", Buf_Len + BlockLen) - else - DllCall("advapi32.dll\CryptDecrypt", "Ptr", hKey, "Ptr", 0, "Uint", 1, "Uint", 0, "Ptr", &encr_Buf, "Uint*", Buf_Len) - - DllCall("advapi32.dll\CryptDestroyKey", "Ptr", hKey) - DllCall("advapi32.dll\CryptDestroyHash", "Ptr", hHash) - DllCall("advapi32.dll\CryptReleaseContext", "Ptr", hProv, "UInt", 0) - return Buf_Len - } - - StrPutVar(string, ByRef var, addBufLen := 0, encoding := "UTF-16") - { - tlen := ((encoding = "UTF-16" || encoding = "CP1200") ? 2 : 1) - str_len := StrPut(string, encoding) * tlen - VarSetCapacity(var, str_len + addBufLen, 0) - StrPut(string, &var, encoding) - return str_len - tlen - } - - b64Encode(ByRef VarIn, SizeIn) - { - static CRYPT_STRING_BASE64 := 0x00000001 - static CRYPT_STRING_NOCRLF := 0x40000000 - DllCall("crypt32.dll\CryptBinaryToStringA", "Ptr", &VarIn, "UInt", SizeIn, "Uint", (CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF), "Ptr", 0, "UInt*", SizeOut) - VarSetCapacity(VarOut, SizeOut, 0) - DllCall("crypt32.dll\CryptBinaryToStringA", "Ptr", &VarIn, "UInt", SizeIn, "Uint", (CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF), "Ptr", &VarOut, "UInt*", SizeOut) - return StrGet(&VarOut, SizeOut, "CP0") - } - b64Decode(ByRef VarIn, ByRef VarOut) - { - static CRYPT_STRING_BASE64 := 0x00000001 - static CryptStringToBinary := "CryptStringToBinary" (A_IsUnicode ? "W" : "A") - DllCall("crypt32.dll\" CryptStringToBinary, "Ptr", &VarIn, "UInt", 0, "Uint", CRYPT_STRING_BASE64, "Ptr", 0, "UInt*", SizeOut, "Ptr", 0, "Ptr", 0) - VarSetCapacity(VarOut, SizeOut, 0) - DllCall("crypt32.dll\" CryptStringToBinary, "Ptr", &VarIn, "UInt", 0, "Uint", CRYPT_STRING_BASE64, "Ptr", &VarOut, "UInt*", SizeOut, "Ptr", 0, "Ptr", 0) - return SizeOut - } -} \ No newline at end of file diff --git a/src/lib/OTP.ahk b/src/lib/OTP.ahk new file mode 100644 index 0000000..9e83506 --- /dev/null +++ b/src/lib/OTP.ahk @@ -0,0 +1,25 @@ +XOR_String_Plus(String,Key) +{ + Key_Pos := 1 + Loop, Parse, String + { + String_XOR .= Chr((Asc(A_LoopField) ^ Asc(SubStr(Key,Key_Pos,1))) + 15000) + Key_Pos += 1 + if (Key_Pos > StrLen(Key)) + Key_Pos := 1 + } + return String_XOR +} + +XOR_String_Minus(String,Key) +{ + Key_Pos := 1 + Loop, Parse, String + { + String_XOR .= Chr(((Asc(A_LoopField) - 15000) ^ Asc(SubStr(Key,Key_Pos,1)))) + Key_Pos += 1 + if (Key_Pos > StrLen(Key)) + Key_Pos := 1 + } + return String_XOR +} \ No newline at end of file