summaryrefslogtreecommitdiff
path: root/plugins/Dbx_sqlite/src/dbcrypt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Dbx_sqlite/src/dbcrypt.cpp')
-rw-r--r--plugins/Dbx_sqlite/src/dbcrypt.cpp58
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" };