diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-31 01:31:47 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-31 01:31:47 +0300 |
commit | 68706e0c527bc50ada54e3b93a88c5ee3e33b8e2 (patch) | |
tree | bb28935bd5a9b61a122bb72c6eb866619b0fc3c4 /messages.cpp | |
parent | bef8e360e5e40ee4e8648a5c56b2fae3fefb1c0a (diff) |
support password for every KeyID (but only one password in memory at same time)
Diffstat (limited to 'messages.cpp')
-rw-r--r-- | messages.cpp | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/messages.cpp b/messages.cpp index 788c5bc..8a909c1 100644 --- a/messages.cpp +++ b/messages.cpp @@ -19,6 +19,7 @@ wstring new_key; HANDLE new_key_hcnt = NULL; +bool _terminate = false; BOOL isProtoMetaContacts(HANDLE hContact); @@ -57,8 +58,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if((s2 != wstring::npos) && (s1 != wstring::npos)) { //this is public key -/* if(!DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0)) - ; */ + debuglog<<"info: "<<"received key from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n"; void ShowNewKeyDialog(); s1 = 0; while((s1 = str.find(_T("\r"), s1)) != wstring::npos) @@ -91,6 +91,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) bool isContactHaveKey(HANDLE hContact); if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) { + debuglog<<"info: "<<"received message from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" whith tyrned off encryption\n"; 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) { if(!isContactHaveKey(hContact)) @@ -139,11 +140,21 @@ int RecvMsgSvc(WPARAM w, LPARAM l) wstring cmd; cmd += _T("--batch "); { - TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); - if(_tcslen(tmp) > 0) + char *inkeyid = UniGetContactSettingUtf(hContact, szGPGModuleName, "InKeyID", ""); + TCHAR *pass = NULL; + if(strlen(inkeyid) > 0) + { + string dbsetting = "szKey_"; + dbsetting += inkeyid; + dbsetting += "_Password"; + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); + } + else + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); + if(_tcslen(pass) > 0) { cmd += _T("--passphrase \""); - cmd += tmp; + cmd += pass; cmd += _T("\" "); } else if(password) @@ -152,7 +163,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l) cmd += password; cmd += _T("\" "); } - mir_free(tmp); + mir_free(pass); + mir_free(inkeyid); } cmd += _T("--output \""); cmd += tmp2; @@ -179,9 +191,20 @@ int RecvMsgSvc(WPARAM w, LPARAM l) DeleteFile(path.c_str()); return CallService(MS_PROTO_CHAINRECV, w, l); } + _terminate = false; while(out.find("public key decryption failed: bad passphrase") != string::npos) { + 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(hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + } void ShowLoadKeyPasswordWindow(); + new_key_hcnt = hContact; ShowLoadKeyPasswordWindow(); wstring cmd2 = cmd; if(password) @@ -489,11 +512,16 @@ int TestHook(WPARAM w, LPARAM l) static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + HANDLE hContact = new_key_hcnt; TCHAR *tmp = NULL; + char *inkeyid = UniGetContactSettingUtf(hContact, szGPGModuleName, "InKeyID", ""); switch (msg) { case WM_INITDIALOG: { + string questionstr = "Please enter password for key with ID: "; + questionstr += inkeyid; + SetDlgItemTextA(hwndDlg, IDC_KEYID, questionstr.c_str()); TranslateDialogDefault(hwndDlg); return TRUE; } @@ -511,17 +539,30 @@ static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, L { extern TCHAR *password; if(IsDlgButtonChecked(hwndDlg, IDC_SAVE_PASSWORD)) - DBWriteContactSettingTString(NULL, szGPGModuleName, "szKeyPassword", tmp); + { + if(strlen(inkeyid) > 0) + { + string dbsetting = "szKey_"; + dbsetting += inkeyid; + dbsetting += "_Password"; + DBWriteContactSettingTString(NULL, szGPGModuleName, dbsetting.c_str(), tmp); + } + else + DBWriteContactSettingTString(NULL, szGPGModuleName, "szKeyPassword", tmp); + } if(password) delete [] password; password = new TCHAR [_tcslen(tmp)+1]; _tcscpy(password, tmp); } mir_free(tmp); + mir_free(inkeyid); DestroyWindow(hwndDlg); break; } case IDCANCEL: + mir_free(inkeyid); + _terminate = true; DestroyWindow(hwndDlg); break; default: @@ -541,6 +582,7 @@ static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, L } break; case WM_CLOSE: + mir_free(inkeyid); DestroyWindow(hwndDlg); break; case WM_DESTROY: |