summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp191
1 files changed, 189 insertions, 2 deletions
diff --git a/main.cpp b/main.cpp
index 197623f..dd3b39f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -463,7 +463,6 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM
SetWindowText(hwndCurKey_p, path.c_str());
}
}
- bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange");
DestroyWindow(hwndDlg);
break;
}
@@ -574,9 +573,11 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
params.out = &out;
params.code = &code;
params.result = &result;
+ gpg_configured = true;
boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
gpg_thread.~thread();
+ gpg_configured = false;
DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath");
string::size_type p1 = out.find("(GnuPG) ");
if(p1 != string::npos)
@@ -685,9 +686,11 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
params.out = &out;
params.code = &code;
params.result = &result;
+ gpg_configured = true;
boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
gpg_thread.~thread();
+ gpg_configured = false;
DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath");
string::size_type p1 = out.find("(GnuPG) ");
if(p1 != string::npos)
@@ -724,11 +727,195 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
}
mir_free(path);
}
+ gpg_configured = true;
DestroyWindow(hwndDlg);
ShowFirstRunDialog();
- break;
}
+ break;
+ case IDC_GENERATE_RANDOM:
+ {
+ TCHAR tmp[512];
+ GetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp, 512);
+ if(tmp[0])
+ {
+ char *mir_path = new char [MAX_PATH];
+ CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
+ SetCurrentDirectoryA(mir_path);
+ delete [] mir_path;
+ if(_waccess(tmp, 0) == -1)
+ {
+ if(errno == ENOENT)
+ {
+ MessageBox(0, _T("gpg binary does not exists.\nplease choose another location"), _T("Warning"), MB_OK);
+ break;
+ }
+ }
+ }
+ else
+ {
+ MessageBox(0, _T("please choose gpg binary location"), _T("Warning"), MB_OK);
+ break;
+ }
+ {
+ bool bad_version = false;
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp);
+ string out;
+ DWORD code;
+ wstring cmd = _T("--version");
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ gpg_configured = true;
+ boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ gpg_thread.~thread();
+ gpg_configured = false;
+ DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath");
+ string::size_type p1 = out.find("(GnuPG) ");
+ if(p1 != string::npos)
+ {
+ p1 += strlen("(GnuPG) ");
+ if(out[p1] != '1')
+ bad_version = true;
+ }
+ else
+ {
+ bad_version = false;
+ MessageBox(0, _T("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK);
+ }
+ if(bad_version)
+ MessageBox(0, _T("Unsupported gnupg version found, use at you own risk!\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK);
+ }
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp);
+ GetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp, 512);
+ while(tmp[_tcslen(tmp)-1] == '\\')
+ tmp[_tcslen(tmp)-1] = '\0';
+ if(!tmp[0])
+ {
+ MessageBox(0, _T("please set keyring's home directory"), _T("Warning"), MB_OK);
+ break;
+ }
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp);
+ {
+ TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ DWORD dwFileAttr = GetFileAttributes(path);
+ if (dwFileAttr != INVALID_FILE_ATTRIBUTES)
+ {
+ dwFileAttr &=~ FILE_ATTRIBUTE_READONLY;
+ SetFileAttributes(path, dwFileAttr);
+ }
+ mir_free(path);
+ }
+ }
+ {
+ wstring path;
+ { //generating key file
+ TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ path = tmp;
+ mir_free(tmp);
+ path.append(_T("\\new_key"));
+ wfstream f(path.c_str(), std::ios::out);
+ if(!f.is_open())
+ {
+ MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK);
+ break;
+ }
+ f<<"Key-Type: RSA";
+ f<<"\n";
+ f<<"Key-Length: 2048";
+ f<<"\n";
+ f<<"Subkey-Type: RSA";
+ f<<"\n";
+ f<<"Name-Real: ";
+ f<<get_random(6).c_str();
+ f<<"\n";
+ f<<"Name-Email: ";
+ f<<get_random(5).c_str();
+ f<<"@";
+ f<<get_random(5).c_str();
+ f<<".";
+ f<<get_random(3).c_str();
+ f<<"\n";
+ f.close();
+ }
+ { //gpg execution
+ DWORD code;
+ string out;
+ wstring cmd;
+ cmd += _T("--batch --yes --gen-key \"");
+ cmd += path;
+ cmd += _T("\"");
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ gpg_configured = true;
+ boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::minutes(10)))
+ {
+ gpg_thread.~thread();
+ debuglog<<time_str()<<": GPG execution timed out, aborted";
+ gpg_configured = false;
+ break;
+ }
+ gpg_configured = false;
+ if(result == pxNotFound)
+ break;
+ DeleteFile(path.c_str());
+ string::size_type p1 = 0;
+ if((p1 = out.find("key ")) != string::npos)
+ path = toUTF16(out.substr(p1+4, 8));
+ else
+ path.clear();
+ }
+ if(!path.empty())
+ {
+ string out;
+ DWORD code;
+ wstring cmd = _T("--batch -a --export ");
+ cmd += path;
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ gpg_configured = true;
+ boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ debuglog<<time_str()<<"GPG execution timed out, aborted\n";
+ gpg_configured = false;
+ break;
+ }
+ gpg_configured = false;
+ if(result == pxNotFound)
+ break;
+ string::size_type s = 0;
+ while((s = out.find("\r", s)) != string::npos)
+ {
+ out.erase(s, 1);
+ }
+ DBWriteContactSettingString(NULL, szGPGModuleName, "GPGPubKey", out.c_str());
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", path.c_str());
+ extern HWND hwndCurKey_p;
+ SetWindowText(hwndCurKey_p, path.c_str());
+ }
+ }
+ bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange");
+ gpg_configured = true;
+ DestroyWindow(hwndDlg);
+ break;
default:
break;
}