Browse Source

Merge pull request #226 from Hoikas/no-encryption

Deprecate WDYS Encryption
Branan Purvine-Riley 12 years ago
parent
commit
4ee424df34
  1. 1
      Sources/Plasma/Apps/CMakeLists.txt
  2. 2
      Sources/Plasma/Apps/plClient/winmain.cpp
  3. 17
      Sources/Plasma/Apps/plLogDecrypt/CMakeLists.txt
  4. 128
      Sources/Plasma/Apps/plLogDecrypt/plLogDecrypt.cpp
  5. 2
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp
  6. 6
      Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp
  7. 17
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp
  8. 4
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h
  9. 5
      Sources/Plasma/PubUtilLib/plFile/plInitFileReader.cpp
  10. 3
      Sources/Plasma/PubUtilLib/plFile/plInitFileReader.h
  11. 23
      Sources/Plasma/PubUtilLib/plStatusLog/plEncryptLogLine.cpp
  12. 1
      Sources/Plasma/PubUtilLib/plStatusLog/plEncryptLogLine.h
  13. 52
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp
  14. 1
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h

1
Sources/Plasma/Apps/CMakeLists.txt

@ -5,7 +5,6 @@ add_subdirectory(plPythonPack)
add_subdirectory(plUruLauncher) add_subdirectory(plUruLauncher)
add_subdirectory(plFileSecure) add_subdirectory(plFileSecure)
add_subdirectory(plFileEncrypt) add_subdirectory(plFileEncrypt)
add_subdirectory(plLogDecrypt)
add_subdirectory(plMD5) add_subdirectory(plMD5)
add_subdirectory(plPageInfo) add_subdirectory(plPageInfo)
add_subdirectory(plSHA) add_subdirectory(plSHA)

2
Sources/Plasma/Apps/plClient/winmain.cpp

