summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-08-31 01:31:47 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2010-08-31 01:31:47 +0300
commit68706e0c527bc50ada54e3b93a88c5ee3e33b8e2 (patch)
treebb28935bd5a9b61a122bb72c6eb866619b0fc3c4
parentbef8e360e5e40ee4e8648a5c56b2fae3fefb1c0a (diff)
support password for every KeyID (but only one password in memory at same time)
-rw-r--r--commonheaders.h1
-rw-r--r--gpg_wrapper.cpp9
-rw-r--r--messages.cpp56
-rw-r--r--new_gpg.rc17
-rw-r--r--resource.h149
5 files changed, 140 insertions, 92 deletions
diff --git a/commonheaders.h b/commonheaders.h
index 24fcb69..e80d81f 100644
--- a/commonheaders.h
+++ b/commonheaders.h
@@ -66,4 +66,5 @@ using std::fstream;
#include "jabber_account.h"
#include "metacontacts.h"
#include "log.h"
+extern logtofile debuglog;
#endif
diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp
index fa8c8f7..e1910af 100644
--- a/gpg_wrapper.cpp
+++ b/gpg_wrapper.cpp
@@ -88,13 +88,16 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD
debuglog<<"in: "<<commandline<<"\n";
- TCHAR chNewEnv[128];
+/* TCHAR chNewEnv[128];
LPTSTR lpszCurrentVariable;
lpszCurrentVariable = (LPTSTR)chNewEnv;
- _tcscpy(lpszCurrentVariable, _T("LANGUAGE=0"));
+ _tcscpy(lpszCurrentVariable, _T("LANGUAGE=0")); */
+
- success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, (LPVOID)chNewEnv, NULL, &sinfo, &pri);
+ setlocale( LC_ALL, "C" );
+// success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, (LPVOID)chNewEnv, NULL, &sinfo, &pri);
+ success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &sinfo, &pri);
if (!success)
{
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:
diff --git a/new_gpg.rc b/new_gpg.rc
index 8bd1dff..73702bf 100644
--- a/new_gpg.rc
+++ b/new_gpg.rc
@@ -142,16 +142,17 @@ 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
+IDD_KEY_PASSWD DIALOGEX 0, 0, 207, 89
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
+ DEFPUSHBUTTON "ÎÊ",IDOK,7,68,50,14
+ PUSHBUTTON "Îòìåíà",IDCANCEL,150,68,50,14
+ EDITTEXT IDC_PASSWORD,13,38,179,14,ES_PASSWORD | ES_AUTOHSCROLL
+ LTEXT "Password:",IDC_STATIC,14,28,34,8
+ CONTROL "Save password to database",IDC_SAVE_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,56,124,10
+ LTEXT "",IDC_KEYID,14,14,179,8
END
@@ -215,9 +216,9 @@ BEGIN
IDD_KEY_PASSWD, DIALOG
BEGIN
LEFTMARGIN, 7
- RIGHTMARGIN, 158
+ RIGHTMARGIN, 200
TOPMARGIN, 7
- BOTTOMMARGIN, 71
+ BOTTOMMARGIN, 82
END
END
#endif // APSTUDIO_INVOKED
diff --git a/resource.h b/resource.h
index 13531c2..4584b95 100644
--- a/resource.h
+++ b/resource.h
@@ -1,74 +1,75 @@
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by new_gpg.rc
-//
-#define IDD_LOAD_PUBLIC_KEY 102
-#define IDD_FIRST_RUN 103
-#define IDD_OPT_GPG 104
-#define IDD_OPT_GPG_BIN 105
-#define IDD_BIN_PATH 106
-#define IDD_OPT_GPG_MESSAGES 107
-#define IDD_NEW_KEY 108
-#define IDD_KEY_GEN 109
-#define IDD_LOAD_EXISTING_KEY 110
-#define IDD_KEY_PASSWD 111
-#define IDI_SECURED 112
-#define IDI_UNSECURED 113
-#define IDC_SET_BIN_PATH 1016
-#define IDC_SET_HOME_DIR 1017
-#define IDC_BIN_PATH 1018
-#define IDC_HOME_DIR 1019
-#define IDC_USERLIST 1020
-#define IDC_LOAD_KEY_BUTTON 1022
-#define ID_OK 1023
-#define ID_LOD_FROM_FILE 1024
-#define ID_LOAD_FROM_FILE 1024
-#define IDC_EDIT1 1025
-#define IDC_PUBLIC_KEY_EDIT 1025
-#define IDC_KEY_PASSWORD 1025
-#define IDC_IN_OPEN_TAG 1025
-#define IDC_KEY_PASSWD 1025
-#define IDC_PASSWORD 1025
-#define IDC_LOG_FILE_EDIT 1025
-#define IDC_BUTTON1 1026
-#define IDC_SAVE_KEY_BUTTON 1026
-#define IDC_GENERATE_KEY 1026
-#define IDC_IGNORE_KEY 1026
-#define IDC_SELECT_EXISTING 1026
-#define IDC_KEY_EMAIL 1026
-#define IDC_DELETE_KEY_BUTTON 1027
-#define IDC_IN_CLOSE_TAG 1027
-#define IDC_KEY_REAL_NAME 1027
-#define IDC_KEY_LIST 1028
-#define IDC_KEY_COMMENT 1028
-#define IDC_OUT_OPEN_TAG 1029
-#define IDC_APPEND_TAGS 1030
-#define IDC_OUT_CLOSE_TAG 1031
-#define IDC_SELECT_KEY 1033
-#define IDC_MESSAGE 1034
-#define ID_IMPORT 1035
-#define IDC_IMPORT_AND_USE 1036
-#define IDC_KEY_TYPE 1039
-#define IDC_KEY_LENGTH 1040
-#define IDC_KEY_EXPIRE_DATE 1043
-#define IDC_EXISTING_KEY_LIST 1045
-#define IDC_BUTTON2 1046
-#define IDC_OTHER 1046
-#define IDC_LOG_FILE_SET 1046
-#define IDC_SAVE_PASSWORD 1047
-#define IDC_DEBUG_LOG 1048
-#define IDC_JABBER_API 1049
-#define IDC_ENABLE_ENCRYPTION 1050
-#define IDC_KEY_FROM 1051
-#define IDC_DELETE_KEY 1052
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 114
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1053
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by new_gpg.rc
+//
+#define IDD_LOAD_PUBLIC_KEY 102
+#define IDD_FIRST_RUN 103
+#define IDD_OPT_GPG 104
+#define IDD_OPT_GPG_BIN 105
+#define IDD_BIN_PATH 106
+#define IDD_OPT_GPG_MESSAGES 107
+#define IDD_NEW_KEY 108
+#define IDD_KEY_GEN 109
+#define IDD_LOAD_EXISTING_KEY 110
+#define IDD_KEY_PASSWD 111
+#define IDI_SECURED 112
+#define IDI_UNSECURED 113
+#define IDC_SET_BIN_PATH 1016
+#define IDC_SET_HOME_DIR 1017
+#define IDC_BIN_PATH 1018
+#define IDC_HOME_DIR 1019
+#define IDC_USERLIST 1020
+#define IDC_LOAD_KEY_BUTTON 1022
+#define ID_OK 1023
+#define ID_LOD_FROM_FILE 1024
+#define ID_LOAD_FROM_FILE 1024
+#define IDC_EDIT1 1025
+#define IDC_PUBLIC_KEY_EDIT 1025
+#define IDC_KEY_PASSWORD 1025
+#define IDC_IN_OPEN_TAG 1025
+#define IDC_KEY_PASSWD 1025
+#define IDC_PASSWORD 1025
+#define IDC_LOG_FILE_EDIT 1025
+#define IDC_BUTTON1 1026
+#define IDC_SAVE_KEY_BUTTON 1026
+#define IDC_GENERATE_KEY 1026
+#define IDC_IGNORE_KEY 1026
+#define IDC_SELECT_EXISTING 1026
+#define IDC_KEY_EMAIL 1026
+#define IDC_DELETE_KEY_BUTTON 1027
+#define IDC_IN_CLOSE_TAG 1027
+#define IDC_KEY_REAL_NAME 1027
+#define IDC_KEY_LIST 1028
+#define IDC_KEY_COMMENT 1028
+#define IDC_OUT_OPEN_TAG 1029
+#define IDC_APPEND_TAGS 1030
+#define IDC_OUT_CLOSE_TAG 1031
+#define IDC_SELECT_KEY 1033
+#define IDC_MESSAGE 1034
+#define ID_IMPORT 1035
+#define IDC_IMPORT_AND_USE 1036
+#define IDC_KEY_TYPE 1039
+#define IDC_KEY_LENGTH 1040
+#define IDC_KEY_EXPIRE_DATE 1043
+#define IDC_EXISTING_KEY_LIST 1045
+#define IDC_BUTTON2 1046
+#define IDC_OTHER 1046
+#define IDC_LOG_FILE_SET 1046
+#define IDC_SAVE_PASSWORD 1047
+#define IDC_DEBUG_LOG 1048
+#define IDC_JABBER_API 1049
+#define IDC_ENABLE_ENCRYPTION 1050
+#define IDC_KEY_FROM 1051
+#define IDC_DELETE_KEY 1052
+#define IDC_KEYID 1053
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 114
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1054
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif