Browse Source

COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.

- Code Reformat (whitespace only changes)
COM-121
Markus Schaber 4 years ago
parent
commit
5d5d97e026
11 changed files with 379 additions and 379 deletions
  1. +19
    -19
      CpEpEngine.cpp
  2. +59
    -59
      CpEpEngine.h
  3. +75
    -75
      GateKeeper.cpp
  4. +1
    -1
      GateKeeper.h
  5. +42
    -42
      locked_queue.hh
  6. +1
    -1
      pEpCOMServerAdapter.cpp
  7. +90
    -90
      pEpCOMServerAdapter.idl
  8. +76
    -76
      pEp_utility.cpp
  9. +5
    -5
      pEp_utility.h
  10. +4
    -4
      utf8_helper.cpp
  11. +7
    -7
      xdlldata.h

+ 19
- 19
CpEpEngine.cpp View File

@ -611,15 +611,15 @@ STDMETHODIMP CpEpEngine::KeyMistrusted(struct pEpIdentity *ident)
STDMETHODIMP CpEpEngine::UndoLastMistrust()
{
PEP_STATUS status = ::undo_last_mistrust(get_session());
PEP_STATUS status = ::undo_last_mistrust(get_session());
if (status == PEP_CANNOT_FIND_IDENTITY)
return FAIL(L"Cannot find identity!", status);
if (status == PEP_CANNOT_FIND_IDENTITY)
return FAIL(L"Cannot find identity!", status);
if (status != ::PEP_STATUS_OK)
return FAIL(L"cannot revoke compromized key", status);
if (status != ::PEP_STATUS_OK)
return FAIL(L"cannot revoke compromized key", status);
return S_OK;
return S_OK;
}
STDMETHODIMP CpEpEngine::KeyResetTrust(struct pEpIdentity *ident)
@ -1162,12 +1162,12 @@ void CpEpEngine::start_keysync()
keysync_abort_requested = false;
// Init our keysync session
{ // begin lock scope
std::lock_guard<std::mutex> lock(init_mutex);
PEP_STATUS status = ::init(&keysync_session);
::register_sync_callbacks(keysync_session, (void*)this, messageToSend, notifyHandshake, inject_sync_msg, retrieve_next_sync_msg);
assert(status == PEP_STATUS_OK);
} // end lock scope
{ // begin lock scope
std::lock_guard<std::mutex> lock(init_mutex);
PEP_STATUS status = ::init(&keysync_session);
::register_sync_callbacks(keysync_session, (void*)this, messageToSend, notifyHandshake, inject_sync_msg, retrieve_next_sync_msg);
assert(status == PEP_STATUS_OK);
} // end lock scope
attach_sync_session(get_session(), keysync_session);
@ -1248,7 +1248,7 @@ void CpEpEngine::stop_keysync()
::detach_sync_session(get_session());
::unregister_sync_callbacks(keysync_session);
std::lock_guard<std::mutex> releaselock(init_mutex);
std::lock_guard<std::mutex> releaselock(init_mutex);
release(keysync_session);
keysync_session = NULL;
}
@ -1326,16 +1326,16 @@ void * CpEpEngine::retrieve_next_sync_msg(void * management, time_t *timeout)
{
*timeout = 1; // Signal timeout
return NULL;
}
else
}
else
{
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
if (now < end_time)
if (now < end_time)
{
*timeout = std::chrono::duration_cast<std::chrono::seconds>(end_time - now).count();
}
else
}
else
{
*timeout = 0;
}
@ -1522,7 +1522,7 @@ PEP_STATUS CpEpEngine::notifyHandshake(void * obj, pEp_identity *self, pEp_ident
if (res != S_OK)
return PEP_STATUS_OK;
return PEP_STATUS_OK;
}
::log_event(me->keysync_session, "Reentrant notify_handshake call!", "pEp COM Adapter", NULL, NULL);


+ 59
- 59
CpEpEngine.h View File

