summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp54
-rw-r--r--messages.cpp23
-rw-r--r--new_gpg.rc9
-rw-r--r--options.cpp4
-rw-r--r--resource.h3
-rw-r--r--utilities.cpp34
6 files changed, 92 insertions, 35 deletions
diff --git a/main.cpp b/main.cpp
index 7b743e5..b11b969 100644
--- a/main.cpp
+++ b/main.cpp
@@ -159,12 +159,23 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM
ShowKeyGenDialog();
break;
case ID_OK:
- ListView_GetItemText(hwndList, itemnum, 0, fp, 16);
{
+ ListView_GetItemText(hwndList, itemnum, 0, fp, 16);
+ TCHAR *name = new TCHAR [64];
+ ListView_GetItemText(hwndList, itemnum, 2, name, 64);
+ {
+ if(_tcschr(name, _T('(')))
+ {
+ wstring str = name;
+ wstring::size_type p = str.find(_T("("))-1;
+ _tcscpy(name, str.substr(0, p).c_str());
+ }
+ }
string out;
DWORD code;
- wstring cmd = _T("--batch -a --export ");
- cmd += fp;
+ wstring cmd = _T("--batch -a --export \"");
+ cmd += name;
+ cmd += _T("\"");
gpg_execution_params params;
pxResult result;
params.cmd = &cmd;
@@ -189,22 +200,23 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM
out.erase(s, 1);
}
DBWriteContactSettingString(NULL, szGPGModuleName, "GPGPubKey", out.c_str());
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyMainName", name);
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", fp);
+ TCHAR passwd[64];
+ 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);
+ {
+ wstring keyinfo = _T("Current private key id: ");
+ keyinfo += (_tcslen(fp) > 0)?fp:_T("not set");
+ extern HWND hwndCurKey_p;
+ SetWindowText(hwndCurKey_p, keyinfo.c_str());
+ }
+ delete [] name;
}
- DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", fp);
- TCHAR passwd[64];
- 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);
- {
- wstring keyinfo = _T("Current private key id: ");
- keyinfo += (_tcslen(fp) > 0)?fp:_T("not set");
- extern HWND hwndCurKey_p;
- SetWindowText(hwndCurKey_p, keyinfo.c_str());
- }
-
DestroyWindow(hwndDlg);
break;
case IDC_OTHER:
@@ -611,6 +623,12 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
delete [] tmp;
break;
}
+ else if (_tcschr(tmp, _T('(')) || _tcschr(tmp, _T(')')))
+ {
+ MessageBox(0, _T("Name cannot contain '(' or ')'"), _T("Error"), MB_OK);
+ delete [] tmp;
+ break;
+ }
delete [] tmp;
tmp = new TCHAR [128];
GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128);
diff --git a/messages.cpp b/messages.cpp
index 46e54ad..f4e9ad6 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -132,6 +132,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
wstring path = tmp2;
path.append(_T("\\encrypted_data.asc"));
+ DeleteFile(path.c_str());
wfstream f(path.c_str(), std::ios::out);
f<<tmp;
mir_free(tmp);
@@ -151,26 +152,38 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
dbsetting += inkeyid;
dbsetting += "_Password";
pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T(""));
+ if(_tcslen(pass) > 0)
+ debuglog<<"info: found password in database for key id: "<<inkeyid<<", trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n";
}
else
+ {
pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
+ if(_tcslen(pass) > 0)
+ debuglog<<"info: found password for all keys in database, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n";
+ }
if(_tcslen(pass) > 0)
{
- debuglog<<"info: found password in database, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n";
cmd += _T("--passphrase \"");
cmd += pass;
cmd += _T("\" ");
}
else if(password)
{
- debuglog<<"info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n";
+ debuglog<<"info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n";
cmd += _T("--passphrase \"");
cmd += password;
cmd += _T("\" ");
}
+ else
+ debuglog<<"info: passwords not found in database or memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with out password\n";
mir_free(pass);
mir_free(inkeyid);
}
+ {
+ wstring path = tmp2;
+ path += _T("\\decrypted_data");
+ DeleteFile(path.c_str());
+ }
cmd += _T("--output \"");
cmd += tmp2;
cmd += _T("\\decrypted_data\"");
@@ -529,10 +542,11 @@ static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, L
{
case WM_INITDIALOG:
{
+ TranslateDialogDefault(hwndDlg);
string questionstr = "Please enter password for key with ID: ";
questionstr += inkeyid;
SetDlgItemTextA(hwndDlg, IDC_KEYID, questionstr.c_str());
- TranslateDialogDefault(hwndDlg);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_PASSWORD), 0);
return TRUE;
}
@@ -550,7 +564,7 @@ static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, L
extern TCHAR *password;
if(IsDlgButtonChecked(hwndDlg, IDC_SAVE_PASSWORD))
{
- if(strlen(inkeyid) > 0)
+ if((strlen(inkeyid) > 0) && !IsDlgButtonChecked(hwndDlg, IDC_DEFAULT_PASSWORD))
{
string dbsetting = "szKey_";
dbsetting += inkeyid;
@@ -587,6 +601,7 @@ static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, L
switch (((LPNMHDR)lParam)->code)
{
default:
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_PASSWORD), IsDlgButtonChecked(hwndDlg, IDC_SAVE_PASSWORD)?1:0);
break;
}
}
diff --git a/new_gpg.rc b/new_gpg.rc
index 026d987..3c8d960 100644
--- a/new_gpg.rc
+++ b/new_gpg.rc
@@ -142,17 +142,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, 207, 89
+IDD_KEY_PASSWD DIALOGEX 0, 0, 207, 108
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,68,50,14
- PUSHBUTTON "Îòìåíà",IDCANCEL,150,68,50,14
+ DEFPUSHBUTTON "ÎÊ",IDOK,7,87,50,14
+ PUSHBUTTON "Îòìåíà",IDCANCEL,150,87,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
+ CONTROL "Default password",IDC_DEFAULT_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,67,151,10
END
@@ -218,7 +219,7 @@ BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 200
TOPMARGIN, 7
- BOTTOMMARGIN, 82
+ BOTTOMMARGIN, 101
END
END
#endif // APSTUDIO_INVOKED
diff --git a/options.cpp b/options.cpp
index 161a5e5..0c19b60 100644
--- a/options.cpp
+++ b/options.cpp
@@ -945,9 +945,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
}
if(!hContact)
{
- char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
- TCHAR *fp = mir_a2t(tmp);
- mir_free(tmp);
+ TCHAR *fp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", _T(""));
{
string out;
DWORD code;
diff --git a/resource.h b/resource.h
index 067972b..ce35553 100644
--- a/resource.h
+++ b/resource.h
@@ -63,6 +63,7 @@
#define IDC_DELETE_KEY 1052
#define IDC_KEYID 1053
#define IDC_CURRENT_KEY 1054
+#define IDC_DEFAULT_PASSWORD 1055
// Next default values for new objects
//
@@ -70,7 +71,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 114
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1055
+#define _APS_NEXT_CONTROL_VALUE 1056
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/utilities.cpp b/utilities.cpp
index 03cb2c4..5f1ad0a 100644
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -45,7 +45,8 @@ char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,co
char *date()
{
- static char d[11];
+ setlocale( LC_ALL, "C" );
+ static char d[11];
char *tmp = __DATE__, m[4], mn[3] = "01";
m[0]=tmp[0];
m[1]=tmp[1];
@@ -402,6 +403,9 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
wstring path_out = path_c;
mir_free(path_c);
path_out += _T("\\prescense_text");
+ {
+ DeleteFile(path_out.c_str());
+ }
wfstream f(path_out.c_str(), std::ios::out);
char *tmp = mir_utf8encodeW(str);
f<<tmp;
@@ -413,20 +417,40 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
DWORD code;
wstring cmd;
{
- TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
- if(_tcslen(tmp) > 0)
+ char *inkeyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", "");
+ TCHAR *pass = NULL;
+ if(strlen(inkeyid) > 0)
+ {
+ string dbsetting = "szKey_";
+ dbsetting += inkeyid;
+ dbsetting += "_Password";
+ pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T(""));
+ if(_tcslen(pass) > 0)
+ debuglog<<"info: found password in database for key id: "<<inkeyid<<", trying to encrypt message from self with password\n";
+ }
+ else
+ {
+ pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
+ if(_tcslen(pass) > 0)
+ debuglog<<"info: found password for all keys in database, trying to encrypt message from self with password\n";
+ }
+ if(_tcslen(pass) > 0)
{
cmd += _T("--passphrase \"");
- cmd += tmp;
+ cmd += pass;
cmd += _T("\" ");
}
else if(password)
{
+ debuglog<<"info: found password in memory, trying to encrypt message from self with password\n";
cmd += _T("--passphrase \"");
cmd += password;
cmd += _T("\" ");
}
- mir_free(tmp);
+ else
+ debuglog<<"info: passwords not found in database or memory, trying to encrypt message from self with out password\n";
+ mir_free(pass);
+ mir_free(inkeyid);
}
cmd += _T("--default-key ");
path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T(""));