diff options
author | George Hazan <ghazan@miranda.im> | 2021-01-08 17:55:06 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-01-08 17:55:06 +0300 |
commit | 8f3e583fffeba6606cf4442008c65e6902308080 (patch) | |
tree | 3dc085bc50bb64993faaaa5e4aeeaa273396887e /plugins/Dbx_sqlite/src | |
parent | 64579d553e4089d55c136140bd0058696d2cf526 (diff) |
encryption code unification, part 2: initialization & data storage
Diffstat (limited to 'plugins/Dbx_sqlite/src')
-rw-r--r-- | plugins/Dbx_sqlite/src/dbcrypt.cpp | 58 | ||||
-rwxr-xr-x | plugins/Dbx_sqlite/src/dbintf.cpp | 5 | ||||
-rwxr-xr-x | plugins/Dbx_sqlite/src/dbintf.h | 8 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/resource.h | 1 |
4 files changed, 70 insertions, 2 deletions
diff --git a/plugins/Dbx_sqlite/src/dbcrypt.cpp b/plugins/Dbx_sqlite/src/dbcrypt.cpp index f0dca5a0bc..af4aa22682 100644 --- a/plugins/Dbx_sqlite/src/dbcrypt.cpp +++ b/plugins/Dbx_sqlite/src/dbcrypt.cpp @@ -1,5 +1,63 @@ #include "stdafx.h" +///////////////////////////////////////////////////////////////////////////////////////// +// Saving encryption key in a database + +STDMETHODIMP_(BOOL) CDbxSQLite::ReadCryptoKey(MBinBuffer &buf) +{ + DBVARIANT dbv = {}; + dbv.type = DBVT_BLOB; + if (GetContactSetting(0, "CryptoEngine", "StoredKey", &dbv)) + return FALSE; + + buf.append(dbv.pbVal, dbv.cpbVal); + return TRUE; +} + +STDMETHODIMP_(BOOL) CDbxSQLite::StoreCryptoKey() +{ + size_t iKeyLength = m_crypto->getKeyLength(); + BYTE *pKey = (BYTE*)_alloca(iKeyLength); + m_crypto->getKey(pKey, iKeyLength); + + DBCONTACTWRITESETTING dbcws = { "CryptoEngine", "StoredKey" }; + dbcws.value.type = DBVT_BLOB; + dbcws.value.cpbVal = (WORD)iKeyLength; + dbcws.value.pbVal = pKey; + WriteContactSetting(0, &dbcws); + + SecureZeroMemory(pKey, iKeyLength); + return TRUE; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Saving encryption flag + +STDMETHODIMP_(BOOL) CDbxSQLite::ReadEncryption() +{ + DBVARIANT dbv = {}; + dbv.type = DBVT_BYTE; + return (GetContactSetting(0, "CryptoEngine", "DatabaseEncryption", &dbv)) ? false : dbv.bVal != 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Saving provider in a database + +STDMETHODIMP_(CRYPTO_PROVIDER*) CDbxSQLite::ReadProvider() +{ + DBVARIANT dbv = {}; + dbv.type = DBVT_BLOB; + if (GetContactSetting(0, "CryptoEngine", "Provider", &dbv)) + return nullptr; + + if (dbv.type != DBVT_BLOB) + return nullptr; + + auto *pProvider = Crypto_GetProvider(LPCSTR(dbv.pbVal)); + FreeVariant(&dbv); + return pProvider; +} + STDMETHODIMP_(BOOL) CDbxSQLite::StoreProvider(CRYPTO_PROVIDER *pProvider) { DBCONTACTWRITESETTING dbcws = { "CryptoEngine", "Provider" }; diff --git a/plugins/Dbx_sqlite/src/dbintf.cpp b/plugins/Dbx_sqlite/src/dbintf.cpp index 862ecdae75..9cc637103d 100755 --- a/plugins/Dbx_sqlite/src/dbintf.cpp +++ b/plugins/Dbx_sqlite/src/dbintf.cpp @@ -142,6 +142,11 @@ MDatabaseCommon* CDbxSQLite::Load(const wchar_t *profile, int readonly) CDbxSQLite *db = new CDbxSQLite(database); + if (!db->InitCrypt()) { + delete db; + return nullptr; + } + db->InitContacts(); db->InitSettings(); db->InitEvents(); diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h index ca220289c0..88638623a5 100755 --- a/plugins/Dbx_sqlite/src/dbintf.h +++ b/plugins/Dbx_sqlite/src/dbintf.h @@ -91,7 +91,13 @@ public: STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam) override; - STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*); + STDMETHODIMP_(BOOL) ReadCryptoKey(MBinBuffer&) override; + STDMETHODIMP_(BOOL) StoreCryptoKey() override; + + STDMETHODIMP_(CRYPTO_PROVIDER*) ReadProvider() override; + STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*) override; + + STDMETHODIMP_(BOOL) ReadEncryption() override; STDMETHODIMP_(BOOL) WriteContactSettingWorker(MCONTACT contactID, DBCONTACTWRITESETTING &dbcws) override; STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting) override; diff --git a/plugins/Dbx_sqlite/src/resource.h b/plugins/Dbx_sqlite/src/resource.h index 135f6899d0..9e2976c927 100644 --- a/plugins/Dbx_sqlite/src/resource.h +++ b/plugins/Dbx_sqlite/src/resource.h @@ -5,7 +5,6 @@ #define IDREMOVE 3 #define IDI_ICONPASS 100 #define IDI_LOGO 101 -#define IDD_LOGIN 102 #define IDD_NEWPASS 103 #define IDD_CHANGEPASS 104 #define IDD_OPTIONS 105 |