From: Jeffrey D. <ha...@us...> - 2003-10-15 20:10:35
|
Log Message: ----------- encrypted messages support Modified Files: -------------- /cvsroot/decaldev/source/DecalNet: Message.cpp Message.h StdAfx.h Revision Data ------------- Index: Message.cpp =================================================================== RCS file: /cvsroot/decaldev/source/DecalNet/Message.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Message.cpp 19 Nov 2002 02:25:02 -0000 1.5 +++ Message.cpp 15 Oct 2003 20:10:03 -0000 1.6 @@ -44,11 +44,76 @@ m_pService->m_pDecal->MapPath( strTemplate, &strPath ); g_pXML.CreateInstance( __uuidof( MSXML::DOMDocument ) ); - g_pXML->load( strPath.m_str ); + BOOL bSuccess = g_pXML->load( strPath.m_str ); + + if( ! bSuccess ) + { + USES_CONVERSION; + std::string szXML; + DecryptXML( OLE2A( strPath.m_str ), szXML ); + + if( szXML != "" ) + bSuccess = g_pXML->loadXML( _bstr_t( szXML.c_str() ) ); + } // Initialize our schema helper objects cFieldLoader::init(); cElementParser::init(); +} + +void cMessage::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 ); } void cMessage::term() Index: Message.h =================================================================== RCS file: /cvsroot/decaldev/source/DecalNet/Message.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Message.h 12 Apr 2002 01:07:34 -0000 1.3 +++ Message.h 15 Oct 2003 20:10:03 -0000 1.4 @@ -8,6 +8,9 @@ class cNetService; class cMessageRoot; +// the public key to unencrypt xmls +#include "..\include\DecalKey.h" + ///////////////////////////////////////////////////////////////////////////// // cMessage class ATL_NO_VTABLE cMessage : @@ -15,7 +18,9 @@ public IDispatchImpl< IMessage2, &IID_IMessage2, &LIBID_DecalNet > { public: - class cMessageElement; + void DecryptXML( const char *szFilename, std::string &szXML ); + + class cMessageElement; class cField { Index: StdAfx.h =================================================================== RCS file: /cvsroot/decaldev/source/DecalNet/StdAfx.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- StdAfx.h 11 Oct 2003 01:45:21 -0000 1.6 +++ StdAfx.h 15 Oct 2003 20:10:03 -0000 1.7 @@ -20,6 +20,8 @@ #include <stdlib.h> #include <atlbase.h> +#include <atlcrypt.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 extern CComModule _Module; @@ -29,6 +31,7 @@ #include <time.h> #include <list> +#include <string> #include <map> #include <deque> #include <vector> |