From c7417593521a2a96442e97508354e32f502bd931 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 27 Oct 2010 06:31:24 +0300 Subject: random key generation --- commonheaders.h | 4 ++ init.cpp | 2 +- main.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- new_gpg.rc | 15 +++----- new_gpg.sln | 6 +-- resource.h | 3 +- utilities.cpp | 11 ++++++ utilities.h | 1 + 8 files changed, 136 insertions(+), 18 deletions(-) diff --git a/commonheaders.h b/commonheaders.h index 713622f..3670a86 100644 --- a/commonheaders.h +++ b/commonheaders.h @@ -44,6 +44,10 @@ using std::fstream; //boost #include #include +#include +#include +#include + //utf8cpp #include diff --git a/init.cpp b/init.cpp index 137c879..a8fcaf1 100644 --- a/init.cpp +++ b/init.cpp @@ -231,7 +231,7 @@ static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) extern list transfers; extern "C" int __declspec(dllexport) Unload(void) -{ +{ for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) DBDeleteContactSetting(hContact, szGPGModuleName, "KeyID_Prescense"); if(!transfers.empty()) diff --git a/main.cpp b/main.cpp index 27ed44e..898b672 100644 --- a/main.cpp +++ b/main.cpp @@ -218,7 +218,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM DBWriteContactSettingByte(NULL, szGPGModuleName, "FirstRun", 0); { wstring keyinfo = _T("Current private key id: "); - keyinfo += (_tcslen(fp) > 0)?fp:_T("not set"); + keyinfo += (fp[0])?fp:_T("not set"); extern HWND hwndCurKey_p; SetWindowText(hwndCurKey_p, keyinfo.c_str()); } @@ -379,9 +379,113 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM DBDeleteContactSetting(NULL, szGPGModuleName, "KeyType"); ListView_DeleteItem(hwndList, itemnum); break; - } - break; - } + case IDC_GENERATE_RANDOM: + { + 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<> gen(rng, boost::uniform_int<>(0, chars.length()-1)); + for(int i = 0; i < length; ++i) + data += chars[gen()]; + return data; } \ No newline at end of file diff --git a/utilities.h b/utilities.h index 431c567..0971265 100644 --- a/utilities.h +++ b/utilities.h @@ -31,5 +31,6 @@ bool isContactSecured(HANDLE hContact); const bool StriStr(const char *str, const char *substr); string toUTF8(wstring str); wstring toUTF16(string str); +string get_random(int length); #endif -- cgit v1.2.3