|
From: Jeffrey D. <ha...@us...> - 2003-10-15 19:49:58
|
Log Message:
-----------
Encrypted memloc support
Modified Files:
--------------
/cvsroot/decaldev/source/DenAgent:
DenAgent.cpp
DenAgent.h
DenAgentDlg.cpp
StdAfx.h
Revision Data
-------------
Index: DenAgent.cpp
===================================================================
RCS file: /cvsroot/decaldev/source/DenAgent/DenAgent.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- DenAgent.cpp 29 May 2003 21:30:16 -0000 1.18
+++ DenAgent.cpp 15 Oct 2003 19:46:52 -0000 1.19
@@ -245,8 +245,19 @@
{
pDoc.CreateInstance ( __uuidof ( MSXML::DOMDocument ), NULL, CLSCTX_INPROC_SERVER );
pDoc->async = false;
- if ( !pDoc->load ( static_cast< LPCTSTR > ( strXMLFile ) ) )
- {
+ BOOL bSuccess = pDoc->load( static_cast< LPCTSTR > ( strXMLFile ) );
+
+ if( !bSuccess )
+ {
+ std::string szXIML;
+ DecryptXML( static_cast< LPCSTR >( strXMLFile ), szXML );
+
+ if( szXML != "" )
+ bSuccess = pDoc->loadXML( _bstr_t( szXML.c_str() ) );
+ }
+
+ if( ! bSuccess )
+ {
CString strMessage;
strMessage.FormatMessage ( IDE_NOXMLDOC, static_cast< LPCTSTR > ( strXMLFile ) );
@@ -312,6 +323,61 @@
return true;
}
+void CDenAgentApp::DecryptXML( const char *szPath, std::string &szXML )
+{
+ if( szPath == NULL )
+ {
+ szXML = "";
+ return;
+ }
+
+ FILE *f = fopen( szPath, "rb" );
+ if( f == NULL )
+ {
+ szXML = "";
+ return;
+ }
+
+ szXML.clear();
+ unsigned char szBuffer[1025];
+
+ try
+ {
+ CCryptProv crypt;
+ if( crypt.Initialize( PROV_RSA_FULL, "Decal_Memlocs", MS_DEF_PROV ) == NTE_BAD_KEYSET )
+ crypt.Initialize( PROV_RSA_FULL, "Decal_Memlocs", MS_DEF_PROV, CRYPT_NEWKEYSET );
+
+ CCryptMD5Hash hash;
+ hash.Initialize( crypt );
+ hash.AddString( DECAL_KEY );
+
+ CCryptDerivedKey key;
+ key.Initialize( crypt, hash );
+
+ DWORD dwDecLen = 0;
+
+ while( ! feof(f) )
+ {
+ memset( szBuffer, 0, sizeof( szBuffer ) );
+ dwDecLen = fread( szBuffer, 1, 1024, f );
+ key.Decrypt( feof(f), (BYTE *) szBuffer, &dwDecLen );
+ szXML += (char *)szBuffer;
+ }
+
+ key.Destroy();
+ hash.Destroy();
+ crypt.Release();
+ }
+
+ catch( ... )
+ {
+ // crap...
+ szXML = "";
+ }
+
+ fclose( f );
+}
+
bool CDenAgentApp::checkXMLVersions ( CTrayWnd* pTrayWnd )
{
bool bOK = true;
@@ -342,10 +408,21 @@
try
{
- if ( !pDoc->load ( static_cast< LPCTSTR > ( pFirst->XMLFile ) ) )
- {
+ BOOL bSuccess = pDoc->load( static_cast< LPCTSTR > ( pFirst->XMLFile ) );
+
+ if( ! bSuccess )
+ {
+ std::string szXML;
+ DecryptXML( static_cast< LPCSTR >( pFirst->XMLFile ), szXML );
+
+ if( szXML != "" )
+ bSuccess = pDoc->loadXML( _bstr_t( szXML.c_str() ) );
+ }
+
+ if( ! bSuccess )
+ {
CString strMessage;
- strMessage.FormatMessage ( IDE_NOXMLDOC, pFirst->XMLFile );
+ strMessage.FormatMessage( IDE_NOXMLDOC, pFirst->XMLFile );
::AfxMessageBox ( strMessage, MB_ICONERROR );
pFirst->build = 0;
Index: DenAgent.h
===================================================================
RCS file: /cvsroot/decaldev/source/DenAgent/DenAgent.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- DenAgent.h 20 Apr 2002 20:29:52 -0000 1.6
+++ DenAgent.h 15 Oct 2003 19:46:52 -0000 1.7
@@ -17,6 +17,10 @@
class CTrayWnd;
+
+// the public key to unencrypt memlocs.xml
+#include "..\include\DecalKey.h"
+
/////////////////////////////////////////////////////////////////////////////
// CDenAgentApp:
// See DenAgent.cpp for the implementation of this class
@@ -32,6 +36,9 @@
static bool getVersionInfo ( LPCTSTR szFilename, int &iReleaseMajor, int &iReleaseMinor, int &iBuildMajor, int &iBuildMinor );
static bool getACVersionString ( CString &strVersion );
static bool getCOMObjectDLL ( REFCLSID rclsid, CString &strFilename );
+
+ // decrypts xml file
+ static void DecryptXML( const char *szPath, std::string &szXML );
// Prepends the agent path to a filename
static bool getAgentPath ( LPCTSTR szFilename, CString &strPath );
Index: DenAgentDlg.cpp
===================================================================
RCS file: /cvsroot/decaldev/source/DenAgent/DenAgentDlg.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- DenAgentDlg.cpp 23 Jun 2003 04:58:21 -0000 1.36
+++ DenAgentDlg.cpp 15 Oct 2003 19:46:52 -0000 1.37
@@ -581,7 +581,17 @@
m_pDoc.CreateInstance( __uuidof( MSXML::DOMDocument ) );
m_pDoc->async = false;
- if (m_pDoc->load(_bstr_t(szFilename)) == VARIANT_FALSE)
+ BOOL bSuccess = m_pDoc->load( _bstr_t(szFilename) );
+ if( !bSuccess )
+ {
+ std::string szXML;
+ CDenAgentApp::DecryptXML( static_cast< LPCSTR >( szFilename ), szXML );
+
+ if( szXML != "" )
+ bSuccess = m_pDoc->loadXML( _bstr_t( szXML.c_str() ) );
+ }
+
+ if( !bSuccess )
return;
if (strlen(pszRootElement)) {
Index: StdAfx.h
===================================================================
RCS file: /cvsroot/decaldev/source/DenAgent/StdAfx.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- StdAfx.h 29 May 2003 21:30:15 -0000 1.10
+++ StdAfx.h 15 Oct 2003 19:46:52 -0000 1.11
@@ -28,8 +28,9 @@
#include <atlbase.h>
#include <comdef.h>
+#include <atlcrypt.h>
- #define _ATL_APARTMENT_THREADED
+#define _ATL_APARTMENT_THREADED
#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
|