From edf0d7a9790d958023fe5280f0ee2097e2b4d7f5 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 22 Mar 2011 03:29:51 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 0ba8e12..3168f7f 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -439,10 +439,10 @@ int onSendFile(WPARAM w, LPARAM l) } } } -// 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()); + 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); } -- cgit v1.2.3 From 56581778c96e4955f90b7f492d1419503f12fd94 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 22 Mar 2011 05:09:10 +0200 Subject: password checking in file sending code --- utilities.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 99 insertions(+), 15 deletions(-) (limited to 'utilities.cpp') 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<hContact, GCDNF_TCHAR)<<" with password\n"; + } + else + { + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); + if(_tcslen(pass) > 0) + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + } + if(_tcslen(pass) > 0) + { + cmd += _T("--passphrase \""); + cmd += pass; + cmd += _T("\" "); + } + else if(password) + { + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + cmd += _T("--passphrase \""); + cmd += password; + cmd += _T("\" "); + } + else + debuglog<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<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<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, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) + { + delete gpg_thread; + debuglog<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, ¶ms)); if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) { delete gpg_thread; debuglog<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, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(180))) + gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) { - gpg_thread.~thread(); + delete gpg_thread; debuglog< Date: Tue, 22 Mar 2011 14:09:37 +0200 Subject: new threading code (part 2, usable) --- utilities.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 05d0bde..40c4b32 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -933,7 +933,12 @@ void AddHandlers() bool isContactSecured(HANDLE hContact) { TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); - if(DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0) && (_tcslen(key) > 0)) + if(!key[0]) + { + mir_free(key); + key = UniGetContactSettingUtf(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", _T("")); + } + if((DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0) > 0 || DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0) > 0) && (_tcslen(key) > 0)) { mir_free(key); return true; -- cgit v1.2.3 From 9588dec6833519fa4060cc347f11f808f99ca1e6 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 23 Mar 2011 13:44:24 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 40c4b32..afa9440 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -831,6 +831,8 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi sign_file_mutex.lock(); DeleteFile(path_out.c_str()); wfstream f(path_out.c_str(), std::ios::out); + while(!f.is_open()) + f.open(path_out.c_str(), std::ios::out); f<getJabberInterface()->Sys()->ContactFromJID(xi.getAttrValue(node, _T("from"))); if(hContact) -// DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID_Prescense", out.substr(p1, p2-p1-1).c_str()); hcontact_data[hContact].key_in_prescense = out.substr(p1, p2-p1-1).c_str(); } } -- cgit v1.2.3 From b32258ea916b0ba101decfbc0b59b4088c707202 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 23 Mar 2011 22:39:52 +0200 Subject: file recieving fix --- utilities.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index afa9440..2ba305a 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -282,11 +282,6 @@ int onProtoAck(WPARAM w, LPARAM l) CCSDATA *ccs=(CCSDATA*)ack->lParam; if (ack->type!=ACKTYPE_FILE) return 0; - PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->lParam; -// if(!f) -// f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; - if(!f) - return 0; switch(ack->result) { @@ -294,6 +289,7 @@ int onProtoAck(WPARAM w, LPARAM l) break; case ACKRESULT_SUCCESS: { + PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; TCHAR *filename = NULL; if(f->flags & PFTS_UNICODE) { -- cgit v1.2.3 From ca3192f3ccce5f59c9fbe58701c48fca557532b7 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 23 Mar 2011 22:43:49 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 2ba305a..a2ca82b 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -449,6 +449,7 @@ int onSendFile(WPARAM w, LPARAM l) if(isContactSecured(ccs->hContact)) { TCHAR **file=(TCHAR **)ccs->lParam; + DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here int i; for(i = 0; file[i]; i++) { -- cgit v1.2.3 From 3d5b89807b16d724a877b305c1bd023e177f92fc Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 24 Mar 2011 02:20:32 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 172 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 101 insertions(+), 71 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index a2ca82b..34307cc 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -440,6 +440,76 @@ int onProtoAck(WPARAM w, LPARAM l) return 0; } +std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) +{ + string out; + DWORD code; + pxResult result; + wstring cmd = _T("--batch --yes -r "); + char *keyid = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) + cmd += _T("--trust-model always "); + TCHAR *szKeyid = mir_a2t(keyid); + TCHAR *name = _tcsrchr(filename,_T('\\')); + if( !name ) + name = filename; + else + name++; + TCHAR *file_out = new TCHAR [_tcslen(filename)+4]; + mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); + cmd += szKeyid; + mir_free(szKeyid); + mir_free(keyid); + cmd += _T(" -o \""); + TCHAR *temp = _tgetenv(_T("TEMP")); + cmd += temp; + cmd += _T("\\"); + cmd += file_out; + wstring path_out = temp; + path_out += _T("\\"); + path_out += file_out; + DeleteFile(path_out.c_str()); + cmd += _T("\" "); + mir_free(temp); + cmd += _T(" -e \""); + cmd += filename; + cmd += _T("\" "); + gpg_execution_params params; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + mir_free(keyid); + delete [] file_out; + boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) + { + delete gpg_thread; + debuglog<timed_join(boost::posix_time::seconds(180))) + { + delete gpg_thread; + debuglog<hContact)) { - TCHAR **file=(TCHAR **)ccs->lParam; + DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here int i; - for(i = 0; file[i]; i++) + if(flags & PFTS_UNICODE) { - if (_tcsstr(file[i],_T(".gpg"))) - continue; - if(_waccess(file[i], 0) == -1) - if(errno == ENOENT) - return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) - TCHAR *name = _tcsrchr(file[i],_T('\\')); - if( !name ) - name = file[i]; - else - name++; - TCHAR *file_out = new TCHAR [_tcslen(file[i])+4]; - mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); - string out; - DWORD code; - pxResult result; - 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); - cmd += szKeyid; - mir_free(szKeyid); - mir_free(keyid); - cmd += _T(" -o \""); - TCHAR *temp = _tgetenv(_T("TEMP")); - cmd += temp; - cmd += _T("\\"); - cmd += file_out; - wstring path_out = temp; - path_out += _T("\\"); - path_out += file_out; - DeleteFile(path_out.c_str()); - cmd += _T("\" "); - mir_free(temp); - cmd += _T(" -e \""); - cmd += file[i]; - cmd += _T("\" "); - gpg_execution_params params; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - mir_free(keyid); - boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) + TCHAR **file=(TCHAR **)ccs->lParam; + for(i = 0; file[i]; i++) { - delete gpg_thread; - debuglog<hContact, file[i]); + mir_free(file[i]); + file[i] = mir_tstrdup(path_out.c_str()); + transfers.push_back(path_out); } - if(out.find("There is no assurance this key belongs to the named user") != string::npos) + } + else + { + char **file = (char**) ccs->lParam; + for(i = 0; file[i]; i++) { - out.clear(); - if(MessageBox(0, _T("We trying to encrypt with untrusted key, do you want to trust this key permanently ?"), _T("Warning"), MB_YESNO) == IDYES) - { - DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 1); - cmd.insert(0, _T("--trust-model always ")); - gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) - { - delete gpg_thread; - debuglog<hContact, tmp); + mir_free(tmp); + char* tmp2 = mir_utf8encodeW(path_out.c_str()); + mir_free(file[i]); + file[i] = tmp2; + transfers.push_back(path_out); + } - mir_free(file[i]); - file[i] = mir_tstrdup(path_out.c_str()); - delete [] file_out; - transfers.push_back(path_out); } } return CallService(MS_PROTO_CHAINSEND, w, l); -- cgit v1.2.3 From c5e0140f26c8f95a1f83f1e2c86e1eb11820e901 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 24 Mar 2011 04:47:22 +0200 Subject: modified: messages.cpp modified: utilities.cpp --- utilities.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 34307cc..e87bb8c 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -231,10 +231,11 @@ int ToggleEncryption(WPARAM w, LPARAM l) if(hcnt) DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", enc?0:1); } + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); } } else - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); + DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", enc?0:1); } void setSrmmIcon(HANDLE hContact); void setClistIcon(HANDLE hContact); -- cgit v1.2.3 From 8174eb73282e177112615c2dd332b69401959764 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 30 Mar 2011 08:51:28 +0300 Subject: one more threading variant (without mutexes) --- utilities.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index e87bb8c..43d5828 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -376,7 +376,7 @@ int onProtoAck(WPARAM w, LPARAM l) params.code = &code; params.result = &result; boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::minutes(10))) + if(!gpg_thread->timed_join(boost::posix_time::minutes(15))) { delete gpg_thread; debuglog<timed_join(boost::posix_time::seconds(10))) + if(!gpg_thread->timed_join(boost::posix_time::seconds(15))) { delete gpg_thread; debuglog< 0 || DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0) > 0) && (_tcslen(key) > 0)) - { - mir_free(key); - return true; + return false; } mir_free(key); - return false; + return true; } bool isContactHaveKey(HANDLE hContact) -- cgit v1.2.3 From 903cf85316f641a2d7fcc7fb87ed75889469d2dc Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 30 Mar 2011 09:36:35 +0300 Subject: some agression ) --- utilities.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 43d5828..8a2fe53 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -379,6 +379,7 @@ int onProtoAck(WPARAM w, LPARAM l) if(!gpg_thread->timed_join(boost::posix_time::minutes(15))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(15))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(180))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(180))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog< Date: Thu, 31 Mar 2011 20:32:41 +0300 Subject: fixed another metacontacts problem, optimized some functions --- utilities.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 8a2fe53..f05ebed 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -975,7 +975,13 @@ void AddHandlers() bool isContactSecured(HANDLE hContact) { - if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) + BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + if(!gpg_enc) + { + hContact = metaGetContact(hContact); + gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + } + if(!gpg_enc) return false; TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); if(!key[0]) -- cgit v1.2.3 From 089c1fb6bcbdb5ea07419486b78da9c3e120ee9c Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 1 Apr 2011 01:28:48 +0300 Subject: ) --- utilities.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index f05ebed..201f359 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -975,12 +975,9 @@ void AddHandlers() bool isContactSecured(HANDLE hContact) { - BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - if(!gpg_enc) - { + if(metaIsProtoMetaContacts(hContact)) hContact = metaGetContact(hContact); - gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - } + BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); if(!gpg_enc) return false; TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); -- cgit v1.2.3 From 8cdda41b119526a2741938d57b7e066e1697315b Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 1 Apr 2011 02:20:17 +0300 Subject: hm )) --- utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 201f359..d368c56 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -396,7 +396,7 @@ int onProtoAck(WPARAM w, LPARAM l) 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()); + DBWriteContactSettingString(metaGetMostOnline(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); } void ShowLoadKeyPasswordWindow(); new_key_hcnt_mutex.lock(); -- cgit v1.2.3