From 4204685b3cc7094e02416952a81b427ed5be7a81 Mon Sep 17 00:00:00 2001 From: wydeep Date: Fri, 28 Jun 2019 21:50:13 -0700 Subject: [PATCH] SQLyog 13.1.4 GA --- include/CommonHelper.h | 2 +- include/Version.h | 2 +- include/wyString.h | 3 ++ src/CommonHelper.cpp | 22 ++++++++++---- src/ConnectionBase.cpp | 36 ++++++++++++++++------- src/ConnectionCommunity.cpp | 4 +++ src/FrameWindow.cpp | 9 ++++-- src/GUIHelper.cpp | 56 ++++++++++++++++++++++++++--------- src/wyString.cpp | 58 +++++++++++++++++++++++++++++++++++-- 9 files changed, 154 insertions(+), 38 deletions(-) diff --git a/include/CommonHelper.h b/include/CommonHelper.h index 254213c..a4082d9 100644 --- a/include/CommonHelper.h +++ b/include/CommonHelper.h @@ -59,7 +59,7 @@ #define FMT_SPACE_4 " " -#define REGKEY "Use any UUID here" +#define REGKEY "xxx" //Provide any UUID here #define SSHTUNNELER "plink.exe" diff --git a/include/Version.h b/include/Version.h index a53fe42..b1f5ed7 100644 --- a/include/Version.h +++ b/include/Version.h @@ -1,5 +1,5 @@ #define MAJOR_VERSION_INT 13 #define MINOR_VERSION_INT 1 -#define UPDATE_VERSION_INT 3 +#define UPDATE_VERSION_INT 4 #define RELEASE_VERSION_INT 0 #define EXTRAINFO " " diff --git a/include/wyString.h b/include/wyString.h index 1439289..f5ee697 100644 --- a/include/wyString.h +++ b/include/wyString.h @@ -479,6 +479,9 @@ class wyString void JsonEscape(); void JsonEscapeForEncryptPassword(); static void JsonDeEscapeForEncryptPassword(wyString &pwstr); + static void DecodeBase64Password(wyString &pwstr); + wyChar* EncodeBase64Password(); + void EscapeNullFromPassword(); private: /// Actual data container. diff --git a/src/CommonHelper.cpp b/src/CommonHelper.cpp index 33390d2..875ab0d 100644 --- a/src/CommonHelper.cpp +++ b/src/CommonHelper.cpp @@ -75,8 +75,8 @@ extern FILE *logfilehandle; static wyChar table64[]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static CryptoPP::byte AESKey[16] = { 0 }; //Provide any IV -static CryptoPP::byte AESiv[16] = { 0 }; //Provide any key +static CryptoPP::byte AESKey[16] = { };// Type any key +static CryptoPP::byte AESiv[16] = { };//Type any IV Tunnel * CreateTunnel(wyBool istunnel) @@ -4608,7 +4608,7 @@ EncodePassword(wyString &text) //encryption encFilter.Put(reinterpret_cast(plaintext.GetString()), plaintext.GetLength()); encFilter.MessageEnd(); - text.SetAs(encText.data(), encText.length()); + text.SetAsDirect(encText.data(), encText.length()); return wyTrue; } @@ -4623,7 +4623,7 @@ DecodePassword(wyString &text) return wyFalse; } - ciphertext.SetAs(text); + ciphertext.SetAsDirect(text.GetString(), text.GetLength()); CryptoPP::CTR_Mode::Decryption dec; dec.SetKeyWithIV(AESKey, sizeof(AESKey), AESiv); @@ -4645,7 +4645,12 @@ MigratePassword(wyString conn, wyString dirstr, wyString &pwdstr) DecodePassword_Absolute(pwdstr); EncodePassword(pwdstr); - pwdstr.JsonEscapeForEncryptPassword(); + wyChar *encodestr=pwdstr.EncodeBase64Password(); + pwdstr.Clear(); + pwdstr.SetAs(encodestr); + + if (encodestr) + free(encodestr); return wyTrue; } @@ -4656,7 +4661,12 @@ MigratePassword(wyString &pwdstr) DecodePassword_Absolute(pwdstr); EncodePassword(pwdstr); - pwdstr.JsonEscapeForEncryptPassword(); + wyChar *encodestr=pwdstr.EncodeBase64Password(); + pwdstr.Clear(); + pwdstr.SetAs(encodestr); + + if (encodestr) + free(encodestr); return wyTrue; } diff --git a/src/ConnectionBase.cpp b/src/ConnectionBase.cpp index 47e205f..791fd5f 100644 --- a/src/ConnectionBase.cpp +++ b/src/ConnectionBase.cpp @@ -1655,9 +1655,16 @@ ConnectionBase::GetInitialDetails(HWND hdlg) strcpy(pwd, pwdstr.GetString()); - //pwdstr.FindAndReplace("\\n", "\n"); - wyString::JsonDeEscapeForEncryptPassword(pwdstr); - + /*wyChar *decodedstr = NULL; + decodedstr = AllocateBuff(512); + wyInt32 len = DecodeBase64(pwdstr.GetString(), decodedstr); + pwdstr.SetAsDirect(decodedstr, len);*/ + wyString::DecodeBase64Password(pwdstr); + DecodePassword(pwdstr); + + /*if (decodedstr) + free(decodedstr);*/ + ret = wyIni::IniGetString(conn.GetString(), "User", "root", &userstr, dirstr.GetString()); ret = wyIni::IniGetString(conn.GetString(), "Host", "localhost", &hoststr, dirstr.GetString()); ret = wyIni::IniGetString(conn.GetString(), "Port", "3306", &portstr, dirstr.GetString()); @@ -1668,8 +1675,6 @@ ConnectionBase::GetInitialDetails(HWND hdlg) storepwd = wyIni::IniGetInt(conn.GetString(), "StorePassword", 1, dirstr.GetString()); Button_SetCheck(GetDlgItem(hdlg, IDC_DLGCONNECT_STOREPASSWORD), storepwd); - DecodePassword(pwdstr); - //Compressed prtocol usecompress = wyIni::IniGetInt(conn.GetString(), "compressedprotocol", 1, dirstr.GetString()); Button_SetCheck(GetDlgItem(hdlg, IDC_COMPRESS), usecompress); @@ -1743,14 +1748,15 @@ ConnectionBase::GetInitialDetails(HWND hdlg) /* now it may happen that without saving anything the user has connected so the field will be removed and the next time he wont get anything to handle such cases we have to by default write the encodedpassword */ + wyChar* encodestr = NULL; if(!decodepwd) { pwdstr.SetAs(pwd); EncodePassword(pwdstr); - pwdstr.JsonEscapeForEncryptPassword(); - strcpy(pwd, pwdstr.GetString()); + encodestr=pwdstr.EncodeBase64Password(); + //strcpy(pwd, pwdstr.GetString()); dirstr.SetAs(directory); - wyIni::IniWriteString(conn.GetString(), "Password", pwdstr.GetString(), dirstr.GetString()); + wyIni::IniWriteString(conn.GetString(), "Password", encodestr, dirstr.GetString()); } /*Gets the 'AutocompleteTagbuilded' info from .ini to decides the statusbar message to be 'Building tags' or 'Rebuilding tags' @@ -1759,6 +1765,8 @@ ConnectionBase::GetInitialDetails(HWND hdlg) SetAutocompleteTagBuildFlag(&conn, &dirstr); //SetFocus(GetDlgItem(hdlg, IDOK)); + if (encodestr) + free(encodestr); return wyTrue; } @@ -2631,11 +2639,17 @@ ConnectionBase::SaveServerDetails(HWND hwnd, const wyChar *conn, const wyChar *d { ret = SendMessage(GetDlgItem(hwnd, IDC_DLGCONNECT_PASSWORD), WM_GETTEXT, sizeof(temp), (LPARAM)temp); tempstr.SetAs(temp); - tempstr.JsonEscapeForEncryptPassword(); EncodePassword(tempstr); - tempstr.JsonEscapeForEncryptPassword(); - ret = wyIni::IniWriteString(conn, "Password", tempstr.GetString(), directory); + + //wyChar *encodestr = NULL; + /*encodestr = AllocateBuff(512); + EncodeBase64(tempstr.GetString(), tempstr.GetLength(), &encodestr);*/ + wyChar *encodestr = tempstr.EncodeBase64Password(); + ret = wyIni::IniWriteString(conn, "Password", encodestr, directory); wyIni::IniWriteString(conn, "Isencrypted", "1", directory); + + if(encodestr) + free(encodestr); } else { diff --git a/src/ConnectionCommunity.cpp b/src/ConnectionCommunity.cpp index 11f897b..a150273 100644 --- a/src/ConnectionCommunity.cpp +++ b/src/ConnectionCommunity.cpp @@ -570,7 +570,11 @@ ConnectionCommunity::OnConnect(HWND hwnd, ConnectionInfo * dbname) GetWindowText(GetDlgItem(hwnd, IDC_DLGCONNECT_PASSWORD), pass, MAX_PATH); temp.SetAs(pass); EncodePassword(temp); + wyChar *encodestr = temp.EncodeBase64Password(); + temp.SetAs(encodestr); wyIni::IniWriteString(conn.GetString(), "Password", temp.GetString(), dirnamestr.GetString()); + if (encodestr) + free(encodestr); } /* write the store password value too */ diff --git a/src/FrameWindow.cpp b/src/FrameWindow.cpp index eac7491..c2bde0c 100644 --- a/src/FrameWindow.cpp +++ b/src/FrameWindow.cpp @@ -6712,12 +6712,15 @@ FrameWindow::ConvertAndWritePwd(wyString &conncount, wyChar *whichpwd, wyString wyIni::IniGetString(conncount.GetString(), whichpwd, "", &passwordstr, path.GetString()); if(passwordstr.GetLength()) { - wyString::JsonDeEscapeForEncryptPassword(passwordstr); + wyString::DecodeBase64Password(passwordstr); DecodePassword(passwordstr); temppwd.SetAs(passwordstr.GetString(), wyFalse); EncodePassword(temppwd); - temppwd.JsonEscapeForEncryptPassword(); - wyIni::IniWriteString(conncount.GetString(), whichpwd, temppwd.GetString(), path.GetString()); + wyChar * encodestr=temppwd.EncodeBase64Password(); + wyIni::IniWriteString(conncount.GetString(), whichpwd, encodestr, path.GetString()); + + if (encodestr) + free(encodestr); } } diff --git a/src/GUIHelper.cpp b/src/GUIHelper.cpp index 3131f65..b5a426e 100644 --- a/src/GUIHelper.cpp +++ b/src/GUIHelper.cpp @@ -9166,7 +9166,7 @@ wyBool GetSessionDetails(wyWChar* conn, wyWChar* path, ConnectionInfo *conninfo, conninfo->m_isstorepwd = inimgr->IniGetInt2(connstr.GetString(), "StorePassword", 1, pathstr.GetString()) ? wyTrue: wyFalse; inimgr->IniGetString2(connstr.GetString(), "Password", "", &conninfo->m_pwd, pathstr.GetString()); - wyString::JsonDeEscapeForEncryptPassword(conninfo->m_pwd); + wyString::DecodeBase64Password(conninfo->m_pwd); DecodePassword(conninfo->m_pwd); conninfo->m_port = inimgr->IniGetInt2(connstr.GetString(), "Port", 3306, pathstr.GetString()); @@ -9210,7 +9210,7 @@ wyBool GetSessionDetails(wyWChar* conn, wyWChar* path, ConnectionInfo *conninfo, if (proxypwd.GetLength()) { - wyString::JsonDeEscapeForEncryptPassword(proxypwd); + wyString::DecodeBase64Password(proxypwd); DecodePassword(proxypwd); } wcscpy(auth->proxypwd, proxypwd.GetAsWideChar()); @@ -9223,7 +9223,7 @@ wyBool GetSessionDetails(wyWChar* conn, wyWChar* path, ConnectionInfo *conninfo, if (chalpwd.GetLength()) { - wyString::JsonDeEscapeForEncryptPassword(chalpwd); + wyString::DecodeBase64Password(chalpwd); DecodePassword(chalpwd); } @@ -9240,7 +9240,7 @@ wyBool GetSessionDetails(wyWChar* conn, wyWChar* path, ConnectionInfo *conninfo, conninfo->m_isssh = inimgr->IniGetInt2(connstr.GetString(), "SSH", 0, pathstr.GetString()) ? wyTrue: wyFalse; inimgr->IniGetString2(connstr.GetString(), "SshUser", "", &conninfo->m_sshuser, pathstr.GetString()); inimgr->IniGetString2(connstr.GetString(), "SshPwd", "", &conninfo->m_sshpwd, pathstr.GetString()); - wyString::JsonDeEscapeForEncryptPassword(conninfo->m_sshpwd); + wyString::DecodeBase64Password(conninfo->m_sshpwd); DecodePassword(conninfo->m_sshpwd); inimgr->IniGetString2(connstr.GetString(), "SshHost", "", &conninfo->m_sshhost, pathstr.GetString()); conninfo->m_sshport = inimgr->IniGetInt2 (connstr.GetString(), "SshPort", 0, pathstr.GetString()); @@ -9594,7 +9594,7 @@ wyBool GetSessionDetailsFromTable(wyWChar* path, ConnectionInfo *conninfo, wyInt conninfo->m_pwd.SetAs(pwdstr); } - wyString::JsonDeEscapeForEncryptPassword(conninfo->m_pwd); + wyString::DecodeBase64Password(conninfo->m_pwd); DecodePassword(conninfo->m_pwd); colval = sqliteobj->GetText(&res , "Port"); if(colval) @@ -9703,7 +9703,7 @@ wyBool GetSessionDetailsFromTable(wyWChar* path, ConnectionInfo *conninfo, wyInt if (proxypwd.GetLength()) { - wyString::JsonDeEscapeForEncryptPassword(proxypwd); + wyString::DecodeBase64Password(proxypwd); DecodePassword(proxypwd); } wcscpy(auth->proxypwd, proxypwd.GetAsWideChar()); @@ -9724,7 +9724,7 @@ wyBool GetSessionDetailsFromTable(wyWChar* path, ConnectionInfo *conninfo, wyInt } if (chalpwd.GetLength()) { - wyString::JsonDeEscapeForEncryptPassword(chalpwd); + wyString::DecodeBase64Password(chalpwd); DecodePassword(chalpwd); } @@ -9762,8 +9762,7 @@ wyBool GetSessionDetailsFromTable(wyWChar* path, ConnectionInfo *conninfo, wyInt { MigratePassword(conninfo->m_sshpwd); } - - wyString::JsonDeEscapeForEncryptPassword(conninfo->m_sshpwd); + wyString::DecodeBase64Password(conninfo->m_sshpwd); DecodePassword(conninfo->m_sshpwd); colval = sqliteobj->GetText(&res , "SshHost"); @@ -9931,10 +9930,14 @@ WriteFullSectionToFile(FILE *out_stream, wyInt32 conno, ConnectionInfo *coninfo, pass.SetAs(coninfo->m_pwd); } EncodePassword(pass); - pass.JsonEscapeForEncryptPassword(); + wyChar *encodestr=pass.EncodeBase64Password(); + pass.SetAs(encodestr); temp.Sprintf("Password=%s\r\n", pass.GetString()); fputs(temp.GetString(), out_stream); + if (encodestr) + free(encodestr); + temp.Sprintf("Port=%d\r\n", coninfo->m_port); fputs(temp.GetString(), out_stream); @@ -10001,7 +10004,10 @@ WriteFullSectionToFile(FILE *out_stream, wyInt32 conno, ConnectionInfo *coninfo, if (tempstr.GetLength() != 0) { EncodePassword(tempstr); - tempstr.JsonEscapeForEncryptPassword(); + wyChar *encodestr=tempstr.EncodeBase64Password(); + tempstr.SetAs(encodestr); + if (encodestr) + free(encodestr); } temp.Sprintf("ProxyPwd=%s\r\n", tempstr.GetString()); @@ -10019,7 +10025,10 @@ WriteFullSectionToFile(FILE *out_stream, wyInt32 conno, ConnectionInfo *coninfo, if (tempstr.GetLength()) { EncodePassword(tempstr); - tempstr.JsonEscapeForEncryptPassword(); + wyChar *encodestr=tempstr.EncodeBase64Password(); + tempstr.SetAs(encodestr); + if (encodestr) + free(encodestr); } temp.Sprintf("401Pwd=%s\r\n", tempstr.GetString()); @@ -10043,7 +10052,10 @@ WriteFullSectionToFile(FILE *out_stream, wyInt32 conno, ConnectionInfo *coninfo, if(tempstr.GetLength()) { EncodePassword(tempstr); - tempstr.JsonEscapeForEncryptPassword(); + wyChar *encodestr=tempstr.EncodeBase64Password(); + tempstr.SetAs(encodestr); + if (encodestr) + free(encodestr); } temp.Sprintf("SshPwd=%s\r\n", tempstr.GetString()); @@ -10199,9 +10211,12 @@ WriteFullSectionToTable(wyString *sqlitequery, wyInt32 id, wyInt32 position, Con pass.SetAs(coninfo->m_pwd); } EncodePassword(pass); + wyChar *encodestr=pass.EncodeBase64Password(); + wyString password(""); + password.SetAs(encodestr); //pass.JsonEscapeForEncryptPassword(); - sqliteobj->SetText(&stmt, 9, pass.GetLength()?pass.GetString():""); + sqliteobj->SetText(&stmt, 9, password.GetLength()?password.GetString():""); sqliteobj->SetInt(&stmt, 10, coninfo->m_port); @@ -10264,10 +10279,15 @@ WriteFullSectionToTable(wyString *sqlitequery, wyInt32 id, wyInt32 position, Con tempstr.SetAs(auth->proxypwd); + wyChar* encodestr = NULL; if (tempstr.GetLength() != 0) { EncodePassword(tempstr); + encodestr = tempstr.EncodeBase64Password(); + tempstr.SetAs(encodestr); } + if (encodestr) + free(encodestr); sqliteobj->SetText(&stmt, 26, tempstr.GetLength() ? tempstr.GetString() : ""); @@ -10285,6 +10305,10 @@ WriteFullSectionToTable(wyString *sqlitequery, wyInt32 id, wyInt32 position, Con if (tempstr.GetLength()) { EncodePassword(tempstr); + wyChar* encodestr=tempstr.EncodeBase64Password(); + tempstr.SetAs(encodestr); + if (encodestr) + free(encodestr); } sqliteobj->SetText(&stmt, 29, tempstr.GetLength()? tempstr.GetString():""); @@ -10306,6 +10330,10 @@ WriteFullSectionToTable(wyString *sqlitequery, wyInt32 id, wyInt32 position, Con if(tempstr.GetLength()) { EncodePassword(tempstr); + wyChar* encodestr = tempstr.EncodeBase64Password(); + tempstr.SetAs(encodestr); + if (encodestr) + free(encodestr); } sqliteobj->SetText(&stmt, 34, tempstr.GetLength()? tempstr.GetString():""); diff --git a/src/wyString.cpp b/src/wyString.cpp index 493c51b..358845c 100644 --- a/src/wyString.cpp +++ b/src/wyString.cpp @@ -1503,8 +1503,8 @@ void wyString::JsonEscapeForEncryptPassword() { // index++; break; case '\\': - // Replace(index, 1, "\\\\"); - // index++; + Replace(index, 1, "\\\\"); + index++; break; case '\b': Replace(index, 1, "\\b"); @@ -1526,6 +1526,10 @@ void wyString::JsonEscapeForEncryptPassword() { // Replace(index, 1, "\\t"); // index++; break; + case '\0': + Replace(index, 1, "\\0"); + index++; + break; } } @@ -1537,4 +1541,54 @@ void wyString::JsonDeEscapeForEncryptPassword(wyString &pwdstr) { pwdstr.FindAndReplace("\\n", "\n"); pwdstr.FindAndReplace("\\r", "\r"); pwdstr.FindAndReplace("\\b", "\b"); + pwdstr.EscapeNullFromPassword(); } + +void wyString::EscapeNullFromPassword() +{ + wyInt32 index; + wyChar ch,prev, next,ch1=NULL; + wyString temp; + bool isnull = FALSE; + wyInt32 len = GetLength(); + + for (index = 0; index < len-1; index++) { + isnull = FALSE; + ch = GetCharAt(index); + next = GetCharAt(index + 1); + + switch (ch) { + case '\\': + if ((index+1)