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/dbcrypt.cpp | |
parent | 64579d553e4089d55c136140bd0058696d2cf526 (diff) |
encryption code unification, part 2: initialization & data storage
Diffstat (limited to 'plugins/Dbx_sqlite/src/dbcrypt.cpp')
-rw-r--r-- | plugins/Dbx_sqlite/src/dbcrypt.cpp | 58 |
1 files changed, 58 insertions, 0 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" }; |