summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp194
-rw-r--r--new_gpg.rc18
-rw-r--r--options.cpp83
-rw-r--r--resource.h8
4 files changed, 271 insertions, 32 deletions
diff --git a/main.cpp b/main.cpp
index 9921b65..8db3d14 100644
--- a/main.cpp
+++ b/main.cpp
@@ -30,7 +30,7 @@ void test()
}
-HWND hwndFirstRun = NULL, hwndSetDirs = NULL, hwndNewKey = NULL, hwndKeyGen = NULL;
+HWND hwndFirstRun = NULL, hwndSetDirs = NULL, hwndNewKey = NULL, hwndKeyGen = NULL, hwndSelectExistingKey = NULL;
int itemnum = 0;
@@ -598,6 +598,188 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
return FALSE;
}
+int itemnum2 = 0;
+
+static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
+{
+ HWND hwndList=GetDlgItem(hwndDlg, IDC_EXISTING_KEY_LIST);
+ hwndList_g = hwndList;
+ LVCOLUMN col = {0};
+ LVITEM item = {0};
+ NMLISTVIEW * hdr = (NMLISTVIEW *) lParam;
+ TCHAR id[16] = {0};
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwndDlg);
+ col.pszText = _T("Key ID");
+ col.mask = LVCF_TEXT | LVCF_WIDTH;
+ col.fmt = LVCFMT_LEFT;
+ col.cx = 50;
+ ListView_InsertColumn(hwndList, 0, &col);
+ ZeroMemory(&col,sizeof(col));
+ col.pszText = _T("Email");
+ col.mask = LVCF_TEXT | LVCF_WIDTH;
+ col.fmt = LVCFMT_LEFT;
+ col.cx = 30;
+ ListView_InsertColumn(hwndList, 1, &col);
+ ZeroMemory(&col,sizeof(col));
+ col.pszText = _T("Name");
+ col.mask = LVCF_TEXT | LVCF_WIDTH;
+ col.fmt = LVCFMT_LEFT;
+ col.cx = 250;
+ ListView_InsertColumn(hwndList, 2, &col);
+ ZeroMemory(&col,sizeof(col));
+ col.pszText = _T("Creation date");
+ col.mask = LVCF_TEXT | LVCF_WIDTH;
+ col.fmt = LVCFMT_LEFT;
+ col.cx = 30;
+ ListView_InsertColumn(hwndList, 3, &col);
+ ZeroMemory(&col,sizeof(col));
+ col.pszText = _T("Key length");
+ col.mask = LVCF_TEXT | LVCF_WIDTH;
+ col.fmt = LVCFMT_LEFT;
+ col.cx = 30;
+ ListView_InsertColumn(hwndList, 4, &col);
+ ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT);
+ int i = 1, iRow = 0;
+ {
+ item.mask = LVIF_TEXT;
+ item.iItem = i;
+ item.iSubItem = 0;
+ item.pszText = _T("");
+ {//parse gpg output
+ string out;
+ DWORD code;
+ string::size_type p = 0, p2 = 0, stop = 0;
+ {
+ wstring cmd = _T("--list-secret-keys");
+ if(pxExecute(&cmd, "", &out, &code) == pxNotFound)
+ {
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
+ break;
+ }
+ }
+ cp866_to_cp1251(&out);
+ while(p != string::npos)
+ {
+ if((p = out.find("sec ", p)) == string::npos)
+ break;
+ p += 5;
+ if(p < stop)
+ break;
+ stop = p;
+ p2 = out.find("/", p) - 1;
+ TCHAR *tmp = mir_a2t(out.substr(p,p2-p).c_str());
+ item.pszText = tmp;
+ iRow = ListView_InsertItem(hwndList, &item);
+ ListView_SetItemText(hwndList, iRow, 4, tmp);
+ mir_free(tmp);
+ p2+=2;
+ p = out.find(" ", p2);
+ tmp = mir_a2t(out.substr(p2,p-p2).c_str());
+ ListView_SetItemText(hwndList, iRow, 0, tmp);
+ mir_free(tmp);
+ p = out.find("uid ", p);
+ p2 = out.find_first_not_of(" ", p+5);
+ p = out.find("<", p2);
+ tmp = mir_a2t(out.substr(p2,p-p2).c_str());
+ ListView_SetItemText(hwndList, iRow, 2, tmp);
+ mir_free(tmp);
+ p++;
+ p2 = out.find(">", p);
+ tmp = mir_a2t(out.substr(p,p2-p).c_str());
+ ListView_SetItemText(hwndList, iRow, 1, tmp);
+ mir_free(tmp);
+ p = out.find("ssb ", p2) + 6;
+ p = out.find(" ", p) + 1;
+ p2 = out.find("\n", p);
+ tmp = mir_a2t(out.substr(p,p2-p-1).c_str());
+ ListView_SetItemText(hwndList, iRow, 3, tmp);
+ mir_free(tmp);
+ i++;
+ }
+ }
+ ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this
+ ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE);
+ ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE);
+ ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE);
+ ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE);
+ }
+ return TRUE;
+ }
+
+
+ case WM_COMMAND:
+ {
+ switch (LOWORD(wParam))
+ {
+ case IDOK:
+ {
+ ListView_GetItemText(hwndList, itemnum2, 0, id, 16);
+ extern HWND hPubKeyEdit;
+ string out;
+ DWORD code;
+ wstring cmd = _T("--export -a ");
+ cmd += id;
+ if(pxExecute(&cmd, "", &out, &code) == pxNotFound)
+ {
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
+ break;
+ }
+ string::size_type s = 0;
+ while((s = out.find("\r", s)) != string::npos)
+ {
+ out.erase(s, 1);
+ }
+ TCHAR *tmp = mir_a2t(out.c_str());
+// SetDlgItemText(hPubKeyEdit, IDC_PUBLIC_KEY_EDIT, tmp);
+ SetWindowText(hPubKeyEdit, tmp);
+ mir_free(tmp);
+ }
+ DestroyWindow(hwndDlg);
+ break;
+ case IDCANCEL:
+ DestroyWindow(hwndDlg);
+ break;
+ }
+ break;
+ }
+
+ case WM_NOTIFY:
+ {
+ if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1))
+ {
+ if(hdr->hdr.code == LVN_ITEMCHANGED)
+ {
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), 1);
+ itemnum2 = hdr->iItem;
+ }
+ }
+
+ switch (((LPNMHDR)lParam)->code)
+ {
+
+ case PSN_APPLY:
+ {
+ return TRUE;
+ }
+ }
+ }
+ break;
+ case WM_CLOSE:
+ DestroyWindow(hwndDlg);
+ break;
+ case WM_DESTROY:
+ hwndSelectExistingKey = NULL;
+ break;
+
+ }
+
+ return FALSE;
+}
+
extern HINSTANCE hInst;
@@ -636,6 +818,16 @@ void ShowKeyGenDialog()
SetForegroundWindow(hwndKeyGen);
}
+void ShowSelectExistingKeyDialog()
+{
+ if (hwndSelectExistingKey == NULL)
+ {
+ hwndSelectExistingKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_LOAD_EXISTING_KEY), NULL, DlgProcLoadExistingKey);
+ }
+ SetForegroundWindow(hwndSelectExistingKey);
+}
+
+
diff --git a/new_gpg.rc b/new_gpg.rc
index e64a3dc..465aed8 100644
--- a/new_gpg.rc
+++ b/new_gpg.rc
@@ -126,6 +126,16 @@ BEGIN
LTEXT "From 1024 to 4096",IDC_STATIC,113,33,62,8
END
+IDD_LOAD_EXISTING_KEY DIALOGEX 0, 0, 316, 156
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+CAPTION "Select existing public key from list"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "ÎÊ",IDOK,7,135,50,14,WS_DISABLED
+ PUSHBUTTON "Îòìåíà",IDCANCEL,259,135,50,14
+ CONTROL "",IDC_EXISTING_KEY_LIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,14,292,113
+END
+
/////////////////////////////////////////////////////////////////////////////
//
@@ -175,6 +185,14 @@ BEGIN
TOPMARGIN, 7
BOTTOMMARGIN, 159
END
+
+ IDD_LOAD_EXISTING_KEY, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 309
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 149
+ END
END
#endif // APSTUDIO_INVOKED
diff --git a/options.cpp b/options.cpp
index d1c26e2..989b443 100644
--- a/options.cpp
+++ b/options.cpp
@@ -78,7 +78,7 @@ int GpgOptInit(WPARAM wParam,LPARAM lParam)
return 0;
}
-static HWND hwndLoadPublicKey = NULL;
+HWND hwndLoadPublicKey = NULL;
map<int, HANDLE> user_data;
@@ -229,6 +229,7 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyType");
DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyMainEmail");
DBDeleteContactSetting(user_data[item_num+1], szModuleName, "KeyComment");
+ ListView_SetItemText(hwndList, item_num, 3, _T("not set"));
ListView_SetItemText(hwndList, item_num, 2, _T("not set"));
ListView_SetItemText(hwndList, item_num, 1, _T("not set"));
break;
@@ -441,6 +442,7 @@ static BOOL CALLBACK DlgProcGpgMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
return FALSE;
}
+HWND hPubKeyEdit = NULL;
static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
@@ -457,6 +459,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
TranslateDialogDefault(hwndDlg);
tmp = UniGetContactSettingUtf(hContact, szModuleName, "GPGPubKey", _T(""));
SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, (_tcslen(tmp) > 1)?tmp:_T(""));
+ hPubKeyEdit = GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT);
return TRUE;
}
@@ -485,7 +488,6 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
DBWriteContactSettingTString(hContact, szModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str());
tmp = new TCHAR [key_buf.length()+1];
_tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str());
- ListView_SetItemText(hwndList_p, item_num, 2, tmp);
{ //gpg execute block
wstring cmd;
TCHAR tmp2[MAX_PATH] = {0};
@@ -523,17 +525,26 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
cp866_to_cp1251(&output);
DBDeleteContactSetting(user_data[item_num+1], szModuleName, "bAlwatsTrust");
{
+ TCHAR *tmp;
string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
string::size_type s2 = output.find(":", s);
DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyID", output.substr(s,s2-s).c_str());
+ tmp = mir_a2t(output.substr(s,s2-s).c_str());
+ ListView_SetItemText(hwndList_p, item_num, 1, tmp);
+ mir_free(tmp);
s2+=2;
s = output.find("\"", s2)-1;
if(s != s2-1)
+ {
DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyType", output.substr(s2,s-s2).c_str());
+ }
s+=2;
if((s2 = output.find("(", s)) == string::npos)
s2 = output.find("<", s);
DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str());
+ tmp = mir_a2t(output.substr(s,s2-s-1).c_str());
+ ListView_SetItemText(hwndList_p, item_num, 2, tmp);
+ mir_free(tmp);
if((s = output.find(")", s2)) == string::npos)
s = output.find(">", s2);
s2++;
@@ -543,9 +554,17 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
s+=3;
s2 = output.find(">", s);
DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str());
+ tmp = mir_a2t(output.substr(s,s2-s).c_str());
+ ListView_SetItemText(hwndList_p, item_num, 3, tmp);
+ mir_free(tmp);
}
else
+ {
DBWriteContactSettingString(user_data[item_num+1], szModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str());
+ tmp = mir_a2t(output.substr(s2,s-s2).c_str());
+ ListView_SetItemText(hwndList_p, item_num, 3, tmp);
+ mir_free(tmp);
+ }
}
MessageBoxA(0, output.c_str(), "", MB_OK);
DeleteFile(tmp2);
@@ -555,35 +574,41 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
DestroyWindow(hwndDlg);
break;
case ID_LOAD_FROM_FILE:
- tmp = GetFilePath(_T("Set file containing GPG public key"), _T("*"), _T("GPG public key file"));
- if(!tmp)
- {
- break;
- }
- wfstream f(tmp, std::ios::in);
- delete [] tmp;
- if(!f.is_open())
- {
- MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK);
- break;
- }
- while(!f.eof())
{
- tmp = new TCHAR [1024];
- f.getline(tmp, 1024, '\n');
- key_buf.append(tmp);
- key_buf.append(_T("\n"));
+ tmp = GetFilePath(_T("Set file containing GPG public key"), _T("*"), _T("GPG public key file"));
+ if(!tmp)
+ {
+ break;
+ }
+ wfstream f(tmp, std::ios::in);
delete [] tmp;
+ if(!f.is_open())
+ {
+ MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK);
+ break;
+ }
+ while(!f.eof() && f.is_open())
+ {
+ tmp = new TCHAR [1024];
+ f.getline(tmp, 1024, '\n');
+ key_buf.append(tmp);
+ key_buf.append(_T("\n"));
+ delete [] tmp;
+ }
+ f.close();
+ if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) == wstring::npos) || ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) == wstring::npos))
+ {
+ MessageBox(0, _T("This is not public key"), _T("INFO"), MB_OK);
+ break;
+ }
+ ws2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----"));
+ SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, key_buf.substr(ws1,ws2-ws1).c_str());
+ key_buf.clear();
}
- f.close();
- if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) == wstring::npos) || ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) == wstring::npos))
- {
- MessageBox(0, _T("This is not public key"), _T("INFO"), MB_OK);
- break;
- }
- ws2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----"));
- SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, key_buf.substr(ws1,ws2-ws1).c_str());
- key_buf.clear();
+ break;
+ case IDC_SELECT_EXISTING:
+ void ShowSelectExistingKeyDialog();
+ ShowSelectExistingKeyDialog();
break;
}
break;
@@ -613,6 +638,8 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
return FALSE;
}
+
+
void ShowLoadPublicKeyDialog()
{
if (hwndLoadPublicKey == NULL)
diff --git a/resource.h b/resource.h
index 4e6dd17..b934c1d 100644
--- a/resource.h
+++ b/resource.h
@@ -10,6 +10,7 @@
#define IDD_OPT_GPG_MESSAGES 107
#define IDD_NEW_KEY 108
#define IDD_KEY_GEN 109
+#define IDD_LOAD_EXISTING_KEY 110
#define IDC_SET_BIN_PATH 1016
#define IDC_SET_HOME_DIR 1017
#define IDC_BIN_PATH 1018
@@ -45,15 +46,16 @@
#define IDC_KEY_TYPE 1039
#define IDC_KEY_LENGTH 1040
#define IDC_KEY_EXPIRE_DATE 1043
-#define IDC_EDIT2 1044
+#define IDC_LIST1 1045
+#define IDC_EXISTING_KEY_LIST 1045
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 110
+#define _APS_NEXT_RESOURCE_VALUE 111
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1045
+#define _APS_NEXT_CONTROL_VALUE 1046
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif