Browse Source

merging in COM-115

COM-121
Volker Birk 2 years ago
parent
commit
4cbd6405fe
17 changed files with 545 additions and 69 deletions
  1. +157
    -0
      CMainWindow.cpp
  2. +33
    -0
      CMainWindow.h
  3. +68
    -29
      CpEpEngine.cpp
  4. +11
    -18
      CpEpEngine.h
  5. +55
    -8
      GateKeeper.cpp
  6. +7
    -1
      GateKeeper.h
  7. +10
    -0
      LocalJSONAdapter.cpp
  8. +16
    -0
      LocalJSONAdapter.h
  9. BIN
      logo.ico
  10. +84
    -3
      pEpCOMServerAdapter.cpp
  11. +12
    -0
      pEpCOMServerAdapter.idl
  12. BIN
      pEpCOMServerAdapter.rc
  13. +40
    -4
      pEpCOMServerAdapter.vcxproj
  14. +21
    -0
      pEpCOMServerAdapter.vcxproj.filters
  15. +10
    -0
      packages.config
  16. BIN
      resource.h
  17. +21
    -6
      stdafx.h

+ 157
- 0
CMainWindow.cpp View File

@ -0,0 +1,157 @@
#include "stdafx.h"
#include "CMainWindow.h"
#include "GateKeeper.h"
static const GUID nidGUID =
{ 0xa4dbdbe1, 0x4051, 0x4d89, { 0xb1, 0x17, 0x62, 0x82, 0x18, 0x5a, 0x61, 0x5c } };
CMainWindow::CMainWindow() :
_schedule_updates(true), CWindowImpl<CMainWindow>()
{
ULONG ulNumLanguages = 0;
PZZWSTR pwszLanguagesBuffer = NULL;
ULONG pcchLanguagesBuffer = 0;
BOOL bResult = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, NULL, &pcchLanguagesBuffer);
assert(bResult);
pwszLanguagesBuffer = new WCHAR[pcchLanguagesBuffer];
bResult = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, pwszLanguagesBuffer, &pcchLanguagesBuffer);
assert(bResult);
bResult = SetProcessPreferredUILanguages(MUI_LANGUAGE_NAME, pwszLanguagesBuffer, &ulNumLanguages);
assert(bResult);
delete[] pwszLanguagesBuffer;
}
LRESULT CMainWindow::OnCreate(UINT, WPARAM, LPARAM, BOOL&)
{
// remove leftoff before creating a new one
BOOL _b;
OnDestroy(0, 0, 0, _b);
NOTIFYICONDATA nid = {};
nid.cbSize = sizeof(nid);
nid.uFlags = NIF_ICON | NIF_TIP | NIF_GUID | NIF_MESSAGE;
nid.hWnd = m_hWnd;
nid.guidItem = nidGUID;
StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), r(IDS_PROJNAME).c_str());
nid.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LOGO));
nid.uCallbackMessage = WM_PEP_NOTIFICATION;
Shell_NotifyIcon(NIM_ADD, &nid);
nid = {};
nid.cbSize = sizeof(nid);
nid.uVersion = NOTIFYICON_VERSION_4;
Shell_NotifyIcon(NIM_SETVERSION, &nid);
return S_OK;
}
LRESULT CMainWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&)
{
NOTIFYICONDATA nid = {};
nid.cbSize = sizeof(nid);
nid.uFlags = NIF_ICON | NIF_GUID;
nid.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LOGO));
nid.guidItem = nidGUID;
Shell_NotifyIcon(NIM_DELETE, &nid);
return S_OK;
}
LRESULT CMainWindow::OnNotification(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
auto event = LOWORD(lParam);
auto icon_id = HIWORD(lParam);
auto x = GET_X_LPARAM(wParam);
auto y = GET_Y_LPARAM(wParam);
HMENU menuContext;
HMENU _menuContext = NULL;
MENUINFO info;
BOOL enabled;
switch (event) {
case WM_CONTEXTMENU:
case WM_RBUTTONDOWN:
menuContext = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_POPUPMENU));
info = {};
info.cbSize = sizeof(info);
info.fMask = MIM_APPLYTOSUBMENUS | MIM_STYLE;
info.dwStyle = MNS_AUTODISMISS | MNS_NOTIFYBYPOS;
SetMenuInfo(menuContext, &info);
_menuContext = GetSubMenu(menuContext, 0);
enabled = pEp::GateKeeper::gatekeeper()->update_enabled();
CheckMenuItem(_menuContext, ID_POPUP_SCHEDULEUPDATES, enabled ? MF_CHECKED : MF_UNCHECKED);
SetForegroundWindow(m_hWnd); // this is utter nonsense, but required by TrackPopupMenuEx
POINT point;
GetCursorPos(&point);
TrackPopupMenuEx(_menuContext, TPM_LEFTALIGN | TPM_BOTTOMALIGN, point.x, point.y, m_hWnd, NULL);
PostMessage(WM_NULL, 0, 0); // this is utter nonsense, but required by TrackPopupMenuEx
DestroyMenu(menuContext);
bHandled = true;
break;
default:
bHandled = false;
}
return S_OK;
}
static const auto UPDATE_NOW = 0;
static const auto SCHEDULE_UPDATES = 2;
LRESULT CMainWindow::OnMenuCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
auto index = wParam;
HMENU hMenu = (HMENU)lParam;
BOOL enabled;
switch (index) {
case UPDATE_NOW:
ShowNotificationInfo(r(IDS_UPDATESTITLE), r(IDS_UPDATESTEXT));
pEp::GateKeeper::gatekeeper()->update_now();
bHandled = true;
break;
case SCHEDULE_UPDATES:
enabled = !pEp::GateKeeper::gatekeeper()->update_enabled();
if (enabled)
pEp::GateKeeper::gatekeeper()->enable_update();
else
pEp::GateKeeper::gatekeeper()->disable_update();
CheckMenuItem(hMenu, ID_POPUP_SCHEDULEUPDATES, enabled ? MF_CHECKED : MF_UNCHECKED);
bHandled = true;
break;
default:
bHandled = false;
}
return S_OK;
}
CMainWindow::tstring CMainWindow::r(UINT resid)
{
LPCTSTR rstr;
size_t rsize = LoadString(GetModuleHandle(NULL), resid, (LPWSTR) &rstr, 0);
tstring str = tstring(rstr, rsize);
return str;
}
void CMainWindow::ShowNotificationInfo(tstring title, tstring text)
{
NOTIFYICONDATA nid = {};
nid.cbSize = sizeof(nid);
nid.uFlags = NIF_GUID | NIF_MESSAGE | NIF_INFO;
nid.dwInfoFlags = NIIF_LARGE_ICON;
nid.hWnd = m_hWnd;
nid.guidItem = nidGUID;
nid.hBalloonIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LOGO));
StringCchCopy(nid.szInfoTitle, ARRAYSIZE(nid.szInfoTitle), title.substr(0, ARRAYSIZE(nid.szInfoTitle)-1).c_str());
StringCchCopy(nid.szInfo, ARRAYSIZE(nid.szInfo), text.substr(0, ARRAYSIZE(nid.szInfo) - 1).c_str());
nid.uCallbackMessage = WM_PEP_NOTIFICATION;
Shell_NotifyIcon(NIM_MODIFY, &nid);
}

