diff options
21 files changed, 58 insertions, 59 deletions
diff --git a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj index cc1048d8aa..e7d51c37b5 100644 --- a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj +++ b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj @@ -194,6 +194,7 @@ <ClCompile Include="src\database.cpp" />
<ClCompile Include="src\dbcache.cpp" />
<ClCompile Include="src\dbcontacts.cpp" />
+ <ClCompile Include="src\dbcrypt.cpp" />
<ClCompile Include="src\dbevents.cpp" />
<ClCompile Include="src\dbheaders.cpp" />
<ClCompile Include="src\dbintf.cpp" />
diff --git a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters index c775e8db4e..d4e3c10739 100644 --- a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters +++ b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters @@ -27,6 +27,9 @@ <ClCompile Include="src\dbcontacts.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\dbcrypt.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="src\dbevents.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/plugins/Db3x_mmap/db3x_mmap_11.vcxproj b/plugins/Db3x_mmap/db3x_mmap_11.vcxproj index 751fab5e64..f2ba160fb7 100644 --- a/plugins/Db3x_mmap/db3x_mmap_11.vcxproj +++ b/plugins/Db3x_mmap/db3x_mmap_11.vcxproj @@ -197,6 +197,7 @@ <ClCompile Include="src\database.cpp" />
<ClCompile Include="src\dbcache.cpp" />
<ClCompile Include="src\dbcontacts.cpp" />
+ <ClCompile Include="src\dbcrypt.cpp" />
<ClCompile Include="src\dbevents.cpp" />
<ClCompile Include="src\dbheaders.cpp" />
<ClCompile Include="src\dbintf.cpp" />
diff --git a/plugins/Db3x_mmap/db3x_mmap_11.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap_11.vcxproj.filters index c775e8db4e..d4e3c10739 100644 --- a/plugins/Db3x_mmap/db3x_mmap_11.vcxproj.filters +++ b/plugins/Db3x_mmap/db3x_mmap_11.vcxproj.filters @@ -27,6 +27,9 @@ <ClCompile Include="src\dbcontacts.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\dbcrypt.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="src\dbevents.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/plugins/Db3x_mmap/db3x_mmap_12.vcxproj b/plugins/Db3x_mmap/db3x_mmap_12.vcxproj index 4cdaf1e462..99cd776dd2 100644 --- a/plugins/Db3x_mmap/db3x_mmap_12.vcxproj +++ b/plugins/Db3x_mmap/db3x_mmap_12.vcxproj @@ -197,6 +197,7 @@ <ClCompile Include="src\database.cpp" />
<ClCompile Include="src\dbcache.cpp" />
<ClCompile Include="src\dbcontacts.cpp" />
+ <ClCompile Include="src\dbcrypt.cpp" />
<ClCompile Include="src\dbevents.cpp" />
<ClCompile Include="src\dbheaders.cpp" />
<ClCompile Include="src\dbintf.cpp" />
diff --git a/plugins/Db3x_mmap/db3x_mmap_12.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap_12.vcxproj.filters index c775e8db4e..a9d064b34d 100644 --- a/plugins/Db3x_mmap/db3x_mmap_12.vcxproj.filters +++ b/plugins/Db3x_mmap/db3x_mmap_12.vcxproj.filters @@ -78,6 +78,9 @@ <ClCompile Include="src\stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\dbcrypt.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\commonheaders.h">
diff --git a/plugins/Db3x_mmap/src/commonheaders.h b/plugins/Db3x_mmap/src/commonheaders.h index d122b08d1e..12286e83d6 100644 --- a/plugins/Db3x_mmap/src/commonheaders.h +++ b/plugins/Db3x_mmap/src/commonheaders.h @@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_system_cpp.h>
#include <m_database.h>
#include <m_langpack.h>
+#include <m_crypto.h>
#include "database.h"
#include "dbintf.h"
diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp index 874a3b733e..8862c7192f 100644 --- a/plugins/Db3x_mmap/src/dbcache.cpp +++ b/plugins/Db3x_mmap/src/dbcache.cpp @@ -26,15 +26,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void CDb3Mmap::Map()
{
m_hMap = CreateFileMapping(m_hDbFile, NULL, PAGE_READWRITE, 0, m_dwFileSize, NULL);
-
- if (m_hMap)
- {
+ if (m_hMap) {
m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, FILE_MAP_ALL_ACCESS/*FILE_MAP_WRITE*/, 0, 0 ,0);
if (!m_pDbCache)
DatabaseCorruption( _T("%s (MapViewOfFile failed. Code: %d)"));
}
- else
- DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)"));
+ else DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)"));
}
void CDb3Mmap::ReMap(DWORD needed)
@@ -43,18 +40,15 @@ void CDb3Mmap::ReMap(DWORD needed) log3("remapping %d + %d (file end: %d)",m_dwFileSize,needed,m_dbHeader.ofsFileEnd);
- if (needed > m_ChunkSize)
- {
+ if (needed > m_ChunkSize) {
if (needed + m_dwFileSize > m_dbHeader.ofsFileEnd + m_ChunkSize)
DatabaseCorruption( _T("%s (Too large increment)"));
- else
- {
+ else {
DWORD x = m_dbHeader.ofsFileEnd/m_ChunkSize;
m_dwFileSize = (x+1)*m_ChunkSize;
}
}
- else
- m_dwFileSize += m_ChunkSize;
+ else m_dwFileSize += m_ChunkSize;
// FlushViewOfFile(m_pDbCache, 0);
UnmapViewOfFile(m_pDbCache);
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 0888e8c7f9..caaa1e5a74 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -58,7 +58,7 @@ CDb3Base::CDb3Base(const TCHAR *tszFileName) : m_ChunkSize = sinf.dwAllocationGranularity;
m_codePage = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
- m_hModHeap = HeapCreate(0,0,0);
+ m_hModHeap = HeapCreate(0, 0, 0);
}
CDb3Base::~CDb3Base()
@@ -71,12 +71,15 @@ CDb3Base::~CDb3Base() m_lOfs.destroy();
// destroy map
- KillTimer(NULL,m_flushBuffersTimerId);
+ KillTimer(NULL, m_flushBuffersTimerId);
if (m_pDbCache) {
FlushViewOfFile(m_pDbCache, 0);
UnmapViewOfFile(m_pDbCache);
}
+ if (m_crypto)
+ m_crypto->destroy();
+
if (m_hMap)
CloseHandle(m_hMap);
@@ -114,6 +117,7 @@ int CDb3Base::Load(bool bSkipInit) if ( !bSkipInit) {
if (InitCache()) return 1;
if (InitModuleNames()) return 1;
+ if (InitCrypt()) return 1;
m_bReadOnly = false;
@@ -142,26 +146,6 @@ STDMETHODIMP_(void) CDb3Base::SetCacheSafetyMode(BOOL bIsSet) DBFlush(1);
}
-void CDb3Base::EncodeCopyMemory(void *dst, void *src, size_t size)
-{
- MoveMemory(dst, src, size);
-}
-
-void CDb3Base::DecodeCopyMemory(void *dst, void *src, size_t size)
-{
- MoveMemory(dst, src, size);
-}
-
-void CDb3Base::EncodeDBWrite(DWORD ofs, void *src, int size)
-{
- DBWrite(ofs, src, size);
-}
-
-void CDb3Base::DecodeDBWrite(DWORD ofs, void *src, int size)
-{
- DBWrite(ofs, src, size);
-}
-
///////////////////////////////////////////////////////////////////////////////
// MIDatabaseChecker
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index 152e8613b2..80f1d32790 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -204,6 +204,7 @@ protected: virtual int InitCache(void) = 0;
protected:
+ int InitCrypt(void);
virtual void EncodeCopyMemory(void *dst, void *src, size_t size);
virtual void DecodeCopyMemory(void *dst, void *src, size_t size);
virtual void EncodeDBWrite(DWORD ofs, void *src, int size);
@@ -223,7 +224,9 @@ protected: DBHeader m_dbHeader;
DWORD m_ChunkSize;
bool m_safetyMode, m_bReadOnly;
-
+
+ MICryptoEngine *m_crypto;
+
////////////////////////////////////////////////////////////////////////////
// database stuff
public:
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj index 5aa4e3f5d6..7a548ce305 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj @@ -194,6 +194,7 @@ <ClCompile Include="..\Db3x_mmap\src\database.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbcache.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbcontacts.cpp" />
+ <ClCompile Include="..\Db3x_mmap\src\dbcrypt.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbevents.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbheaders.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbintf.cpp" />
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters index ecddf5d298..ab9907fdb9 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters @@ -90,6 +90,9 @@ <ClCompile Include="src\stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\Db3x_mmap\src\dbcrypt.cpp">
+ <Filter>Mmap files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\commonheaders.h">
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_11.vcxproj b/plugins/Dbx_mmap_SA/db3x_mmap_sa_11.vcxproj index 211cd216f3..6f1fd99934 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_11.vcxproj +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_11.vcxproj @@ -197,6 +197,7 @@ <ClCompile Include="..\Db3x_mmap\src\database.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbcache.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbcontacts.cpp" />
+ <ClCompile Include="..\Db3x_mmap\src\dbcrypt.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbevents.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbheaders.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbintf.cpp" />
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_11.vcxproj.filters b/plugins/Dbx_mmap_SA/db3x_mmap_sa_11.vcxproj.filters index ecddf5d298..ab9907fdb9 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_11.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_11.vcxproj.filters @@ -90,6 +90,9 @@ <ClCompile Include="src\stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\Db3x_mmap\src\dbcrypt.cpp">
+ <Filter>Mmap files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\commonheaders.h">
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_12.vcxproj b/plugins/Dbx_mmap_SA/db3x_mmap_sa_12.vcxproj index 5710d3c924..8168d59428 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_12.vcxproj +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_12.vcxproj @@ -197,6 +197,7 @@ <ClCompile Include="..\Db3x_mmap\src\database.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbcache.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbcontacts.cpp" />
+ <ClCompile Include="..\Db3x_mmap\src\dbcrypt.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbevents.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbheaders.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbintf.cpp" />
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_12.vcxproj.filters b/plugins/Dbx_mmap_SA/db3x_mmap_sa_12.vcxproj.filters index ecddf5d298..ab9907fdb9 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_12.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_12.vcxproj.filters @@ -90,6 +90,9 @@ <ClCompile Include="src\stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\Db3x_mmap\src\dbcrypt.cpp">
+ <Filter>Mmap files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\commonheaders.h">
diff --git a/plugins/Dbx_mmap_SA/src/commonheaders.h b/plugins/Dbx_mmap_SA/src/commonheaders.h index 87255bdc18..cfee1a77ae 100644 --- a/plugins/Dbx_mmap_SA/src/commonheaders.h +++ b/plugins/Dbx_mmap_SA/src/commonheaders.h @@ -39,6 +39,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_langpack.h>
#include <m_options.h>
#include <m_skin.h>
+#include <m_crypto.h>
#include <m_folders.h>
diff --git a/plugins/Dbx_mmap_SA/src/security.cpp b/plugins/Dbx_mmap_SA/src/security.cpp index 04d7c82b49..6d41787d24 100644 --- a/plugins/Dbx_mmap_SA/src/security.cpp +++ b/plugins/Dbx_mmap_SA/src/security.cpp @@ -69,37 +69,27 @@ void CDbxMmapSA::EncodeCopyMemory(void * dst, void * src, size_t size ) {
memcpy(dst, src, size);
- if (!m_bEncoding)
- return;
-
- CryptoEngine->EncryptMem((BYTE *)dst, (int)size, key);
+ if (m_bEncoding)
+ CryptoEngine->EncryptMem((BYTE *)dst, (int)size, key);
}
void CDbxMmapSA::DecodeCopyMemory(void * dst, void * src, size_t size )
{
memcpy(dst, src, size);
- if (!m_bEncoding)
- return;
-
- CryptoEngine->DecryptMem((BYTE *)dst, (int)size, key);
+ if (m_bEncoding)
+ CryptoEngine->DecryptMem((BYTE *)dst, (int)size, key);
}
void CDbxMmapSA::EncodeDBWrite(DWORD ofs, void *src, int size)
{
- if (m_bEncoding)
- {
- BYTE * buf;
-
- buf = (BYTE*)GlobalAlloc(GPTR, sizeof(BYTE)*size);
+ if (m_bEncoding) {
+ BYTE *buf = (BYTE*)GlobalAlloc(GPTR, sizeof(BYTE)*size);
EncodeCopyMemory(buf, src, size);
DBWrite(ofs, buf, (int)size);
GlobalFree(buf);
}
- else
- {
- DBWrite(ofs, src, (int)size);
- }
+ else DBWrite(ofs, src, (int)size);
}
void CDbxMmapSA::DecodeDBWrite(DWORD ofs, void *src, int size)
@@ -242,9 +232,8 @@ void CDbxMmapSA::EncryptDB() return;
}
- if (SelectEncoder()) {
+ if (SelectEncoder())
return;
- }
bEncProcess = 1;
@@ -366,4 +355,4 @@ void CDbxMmapSA::ChangePwd() zero_fill((BYTE *)newpass, sizeof newpass);
LeaveCriticalSection(&m_csDbAccess);
-}
\ No newline at end of file +}
diff --git a/src/core/stdcrypt/encrypt.cpp b/src/core/stdcrypt/encrypt.cpp index 851bae8450..7414d999f3 100644 --- a/src/core/stdcrypt/encrypt.cpp +++ b/src/core/stdcrypt/encrypt.cpp @@ -34,7 +34,7 @@ void CStdCrypt::destroy() size_t CStdCrypt::getKeyLength()
{
- return m_aes.GetKeyLength();
+ return KEY_LENGTH;
}
bool CStdCrypt::getKey(BYTE *pKey, size_t cbKeyLen)
@@ -65,10 +65,12 @@ int CStdCrypt::setKey(const BYTE *pKey, size_t cbKeyLen) void CStdCrypt::generateKey(void)
{
LARGE_INTEGER counter;
+ QueryPerformanceCounter(&counter);
+ srand(counter.LowPart);
+
for (int i = 0; i < sizeof(m_key); i++) {
- QueryPerformanceCounter(&counter);
- srand(counter.LowPart);
m_key[i] = (BYTE)rand();
+ Sleep(0);
}
m_aes.MakeKey(m_key, m_password, KEY_LENGTH, BLOCK_SIZE);
diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp index b529a1af2c..7fec687d63 100644 --- a/src/modules/plugins/newplugins.cpp +++ b/src/modules/plugins/newplugins.cpp @@ -413,7 +413,7 @@ pluginEntry* OpenPlugin(TCHAR *tszFileName, TCHAR *dir, TCHAR *path) BASIC_PLUGIN_INFO bpi;
if ( checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
// plugin is valid
- p->pclass |= ((bIsDb ? PCLASS_DB : PCLASS_OK) | PCLASS_BASICAPI);
+ p->pclass |= ((bIsDb ? PCLASS_DB : PCLASS_CRYPT) | PCLASS_BASICAPI);
// copy the dblink stuff
p->bpi = bpi;
@@ -849,7 +849,7 @@ void UnloadNewPluginsModule(void) // unload everything but the DB
for (int i = pluginList.getCount()-1; i >= 0; i--) {
pluginEntry* p = pluginList[i];
- if ( !(p->pclass & PCLASS_DB) && p != pluginList_crshdmp)
+ if (!(p->pclass & (PCLASS_DB | PCLASS_CRYPT)) && p != pluginList_crshdmp)
Plugin_Uninit(p);
}
diff --git a/src/modules/plugins/plugins.h b/src/modules/plugins/plugins.h index 72e3087f4a..2b7adb7f9b 100644 --- a/src/modules/plugins/plugins.h +++ b/src/modules/plugins/plugins.h @@ -37,6 +37,7 @@ struct BASIC_PLUGIN_INFO #define PCLASS_CLIST 0x80 // a CList implementation
#define PCLASS_SERVICE 0x100 // has Service Mode implementation
#define PCLASS_CORE 0x200 // a plugin from the /Core directory
+#define PCLASS_CRYPT 0x400 // crypto provider
struct pluginEntry
{
|