summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utilities.cpp114
1 files changed, 99 insertions, 15 deletions
diff --git a/utilities.cpp b/utilities.cpp
index 3168f7f..05d0bde 100644
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -314,7 +314,7 @@ int onProtoAck(WPARAM w, LPARAM l)
if(_waccess(f->tszCurrentFile, 0) == -1)
{
if(errno == ENOENT)
- break;
+ return 0;
}
string out;
DWORD code;
@@ -326,7 +326,7 @@ int onProtoAck(WPARAM w, LPARAM l)
if(_waccess(file.c_str(), 0) != -1)
{
if(MessageBox(0, _T("Target file exists, do you want to replace it ?"), _T("Warning"), MB_YESNO) == IDNO)
- break;
+ return 0;
}
DeleteFile(file.c_str());
file.insert(0, _T("\""));
@@ -335,6 +335,43 @@ int onProtoAck(WPARAM w, LPARAM l)
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);
+ }
gpg_execution_params params;
params.cmd = &cmd;
params.useless = "";
@@ -346,6 +383,57 @@ int onProtoAck(WPARAM w, LPARAM l)
{
delete gpg_thread;
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(metaGetCurrent(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(10)))
+ {
+ delete gpg_thread;
+ 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);
@@ -383,8 +471,8 @@ int onSendFile(WPARAM w, LPARAM l)
string out;
DWORD code;
pxResult result;
- char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", "");
wstring cmd = _T("--batch --yes -r ");
+ char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", "");
if(DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 0))
cmd += _T("--trust-model always ");
TCHAR *szKeyid = mir_a2t(keyid);
@@ -411,11 +499,13 @@ int onSendFile(WPARAM w, LPARAM l)
params.out = &out;
params.code = &code;
params.result = &result;
+ mir_free(keyid);
boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread->timed_join(boost::posix_time::seconds(180)))
{
delete gpg_thread;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ return 0;
}
if(out.find("There is no assurance this key belongs to the named user") != string::npos)
{
@@ -424,25 +514,19 @@ int onSendFile(WPARAM w, LPARAM l)
{
DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 1);
cmd.insert(0, _T("--trust-model always "));
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &out;
- params.code = &code;
- params.result = &result;
- boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
- if(!gpg_thread.timed_join(boost::posix_time::seconds(180)))
+ gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, &params));
+ if(!gpg_thread->timed_join(boost::posix_time::seconds(180)))
{
- gpg_thread.~thread();
+ delete gpg_thread;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ return 0;
}
}
+ else
+ return 0;
}
mir_free(file[i]);
file[i] = mir_tstrdup(path_out.c_str());
-// mir_realloc(file[i], path_out.length()*sizeof(TCHAR)+1);
-// _tcscpy(file[i], path_out.c_str());
delete [] file_out;
transfers.push_back(path_out);
}