summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmessages.cpp6
-rwxr-xr-x[-rw-r--r--]new_gpg.vcxproj10
-rwxr-xr-x[-rw-r--r--]utilities.cpp264
3 files changed, 148 insertions, 132 deletions
diff --git a/messages.cpp b/messages.cpp
index 2d48052..44172df 100755
--- a/messages.cpp
+++ b/messages.cpp
@@ -23,6 +23,8 @@ boost::mutex new_key_hcnt_mutex;
bool _terminate = false;
int returnNoError(HANDLE hContact);
+std::list<HANDLE> sent_msgs;
+
int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, DWORD timestamp)
{
DWORD dbflags = DBEF_UTF;
@@ -608,7 +610,9 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0,0, DBEF_SENT));
hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG");
mir_free(msg);
- return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ HANDLE h = (HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ sent_msgs.push_back(h);
+ return (int)h;
}
if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself
cmd += _T("--comment \"\" --no-version ");
diff --git a/new_gpg.vcxproj b/new_gpg.vcxproj
index ee7f0aa..44dc517 100644..100755
--- a/new_gpg.vcxproj
+++ b/new_gpg.vcxproj
@@ -477,7 +477,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>e:\temp\windows\libs\utf8cpp\include;E:\temp\windows\libs\Boost\include;e:\install\git\miranda\miranda-im\miranda\include;e:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>x:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\Boost\include;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@@ -502,9 +502,9 @@
<Culture>0x0809</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>shlwapi.lib;%(AdditionalDependencies) libboost_thread-vc100-mt-sgd-1_47.lib</AdditionalDependencies>
+ <AdditionalDependencies>shlwapi.lib;%(AdditionalDependencies) libboost_thread-vc100-mt-sgd-1_48.lib</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
- <AdditionalLibraryDirectories>e:\temp\windows\libs\Boost\lib-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>x:\temp\windows\libs\Boost\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AssemblyDebug>true</AssemblyDebug>
<GenerateMapFile>true</GenerateMapFile>
@@ -689,7 +689,7 @@
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<WholeProgramOptimization>true</WholeProgramOptimization>
- <AdditionalIncludeDirectories>e:\temp\windows\libs\utf8cpp\include;e:\temp\windows\libs\Boost\include\boost-1_46;e:\install\git\miranda\miranda-im\miranda\include;e:\install\git\miranda\mim_plugs;../../include</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@@ -712,7 +712,7 @@
<Link>
<AdditionalDependencies>shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
- <AdditionalLibraryDirectories>e:\temp\windows\libs\Boost\lib-release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>X:\temp\windows\libs\Boost\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>NotSet</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
diff --git a/utilities.cpp b/utilities.cpp
index dbf8786..b7498e5 100644..100755
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -282,164 +282,176 @@ int onProtoAck(WPARAM w, LPARAM l)
if (ack->type!=ACKTYPE_FILE)
return 0;
- switch(ack->result)
+ if(ack->type == ACKTYPE_FILE)
{
- case ACKRESULT_DENIED: case ACKRESULT_FAILED:
- break;
- case ACKRESULT_SUCCESS:
+ switch(ack->result)
{
- PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->hProcess;
- TCHAR *filename = NULL;
- if(f->flags & PFTS_UNICODE)
- {
- if(f->tszCurrentFile && f->tszCurrentFile[0])
- filename = mir_wstrdup(f->tszCurrentFile);
- if(!filename)
- return 0;
- }
- else
+ case ACKRESULT_DENIED: case ACKRESULT_FAILED:
+ break;
+ case ACKRESULT_SUCCESS:
{
- if(f->szCurrentFile && f->szCurrentFile[0])
- filename = mir_utf8decodeT(f->szCurrentFile);
- if(!filename)
- return 0;
- }
- if(_tcsstr(filename, _T(".gpg"))) //decrypt it
- { //process encrypted file
- if(_waccess(f->tszCurrentFile, 0) == -1)
+ PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->hProcess;
+ TCHAR *filename = NULL;
+ if(f->flags & PFTS_UNICODE)
{
- if(errno == ENOENT)
+ if(f->tszCurrentFile && f->tszCurrentFile[0])
+ filename = mir_wstrdup(f->tszCurrentFile);
+ if(!filename)
return 0;
}
- string out;
- DWORD code;
- pxResult result;
- wstring cmd = _T("-o ");
- wstring file = filename;
- wstring::size_type p1 = file.rfind(_T(".gpg"));
- file.erase(p1, _tcslen(_T(".gpg")));
- if(_waccess(file.c_str(), 0) != -1)
+ else
{
- if(MessageBox(0, _T("Target file exists, do you want to replace it ?"), _T("Warning"), MB_YESNO) == IDNO)
+ if(f->szCurrentFile && f->szCurrentFile[0])
+ filename = mir_utf8decodeT(f->szCurrentFile);
+ if(!filename)
return 0;
}
- DeleteFile(file.c_str());
- file.insert(0, _T("\""));
- file.insert(file.length(), _T("\" "));
- cmd += file;
- cmd += _T(" -d \"");
- cmd += filename;
- cmd += _T("\"");
- extern TCHAR *password;
- { // password
- TCHAR *pass = NULL;
- char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", "");
- if(strlen(keyid) > 0)
- {
- string dbsetting = "szKey_";
- dbsetting += keyid;
- dbsetting += "_Password";
- pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T(""));
- if(_tcslen(pass) > 0)
- debuglog<<time_str()<<": info: found password in database for key id: "<<keyid<<", trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
- }
- else
- {
- pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
- if(_tcslen(pass) > 0)
- debuglog<<time_str()<<": info: found password for all keys in database, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
- }
- if(_tcslen(pass) > 0)
+ if(_tcsstr(filename, _T(".gpg"))) //decrypt it
+ { //process encrypted file
+ if(_waccess(f->tszCurrentFile, 0) == -1)
{
- cmd += _T("--passphrase \"");
- cmd += pass;
- cmd += _T("\" ");
+ if(errno == ENOENT)
+ return 0;
}
- else if(password)
+ string out;
+ DWORD code;
+ pxResult result;
+ wstring cmd = _T("-o ");
+ wstring file = filename;
+ wstring::size_type p1 = file.rfind(_T(".gpg"));
+ file.erase(p1, _tcslen(_T(".gpg")));
+ if(_waccess(file.c_str(), 0) != -1)
{
- debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
- cmd += _T("--passphrase \"");
- cmd += password;
- cmd += _T("\" ");
+ if(MessageBox(0, _T("Target file exists, do you want to replace it ?"), _T("Warning"), MB_YESNO) == IDNO)
+ return 0;
}
- else
- debuglog<<time_str()<<": info: passwords not found in database or memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with out password\n";
- mir_free(pass);
- mir_free(keyid);
- }
- gpg_execution_params params;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, &params));
- if(!gpg_thread->timed_join(boost::posix_time::minutes(15)))
- {
- delete gpg_thread;
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
- debuglog<<time_str()<<": GPG execution timed out, aborted\n";
- return 0;
- }
- while(out.find("public key decryption failed: bad passphrase") != string::npos)
- {
- extern bool _terminate;
- extern HANDLE new_key_hcnt;
- extern boost::mutex new_key_hcnt_mutex;
- debuglog<<time_str()<<": info: failed to decrypt messaage from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n";
- if(_terminate)
- break;
- { //save inkey id
- string::size_type s = out.find(" encrypted with ");
- s = out.find(" ID ", s);
- s += strlen(" ID ");
- string::size_type s2 = out.find(",",s);
- DBWriteContactSettingString(metaGetMostOnline(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
- }
- void ShowLoadKeyPasswordWindow();
- new_key_hcnt_mutex.lock();
- new_key_hcnt = ccs->hContact;
- ShowLoadKeyPasswordWindow();
- wstring cmd2 = cmd;
- if(password)
- {
- debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<"\n";
- wstring tmp = _T("--passphrase \"");
- tmp += password;
- tmp += _T("\" ");
- cmd2.insert(0, tmp);
+ DeleteFile(file.c_str());
+ file.insert(0, _T("\""));
+ file.insert(file.length(), _T("\" "));
+ cmd += file;
+ cmd += _T(" -d \"");
+ cmd += filename;
+ cmd += _T("\"");
+ extern TCHAR *password;
+ { // password
+ TCHAR *pass = NULL;
+ char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", "");
+ if(strlen(keyid) > 0)
+ {
+ string dbsetting = "szKey_";
+ dbsetting += keyid;
+ dbsetting += "_Password";
+ pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T(""));
+ if(_tcslen(pass) > 0)
+ debuglog<<time_str()<<": info: found password in database for key id: "<<keyid<<", trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
+ }
+ else
+ {
+ pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
+ if(_tcslen(pass) > 0)
+ debuglog<<time_str()<<": info: found password for all keys in database, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
+ }
+ if(_tcslen(pass) > 0)
+ {
+ cmd += _T("--passphrase \"");
+ cmd += pass;
+ cmd += _T("\" ");
+ }
+ else if(password)
+ {
+ debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
+ cmd += _T("--passphrase \"");
+ cmd += password;
+ cmd += _T("\" ");
+ }
+ else
+ debuglog<<time_str()<<": info: passwords not found in database or memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with out password\n";
+ mir_free(pass);
+ mir_free(keyid);
}
- out.clear();
gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd2;
+ params.cmd = &cmd;
params.useless = "";
params.out = &out;
params.code = &code;
params.result = &result;
- gpg_thread = gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, &params));
- if(!gpg_thread->timed_join(boost::posix_time::seconds(15)))
+ boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, &params));
+ if(!gpg_thread->timed_join(boost::posix_time::minutes(15)))
{
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
- DeleteFile(filename);
return 0;
}
- if(result == pxNotFound)
+ while(out.find("public key decryption failed: bad passphrase") != string::npos)
{
- DeleteFile(filename);
- return 0;
+ extern bool _terminate;
+ extern HANDLE new_key_hcnt;
+ extern boost::mutex new_key_hcnt_mutex;
+ debuglog<<time_str()<<": info: failed to decrypt messaage from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n";
+ if(_terminate)
+ break;
+ { //save inkey id
+ string::size_type s = out.find(" encrypted with ");
+ s = out.find(" ID ", s);
+ s += strlen(" ID ");
+ string::size_type s2 = out.find(",",s);
+ DBWriteContactSettingString(metaGetMostOnline(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
+ }
+ void ShowLoadKeyPasswordWindow();
+ new_key_hcnt_mutex.lock();
+ new_key_hcnt = ccs->hContact;
+ ShowLoadKeyPasswordWindow();
+ wstring cmd2 = cmd;
+ if(password)
+ {
+ debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<"\n";
+ wstring tmp = _T("--passphrase \"");
+ tmp += password;
+ tmp += _T("\" ");
+ cmd2.insert(0, tmp);
+ }
+ out.clear();
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd2;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ gpg_thread = gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, &params));
+ if(!gpg_thread->timed_join(boost::posix_time::seconds(15)))
+ {
+ delete gpg_thread;
+ TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ DeleteFile(filename);
+ return 0;
+ }
+ if(result == pxNotFound)
+ {
+ DeleteFile(filename);
+ return 0;
+ }
}
- }
- DeleteFile(filename);
- mir_free(filename);
+ DeleteFile(filename);
+ mir_free(filename);
}
}
break;
}
+ }
+ else if(ack->type == ACKTYPE_MESSAGE)
+ {
+ extern std::list<HANDLE> sent_msgs;
+ std::list<HANDLE>::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess);
+ if(it != sent_msgs.end())
+ {
+ HistoryLog(ack->hContact, db_event("Failed to send encrypted message", 0,0, 0));
+ }
+ }
return 0;
}