diff options
-rw-r--r-- | init.cpp | 2 | ||||
-rw-r--r-- | messages.cpp | 39 | ||||
-rw-r--r-- | new_gpg.rc | 5 | ||||
-rw-r--r-- | new_gpg.vcproj | 114 | ||||
-rw-r--r-- | options.cpp | 103 | ||||
-rw-r--r-- | srmm.cpp | 9 | ||||
-rw-r--r-- | utilities.cpp | 12 |
7 files changed, 232 insertions, 52 deletions
@@ -39,7 +39,7 @@ fstream debuglog; PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
0,
- PLUGIN_MAKE_VERSION(0,0,0,3),
+ PLUGIN_MAKE_VERSION(0,0,0,4),
"new GPG encryption support plugin, used code from http://addons.miranda-im.org/details.php?action=viewfile&id=3485",
"sss",
"sss123next@list.ru",
diff --git a/messages.cpp b/messages.cpp index ad87255..f7e0d9c 100644 --- a/messages.cpp +++ b/messages.cpp @@ -80,10 +80,36 @@ int RecvMsgSvc(WPARAM w, LPARAM l) s2 = str.find(_T("-----END PGP MESSAGE-----"));
if((s2 != wstring::npos) && (s1 != wstring::npos))
{ //this is generic encrypted data block
+ void setSrmmIcon(HANDLE);
+ void setClistIcon(HANDLE);
+ bool isContactHaveKey(HANDLE hContact);
if(!DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0))
{
if(MessageBox(0, _T("We received encrypted message from contact with encryption turned off.\nDo you want turn on encryption for this contact ?"), _T("Warning"), MB_YESNO) == IDYES)
- DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1);
+ {
+ if(!isContactHaveKey(ccs->hContact))
+ {
+ void ShowLoadPublicKeyDialog();
+ extern map<int, HANDLE> user_data;
+ extern int item_num;
+ item_num = 0; //black magic here
+ user_data[1] = ccs->hContact;
+ ShowLoadPublicKeyDialog();
+ }
+ else
+ {
+ DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1);
+ setSrmmIcon(ccs->hContact);
+ setClistIcon(ccs->hContact);
+ return 0;
+ }
+ if(isContactHaveKey(ccs->hContact))
+ {
+ DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1);
+ setSrmmIcon(ccs->hContact);
+ setClistIcon(ccs->hContact);
+ }
+ }
else if(MessageBox(0, _T("Do you want try to decrypt encrypted message ?"), _T("Warning"), MB_YESNO) == IDNO)
return CallService(MS_PROTO_CHAINRECV, w, l);
}
@@ -222,6 +248,17 @@ int RecvMsgSvc(WPARAM w, LPARAM l) }
}
}
+ if(DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0))
+ {
+ wchar_t *tmp = mir_utf8decodeW(msg);
+ wstring str = tmp;
+ mir_free(tmp);
+ mir_free((void**)pre->szMessage);
+ str.insert(0, _T("Received unencrypted message:\n"));
+ char *utf = mir_utf8encodeW(str.c_str());
+ pre->szMessage = utf;
+ return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs);
+ }
return CallService(MS_PROTO_CHAINRECV, w, l);
}
@@ -255,9 +255,8 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x0 BEGIN
CONTROL "",IDC_USERLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,17,272,112
CTEXT "Userlist:",IDC_STATIC,25,7,201,8
- PUSHBUTTON "Import PubKey",IDC_LOAD_KEY_BUTTON,7,135,54,14
- PUSHBUTTON "Export PubKey",IDC_SAVE_KEY_BUTTON,64,135,54,14
- PUSHBUTTON "Delete key",IDC_DELETE_KEY_BUTTON,121,135,50,14
+ PUSHBUTTON "Export PubKey",IDC_SAVE_KEY_BUTTON,8,135,54,14
+ PUSHBUTTON "Delete key",IDC_DELETE_KEY_BUTTON,65,135,50,14
PUSHBUTTON "Select own key",IDC_SELECT_KEY,222,193,57,14
CONTROL "Turn on debug log",IDC_DEBUG_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,159,89,10
EDITTEXT IDC_LOG_FILE_EDIT,11,157,98,14,ES_AUTOHSCROLL
diff --git a/new_gpg.vcproj b/new_gpg.vcproj index f195b1a..f1fc7fa 100644 --- a/new_gpg.vcproj +++ b/new_gpg.vcproj @@ -258,7 +258,9 @@ EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="1"
FloatingPointModel="0"
- PrecompiledHeaderFile=".\Release Unicode (static)/testplug.pch"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
AssemblerListingLocation=".\Release Unicode (static)/"
ObjectFile=".\Release Unicode (static)/"
ProgramDataBaseFileName=".\Release Unicode (static)/"
@@ -627,6 +629,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\gpg_wrapper.cpp"
@@ -639,6 +651,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\icons.cpp"
@@ -651,6 +673,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\init.cpp"
@@ -664,6 +696,16 @@ PrecompiledHeaderThrough="commonheaders.h"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\jabber_account.cpp"
@@ -676,6 +718,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\main.cpp"
@@ -688,6 +740,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\messages.cpp"
@@ -700,6 +762,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\metacontacts.cpp"
@@ -712,6 +784,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\options.cpp"
@@ -724,6 +806,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\srmm.cpp"
@@ -736,6 +828,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath=".\utilities.cpp"
@@ -748,6 +850,16 @@ UsePrecompiledHeader="2"
/>
</FileConfiguration>
+ <FileConfiguration
+ Name="Release Unicode (static)|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderThrough="commonheaders.h"
+ PrecompiledHeaderFile="c:\temp\new_gpg.pch"
+ />
+ </FileConfiguration>
</File>
</Filter>
<Filter
diff --git a/options.cpp b/options.cpp index e54eded..b4cdac3 100644 --- a/options.cpp +++ b/options.cpp @@ -129,42 +129,46 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA ListView_InsertColumn(hwndList, 4, &col); ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); int i = 1, iRow = 0; + bool isContactHaveKey(HANDLE); for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact != NULL; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) { - TCHAR *name = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); - item.mask = LVIF_TEXT; - item.iItem = i; - item.iSubItem = 0; - item.pszText = name; - iRow = ListView_InsertItem(hwndList, &item); - ListView_SetItemText(hwndList, iRow, 0, name); - TCHAR *tmp = mir_a2t((char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)); - ListView_SetItemText(hwndList, iRow, 4, tmp); - mir_free(tmp); - tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); - tmp = mir_a2t(tmp2); - mir_free(tmp2); - ListView_SetItemText(hwndList, iRow, 1, (_tcslen(tmp) > 1)?tmp:_T("not set")); - mir_free(tmp); - tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", ""); - tmp = mir_a2t(tmp2); - mir_free(tmp2); - ListView_SetItemText(hwndList, iRow, 2, (_tcslen(tmp) > 1)?tmp:_T("not set")); - mir_free(tmp); - tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainEmail", ""); - tmp = mir_a2t(tmp2); - mir_free(tmp2); - ListView_SetItemText(hwndList, iRow, 3, (_tcslen(tmp) > 1)?tmp:_T("not set")); - mir_free(tmp); - if(DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) - ListView_SetItemState(hwndList, iRow, 0x2000, 0xF000); - user_data[i] = hContact; - ZeroMemory(&item,sizeof(item)); - ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this - ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + if(isContactHaveKey(hContact)) + { + TCHAR *name = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = name; + iRow = ListView_InsertItem(hwndList, &item); + ListView_SetItemText(hwndList, iRow, 0, name); + TCHAR *tmp = mir_a2t((char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)); + ListView_SetItemText(hwndList, iRow, 4, tmp); + mir_free(tmp); + tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + tmp = mir_a2t(tmp2); + mir_free(tmp2); + ListView_SetItemText(hwndList, iRow, 1, (_tcslen(tmp) > 1)?tmp:_T("not set")); + mir_free(tmp); + tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", ""); + tmp = mir_a2t(tmp2); + mir_free(tmp2); + ListView_SetItemText(hwndList, iRow, 2, (_tcslen(tmp) > 1)?tmp:_T("not set")); + mir_free(tmp); + tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainEmail", ""); + tmp = mir_a2t(tmp2); + mir_free(tmp2); + ListView_SetItemText(hwndList, iRow, 3, (_tcslen(tmp) > 1)?tmp:_T("not set")); + mir_free(tmp); + if(DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) + ListView_SetItemState(hwndList, iRow, 0x2000, 0xF000); + user_data[i] = hContact; + ZeroMemory(&item,sizeof(item)); + ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + } i++; } tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("")); @@ -182,9 +186,6 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA { switch (LOWORD(wParam)) { - case IDC_LOAD_KEY_BUTTON: - ShowLoadPublicKeyDialog(); - return TRUE; case IDC_DELETE_KEY_BUTTON: { //gpg execute block TCHAR tmp2[MAX_PATH] = {0}; @@ -481,6 +482,11 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP { TranslateDialogDefault(hwndDlg); tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); + if(!hContact) + { + EnableWindow(GetDlgItem(hwndDlg, IDC_SELECT_EXISTING), 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLE_ENCRYPTION), 0); + } wstring str = tmp; mir_free(tmp); wstring::size_type p = 0, stop = 0; @@ -512,6 +518,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP { case ID_OK: tmp = new TCHAR [40960]; + TCHAR *begin, *end; GetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, tmp, 40960); key_buf.append(tmp); key_buf.append(_T("\n")); //no new line at end of file ) @@ -521,12 +528,26 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP key_buf.erase(ws1, 1); //remove windows specific trash } ws1 = 0; - if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) == wstring::npos) || ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) == wstring::npos)) + if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) != wstring::npos)) + { + begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1]; + _tcscpy(begin, _T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + end = new TCHAR [_tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")) + 1]; + _tcscpy(end, _T("-----END PGP PUBLIC KEY BLOCK-----")); + } + else if(((ws2 = key_buf.find(_T("-----END PGP PRIVATE KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"))) != wstring::npos)) + { + begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1]; + _tcscpy(begin, _T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); + end = new TCHAR [_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1]; + _tcscpy(end, _T("-----END PGP PRIVATE KEY BLOCK-----")); + } + else { - MessageBox(0, _T("This is not public key"), _T("INFO"), MB_OK); + MessageBox(0, _T("This is not public or private key"), _T("INFO"), MB_OK); break; } - ws2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); + ws2 += _tcslen(end); DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); tmp = new TCHAR [key_buf.length()+1]; _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str()); @@ -564,6 +585,8 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; } + mir_free(begin); + mir_free(end); cp866_to_cp1251(&output); DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "bAlwatsTrust"); { @@ -45,7 +45,7 @@ int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam) { void setSrmmIcon(HANDLE);
void setClistIcon(HANDLE);
- TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); + bool isContactHaveKey(HANDLE hContact);
BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); if(enc) { @@ -55,7 +55,7 @@ int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam) { }
else if(!enc)
{
- if(_tcslen(key) < 1)
+ if(!isContactHaveKey(hContact))
{
void ShowLoadPublicKeyDialog();
extern map<int, HANDLE> user_data;
@@ -69,12 +69,9 @@ int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam) { DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
setSrmmIcon(hContact);
setClistIcon(hContact);
- mir_free(key);
return 0;
}
- mir_free(key);
- key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T(""));
- if(_tcslen(key) > 0)
+ if(isContactHaveKey(hContact))
{
DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
setSrmmIcon(hContact);
diff --git a/utilities.cpp b/utilities.cpp index 6988fed..07623e1 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -500,3 +500,15 @@ bool isContactSecured(HANDLE hContact) return false; } +bool isContactHaveKey(HANDLE hContact) +{ + TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); + if(_tcslen(key) > 0) + { + mir_free(key); + return true; + } + mir_free(key); + return false; +} + |