@ -897,7 +897,7 @@ static void LoadUserPass (LoginDialogParam *pLoginParam)
if (PathDoesFileExist(localFileAndPath)) if (PathDoesFileExist(localFileAndPath))
StrCopy(fileAndPath, localFileAndPath, arrsize(localFileAndPath)); StrCopy(fileAndPath, localFileAndPath, arrsize(localFileAndPath));
#endif #endif
hsStream* stream = plEncryptedStream::OpenEncryptedFile(fileAndPath, true, cryptKey); hsStream* stream = plEncryptedStream::OpenEncryptedFile(fileAndPath, cryptKey);
if (stream && !stream->AtEnd()) if (stream && !stream->AtEnd())
{ {
uint32_t savedKey[4]; uint32_t savedKey[4];

17
Sources/Plasma/Apps/plLogDecrypt/CMakeLists.txt

@ -1,17 +0,0 @@
include_directories("../../Apps")
include_directories("../../CoreLib")
include_directories("../../FeatureLib/inc")
include_directories("../../FeatureLib")
include_directories("../../NucleusLib/inc")
include_directories("../../NucleusLib")
include_directories("../../PubUtilLib/inc")
include_directories("../../PubUtilLib")
set(plLogDecrypt_SOURCES
plLogDecrypt.cpp
)
add_executable(plLogDecrypt ${plLogDecrypt_SOURCES})
target_link_libraries(plLogDecrypt CoreLib plStatusLog pnProduct)
source_group("Source Files" FILES ${plLogDecrypt_SOURCES})

128
Sources/Plasma/Apps/plLogDecrypt/plLogDecrypt.cpp

@ -1,128 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* plLogDecrypt - Used by mantis to decrypt log files
*
***/
#include <cstdio>
#include <cstring>
#include "HeadSpin.h"
#include "plStatusLog/plEncryptLogLine.h"
void IProcessFile(const char *path)
{
char out_path[512];
strcpy(out_path, path);
strcat(out_path, ".decrypt");
FILE * fpIn = fopen(path, "rb");
FILE * fpOut = fopen(out_path, "w");
if( fpIn != nil && fpOut != nil)
{
uint8_t line[ 2048 ];
while( !feof( fpIn ) )
{
// Read next string
long pos = ftell(fpIn);
if( pos == -1L )
break;
uint8_t hint = (uint8_t)pos;
uint16_t sizeHint = (uint16_t)pos;
uint16_t size;
if( stricmp( path + strlen( path ) - 4, ".log" ) == 0 )
{
int i;
for( i = 0; i < 511; i++ )
{
int c = fgetc( fpIn );
if( c == EOF || c == hint )
break;
line[ i ] = (uint8_t)c;
}
line[ i ] = 0;
size = i;
}
else
{
// uint16_t line length is encoded first
int c = fgetc( fpIn );
if( c == EOF )
break;
size = ( c & 0xff ) | ( fgetc( fpIn ) << 8 );
size = size ^ sizeHint;
if( size > sizeof( line ) )
{
hsAssert( size <= sizeof( line ) - 1, "Invalid line size" );
break;
}
fread( line, 1, size, fpIn );
line[ size ] = 0;
}
plStatusEncrypt::Decrypt( line, size, hint );
fprintf(fpOut, "%s\n", (const char *)line);
}
}
if (fpIn)
fclose(fpIn);
if (fpOut)
fclose(fpOut);
}
int main(int argc, const char * argv[])
{
if (argc == 2)
{
IProcessFile(argv[1]);
}
return 0;
}

2
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp

@ -394,7 +394,7 @@ bool LocalizationXMLFile::Parse(const std::string & fileName)
XML_SetCharacterDataHandler(fParser, HandleData); XML_SetCharacterDataHandler(fParser, HandleData);
XML_SetUserData(fParser, (void*)this); XML_SetUserData(fParser, (void*)this);
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName.c_str(), false); hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName.c_str());
if (!xmlStream) if (!xmlStream)
{ {
wchar_t *wFilename = hsStringToWString(fileName.c_str()); wchar_t *wFilename = hsStringToWString(fileName.c_str());

6
Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.cpp

@ -217,9 +217,6 @@ bool plManifest::Read(hsStream* stream)
plInitFileReader reader(readers, 4096); // Allow extra long lines plInitFileReader reader(readers, 4096); // Allow extra long lines
reader.SetUnhandledSectionReader(&baseReader); reader.SetUnhandledSectionReader(&baseReader);
// manifests don't need to be encrypted
reader.SetRequireEncrypted(false);
if (!reader.Open(stream)) if (!reader.Open(stream))
return false; return false;
@ -242,9 +239,6 @@ bool plManifest::Read(const char* filename)
plInitFileReader reader(readers, 4096); // Allow extra long lines plInitFileReader reader(readers, 4096); // Allow extra long lines
reader.SetUnhandledSectionReader(&baseReader); reader.SetUnhandledSectionReader(&baseReader);
// manifests don't need to be encrypted
reader.SetRequireEncrypted(false);
if (!reader.Open(filename)) if (!reader.Open(filename))
return false; return false;

17
Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp

@ -543,31 +543,25 @@ bool plEncryptedStream::IsEncryptedFile(const wchar_t* fileName)
return isEncrypted; return isEncrypted;
} }
hsStream* plEncryptedStream::OpenEncryptedFile(const char* fileName, bool requireEncrypted, uint32_t* cryptKey) hsStream* plEncryptedStream::OpenEncryptedFile(const char* fileName, uint32_t* cryptKey)
{ {
wchar_t* wFilename = hsStringToWString(fileName); wchar_t* wFilename = hsStringToWString(fileName);
hsStream* ret = OpenEncryptedFile(wFilename, requireEncrypted, cryptKey); hsStream* ret = OpenEncryptedFile(wFilename, cryptKey);
delete [] wFilename; delete [] wFilename;
return ret; return ret;
} }
hsStream* plEncryptedStream::OpenEncryptedFile(const wchar_t* fileName, bool requireEncrypted, uint32_t* cryptKey) hsStream* plEncryptedStream::OpenEncryptedFile(const wchar_t* fileName, uint32_t* cryptKey)
{ {
#ifndef PLASMA_EXTERNAL_RELEASE
requireEncrypted = false;
#endif
bool isEncrypted = IsEncryptedFile(fileName); bool isEncrypted = IsEncryptedFile(fileName);
hsStream* s = nil; hsStream* s = nil;
if (isEncrypted) if (isEncrypted)
s = new plEncryptedStream(cryptKey); s = new plEncryptedStream(cryptKey);
// If this isn't an external release, let them use unencrypted data
else else
if (!requireEncrypted)
s = new hsUNIXStream; s = new hsUNIXStream;
if (s)
s->Open(fileName, L"rb"); s->Open(fileName, L"rb");
return s; return s;
} }
@ -583,11 +577,10 @@ hsStream* plEncryptedStream::OpenEncryptedFileWrite(const char* fileName, uint32
hsStream* plEncryptedStream::OpenEncryptedFileWrite(const wchar_t* fileName, uint32_t* cryptKey) hsStream* plEncryptedStream::OpenEncryptedFileWrite(const wchar_t* fileName, uint32_t* cryptKey)
{ {
hsStream* s = nil; hsStream* s = nil;
#ifdef PLASMA_EXTERNAL_RELEASE if (IsEncryptedFile(fileName))
s = new plEncryptedStream(cryptKey); s = new plEncryptedStream(cryptKey);
#else else
s = new hsUNIXStream; s = new hsUNIXStream;
#endif
s->Open(fileName, L"wb"); s->Open(fileName, L"wb");
return s; return s;

4
Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h

@ -107,8 +107,8 @@ public:
// Attempts to create a read-binary stream for the requested file. If it's // Attempts to create a read-binary stream for the requested file. If it's
// encrypted, you'll get a plEncryptedStream, otherwise just a standard // encrypted, you'll get a plEncryptedStream, otherwise just a standard
// hsUNIXStream. Remember to delete the stream when you're done with it. // hsUNIXStream. Remember to delete the stream when you're done with it.
static hsStream* OpenEncryptedFile(const char* fileName, bool requireEncrypted = true, uint32_t* cryptKey = nil); static hsStream* OpenEncryptedFile(const char* fileName, uint32_t* cryptKey = nil);
static hsStream* OpenEncryptedFile(const wchar_t* fileName, bool requireEncrypted = true, uint32_t* cryptKey = nil); static hsStream* OpenEncryptedFile(const wchar_t* fileName, uint32_t* cryptKey = nil);
static hsStream* OpenEncryptedFileWrite(const char* fileName, uint32_t* cryptKey = nil); static hsStream* OpenEncryptedFileWrite(const char* fileName, uint32_t* cryptKey = nil);
static hsStream* OpenEncryptedFileWrite(const wchar_t* fileName, uint32_t* cryptKey = nil); static hsStream* OpenEncryptedFileWrite(const wchar_t* fileName, uint32_t* cryptKey = nil);
}; };

5
Sources/Plasma/PubUtilLib/plFile/plInitFileReader.cpp

@ -83,7 +83,6 @@ void plInitFileReader::IInitReaders( plInitSectionReader **readerArray )
plInitFileReader::plInitFileReader( plInitSectionReader **readerArray, uint16_t lineSize ) plInitFileReader::plInitFileReader( plInitSectionReader **readerArray, uint16_t lineSize )
{ {
fRequireEncrypted = true;
fCurrLine = nil; fCurrLine = nil;
fLineSize = lineSize; fLineSize = lineSize;
fStream = fOurStream = nil; fStream = fOurStream = nil;
@ -93,7 +92,6 @@ plInitFileReader::plInitFileReader( plInitSectionReader **readerArray, uint16_t
plInitFileReader::plInitFileReader( const char *fileName, plInitSectionReader **readerArray, uint16_t lineSize ) plInitFileReader::plInitFileReader( const char *fileName, plInitSectionReader **readerArray, uint16_t lineSize )
{ {
fRequireEncrypted = true;
fCurrLine = nil; fCurrLine = nil;
fLineSize = lineSize; fLineSize = lineSize;
fStream = fOurStream = nil; fStream = fOurStream = nil;
@ -105,7 +103,6 @@ plInitFileReader::plInitFileReader( const char *fileName, plInitSectionReader **
plInitFileReader::plInitFileReader( hsStream *stream, plInitSectionReader **readerArray, uint16_t lineSize ) plInitFileReader::plInitFileReader( hsStream *stream, plInitSectionReader **readerArray, uint16_t lineSize )
{ {
fRequireEncrypted = true;
fCurrLine = nil; fCurrLine = nil;
fLineSize = lineSize; fLineSize = lineSize;
fStream = fOurStream = nil; fStream = fOurStream = nil;
@ -129,7 +126,7 @@ bool plInitFileReader::Open( const char *fileName )
return false; return false;
} }
fOurStream = plEncryptedStream::OpenEncryptedFile( fileName, fRequireEncrypted ); fOurStream = plEncryptedStream::OpenEncryptedFile( fileName );
if( fOurStream == nil ) if( fOurStream == nil )
return false; return false;

3
Sources/Plasma/PubUtilLib/plFile/plInitFileReader.h

@ -118,7 +118,6 @@ class plInitFileReader
hsStream *fOurStream; hsStream *fOurStream;
char *fCurrLine; char *fCurrLine;
uint32_t fLineSize; uint32_t fLineSize;
bool fRequireEncrypted;
plInitSectionReader *fCurrSection; plInitSectionReader *fCurrSection;
hsTArray<plInitSectionReader *> fSections; hsTArray<plInitSectionReader *> fSections;
@ -138,8 +137,6 @@ class plInitFileReader
plInitFileReader( hsStream *stream, plInitSectionReader **readerArray, uint16_t lineSize = 256 ); plInitFileReader( hsStream *stream, plInitSectionReader **readerArray, uint16_t lineSize = 256 );
virtual ~plInitFileReader(); virtual ~plInitFileReader();
void SetRequireEncrypted(bool require) { fRequireEncrypted = require; }
bool GetRequireEncrypted() const { return fRequireEncrypted; }
void SetUnhandledSectionReader(plInitSectionReader* reader) { fUnhandledSection = reader; } void SetUnhandledSectionReader(plInitSectionReader* reader) { fUnhandledSection = reader; }
bool Open( const char *fileName ); bool Open( const char *fileName );

23
Sources/Plasma/PubUtilLib/plStatusLog/plEncryptLogLine.cpp

@ -53,29 +53,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <string.h> #include <string.h>
void plStatusEncrypt::Encrypt( uint8_t *line, uint8_t hint )
{
// Current encryption scheme: rotate all characters right by 2 bits,
// then rotate the whole damn line by 3 bits to the right
uint32_t i, len = strlen( (char *)line );
uint8_t newHi, hiBits = ( ( line[ len - 1 ] ) << ( 5 - 2 ) ) & 0xe0;
for( i = 0; i < len; i++ )
{
// So each character will be the src char rotated right 2 bits, then shifted
// right 3 bits, or'ed with the last high bits, and the 3 discarded bits
// become the new high bits
// Too bad C doesn't have a bit-rotate op
line[ i ] = ( line[ i ] << 6 ) | ( line[ i ] >> 2 );
newHi = line[ i ] << 5;
line[ i ] = ( line[ i ] >> 3 ) | hiBits;
line[ i ] ^= hint; // Should wrap around
hiBits = newHi;
}
}
void plStatusEncrypt::Decrypt( uint8_t *line, int32_t len, uint8_t hint ) void plStatusEncrypt::Decrypt( uint8_t *line, int32_t len, uint8_t hint )
{ {
// Da reverse, of course! // Da reverse, of course!

1
Sources/Plasma/PubUtilLib/plStatusLog/plEncryptLogLine.h

@ -56,7 +56,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
namespace plStatusEncrypt namespace plStatusEncrypt
{ {
void Encrypt( uint8_t *line, uint8_t hint );
void Decrypt( uint8_t *line, int32_t length, uint8_t hint ); void Decrypt( uint8_t *line, int32_t length, uint8_t hint );
}; };

52
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp

@ -475,12 +475,6 @@ bool plStatusLog::IReOpen( void )
wchar_t fileNoExt[MAX_PATH]; wchar_t fileNoExt[MAX_PATH];
wchar_t* ext=nil; wchar_t* ext=nil;
IParseFileName(file, MAX_PATH, fileNoExt, &ext); IParseFileName(file, MAX_PATH, fileNoExt, &ext);
fEncryptMe = false;
#ifdef PLASMA_EXTERNAL_RELEASE
fEncryptMe = ( wcsicmp( fFilename.c_str(), L"chat.log" ) != 0 ) ? true : false;
if( fEncryptMe )
ext = L".elf";
#endif
wchar_t fileToOpen[MAX_PATH]; wchar_t fileToOpen[MAX_PATH];
hsSnwprintf(fileToOpen, MAX_PATH, L"%s.0%s", fileNoExt, ext); hsSnwprintf(fileToOpen, MAX_PATH, L"%s.0%s", fileNoExt, ext);
if (!(fFlags & kDontRotateLogs)) if (!(fFlags & kDontRotateLogs))
@ -497,11 +491,11 @@ bool plStatusLog::IReOpen( void )
if (fFlags & kAppendToLast) if (fFlags & kAppendToLast)
{ {
fFileHandle = hsWFopen( fileToOpen, fEncryptMe ? L"ab" : L"at" ); fFileHandle = hsWFopen( fileToOpen, L"at" );
} }
else else
{ {
fFileHandle = hsWFopen( fileToOpen, fEncryptMe ? L"wb" : L"wt" ); fFileHandle = hsWFopen( fileToOpen, L"wt" );
// if we need to reopen lets just append // if we need to reopen lets just append
fFlags |= kAppendToLast; fFlags |= kAppendToLast;
} }
@ -843,58 +837,18 @@ bool plStatusLog::IPrintLineToFile( const char *line, uint32_t count )
} }
size_t remaining = arrsize(buf) - strlen(buf) - 1; size_t remaining = arrsize(buf) - strlen(buf) - 1;
if (!fEncryptMe) remaining -= 1; remaining -= 1;
if (count <= remaining) { if (count <= remaining) {
strncat(buf, line, count); strncat(buf, line, count);
} else { } else {
strncat(buf, line, remaining); strncat(buf, line, remaining);
} }
if(!fEncryptMe )
{
strncat(buf, "\n", 1); strncat(buf, "\n", 1);
} }
}
unsigned length = strlen(buf); unsigned length = strlen(buf);
#ifdef PLASMA_EXTERNAL_RELEASE
// Print to a separate line, since we have to encrypt it
if( fEncryptMe )
{
// Encrypt!
plStatusEncrypt::Encrypt( (uint8_t *)buf, hint );
// xor the line length, then write it out, then the line, no terminating character
uint16_t encrySize = length ^ ((uint16_t)fSize);
// try the first write, if it fails reopen and try again
int err;
err = fputc( encrySize & 0xff, fFileHandle );
if (err == EOF && IReOpen())
{
err = fputc( encrySize & 0xff, fFileHandle );
}
if (err != EOF)
{
fSize++; // inc for the last putc
err = fputc( encrySize >> 8, fFileHandle );
if (err != EOF)
fSize++; // inc for the last putc
err = fwrite( buf, 1, length, fFileHandle );
fSize += err;
if (!(fFlags & kNonFlushedLog))
fflush(fFileHandle);
}
else
{
ret = false;
}
}
else
#endif
{ {
int err; int err;
err = fwrite(buf,1,length,fFileHandle); err = fwrite(buf,1,length,fFileHandle);

1
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.h

@ -90,7 +90,6 @@ class plStatusLog
hsSemaphore* fSema; hsSemaphore* fSema;
FILE* fFileHandle; FILE* fFileHandle;
uint32_t fSize; uint32_t fSize;
bool fEncryptMe;
bool fForceLog; bool fForceLog;
plStatusLog *fNext, **fBack; plStatusLog *fNext, **fBack;

Loading…
Cancel
Save