@ -22,9 +22,9 @@ using namespace pEp::utility;
class ATL_NO_VTABLE CpEpEngine :
public CComObjectRootEx<CComObjectThreadModel>,
public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
public ISupportErrorInfo,
public IpEpEngine2
public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
public ISupportErrorInfo,
public IpEpEngine2
{
protected:
@ -32,62 +32,62 @@ protected:
public:
CpEpEngine() : keymanagement_thread(NULL), identity_queue(NULL), verbose_mode(false)
{
// See FinalConstruct() below for most initialization work, and an
// explanation why it had to be moved there...
}
{
// See FinalConstruct() below for most initialization work, and an
// explanation why it had to be moved there...
}
~CpEpEngine()
{
stop_keysync();
StopKeyserverLookup();
if (m_session) // may be zero when FinalConstruct failed to initialize the engine
{
::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
std::lock_guard<std::mutex> lock(init_mutex);
::release(m_session);
}
if (m_session) // may be zero when FinalConstruct failed to initialize the engine
{
::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
std::lock_guard<std::mutex> lock(init_mutex);
::release(m_session);
}
}
DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
DECLARE_NOT_AGGREGATABLE(CpEpEngine)
DECLARE_NOT_AGGREGATABLE(CpEpEngine)
BEGIN_COM_MAP(CpEpEngine)
COM_INTERFACE_ENTRY(IpEpEngine)
COM_INTERFACE_ENTRY(IpEpEngine2)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
BEGIN_COM_MAP(CpEpEngine)
COM_INTERFACE_ENTRY(IpEpEngine)
COM_INTERFACE_ENTRY(IpEpEngine2)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
DECLARE_PROTECT_FINAL_CONSTRUCT()
DECLARE_PROTECT_FINAL_CONSTRUCT()
// Unfortunately, neither FAIL nor error() work in the constructor, as
// CreateErrorInfo/SetErrorInfo cannot work when the instance is not constructed.
// AtlThrow works, but the exception is caught in CComCreator.CreateInstance, and
// unconditionally turned into E_OUTOFMEMORY. Thus, we need to do most constructor
// work in FinalConstruct. CreateErrorInfo/SetErrorInfo still won't work, but at least,
// we can return a meaningful HRESULT. Thus, we pack our PEP_STATUS into a custom HRESULT.
HRESULT FinalConstruct()
{
std::lock_guard<std::mutex> lock(init_mutex);
PEP_STATUS status = ::init(&m_session);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK) {
HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
return res;
}
// Unfortunately, neither FAIL nor error() work in the constructor, as
// CreateErrorInfo/SetErrorInfo cannot work when the instance is not constructed.
// AtlThrow works, but the exception is caught in CComCreator.CreateInstance, and
// unconditionally turned into E_OUTOFMEMORY. Thus, we need to do most constructor
// work in FinalConstruct. CreateErrorInfo/SetErrorInfo still won't work, but at least,
// we can return a meaningful HRESULT. Thus, we pack our PEP_STATUS into a custom HRESULT.
HRESULT FinalConstruct()
{
std::lock_guard<std::mutex> lock(init_mutex);
PEP_STATUS status = ::init(&m_session);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK) {
HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
return res;
}
::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
return S_OK;
}
::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
return S_OK;
}
void FinalRelease()
{
}
void FinalRelease()
{
}
protected:
@ -145,19 +145,19 @@ private:
bool verbose_mode;
IpEpEngineCallbacks* client_callbacks = NULL;
IpEpEngineCallbacks* client_callbacks = NULL;
IpEpEngineCallbacks* client_callbacks_on_sync_thread = NULL;
IpEpEngineCallbacks2* client_callbacks2_on_sync_thread = NULL;
bool client_last_signalled_polling_state = true;
// Keysync members
// Keysync members
static int inject_sync_msg(void *msg, void* management);
static void* retrieve_next_sync_msg(void* management, time_t *timeout);
void start_keysync();
static void do_keysync_in_thread(CpEpEngine* self, LPSTREAM marshaled_callbacks);
void stop_keysync();
static std::mutex init_mutex;
static std::mutex init_mutex;
std::recursive_mutex keysync_mutex;
std::condition_variable_any keysync_condition;
@ -205,8 +205,8 @@ public:
STDMETHOD(GetCrashdumpLog)(LONG maxlines, BSTR * log);
STDMETHOD(GetEngineVersion)(BSTR * engineVersion);
STDMETHOD(GetLanguageList)(BSTR * languages);
STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
// keymanagement API
@ -218,7 +218,7 @@ public:
STDMETHOD(KeyMistrusted)(struct pEpIdentity *ident);
STDMETHOD(KeyResetTrust)(struct pEpIdentity *ident);
STDMETHOD(TrustPersonalKey)(struct pEpIdentity *ident, struct pEpIdentity *result);
STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
// Blacklist API
@ -234,28 +234,28 @@ public:
STDMETHOD(ReEvaluateMessageRating)(TextMessage * msg, SAFEARRAY * x_KeyList, pEpRating x_EncStatus, pEpRating *rating);
STDMETHOD(OutgoingMessageRating)(TextMessage *msg, pEpRating * pVal);
STDMETHOD(IdentityRating)(pEpIdentity * ident, pEpRating * pVal);
STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
STDMETHOD(EncryptMessageForSelf)(
pEpIdentity * targetId,
pEpIdentity * targetId,
TextMessage* src,
TextMessage *dst,
pEpEncryptFlags flags
);
// Event callbacks
// Event callbacks
STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
STDMETHOD(UnregisterCallbacks)();
STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
STDMETHOD(UnregisterCallbacks)();
// PGP compatibility functions
STDMETHOD(OpenPGPListKeyinfo)(BSTR search_pattern, LPSAFEARRAY* keyinfo_list);
STDMETHOD(UndoLastMistrust)();
STDMETHOD(UndoLastMistrust)();
protected:
HRESULT Fire_MessageToSend(
/* [in] */ struct TextMessage *msg);
HRESULT Fire_MessageToSend(
/* [in] */ struct TextMessage *msg);
};
OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)

+ 75
- 75
GateKeeper.cpp View File