+ 33
- 0
CMainWindow.h View File

@ -0,0 +1,33 @@
#pragma once
#include "stdafx.h"
#include "resource.h"
using namespace ATL;
#define WM_PEP_NOTIFICATION WM_USER + 23
class CMainWindow :
public CWindowImpl<CMainWindow>
{
bool _schedule_updates;
public:
CMainWindow();
DECLARE_WND_CLASS(_T("pEpCOMServerAdapterMainWndClass"))
BEGIN_MSG_MAP(CMainWindow)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_PEP_NOTIFICATION, OnNotification)
MESSAGE_HANDLER(WM_MENUCOMMAND, OnMenuCommand)
END_MSG_MAP()
LRESULT OnCreate(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnDestroy(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnNotification(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnMenuCommand(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
typedef std::basic_string<TCHAR> tstring;
static tstring r(UINT resid);
void ShowNotificationInfo(tstring title, tstring text);
};

+ 68
- 29
CpEpEngine.cpp View File

@ -2,14 +2,11 @@
#include "stdafx.h"
#include "CpEpEngine.h"
#include <mutex>
#include "GateKeeper.h"
#include "..\libpEpAdapter\Adapter.hh"
#include "pEp\status_to_string.h"
#include "LocalJSONAdapter.h"
using namespace std;
using namespace pEp::utility;
using namespace pEp::Adapter;
// CpEpEngine
@ -22,6 +19,8 @@ CpEpEngine::callback_container CpEpEngine::sync_callbacks;
std::mutex CpEpEngine::init_mutex;
atomic< int > CpEpEngine::count = 0;
extern LocalJSONAdapter* ljs;
STDMETHODIMP CpEpEngine::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* const arr[] =
@ -430,7 +429,7 @@ STDMETHODIMP CpEpEngine::GetMessageTrustwords(
char* _words = NULL;
if (result == S_OK) {
auto status = ::get_message_trustwords(
auto status = passphrase_cache.api(::get_message_trustwords,
session(),
_msg,
_keylist,
@ -620,7 +619,7 @@ STDMETHODIMP CpEpEngine::MIMEDecodeMessage(BSTR mimeText, TextMessage *msg)
{
assert(mimeText);
if (!mimeText)
if (!mimeText)
return E_INVALIDARG;
string _mimeText = utf8_string(mimeText);
@ -635,7 +634,7 @@ STDMETHODIMP CpEpEngine::MIMEDecodeMessage(BSTR mimeText, TextMessage *msg)
if (status != PEP_STATUS_OK)
return FAIL(L"mime_decode_message", status);
if (_msg)
if (_msg)
text_message_from_C(msg, _msg);
free_message(_msg);
@ -648,7 +647,7 @@ STDMETHODIMP CpEpEngine::MIMEEncodeMessage(TextMessage *msg, VARIANT_BOOL omitFi
{
assert(msg);
if (!msg)
if (!msg)
return E_INVALIDARG;
::message *_msg = NULL;
@ -703,7 +702,12 @@ STDMETHODIMP CpEpEngine::Myself(struct pEpIdentity *ident, struct pEpIdentity *r
return FAIL(ex.what());;
}
PEP_STATUS status = ::myself(session(), _ident);
PEP_STATUS status;
if (passphrase_for_new_keys != "")
status = ::config_passphrase_for_new_keys(session(), true, passphrase_for_new_keys.c_str());
else
status = ::config_passphrase_for_new_keys(session(), false, passphrase_for_new_keys.c_str());
status = ::myself(session(), _ident);
if (status == PEP_STATUS_OK) {
assert(_ident->fpr);
@ -853,7 +857,7 @@ STDMETHODIMP CpEpEngine::KeyResetIdentity(struct pEpIdentity ident, BSTR fpr)
string _fpr = utf8_string(fpr);
PEP_STATUS status = ::key_reset_identity(session(), _ident, _fpr.c_str());
PEP_STATUS status = passphrase_cache.api(::key_reset_identity, session(), _ident, _fpr.c_str());
free_identity(_ident);
@ -874,7 +878,7 @@ STDMETHODIMP CpEpEngine::KeyResetUser(BSTR userId, BSTR fpr)
string _userId = utf8_string(userId);
string _fpr = utf8_string(fpr);
PEP_STATUS status = ::key_reset_user(session(), _userId.c_str(), _fpr.c_str());
PEP_STATUS status = passphrase_cache.api(::key_reset_user, session(), _userId.c_str(), _fpr.c_str());
if (status == PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
@ -890,7 +894,7 @@ STDMETHODIMP CpEpEngine::KeyResetUser(BSTR userId, BSTR fpr)
STDMETHODIMP CpEpEngine::KeyResetAllOwnKeys()
{
PEP_STATUS status = ::key_reset_all_own_keys(session());
PEP_STATUS status = passphrase_cache.api(::key_reset_all_own_keys, session());
if (status == PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
@ -920,7 +924,7 @@ STDMETHODIMP CpEpEngine::KeyResetTrust(struct pEpIdentity *ident)
return FAIL(ex.what());;
}
PEP_STATUS status = ::key_reset_trust(session(), _ident);
PEP_STATUS status = passphrase_cache.api(::key_reset_trust, session(), _ident);
free_identity(_ident);
if (status == PEP_OUT_OF_MEMORY)
@ -1001,12 +1005,11 @@ static IpEpEngineCallbacks * _unmarshaled_consumer(CpEpEngine::callback_containe
PEP_STATUS CpEpEngine::messageToSend(message *msg)
{
assert(msg);
if (!msg)
return PEP_ILLEGAL_VALUE;
bool in_sync = on_sync_thread();
if (in_sync && !msg)
return pEp::PassphraseCache::messageToSend(passphrase_cache, session());
for (auto p = sync_callbacks.begin(); p != sync_callbacks.end(); ++p) {
IpEpEngineCallbacks *cb = in_sync ? _unmarshaled_consumer(p) : p->pdata->unmarshaled;
@ -1025,15 +1028,18 @@ PEP_STATUS CpEpEngine::messageToSend(message *msg)
}
}
if (ljs)
ljs->messageToSend(msg);
sync_callbacks.compact();
return PEP_STATUS_OK;
}
PEP_STATUS CpEpEngine::notifyHandshake(::pEp_identity *self, ::pEp_identity *partner, sync_handshake_signal signal)
PEP_STATUS CpEpEngine::notifyHandshake(::pEp_identity *self, ::pEp_identity *partner, ::sync_handshake_signal signal)
{
assert(self && partner);
if (!(self && partner))
assert(signal);
if (!signal)
return PEP_ILLEGAL_VALUE;
bool in_sync = on_sync_thread();
@ -1201,7 +1207,7 @@ STDMETHODIMP CpEpEngine::EncryptMessage(TextMessage * src, TextMessage * dst, SA
// Since COM-74, this has been changed to an explicit parameter, to allow the engine to attach
// the keys and headers to outgoing, unencrypted messages.
PEP_encrypt_flags_t engineFlags = (PEP_encrypt_flags_t)flags;
PEP_STATUS status = ::encrypt_message(session(), _src, _extra, &msg_dst, _encFormat, engineFlags);
PEP_STATUS status = passphrase_cache.api(::encrypt_message, session(), _src, _extra, &msg_dst, _encFormat, engineFlags);
::free_stringlist(_extra);
if (status == PEP_STATUS_OK)
@ -1262,7 +1268,7 @@ STDMETHODIMP CpEpEngine::EncryptMessageAndAddPrivKey(TextMessage * src, TextMess
// Since COM-74, this has been changed to an explicit parameter, to allow the engine to attach
// the keys and headers to outgoing, unencrypted messages.
PEP_encrypt_flags_t engineFlags = (PEP_encrypt_flags_t)flags;
PEP_STATUS status = ::encrypt_message_and_add_priv_key(session(), _src, &msg_dst, _to_fpr.c_str(), _encFormat, engineFlags);
PEP_STATUS status = passphrase_cache.api(::encrypt_message_and_add_priv_key, session(), _src, &msg_dst, _to_fpr.c_str(), _encFormat, engineFlags);
if (status == PEP_STATUS_OK)
text_message_from_C(dst, msg_dst);
@ -1328,7 +1334,7 @@ STDMETHODIMP CpEpEngine::EncryptMessageForSelf(pEpIdentity * targetId, TextMessa
// COM-19: Initialize msg_dst to NULL, or we end up calling
// free_message() below with a pointer to random garbage in
// case of an error in encrypt_message_for_self().
status = ::encrypt_message_for_self(session(), _target_id, _src, _extra, &msg_dst, PEP_enc_PEP, engineFlags);
status = passphrase_cache.api(::encrypt_message_for_self, session(), _target_id, _src, _extra, &msg_dst, PEP_enc_PEP, engineFlags);
if (status == PEP_STATUS_OK)
text_message_from_C(dst, msg_dst);
@ -1386,7 +1392,7 @@ STDMETHODIMP CpEpEngine::DecryptMessage(TextMessage * src, TextMessage * dst, SA
::PEP_rating _rating;
PEP_decrypt_flags_t engineflags = (PEP_decrypt_flags_t)*flags;
PEP_STATUS status = ::decrypt_message(session(), _src, &msg_dst, &_keylist, &_rating, &engineflags);
PEP_STATUS status = passphrase_cache.api(::decrypt_message, session(), _src, &msg_dst, &_keylist, &_rating, &engineflags);
*flags = (pEpDecryptFlags)engineflags;
@ -1832,7 +1838,7 @@ STDMETHODIMP CpEpEngine::Startup()
{
try
{
startup<CpEpEngine>(messageToSend, notifyHandshake, this, &CpEpEngine::Startup_sync, &CpEpEngine::Shutdown_sync);
pEp::CallbackDispatcher::start_sync();
}
catch (bad_alloc&) {
return E_OUTOFMEMORY;
@ -1967,7 +1973,7 @@ STDMETHODIMP CpEpEngine::DisableIdentityForSync(struct pEpIdentity * ident)
if (_ident == NULL)
return E_OUTOFMEMORY;
PEP_STATUS status = ::disable_identity_for_sync(session(), _ident);
PEP_STATUS status = passphrase_cache.api(::disable_identity_for_sync, session(), _ident);
::free_identity(_ident);
@ -2060,13 +2066,46 @@ STDMETHODIMP CpEpEngine::RatingFromCommType(pEpComType commType, pEpRating * rat
STDMETHODIMP CpEpEngine::GetIsSyncRunning(VARIANT_BOOL *running)
{
*running = pEp::Adapter::is_sync_running();
return S_OK;
}
STDMETHODIMP CpEpEngine::ShutDownSync()
{
pEp::Adapter::shutdown();
pEp::callback_dispatcher.stop_sync();
return S_OK;
}
STDMETHODIMP CpEpEngine::ConfigPassphrase(BSTR passphrase)
{
string _passphrase = "";
if (passphrase)
_passphrase = utf8_string(passphrase);
PEP_STATUS status = ::config_passphrase(session(), passphrase_cache.add(_passphrase));
if (status == PEP_STATUS_OK)
return S_OK;
else if (status == PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
else
return FAIL(L"ConfigPassphrase", status);
}
STDMETHODIMP CpEpEngine::ConfigPassphraseForNewKeys(VARIANT_BOOL enable, BSTR passphrase)
{
string _passphrase = "";
if (passphrase)
_passphrase = utf8_string(passphrase);
passphrase_for_new_keys = _passphrase;
PEP_STATUS status = ::config_passphrase_for_new_keys(session(), enable, passphrase_cache.add_stored(_passphrase));
if (status == PEP_STATUS_OK)
return S_OK;
else if (status == PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
else
return FAIL(L"ConfigPassphraseForNewKeys", status);
}

+ 11
- 18
CpEpEngine.h View File

@ -2,18 +2,8 @@
#pragma once
#include "resource.h" // main symbols
#include "stdafx.h"
#include "pEpComServerAdapter_i.h"
#include "..\libpEpAdapter\locked_queue.hh"
#include "utf8_helper.h"
#include "pEp_utility.h"
#include "..\libpEpAdapter\Adapter.hh"
#include <queue>
#include <mutex>
#include <vector>
#include "..\libpEpAdapter\pc_container.hh"
#include "..\pEp\sync_codec.h"
#include "..\pEp\mime.h"
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
@ -24,6 +14,8 @@ using namespace utility;
using namespace pEp::utility;
using namespace pEp::Adapter;
extern pEp::PassphraseCache passphrase_cache;
// CpEpEngine
class ATL_NO_VTABLE CpEpEngine :
@ -61,7 +53,6 @@ public:
error(ex.what());
}
session(pEp::Adapter::release);
shutdown();
sync_callbacks.clear([](CpEpEngine::MarshaledCallbacks *p) {
if (p) {
@ -72,6 +63,7 @@ public:
delete p;
}
});
pEp::callback_dispatcher.remove(CpEpEngine::messageToSend);
}
}
@ -99,10 +91,7 @@ public:
{
std::lock_guard<std::mutex> lock(init_mutex);
try {
if (!_messageToSend) {
_messageToSend = messageToSend;
}
session();
pEp::callback_dispatcher.add(CpEpEngine::messageToSend, CpEpEngine::notifyHandshake, CpEpEngine::on_sync_startup, CpEpEngine::on_sync_shutdown);
}
catch (pEp::RuntimeError& e) {
HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & e.status));
@ -150,14 +139,14 @@ private:
static callback_container sync_callbacks;
void Startup_sync()
static void on_sync_startup()
{
HRESULT r = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (!SUCCEEDED(r))
throw runtime_error("CoInitializeEx() failed on sync thread");
}
void Shutdown_sync()
static void on_sync_shutdown()
{
CoUninitialize();
}
@ -172,6 +161,8 @@ private:
static std::mutex init_mutex;
static atomic< int > count;
std::string passphrase_for_new_keys;
public:
// runtime config of the adapter
@ -274,6 +265,8 @@ public:
STDMETHOD(OpenPGPListKeyinfo)(BSTR search_pattern, LPSAFEARRAY* keyinfo_list);
STDMETHOD(SetOwnKey)(pEpIdentity * ident, BSTR fpr, struct pEpIdentity *result);
STDMETHOD(TrustOwnKey)(pEpIdentity * ident);
STDMETHOD(ConfigPassphrase)(BSTR passphrase);
STDMETHOD(ConfigPassphraseForNewKeys)(VARIANT_BOOL enable, BSTR passphrase);
// Trigger an immediate update
STDMETHOD(UpdateNow)(BSTR productCode, VARIANT_BOOL *didUpdate);


+ 55
- 8
GateKeeper.cpp View File

@ -1,11 +1,14 @@
#include "stdafx.h"
#include "stdafx.h"
#include "GateKeeper.h"
#include "pEpCOMServerAdapter.h"
#include "utf8_helper.h"
#include "CMainWindow.h"
using namespace std;
extern CMainWindow mainWindow;
auto r = CMainWindow::r;
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd388945(v=vs.85).aspx
struct PUBLIC_KEY_VALUES {
@ -182,7 +185,8 @@ namespace pEp {
if (now > next) {
next = now + GateKeeper::cycle;
keep_updated();
if (update_enabled())
update_now();
}
Sleep(waiting);
@ -344,6 +348,41 @@ namespace pEp {
return result;
}
void GateKeeper::enable_update()
{
LONG lResult = RegOpenKeyEx(cu, updater_reg_path, 0, KEY_WRITE, &hkUpdater);
if (lResult != ERROR_SUCCESS)
return;
lResult = RegSetValueExW(hkUpdater, NULL, 0, REG_SZ, (const BYTE *) _T("1"), sizeof(TCHAR)*2);
}
void GateKeeper::disable_update()
{
LONG lResult = RegOpenKeyEx(cu, updater_reg_path, 0, KEY_WRITE, &hkUpdater);
if (lResult != ERROR_SUCCESS)
return;
lResult = RegSetValueEx(hkUpdater, NULL, 0, REG_SZ, (const BYTE *) _T("0"), sizeof(TCHAR) * 2);
}
bool GateKeeper::update_enabled()
{
bool enabled = true;
DWORD esize;
RegGetValue(cu, updater_reg_path, NULL, RRF_RT_REG_SZ, NULL, NULL, &esize);
if (esize) {
TCHAR* edata = new TCHAR[esize];
RegGetValue(cu, updater_reg_path, NULL, RRF_RT_REG_SZ, NULL, edata, &esize);
if (tstring(edata) == _T("0"))
enabled = false;
delete[] edata;
}
return enabled;
}
GateKeeper::product_list GateKeeper::registered_products()
{
product_list products;
@ -484,6 +523,9 @@ namespace pEp {
DWORD reading;
InternetReadFile(hUrl, iv, sizeof(iv), &reading);
if (reading)
mainWindow.ShowNotificationInfo(r(IDS_DOWNLOADTITLE), r(IDS_DOWNLOADTEXT));
if (reading) do {
static char buffer[1024 * 1024];
BOOL bResult = InternetReadFile(hUrl, buffer, 1024 * 1024, &reading);
@ -532,17 +574,22 @@ namespace pEp {
BCryptDestroyKey(dk);
TCHAR temp_path[MAX_PATH + 1];
GetTempPath(MAX_PATH, temp_path);
TCHAR download_path[MAX_PATH + 1];
PWSTR _downloads;
SHGetKnownFolderPath(FOLDERID_Downloads, 0, NULL, &_downloads);
StringCchCopy(download_path, MAX_PATH, _downloads);
CoTaskMemFree(_downloads);
GetTempPath(MAX_PATH, download_path);
if (filename == _T("")) {
filename = temp_path;
filename = download_path;
filename += _T("\\pEp_");
filename += delivery.substr(0, 32);
filename += _T(".msi");
}
else {
filename = tstring(temp_path) + _T("\\") + filename;
filename = tstring(download_path) + _T("\\") + filename;
}
hFile = CreateFile(filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
@ -574,7 +621,7 @@ namespace pEp {
return result;
}
void GateKeeper::keep_updated()
void GateKeeper::update_now()
{
NTSTATUS status = BCryptOpenAlgorithmProvider(&hAES, BCRYPT_AES_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
assert(status == 0);


+ 7
- 1
GateKeeper.h View File

@ -1,3 +1,5 @@
#include "stdafx.h"
class CpEpCOMServerAdapterModule;
using namespace std;
@ -37,6 +39,11 @@ namespace pEp {
product_list registered_products();
bool update_product(product p, DWORD context = 0);
bool update_enabled();
void enable_update();
void disable_update();
void update_now();
static GateKeeper *gatekeeper() { return the_gatekeeper; }
protected:
@ -57,7 +64,6 @@ namespace pEp {
BCRYPT_KEY_HANDLE delivery_key();
string wrapped_delivery_key(BCRYPT_KEY_HANDLE hDeliveryKey);
void keep_updated();
static tstring get_lockFile();
static GateKeeper *the_gatekeeper;


+ 10
- 0
LocalJSONAdapter.cpp View File

@ -0,0 +1,10 @@
#include "stdafx.h"
#include "LocalJSONAdapter.h"
void startSync() { }
void stopSync() { }
LocalJSONAdapter& LocalJSONAdapter::createInstance()
{
return dynamic_cast<LocalJSONAdapter&>(JsonAdapter::createInstance(new LocalJSONAdapter()));
}

+ 16
- 0
LocalJSONAdapter.h View File

@ -0,0 +1,16 @@
#pragma once
#include "stdafx.h"
#include "json-adapter.hh"
class LocalJSONAdapter :
public JsonAdapter
{
public:
static LocalJSONAdapter& createInstance();
protected:
virtual inject_sync_event_t getInjectSyncEvent() const override
{
return pEp::Adapter::_inject_sync_event;
}
};

BIN
logo.ico View File

Before After

+ 84
- 3
pEpCOMServerAdapter.cpp View File

@ -7,10 +7,20 @@
#include "GateKeeper.h"
#include "pEpCOMServerAdapter.h"
#include "LocalJSONAdapter.h"
#include "CMainWindow.h"
using namespace ATL;
using namespace std;
#ifndef NDEBUG
// Stuff for the JSON server follows.
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
std::string logfile = "";
#endif
void CpEpCOMServerAdapterModule::gatekeeper(CpEpCOMServerAdapterModule * self)
{
pEp::GateKeeper keeper(self);
@ -18,13 +28,84 @@ void CpEpCOMServerAdapterModule::gatekeeper(CpEpCOMServerAdapterModule * self)
}
CpEpCOMServerAdapterModule _AtlModule;
LocalJSONAdapter* ljs = nullptr;
pEp::PassphraseCache passphrase_cache;
CMainWindow mainWindow;
//
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
LPTSTR /*lpCmdLine*/, int nShowCmd)
LPTSTR lpCmdLine, int nShowCmd)
{
#ifndef NDEBUG
std::ios::sync_with_stdio(false);
// Command line options and console output are for debug only.
// Some Windows acrobatics so we can use this even with a command line
// and get some output onto the console.
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
FILE *f;
freopen_s(&f, "conout$", "w", stdout);
freopen_s(&f, "conout$", "w", stderr);
}
po::options_description desc("Program options for the JSON Server Adapter");
desc.add_options()
("help,h", "print this help messages")
("debug,d", "debug,d ignored, only works in JSON mini adapter")
("logfile,l", po::value<std::string>(&logfile)->default_value(logfile),
"Name of the logfile. Can be \"stderr\" for log to stderr or empty for no log.")
;
po::variables_map vm;
try {
std::vector<std::wstring> args = po::split_winmain(lpCmdLine);
po::store(po::wcommand_line_parser(args).options(desc).run(), vm);
po::notify(vm);
} catch (const po::error& e) {
std::cerr << "Cannot parse command line: " << e.what() << "\n\n" << desc << std::endl;
return 2;
}
if (vm.count("help")) {
std::cout << desc << "\n";
return 0;
}
if (logfile.empty()) {
Logger::setDefaultTarget(Logger::Target::None);
} else if (logfile == "stderr") {
Logger::setDefaultTarget(Logger::Target::Console);
} else {
Logger::setDefaultTarget(Logger::Target::File);
}
Logger::start("JsonAdapter", logfile);
#endif
_AtlModule.hModule(hInstance);
_AtlModule.start_gatekeeper();
return _AtlModule.WinMain(nShowCmd);
PEP_SESSION first_session;
PEP_STATUS status = ::init(&first_session, NULL, NULL);
if (!boost::algorithm::iequals(lpCmdLine, "/regserver")) {
ljs = &LocalJSONAdapter::createInstance();
ljs->startup(pEp::CallbackDispatcher::messageToSend);
pEp::callback_dispatcher.add(JsonAdapter::messageToSend, JsonAdapter::notifyHandshake);
auto mw = mainWindow.Create(HWND_MESSAGE);
assert(mw);
}
auto rv = _AtlModule.WinMain(nShowCmd);
if (ljs) {
BOOL r = true;
mainWindow.OnDestroy(0, 0, 0, r);
pEp::callback_dispatcher.remove(JsonAdapter::messageToSend);
ljs->shutdown_now();
}
::release(first_session);
ExitProcess(rv);
return rv;
}

+ 12
- 0
pEpCOMServerAdapter.idl View File

@ -38,6 +38,12 @@ interface IpEpEngineCallbacks : IUnknown {
// forming group
// SyncNotifyFormingGroup = 10,
SyncNotifyStart = 126,
SyncNotifyStop = 127,
// message cannot be sent, need passphrase
SyncNotifyPassphraseRequired = 128,
// notificaton of actual group status
SyncNotifySole = 254,
SyncNotifyInGroup = 255
@ -528,6 +534,12 @@ interface IpEpEngine : IUnknown {
// Encodes a MIME message
[id(63)] HRESULT MIMEEncodeMessage([in] struct TextMessage *msg, [in] VARIANT_BOOL omitFields, [out, retval] BSTR *mimeText);
// Configures a key passphrase for the current session
[id(64)] HRESULT ConfigPassphrase([in] BSTR passphrase);
// Passphrase enablement for newly-generated secret keys
[id(65)] HRESULT ConfigPassphraseForNewKeys([in] VARIANT_BOOL enable, [in] BSTR passphrase);
};
[


BIN
pEpCOMServerAdapter.rc View File


+ 40
- 4
pEpCOMServerAdapter.vcxproj View File

@ -41,14 +41,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IgnoreImportLibrary>true</IgnoreImportLibrary>
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)..\;$(ProjectDir)..\pEpEngine\src;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)pEpJSONServerAdapter\server;$(ProjectDir)..\;$(ProjectDir)..\pEpEngine\src;$(IncludePath)</IncludePath>
<CodeAnalysisRuleSet>C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets\NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IgnoreImportLibrary>true</IgnoreImportLibrary>
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)..\;$(ProjectDir)..\pEpEngine\src;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)pEpJSONServerAdapter\server;$(ProjectDir)..\;$(ProjectDir)..\pEpEngine\src;$(IncludePath)</IncludePath>
<CodeAnalysisRuleSet>C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets\NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
@ -70,7 +70,7 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>JSON_ADAPTER_LIBRARY;DEBUG_ENABLED;WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<EnablePREfast>false</EnablePREfast>
</ClCompile>
@ -90,6 +90,8 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>
</AdditionalOptions>
</ResourceCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -104,7 +106,7 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>JSON_ADAPTER_LIBRARY;DEBUG_ENABLED;WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<EnablePREfast>false</EnablePREfast>
</ClCompile>
@ -135,8 +137,10 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="CMainWindow.cpp" />
<ClCompile Include="CpEpEngine.cpp" />
<ClCompile Include="GateKeeper.cpp" />
<ClCompile Include="LocalJSONAdapter.cpp" />
<ClCompile Include="pEpCOMServerAdapter.cpp" />
<ClCompile Include="pEpCOMServerAdapter_i.c">
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
@ -162,8 +166,11 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\pEpJSONServerAdapter\server\adapter-library.hh" />
<ClInclude Include="CMainWindow.h" />
<ClInclude Include="CpEpEngine.h" />
<ClInclude Include="GateKeeper.h" />
<ClInclude Include="LocalJSONAdapter.h" />
<ClInclude Include="pEpCOMServerAdapter.h" />
<ClInclude Include="pEpCOMServerAdapter_i.h" />
<ClInclude Include="pEp_utility.h" />
@ -182,6 +189,7 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
</ItemGroup>
<ItemGroup>
<None Include="..\pEpForOutlook\pep_test.snk" />
<None Include="packages.config" />
<None Include="pEpCOMServerAdapter.rgs" />
<None Include="pEpEngine.rgs" />
<None Include="updatekey.bin" />
@ -196,8 +204,36 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
<ProjectReference Include="..\pEpEngine\build-windows\pEpEngine.vcxproj">
<Project>{146e69f8-e1da-456a-b048-6dd29d9acf6b}</Project>
</ProjectReference>
<ProjectReference Include="..\pEpJSONServerAdapter\build-windows\pEpJSONServerAdapter\pEpJSONServerAdapterLibrary.vcxproj">
<Project>{644d1ba4-084c-47b2-8a9e-00a8d9f9a35c}</Project>
</ProjectReference>
<ProjectReference Include="..\pEpJSONServerAdapter\build-windows\pEp\libpEpWebserver\libpEpWebserver.vcxproj">
<Project>{0d25734e-a71b-4536-8dc4-60e945382fc5}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Image Include="logo.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\boost.1.72.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.72.0.0\build\boost.targets')" />
<Import Project="..\packages\boost_date_time-vc142.1.72.0.0\build\boost_date_time-vc142.targets" Condition="Exists('..\packages\boost_date_time-vc142.1.72.0.0\build\boost_date_time-vc142.targets')" />
<Import Project="..\packages\boost_regex-vc142.1.72.0.0\build\boost_regex-vc142.targets" Condition="Exists('..\packages\boost_regex-vc142.1.72.0.0\build\boost_regex-vc142.targets')" />
<Import Project="..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets" Condition="Exists('..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets')" />
<Import Project="..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets" Condition="Exists('..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets')" />
<Import Project="..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets" Condition="Exists('..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets')" />
<Import Project="..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets" Condition="Exists('..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\boost.1.72.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.72.0.0\build\boost.targets'))" />
<Error Condition="!Exists('..\packages\boost_date_time-vc142.1.72.0.0\build\boost_date_time-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_date_time-vc142.1.72.0.0\build\boost_date_time-vc142.targets'))" />
<Error Condition="!Exists('..\packages\boost_regex-vc142.1.72.0.0\build\boost_regex-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_regex-vc142.1.72.0.0\build\boost_regex-vc142.targets'))" />
<Error Condition="!Exists('..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets'))" />
<Error Condition="!Exists('..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets'))" />
<Error Condition="!Exists('..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets'))" />
<Error Condition="!Exists('..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets'))" />
</Target>
</Project>

+ 21
- 0
pEpCOMServerAdapter.vcxproj.filters View File

@ -43,6 +43,12 @@
<ClCompile Include="GateKeeper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LocalJSONAdapter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CMainWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@ -75,6 +81,15 @@
<ClInclude Include="pEpCOMServerAdapter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LocalJSONAdapter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\pEpJSONServerAdapter\server\adapter-library.hh">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CMainWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="pEpCOMServerAdapter.rc">
@ -96,10 +111,16 @@
<Filter>Resource Files</Filter>
</None>
<None Include="..\pEpForOutlook\pep_test.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Midl Include="pEpCOMServerAdapter.idl">
<Filter>Source Files</Filter>
</Midl>
</ItemGroup>
<ItemGroup>
<Image Include="logo.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>

+ 10
- 0
packages.config View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="boost" version="1.72.0.0" targetFramework="native" />
<package id="boost_chrono-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_date_time-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_filesystem-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_program_options-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_regex-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_thread-vc142" version="1.72.0.0" targetFramework="native" />
</packages>

BIN
resource.h View File


+ 21
- 6
stdafx.h View File

@ -20,13 +20,16 @@
#define ATL_NO_ASSERT_ON_DESTROY_NONEXISTENT_WINDOW
#include "resource.h"
#include <atlbase.h>
#include <atlcom.h>
#include <atlctl.h>
#include <atlsafe.h>
#include <atlwin.h>
#include <comutil.h>
#include <comdef.h>
#include <Shlobj.h>
#include <Wininet.h>
#include <intsafe.h>
@ -37,6 +40,7 @@
#include <string>
#include <stdexcept>
#include <list>
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
@ -49,13 +53,24 @@
#include <Strsafe.h>
#include <pEp/pEpEngine.h>
#include <pEp/platform.h>
#include <pEp/sync_api.h>
#include <pEp/keymanagement.h>
#include <pEp/key_reset.h>
#include <pEp/message_api.h>
#include <pEp/stringpair.h>
#include <pEp/blacklist.h>
#include <pEp/sync_api.h>
#include <pEp/openpgp_compat.h>
#include <pEp/platform.h>
#include <pEp/sync_codec.h>
#include <pEp/mime.h>
#include <pEp/blacklist.h>
#include <pEp/locked_queue.hh>
#include <pEp/pc_container.hh>
#include <pEp/passphrase_cache.hh>
#include <pEp/callback_dispatcher.hh>
#include <pEp/status_to_string.hh>
#include "utf8_helper.h"
#include "pEp_utility.h"
#include <boost/algorithm/string/predicate.hpp>
#include "utf8_helper.h"

Loading…
Cancel
Save