From de218850223808a480c092ced92e3097ae553728 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 17 Aug 2010 18:58:54 +0300 Subject: modified: init.cpp modified: main.cpp modified: messages.cpp modified: new_gpg.rc modified: resource.h --- init.cpp | 4 ++- main.cpp | 2 ++ messages.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- new_gpg.rc | 55 +++++++++++++--------------------- resource.h | 7 +++-- 5 files changed, 126 insertions(+), 40 deletions(-) diff --git a/init.cpp b/init.cpp index b5471d8..97d1db1 100644 --- a/init.cpp +++ b/init.cpp @@ -18,7 +18,7 @@ //global variables bool bAppendTags = false; -TCHAR *inopentag, *inclosetag, *outopentag, *outclosetag; +TCHAR *inopentag = NULL, *inclosetag = NULL, *outopentag = NULL, *outclosetag = NULL, *password = NULL; list Accounts; @@ -185,5 +185,7 @@ extern "C" int __declspec(dllexport) Unload(void) mir_free(inclosetag); mir_free(outopentag); mir_free(outclosetag); + if(password) + delete [] password; return 0; } diff --git a/main.cpp b/main.cpp index f572c90..bb4f88c 100644 --- a/main.cpp +++ b/main.cpp @@ -169,6 +169,8 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM GetDlgItemText(hwndDlg, IDC_KEY_PASSWORD, passwd, 64); if(_tcslen(passwd) > 0) DBWriteContactSettingTString(NULL, szGPGModuleName, "szKeyPassword", passwd); + else + DBDeleteContactSetting(NULL, szGPGModuleName, "szKeyPassword"); DBWriteContactSettingByte(NULL, szGPGModuleName, "FirstRun", 0); DestroyWindow(hwndDlg); break; diff --git a/messages.cpp b/messages.cpp index 5c1159a..5208ffb 100644 --- a/messages.cpp +++ b/messages.cpp @@ -102,9 +102,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l) mir_free(tmp); f.close(); { + extern TCHAR *password; string out; DWORD code; wstring cmd; + cmd += _T("--batch "); { TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); if(_tcslen(tmp) > 0) @@ -113,6 +115,12 @@ int RecvMsgSvc(WPARAM w, LPARAM l) cmd += tmp; cmd += _T("\" "); } + else if(password) + { + cmd += _T("--passphrase \""); + cmd += password; + cmd += _T("\" "); + } mir_free(tmp); } cmd += _T("--output \""); @@ -128,7 +136,25 @@ int RecvMsgSvc(WPARAM w, LPARAM l) DeleteFile(path.c_str()); return CallService(MS_PROTO_CHAINRECV, w, l); } - //MessageBoxA(0, out.c_str(), "out", MB_OK); + if(out.find("public key decryption failed: bad passphrase") != string::npos) + { + void ShowLoadKeyPasswordWindow(); + ShowLoadKeyPasswordWindow(); + if(password) + { + wstring tmp = _T("--passphrase \""); + tmp += password; + tmp += _T("\" "); + cmd.insert(0, tmp); + } + } + out.clear(); + if(pxExecute(&cmd, "", &out, &code) == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + DeleteFile(path.c_str()); + return CallService(MS_PROTO_CHAINRECV, w, l); + } { wstring tmp = tmp2; tmp += _T("\\decrypted_data"); @@ -333,4 +359,72 @@ int HookSendMsg(WPARAM w, LPARAM l) int TestHook(WPARAM w, LPARAM l) { return 0; -} \ No newline at end of file +} + + +static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + TCHAR *tmp = NULL; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDOK: + { + TCHAR tmp[64]; + GetDlgItemText(hwndDlg, IDC_KEY_PASSWORD, tmp, 64); + if(_tcslen(tmp) > 0) + { + extern TCHAR *password; + if(IsDlgButtonChecked(hwndDlg, IDC_SAVE_PASSWORD)) + DBWriteContactSettingTString(NULL, szGPGModuleName, "szKeyPassword", tmp); + if(password) + delete [] password; + password = new TCHAR [_tcslen(tmp)+1]; + _tcscpy(password, tmp); + } + mir_free(tmp); + DestroyWindow(hwndDlg); + break; + } + case IDCANCEL: + DestroyWindow(hwndDlg); + break; + default: + break; + } + + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + break; + + } + return FALSE; +} + +void ShowLoadKeyPasswordWindow() +{ + extern HINSTANCE hInst; + DialogBox(hInst, MAKEINTRESOURCE(IDD_KEY_PASSWD), NULL, DlgProcKeyPassword); +} diff --git a/new_gpg.rc b/new_gpg.rc index 18a593d..511bdc8 100644 --- a/new_gpg.rc +++ b/new_gpg.rc @@ -139,6 +139,18 @@ BEGIN CONTROL "",IDC_EXISTING_KEY_LIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,14,292,113 END +IDD_KEY_PASSWD DIALOGEX 0, 0, 165, 78 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Enter password for your secret key" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "ОК",IDOK,7,57,50,14 + PUSHBUTTON "Отмена",IDCANCEL,108,57,50,14 + EDITTEXT IDC_PASSWORD,13,25,137,14,ES_PASSWORD | ES_AUTOHSCROLL + LTEXT "Password:",IDC_STATIC,14,15,34,8 + CONTROL "Save password to database",IDC_SAVE_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,43,124,10 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -196,6 +208,14 @@ BEGIN TOPMARGIN, 7 BOTTOMMARGIN, 149 END + + IDD_KEY_PASSWD, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 158 + TOPMARGIN, 7 + BOTTOMMARGIN, 71 + END END #endif // APSTUDIO_INVOKED @@ -259,41 +279,6 @@ BEGIN RTEXT "Close:",IDC_STATIC,127,49,23,8 END - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_OPT_GPG, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 279 - TOPMARGIN, 7 - BOTTOMMARGIN, 207 - END - - IDD_OPT_GPG_BIN, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 275 - TOPMARGIN, 7 - BOTTOMMARGIN, 207 - END - - IDD_OPT_GPG_MESSAGES, DIALOG - BEGIN - LEFTMARGIN, 3 - RIGHTMARGIN, 292 - TOPMARGIN, 7 - BOTTOMMARGIN, 234 - END -END -#endif // APSTUDIO_INVOKED - #endif // английский (США) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/resource.h b/resource.h index c8fe011..cefcf3c 100644 --- a/resource.h +++ b/resource.h @@ -11,6 +11,7 @@ #define IDD_NEW_KEY 108 #define IDD_KEY_GEN 109 #define IDD_LOAD_EXISTING_KEY 110 +#define IDD_KEY_PASSWD 111 #define IDC_SET_BIN_PATH 1016 #define IDC_SET_HOME_DIR 1017 #define IDC_BIN_PATH 1018 @@ -25,6 +26,7 @@ #define IDC_KEY_PASSWORD 1025 #define IDC_IN_OPEN_TAG 1025 #define IDC_KEY_PASSWD 1025 +#define IDC_PASSWORD 1025 #define IDC_BUTTON1 1026 #define IDC_SAVE_KEY_BUTTON 1026 #define IDC_GENERATE_KEY 1026 @@ -49,14 +51,15 @@ #define IDC_EXISTING_KEY_LIST 1045 #define IDC_BUTTON2 1046 #define IDC_OTHER 1046 +#define IDC_SAVE_PASSWORD 1047 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 111 +#define _APS_NEXT_RESOURCE_VALUE 112 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1047 +#define _APS_NEXT_CONTROL_VALUE 1048 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif -- cgit v1.2.3