@ -18,7 +18,7 @@ static void ReverseMemCopy(
_Out_ BYTE *pbDest,
_In_ BYTE const *pbSource,
_In_ DWORD cb
)
)
{
for (DWORD i = 0; i < cb; i++) {
pbDest[cb - 1 - i] = pbSource[i];
@ -29,7 +29,7 @@ static NTSTATUS ImportRsaPublicKey(
_In_ BCRYPT_ALG_HANDLE hAlg, // CNG provider
_In_ PUBLIC_KEY_VALUES *pKey, // Pointer to the RSAPUBKEY blob.
_In_ BCRYPT_KEY_HANDLE *phKey // Receives a handle the imported public key.
)
)
{
NTSTATUS hr = 0;
@ -62,14 +62,14 @@ static NTSTATUS ImportRsaPublicKey(
cbKey += cbExp;
pbPublicKey = (PBYTE) CoTaskMemAlloc(cbKey);
pbPublicKey = (PBYTE)CoTaskMemAlloc(cbKey);
if (pbPublicKey == NULL) {
hr = E_OUTOFMEMORY;
goto cleanup;
}
ZeroMemory(pbPublicKey, cbKey);
pRsaBlob = (BCRYPT_RSAKEY_BLOB *) (pbPublicKey);
pRsaBlob = (BCRYPT_RSAKEY_BLOB *)(pbPublicKey);
//
// Make the Public Key Blob Header
@ -82,13 +82,13 @@ static NTSTATUS ImportRsaPublicKey(
pRsaBlob->cbPrime1 = 0;
pRsaBlob->cbPrime2 = 0;
pbCurrent = (PBYTE) (pRsaBlob + 1);
pbCurrent = (PBYTE)(pRsaBlob + 1);
//
// Copy pubExp Big Endian
//
ReverseMemCopy(pbCurrent, (PBYTE) &dwExp, cbExp);
ReverseMemCopy(pbCurrent, (PBYTE)&dwExp, cbExp);
pbCurrent += cbExp;
//
@ -101,7 +101,7 @@ static NTSTATUS ImportRsaPublicKey(
// Import the public key
//
hr = BCryptImportKeyPair(hAlg, NULL, BCRYPT_RSAPUBLIC_BLOB, phKey, (PUCHAR) pbPublicKey, cbKey, 0);
hr = BCryptImportKeyPair(hAlg, NULL, BCRYPT_RSAPUBLIC_BLOB, phKey, (PUCHAR)pbPublicKey, cbKey, 0);
cleanup:
CoTaskMemFree(pbPublicKey);
@ -120,9 +120,9 @@ namespace pEp {
GateKeeper::GateKeeper(CpEpCOMServerAdapterModule * self)
: _self(self), now(time(NULL)), next(now /*+ time_diff()*/), hkUpdater(NULL),
internet(NULL), hAES(NULL), hRSA(NULL)
internet(NULL), hAES(NULL), hRSA(NULL)
{
DeleteFile(get_lockFile().c_str());
DeleteFile(get_lockFile().c_str());
LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
assert(lResult == ERROR_SUCCESS);
@ -133,11 +133,11 @@ namespace pEp {
if (cu_open) {
LONG lResult = RegOpenKeyEx(cu, updater_reg_path, 0, KEY_READ, &hkUpdater);
if (lResult != ERROR_SUCCESS)
RegCreateKeyEx(cu, updater_reg_path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkUpdater, NULL);
}
if (lResult != ERROR_SUCCESS)
RegCreateKeyEx(cu, updater_reg_path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkUpdater, NULL);
}
}
GateKeeper::~GateKeeper()
{
if (cu_open) {
@ -153,7 +153,7 @@ namespace pEp {
static random_device rd;
static mt19937 gen(rd());
uniform_int_distribution<time_t> dist(0, cycle/fraction);
uniform_int_distribution<time_t> dist(0, cycle / fraction);
return dist(gen);
}
@ -185,14 +185,14 @@ namespace pEp {
void GateKeeper::keep_plugin()
{
HKEY hkPluginStart = NULL;
HKEY hkPluginStart = NULL;
LONG lResult = RegOpenKeyEx(cu, plugin_reg_path, 0, KEY_WRITE, &hkPluginStart);
if (lResult != ERROR_SUCCESS)
return;
DWORD v = 3;
lResult = RegSetValueEx(hkPluginStart, plugin_reg_value_name, 0, REG_DWORD, (const BYTE *) &v, sizeof(DWORD));
lResult = RegSetValueEx(hkPluginStart, plugin_reg_value_name, 0, REG_DWORD, (const BYTE *)&v, sizeof(DWORD));
assert(lResult == ERROR_SUCCESS);
RegCloseKey(hkPluginStart);
@ -230,11 +230,11 @@ namespace pEp {
uniform_int_distribution<int64_t> dist(0, UINT32_MAX);
for (int i = 0; i < 8; i++)
key.dw_key[i] = (uint32_t) dist(gen);
key.dw_key[i] = (uint32_t)dist(gen);
BCRYPT_KEY_HANDLE hKey;
NTSTATUS status = BCryptGenerateSymmetricKey(hAES, &hKey, NULL, 0, (PUCHAR) &key, (ULONG) sizeof(aeskey_t), 0);
NTSTATUS status = BCryptGenerateSymmetricKey(hAES, &hKey, NULL, 0, (PUCHAR)&key, (ULONG) sizeof(aeskey_t), 0);
assert(status == 0);
if (status)
throw runtime_error("BCryptGenerateSymmetricKey");
@ -242,7 +242,7 @@ namespace pEp {
#ifndef NDEBUG
DWORD keylength = 0;
ULONG copied = 0;
status = BCryptGetProperty(hKey, BCRYPT_KEY_LENGTH, (PUCHAR) &keylength, sizeof(DWORD), &copied, 0);
status = BCryptGetProperty(hKey, BCRYPT_KEY_LENGTH, (PUCHAR)&keylength, sizeof(DWORD), &copied, 0);
assert(keylength == 256);
#endif
@ -260,7 +260,7 @@ namespace pEp {
DWORD uk_size;
BOOL bResult = CryptDecodeObjectEx(X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO,
(const BYTE *) _update_key.data(), _update_key.size(), CRYPT_DECODE_ALLOC_FLAG, NULL, &uk, &uk_size);
(const BYTE *)_update_key.data(), _update_key.size(), CRYPT_DECODE_ALLOC_FLAG, NULL, &uk, &uk_size);
if (!bResult)
throw runtime_error("CryptDecodeObjectEx: X509_PUBLIC_KEY_INFO");
@ -281,8 +281,8 @@ namespace pEp {
ULONG psize;
NTSTATUS status = BCryptGetProperty(hUpdateKey, BCRYPT_ALGORITHM_NAME, NULL, 0, &psize, 0);
char *prop = new char[psize];
TCHAR *_prop = (TCHAR *) prop;
BCryptGetProperty(hUpdateKey, BCRYPT_ALGORITHM_NAME, (PUCHAR) prop, psize, &psize, 0);
TCHAR *_prop = (TCHAR *)prop;
BCryptGetProperty(hUpdateKey, BCRYPT_ALGORITHM_NAME, (PUCHAR)prop, psize, &psize, 0);
ULONG export_size;
status = BCryptExportKey(hDeliveryKey, NULL, BCRYPT_KEY_DATA_BLOB, NULL, NULL,
@ -293,7 +293,7 @@ namespace pEp {
PUCHAR _delivery_key = new UCHAR[export_size];
ULONG copied;
status = BCryptExportKey(hDeliveryKey, NULL, BCRYPT_KEY_DATA_BLOB, _delivery_key, export_size,
&copied, 0);
&copied, 0);
if (status) {
delete[] _delivery_key;
throw runtime_error("BCryptExportKey: delivery_key");
@ -328,7 +328,7 @@ namespace pEp {
stringstream s;
for (ULONG i = 0; i < copied; i++) {
s << hex << setw(2) << setfill('0');
s << (int) _result[i];
s << (int)_result[i];
}
delete[] _result;
s >> result;
@ -350,7 +350,7 @@ namespace pEp {
for (DWORD i = 0; lResult == ERROR_SUCCESS; i++) {
value_name_size = 16383;
value_size = L_MAX_URL_LENGTH + 1;
lResult = RegEnumValue(hkUpdater, i, value_name, &value_name_size, NULL, NULL, (LPBYTE) value, &value_size);
lResult = RegEnumValue(hkUpdater, i, value_name, &value_name_size, NULL, NULL, (LPBYTE)value, &value_size);
if (lResult == ERROR_SUCCESS) {
products.push_back({ value_name, value });
}
@ -361,43 +361,43 @@ namespace pEp {
void GateKeeper::install_msi(tstring filename)
{
HANDLE hMutex = CreateMutex(NULL, TRUE, _T("PEPINSTALLERMUTEX"));
if (hMutex) {
CloseHandle(hMutex);
ShellExecute(NULL, _T("open"), filename.c_str(), NULL, NULL, SW_SHOW);
}
HANDLE hMutex = CreateMutex(NULL, TRUE, _T("PEPINSTALLERMUTEX"));
if (hMutex) {
CloseHandle(hMutex);
ShellExecute(NULL, _T("open"), filename.c_str(), NULL, NULL, SW_SHOW);
}
}
tstring GateKeeper::get_lockFile()
{
static const tstring _fileName = _T("\\pEpSetup.lck");
static tstring fileName;
tstring GateKeeper::get_lockFile()
{
static const tstring _fileName = _T("\\pEpSetup.lck");
static tstring fileName;
if (fileName.length() == 0) {
unique_ptr < TCHAR[] > _pathName(new TCHAR[MAX_PATH + 1]);
DWORD size = GetTempPath(MAX_PATH, _pathName.get());
if (size > MAX_PATH - _fileName.size())
throw runtime_error("TEMP path too long");
if (fileName.length() == 0) {
unique_ptr < TCHAR[] > _pathName(new TCHAR[MAX_PATH + 1]);
DWORD size = GetTempPath(MAX_PATH, _pathName.get());
if (size > MAX_PATH - _fileName.size())
throw runtime_error("TEMP path too long");
fileName = _pathName.get();
fileName += _fileName;
}
fileName = _pathName.get();
fileName += _fileName;
}
return fileName;
}
return fileName;
}
void GateKeeper::update_product(product p, DWORD context)
{
{
HANDLE file = CreateFile(get_lockFile().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE) {
return;
}
else {
CloseHandle(file);
DeleteFile(get_lockFile().c_str());
}
}
{
HANDLE file = CreateFile(get_lockFile().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE) {
return;
}
else {
CloseHandle(file);
DeleteFile(get_lockFile().c_str());
}
}
BCRYPT_KEY_HANDLE dk = delivery_key();
#ifdef UNICODE
@ -410,7 +410,7 @@ namespace pEp {
url += delivery;
tstring headers;
HINTERNET hUrl = InternetOpenUrl(internet, url.c_str(), headers.c_str(), headers.length(),
INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_UI | INTERNET_FLAG_SECURE, context);
INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_UI | INTERNET_FLAG_SECURE, context);
if (hUrl == NULL)
return;
@ -428,8 +428,8 @@ namespace pEp {
InternetReadFile(hUrl, iv, sizeof(iv), &reading);
if (reading) do {
static char buffer[1024*1024];
BOOL bResult = InternetReadFile(hUrl, buffer, 1024*1024, &reading);
static char buffer[1024 * 1024];
BOOL bResult = InternetReadFile(hUrl, buffer, 1024 * 1024, &reading);
if (!bResult || !reading)
break;
crypted += string(buffer, reading);
@ -452,18 +452,18 @@ namespace pEp {
authInfo.cbTag = sizeof(tag);
ULONG unencrypted_size;
NTSTATUS status = BCryptDecrypt(dk, (PUCHAR) crypted.data(), crypted.size(),
&authInfo, iv, sizeof(iv), NULL, 0, &unencrypted_size, 0);
NTSTATUS status = BCryptDecrypt(dk, (PUCHAR)crypted.data(), crypted.size(),
&authInfo, iv, sizeof(iv), NULL, 0, &unencrypted_size, 0);
if (status)
goto closing;
unencrypted_buffer = new char[unencrypted_size];
PUCHAR crypted_data = (PUCHAR) crypted.data();
ULONG crypted_size = (ULONG) crypted.size() - sizeof(tag);
PUCHAR crypted_data = (PUCHAR)crypted.data();
ULONG crypted_size = (ULONG)crypted.size() - sizeof(tag);
memcpy(tag, crypted_data + crypted_size, sizeof(tag));
status = BCryptDecrypt(dk, crypted_data, crypted_size,
&authInfo, iv, sizeof(iv), (PUCHAR) unencrypted_buffer, unencrypted_size, &unencrypted_size, 0);
&authInfo, iv, sizeof(iv), (PUCHAR)unencrypted_buffer, unencrypted_size, &unencrypted_size, 0);
if (status)
goto closing;
@ -503,7 +503,7 @@ namespace pEp {
assert(status == 0);
if (status)
goto closing;
status = BCryptSetProperty(hAES, BCRYPT_CHAINING_MODE, (PUCHAR) BCRYPT_CHAIN_MODE_GCM, sizeof(BCRYPT_CHAIN_MODE_GCM), 0);
status = BCryptSetProperty(hAES, BCRYPT_CHAINING_MODE, (PUCHAR)BCRYPT_CHAIN_MODE_GCM, sizeof(BCRYPT_CHAIN_MODE_GCM), 0);
if (status)
goto closing;
@ -516,19 +516,19 @@ namespace pEp {
if (!internet)
goto closing;
{
product_list products = registered_products();
DWORD context = 0;
{
product_list products = registered_products();
DWORD context = 0;
for (auto i = products.begin(); i != products.end(); i++) {
try {
update_product(*i, context++);
}
catch (exception&) {
for (auto i = products.begin(); i != products.end(); i++) {
try {
update_product(*i, context++);
}
catch (exception&) {
}
}
}
}
}
}
closing:
if (internet)


+ 1
- 1
GateKeeper.h View File

@ -52,7 +52,7 @@ namespace pEp {
void update_product(product p, DWORD context);
product_list registered_products();
void keep_updated();
static tstring get_lockFile();
static tstring get_lockFile();
private:
time_t now;


+ 42
- 42
locked_queue.hh View File

@ -5,48 +5,48 @@
namespace utility
{
using namespace std;
using namespace std;
template<class T> class locked_queue
{
mutex _mtx;
list<T> _q;
template<class T> class locked_queue
{
mutex _mtx;
list<T> _q;
public:
T& back()
{
lock_guard<mutex> lg(_mtx);
return _q.back();
}
T& front()
{
lock_guard<mutex> lg(_mtx);
return _q.front();
}
void pop_back()
{
lock_guard<mutex> lg(_mtx);
_q.pop_back();
}
void pop_front()
{
lock_guard<mutex> lg(_mtx);
_q.pop_front();
}
void push_back(const T& data)
{
lock_guard<mutex> lg(_mtx);
_q.push_back(data);
}
void push_front(const T& data)
{
lock_guard<mutex> lg(_mtx);
_q.push_front(data);
}
size_t size()
{
lock_guard<mutex> lg(_mtx);
return _q.size();
}
};
public:
T& back()
{
lock_guard<mutex> lg(_mtx);
return _q.back();
}
T& front()
{
lock_guard<mutex> lg(_mtx);
return _q.front();
}
void pop_back()
{
lock_guard<mutex> lg(_mtx);
_q.pop_back();
}
void pop_front()
{
lock_guard<mutex> lg(_mtx);
_q.pop_front();
}
void push_back(const T& data)
{
lock_guard<mutex> lg(_mtx);
_q.push_back(data);
}
void push_front(const T& data)
{
lock_guard<mutex> lg(_mtx);
_q.push_front(data);
}
size_t size()
{
lock_guard<mutex> lg(_mtx);
return _q.size();
}
};
};

+ 1
- 1
pEpCOMServerAdapter.cpp View File

@ -21,7 +21,7 @@ CpEpCOMServerAdapterModule _AtlModule;
//
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
LPTSTR /*lpCmdLine*/, int nShowCmd)
LPTSTR /*lpCmdLine*/, int nShowCmd)
{
_AtlModule.hModule(hInstance);
_AtlModule.start_gatekeeper();


+ 90
- 90
pEpCOMServerAdapter.idl View File

@ -53,7 +53,7 @@ interface IpEpEngineCallbacks : IUnknown {
nonextensible,
pointer_default(unique)
]
interface IpEpEngineCallbacks2 : IpEpEngineCallbacks
interface IpEpEngineCallbacks2 : IpEpEngineCallbacks
{
[id(3)] HRESULT NeedFastPolling([in] VARIANT_BOOL enableFastPolling);
};
@ -146,93 +146,93 @@ interface IpEpEngine : IUnknown {
pEpCtpEp = 0xff
} pEpComType;
typedef enum pEpStatus {
pEpStatusOk = 0,
pEpInitCannotLoadGpgme = 0x0110,
pEpInitGpgmeInitFailed = 0x0111,
pEpInitNoGpgHome = 0x0112,
pEpInitNetpgpInitFailed = 0x0113,
pEpInitCannotDetermineGpgVersion = 0x0114,
pEpInitUnsupportedGpgVersion = 0x0115,
pEpInitCannotConfigGpgAgent = 0x0116,
pEpInitSqlite3WithoutMutex = 0x0120,
pEpInitCannotOpenDb = 0x0121,
pEpInitCannotOpenSystemDb = 0x0122,
pEpKeyNotFound = 0x0201,
pEpKeyHasAmbigName = 0x0202,
pEpGetKeyFailed = 0x0203,
pEpCannotExportKey = 0x0204,
pEpCannotEditKey = 0x0205,
pEpKeyUnsuitable = 0x0206,
pEpCannotFindIdentity = 0x0301,
pEpCannotSetPerson = 0x0381,
pEpCannotSetPgpKeypair = 0x0382,
pEpCannotSetIdentity = 0x0383,
pEpCannotSetTrust = 0x0384,
pEpKeyBlacklisted = 0x0385,
pEpCannotFindPerson = 0x0386,
pEpCannotFindAlias = 0x0391,
pEpCannotSetAlias = 0x0392,
pEpUnencrypted = 0x0400,
pEpVerified = 0x0401,
pEpDecrypted = 0x0402,
pEpDecryptedAndVerified = 0x0403,
pEpDecryptWrongFormat = 0x0404,
pEpDecryptNoKey = 0x0405,
pEpDecryptSignatureDoesNotMatch = 0x0406,
pEpVerifyNoKey = 0x0407,
pEpVerifiedAndTrusted = 0x0408,
pEpCannotDecryptUnknown = 0x04ff,
pEpTrustwordNotFound = 0x0501,
pEpTrustwordsFprWrongLength = 0x0502,
pEpTrustwordsDuplicateFpr = 0x0503,
pEpCannotCreateKey = 0x0601,
pEpCannotSendKey = 0x0602,
pEpPhraseNotFound = 0x0701,
pEpSendFunctionNotRegistered = 0x0801,
pEpContraintsViolated = 0x0802,
pEpCannotEncode = 0x0803,
pEpSyncNoNotifyCallback = 0x0901,
pEpSyncIllegalMessage = 0x0902,
pEpSyncNoInjectCallback = 0x0903,
pEpSequenceViolated = 0x0970,
pEpCannotIncreaseSequence = 0x0971,
pEpCannotSetSequenceValue = 0x0972,
pEpOwnSequence = 0x097f,
pEpSyncStatemachineError = 0x0980,
pEpSyncNoTrust = 0x0981,
pEpStatemachineInvalidState = 0x0982,
pEpStatemachineInvalidEvent = 0x0983,
pEpStatemachineInvalidCondition = 0x0984,
pEpStatemachineInvalidAction = 0x0985,
pEpStatemachineInhibitedEvent = 0x0986,
pEpCommitFailed = 0xff01,
pEpMessageConsume = 0xff02,
pEpMessageIgnore = 0xff03,
pEpRecordNotFound = -6,
pEpCannotCreateTempFile = -5,
pEpIllegalValue = -4,
pEpBufferTooSmall = -3,
pEpOutOfMemory = -2,
pEpUnknownError = -1,
pEpVersionMismatch = -7,
} pEpStatus;
typedef enum pEpStatus {
pEpStatusOk = 0,
pEpInitCannotLoadGpgme = 0x0110,
pEpInitGpgmeInitFailed = 0x0111,
pEpInitNoGpgHome = 0x0112,
pEpInitNetpgpInitFailed = 0x0113,
pEpInitCannotDetermineGpgVersion = 0x0114,
pEpInitUnsupportedGpgVersion = 0x0115,
pEpInitCannotConfigGpgAgent = 0x0116,
pEpInitSqlite3WithoutMutex = 0x0120,
pEpInitCannotOpenDb = 0x0121,
pEpInitCannotOpenSystemDb = 0x0122,
pEpKeyNotFound = 0x0201,
pEpKeyHasAmbigName = 0x0202,
pEpGetKeyFailed = 0x0203,
pEpCannotExportKey = 0x0204,
pEpCannotEditKey = 0x0205,
pEpKeyUnsuitable = 0x0206,
pEpCannotFindIdentity = 0x0301,
pEpCannotSetPerson = 0x0381,
pEpCannotSetPgpKeypair = 0x0382,
pEpCannotSetIdentity = 0x0383,
pEpCannotSetTrust = 0x0384,
pEpKeyBlacklisted = 0x0385,
pEpCannotFindPerson = 0x0386,
pEpCannotFindAlias = 0x0391,
pEpCannotSetAlias = 0x0392,
pEpUnencrypted = 0x0400,
pEpVerified = 0x0401,
pEpDecrypted = 0x0402,
pEpDecryptedAndVerified = 0x0403,
pEpDecryptWrongFormat = 0x0404,
pEpDecryptNoKey = 0x0405,
pEpDecryptSignatureDoesNotMatch = 0x0406,
pEpVerifyNoKey = 0x0407,
pEpVerifiedAndTrusted = 0x0408,
pEpCannotDecryptUnknown = 0x04ff,
pEpTrustwordNotFound = 0x0501,
pEpTrustwordsFprWrongLength = 0x0502,
pEpTrustwordsDuplicateFpr = 0x0503,
pEpCannotCreateKey = 0x0601,
pEpCannotSendKey = 0x0602,
pEpPhraseNotFound = 0x0701,
pEpSendFunctionNotRegistered = 0x0801,
pEpContraintsViolated = 0x0802,
pEpCannotEncode = 0x0803,
pEpSyncNoNotifyCallback = 0x0901,
pEpSyncIllegalMessage = 0x0902,
pEpSyncNoInjectCallback = 0x0903,
pEpSequenceViolated = 0x0970,
pEpCannotIncreaseSequence = 0x0971,
pEpCannotSetSequenceValue = 0x0972,
pEpOwnSequence = 0x097f,
pEpSyncStatemachineError = 0x0980,
pEpSyncNoTrust = 0x0981,
pEpStatemachineInvalidState = 0x0982,
pEpStatemachineInvalidEvent = 0x0983,
pEpStatemachineInvalidCondition = 0x0984,
pEpStatemachineInvalidAction = 0x0985,
pEpStatemachineInhibitedEvent = 0x0986,
pEpCommitFailed = 0xff01,
pEpMessageConsume = 0xff02,
pEpMessageIgnore = 0xff03,
pEpRecordNotFound = -6,
pEpCannotCreateTempFile = -5,
pEpIllegalValue = -4,
pEpBufferTooSmall = -3,
pEpOutOfMemory = -2,
pEpUnknownError = -1,
pEpVersionMismatch = -7,
} pEpStatus;
typedef [v1_enum] enum pEpIdentityFlags {
pEpIdfNone = 0,
@ -403,7 +403,7 @@ interface IpEpEngine2 : IpEpEngine
HRESULT EncryptMessageForSelf(
[in] struct pEpIdentity* targetId,
[in] struct TextMessage* src,
[in] struct TextMessage* src,
[out] struct TextMessage* dst,
[in, defaultvalue(pEpEncryptFlagDefault)] pEpEncryptFlags flags
);
@ -415,7 +415,7 @@ interface IpEpEngine2 : IpEpEngine
[out, retval] pEpRating *rating
);
HRESULT UndoLastMistrust();
HRESULT UndoLastMistrust();
};
[


+ 76
- 76
pEp_utility.cpp View File

@ -7,8 +7,8 @@ namespace pEp {
namespace utility {
pEp_identity_cpp::pEp_identity_cpp(const ::pEp_identity *_ident)
{
if (!_ident)
return;
if (!_ident)
return;
if (_ident->address)
address = _ident->address;
@ -18,17 +18,17 @@ namespace pEp {
user_id = _ident->user_id;
if (_ident->username)
username = _ident->username;
comm_type = (pEpComType) _ident->comm_type;
comm_type = (pEpComType)_ident->comm_type;
lang = _ident->lang;
flags = (int) _ident->flags;
flags = (int)_ident->flags;
}
pEp_identity_cpp::pEp_identity_cpp(const pEpIdentity *_ident)
{
if (!_ident)
return;
if (!_ident)
return;
if (_ident->Address)
if (_ident->Address)
address = utf8_string(_ident->Address);
if (_ident->Fpr)
fpr = utf8_string(_ident->Fpr);
@ -39,7 +39,7 @@ namespace pEp {
comm_type = _ident->CommType;
if (_ident->Lang)
lang = utf8_string(_ident->Lang);
flags = (int)_ident->Flags;
flags = (int)_ident->Flags;
}
pEp_identity * pEp_identity_cpp::to_pEp_identity()
@ -58,14 +58,14 @@ namespace pEp {
_ident->lang[1] = this->lang[1];
}
_ident->flags = (identity_flags) this->flags;
_ident->flags = (identity_flags) this->flags;
return _ident;
}
pEpIdentity * pEp_identity_cpp::to_pEp_identity_s()
{
pEpIdentity *_ident = (pEpIdentity *) calloc(1, sizeof(pEpIdentity));
pEpIdentity *_ident = (pEpIdentity *)calloc(1, sizeof(pEpIdentity));
assert(_ident);
if (_ident == NULL)
throw bad_alloc();
@ -76,7 +76,7 @@ namespace pEp {
_ident->Lang = utf16_bstr(this->lang);
_ident->UserName = utf16_bstr(this->username);
_ident->UserId = utf16_bstr(this->user_id);
_ident->Flags = (pEpIdentityFlags) this->flags;
_ident->Flags = (pEpIdentityFlags) this->flags;
return _ident;
}
@ -84,8 +84,8 @@ namespace pEp {
void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident)
{
assert(ident_s);
if (!ident_s)
throw invalid_argument("ident_s");
if (!ident_s)
throw invalid_argument("ident_s");
::memset(ident_s, 0, sizeof(pEpIdentity));
if (ident) {
@ -97,10 +97,10 @@ namespace pEp {
ident_s->UserId = utf16_bstr(ident->user_id);
if (ident->username)
ident_s->UserName = utf16_bstr(ident->username);
ident_s->CommType = (pEpComType) ident->comm_type;
ident_s->CommType = (pEpComType)ident->comm_type;
if (ident->lang)
ident_s->Lang = utf16_bstr(ident->lang);
ident_s->Flags = (pEpIdentityFlags) ident->flags;
ident_s->Flags = (pEpIdentityFlags)ident->flags;
}
}
@ -138,7 +138,7 @@ namespace pEp {
if (_ident == NULL)
throw bad_alloc();
_ident->comm_type = (PEP_comm_type) ident->CommType;
_ident->comm_type = (PEP_comm_type)ident->CommType;
if (ident->Lang) {
string _lang = utf8_string(ident->Lang);
@ -160,7 +160,7 @@ namespace pEp {
}
}
_ident->flags = (identity_flags_t)ident->Flags;
_ident->flags = (identity_flags_t)ident->Flags;
return _ident;
}
@ -177,21 +177,21 @@ namespace pEp {
template<> Blob *from_C< Blob *, bloblist_t >(bloblist_t *tl)
{
assert(tl);
assert(tl);
CComSafeArray<BYTE> sa;
if (tl) {
sa.Create(tl->size);
if (tl->size) {
char *data;
SafeArrayAccessData(sa, (void **)&data);
memcpy(data, tl->value, tl->size);
SafeArrayUnaccessData(sa);
}
}
else {
sa.Create((ULONG)0);
}
if (tl) {
sa.Create(tl->size);
if (tl->size) {
char *data;
SafeArrayAccessData(sa, (void **)&data);
memcpy(data, tl->value, tl->size);
SafeArrayUnaccessData(sa);
}
}
else {
sa.Create((ULONG)0);
}
Blob *_blob = new Blob();
@ -286,9 +286,9 @@ namespace pEp {
void clear_text_message(TextMessage *msg)
{
assert(msg);
if (!msg)
return;
assert(msg);
if (!msg)
return;
SysFreeString(msg->Id);
SysFreeString(msg->ShortMsg);
@ -314,20 +314,20 @@ namespace pEp {
assert(msg2);
assert(msg);
if (!msg2) {
msg2 = (TextMessage *)calloc(1, sizeof(TextMessage));
assert(msg2);
if (!msg2)
throw bad_alloc();
}
else {
clear_text_message(msg2);
}
if (!msg2) {
msg2 = (TextMessage *)calloc(1, sizeof(TextMessage));
assert(msg2);
if (!msg2)
throw bad_alloc();
}
else {
clear_text_message(msg2);
}
if (!msg)
return;
if (!msg)
return;
msg2->Dir = (pEpMsgDirection) msg->dir;
msg2->Dir = (pEpMsgDirection)msg->dir;
msg2->Id = bstr(msg->id);
msg2->ShortMsg = bstr(msg->shortmsg);
msg2->LongMsg = bstr(msg->longmsg);
@ -397,15 +397,15 @@ namespace pEp {
char *buffer;
if (size) {
buffer = (char *) malloc(size + 1);
buffer = (char *)malloc(size + 1);
if (buffer == NULL)
throw bad_alloc();
char *data;
SafeArrayAccessData(b.value, (void **) &data);
SafeArrayAccessData(b.value, (void **)&data);
memcpy(buffer, data, size);
buffer[size] = 0; // safeguard
buffer[size] = 0; // safeguard
SafeArrayUnaccessData(sa);
}
else {
@ -472,14 +472,14 @@ namespace pEp {
stringpair_t *new_stringpair(StringPair *fld)
{
stringpair_t *pair;
if (!fld) {
pair = ::new_stringpair(NULL, NULL);
}
else {
pair = ::new_stringpair(str(fld->Name), str(fld->Value));
}
stringpair_t *pair;
if (!fld) {
pair = ::new_stringpair(NULL, NULL);
}
else {
pair = ::new_stringpair(str(fld->Name), str(fld->Value));
}
if (pair == NULL)
throw bad_alloc();
@ -534,14 +534,14 @@ namespace pEp {
return il;
}
::message * text_message_to_C(TextMessage *msg)
{
assert(msg);
if (!msg)
throw invalid_argument("msg");
if (!msg)
throw invalid_argument("msg");
::message * msg2 = new_message((PEP_msg_direction) msg->Dir);
::message * msg2 = new_message((PEP_msg_direction)msg->Dir);
if (msg2 == NULL)
throw bad_alloc();
@ -566,21 +566,21 @@ namespace pEp {
return msg2;
}
void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out) {
assert(spair_list);
assert(pair_list_out);
if (!spair_list)
return;
*pair_list_out = array_from_C<StringPair, stringpair_list_t>(spair_list);
}
void clear_opt_field_array(LPSAFEARRAY* opt_field_array) {
if (opt_field_array){
SafeArrayDestroy(*opt_field_array);
*opt_field_array = NULL;
}
}
void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out) {
assert(spair_list);
assert(pair_list_out);
if (!spair_list)
return;
*pair_list_out = array_from_C<StringPair, stringpair_list_t>(spair_list);
}
void clear_opt_field_array(LPSAFEARRAY* opt_field_array) {
if (opt_field_array) {
SafeArrayDestroy(*opt_field_array);
*opt_field_array = NULL;
}
}
}
}

+ 5
- 5
pEp_utility.h View File

@ -16,7 +16,7 @@ namespace pEp {
string username;
pEpComType comm_type;
string lang;
int flags;
int flags;
pEp_identity_cpp(
string _address = string(),
@ -25,7 +25,7 @@ namespace pEp {
string _username = string(),
pEpComType _comm_type = pEpCtUnknown,
string _lang = string()
) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang)
) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang)
{ }
pEp_identity_cpp(const ::pEp_identity *_ident);
@ -41,9 +41,9 @@ namespace pEp {
void clear_text_message(TextMessage *msg);
::pEp_identity *new_identity(const pEpIdentity * ident);
void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
void clear_opt_field_array(LPSAFEARRAY* pair_list);
template< class T2, class T > SAFEARRAY * array_from_C(T *tl);
void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
void clear_opt_field_array(LPSAFEARRAY* pair_list);
template< class T2, class T > SAFEARRAY * array_from_C(T *tl);
static LPTYPELIB pTypelib = NULL;


+ 4
- 4
utf8_helper.cpp View File

@ -48,9 +48,9 @@ namespace pEp {
{
if (bstr == NULL)
return "";
_bstr_t _bstr(bstr);
wstring wstr = (wchar_t *) _bstr;
wstring wstr = (wchar_t *)_bstr;
_bstr.Detach();
return utf8_string(wstr, norm);
@ -90,7 +90,7 @@ namespace pEp {
if (len == 0)
return NULL;
CComSafeArray<BSTR> sa_string_list((LONG) len);
CComSafeArray<BSTR> sa_string_list((LONG)len);
LONG n = 0;
for (const ::stringlist_t *k = stringlist; k && k->value; k = k->next) {
if (k->value) {
@ -112,7 +112,7 @@ namespace pEp {
CComSafeArray<BSTR> sa(safearray);
int n_strings = 0;
::stringlist_t *_stringlist = ::new_stringlist((const char *) NULL);
::stringlist_t *_stringlist = ::new_stringlist((const char *)NULL);
assert(_stringlist);
if (_stringlist == NULL)
throw std::bad_alloc();


+ 7
- 7
xdlldata.h View File

@ -2,14 +2,14 @@
#ifdef _MERGE_PROXYSTUB
extern "C"
extern "C"
{
BOOL WINAPI PrxDllMain(HINSTANCE hInstance, DWORD dwReason,
LPVOID lpReserved);
STDAPI PrxDllCanUnloadNow(void);
STDAPI PrxDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv);
STDAPI PrxDllRegisterServer(void);
STDAPI PrxDllUnregisterServer(void);
BOOL WINAPI PrxDllMain(HINSTANCE hInstance, DWORD dwReason,
LPVOID lpReserved);
STDAPI PrxDllCanUnloadNow(void);
STDAPI PrxDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv);
STDAPI PrxDllRegisterServer(void);
STDAPI PrxDllUnregisterServer(void);
}
#endif

Loading…
Cancel
Save