From 4b8b5027be2b8c59a6ff628d1023a147a815d9f0 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 11 Feb 2012 19:52:36 -0800 Subject: [PATCH 01/11] Build plMD5. Refs #1. --- Sources/Plasma/Apps/CMakeLists.txt | 1 + Sources/Plasma/Apps/plMD5/CMakeLists.txt | 19 ++++++++ Sources/Plasma/Apps/plMD5/Intern.h | 51 --------------------- Sources/Plasma/Apps/plMD5/Main.cpp | 8 ++-- Sources/Plasma/Apps/plMD5/Pch.h | 57 ------------------------ 5 files changed, 25 insertions(+), 111 deletions(-) create mode 100644 Sources/Plasma/Apps/plMD5/CMakeLists.txt delete mode 100644 Sources/Plasma/Apps/plMD5/Intern.h delete mode 100644 Sources/Plasma/Apps/plMD5/Pch.h diff --git a/Sources/Plasma/Apps/CMakeLists.txt b/Sources/Plasma/Apps/CMakeLists.txt index a2e648d3..0f6ebec8 100644 --- a/Sources/Plasma/Apps/CMakeLists.txt +++ b/Sources/Plasma/Apps/CMakeLists.txt @@ -5,4 +5,5 @@ add_subdirectory(plUruLauncher) add_subdirectory(plFileSecure) add_subdirectory(plFileEncrypt) add_subdirectory(plLogDecrypt) +add_subdirectory(plMD5) add_subdirectory(plPageInfo) diff --git a/Sources/Plasma/Apps/plMD5/CMakeLists.txt b/Sources/Plasma/Apps/plMD5/CMakeLists.txt new file mode 100644 index 00000000..c1c3aacb --- /dev/null +++ b/Sources/Plasma/Apps/plMD5/CMakeLists.txt @@ -0,0 +1,19 @@ +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") +include_directories(${OPENSSL_INCLUDE_DIR}) + +set(plMD5_SOURCES + Main.cpp +) + +add_executable(plMD5 ${plMD5_SOURCES}) +target_link_libraries(plMD5 CoreLib pnUtils pnProduct plEncryption) +target_link_libraries(plMD5 ${OPENSSL_LIBRARIES}) + +source_group("Source Files" FILES ${plMD5_SOURCES}) diff --git a/Sources/Plasma/Apps/plMD5/Intern.h b/Sources/Plasma/Apps/plMD5/Intern.h deleted file mode 100644 index 216c3c18..00000000 --- a/Sources/Plasma/Apps/plMD5/Intern.h +++ /dev/null @@ -1,51 +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 . - -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==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/Apps/plMD5/Intern.h -* -***/ - -#ifdef PLASMA20_SOURCES_PLASMA_APPS_PLMD5_INTERN_H -#error "Header $/Plasma20/Sources/Plasma/Apps/plMD5/Intern.h included more than once" -#endif -#define PLASMA20_SOURCES_PLASMA_APPS_PLMD5_INTERN_H diff --git a/Sources/Plasma/Apps/plMD5/Main.cpp b/Sources/Plasma/Apps/plMD5/Main.cpp index 2c0da5ce..1726c2a4 100644 --- a/Sources/Plasma/Apps/plMD5/Main.cpp +++ b/Sources/Plasma/Apps/plMD5/Main.cpp @@ -45,9 +45,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com * ***/ -#include "Pch.h" -#pragma hdrstop +#include "pnUtils/pnUtils.h" +#include "pnProduct/pnProduct.h" +#include "plEncryption/plChecksum.h" +#include /***************************************************************************** * @@ -56,7 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ //============================================================================ -int __cdecl main (int argc, char ** argv) { +int CDECL main (int argc, char ** argv) { if (argc < 2) { fprintf(stderr, "ERROR: Please specify filename.\n"); diff --git a/Sources/Plasma/Apps/plMD5/Pch.h b/Sources/Plasma/Apps/plMD5/Pch.h deleted file mode 100644 index 8f0b5758..00000000 --- a/Sources/Plasma/Apps/plMD5/Pch.h +++ /dev/null @@ -1,57 +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 . - -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==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/Apps/plMD5/Pch.h -* -***/ - -#ifdef PLASMA20_SOURCES_PLASMA_APPS_PLMD5_PCH_H -#error "Header $/Plasma20/Sources/Plasma/Apps/plMD5/Pch.h included more than once" -#endif -#define PLASMA20_SOURCES_PLASMA_APPS_PLMD5_PCH_H - -#include "pnUtils/pnUtils.h" -#include "pnProduct/pnProduct.h" -#include "plEncryption/plChecksum.h" - -#include From 76a754f55a5456671943ec48660e6ab6d16e4f67 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 11 Feb 2012 21:57:28 -0800 Subject: [PATCH 02/11] Added plSHAChecksum and plSHA1Checksum. --- Sources/Plasma/Apps/CMakeLists.txt | 1 + .../PubUtilLib/plEncryption/plChecksum.cpp | 336 +++++++++++++++--- .../PubUtilLib/plEncryption/plChecksum.h | 121 +++++-- 3 files changed, 396 insertions(+), 62 deletions(-) diff --git a/Sources/Plasma/Apps/CMakeLists.txt b/Sources/Plasma/Apps/CMakeLists.txt index 0f6ebec8..0140ce05 100644 --- a/Sources/Plasma/Apps/CMakeLists.txt +++ b/Sources/Plasma/Apps/CMakeLists.txt @@ -7,3 +7,4 @@ add_subdirectory(plFileEncrypt) add_subdirectory(plLogDecrypt) add_subdirectory(plMD5) add_subdirectory(plPageInfo) +add_subdirectory(plSHA) diff --git a/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.cpp b/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.cpp index 81db5419..b7c79c0e 100644 --- a/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.cpp +++ b/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.cpp @@ -44,6 +44,41 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include + +static uint8_t IHexCharToInt(char c) +{ + switch( c ) + { + // yes, it's ugly, but it'll be fast :) + case '0': return 0; + case '1': return 1; + case '2': return 2; + case '3': return 3; + case '4': return 4; + case '5': return 5; + case '6': return 6; + case '7': return 7; + case '8': return 8; + case '9': return 9; + + case 'a': return 10; + case 'b': return 11; + case 'c': return 12; + case 'd': return 13; + case 'e': return 14; + case 'f': return 15; + + case 'A': return 10; + case 'B': return 11; + case 'C': return 12; + case 'D': return 13; + case 'E': return 14; + case 'F': return 15; + } + + return 0xff; +} + plChecksum::plChecksum(unsigned int bufsize, const char* buffer) { unsigned int wndsz = GetWindowSize(),i = 0; @@ -67,6 +102,8 @@ plChecksum::plChecksum(unsigned int bufsize, const char* buffer) fSum+= hsToLE32(last); } +//============================================================================ + plMD5Checksum::plMD5Checksum( uint32_t size, uint8_t *buffer ) { fValid = false; @@ -102,11 +139,11 @@ void plMD5Checksum::Clear() fValid = false; } -void plMD5Checksum::CalcFromFile( const char *fileName ) +void plMD5Checksum::CalcFromFile( const char *fileName ) { hsUNIXStream s; fValid = false; - + if( s.Open(fileName) ) { CalcFromStream(&s); @@ -121,7 +158,7 @@ void plMD5Checksum::CalcFromStream( hsStream* stream ) Start(); uint8_t *buf = new uint8_t[loadLen]; - + while(int read = stream->Read(loadLen, buf)) AddTo( read, buf ); delete[] buf; @@ -130,24 +167,24 @@ void plMD5Checksum::CalcFromStream( hsStream* stream ) stream->SetPosition(sPos); } -void plMD5Checksum::Start( void ) +void plMD5Checksum::Start() { MD5_Init( &fContext ); fValid = false; } -void plMD5Checksum::AddTo( uint32_t size, const uint8_t *buffer ) +void plMD5Checksum::AddTo( uint32_t size, const uint8_t *buffer ) { MD5_Update( &fContext, buffer, size ); } -void plMD5Checksum::Finish( void ) +void plMD5Checksum::Finish() { MD5_Final( fChecksum, &fContext ); fValid = true; } -const char *plMD5Checksum::GetAsHexString( void ) const +const char *plMD5Checksum::GetAsHexString() const { const int kHexStringSize = ( 2 * MD5_DIGEST_LENGTH ) + 1; static char tempString[ kHexStringSize ]; @@ -166,61 +203,280 @@ const char *plMD5Checksum::GetAsHexString( void ) const return tempString; } -uint8_t plMD5Checksum::IHexCharToInt( char c ) const +void plMD5Checksum::SetFromHexString( const char *string ) { - switch( c ) + const char *ptr; + int i; + + + hsAssert( strlen( string ) == 2 * MD5_DIGEST_LENGTH, "Invalid string in MD5Checksum Set()" ); + + for( i = 0, ptr = string; i < sizeof( fChecksum ); i++, ptr += 2 ) + fChecksum[ i ] = ( IHexCharToInt( ptr[ 0 ] ) << 4 ) | IHexCharToInt( ptr[ 1 ] ); + + fValid = true; +} + +void plMD5Checksum::SetValue(uint8_t* checksum) +{ + fValid = true; + memcpy(fChecksum, checksum, sizeof(fChecksum)); +} + +bool plMD5Checksum::operator==( const plMD5Checksum &rhs ) const +{ + return (fValid && rhs.fValid && memcmp(fChecksum, rhs.fChecksum, sizeof(fChecksum)) == 0); +} + +//============================================================================ + +plSHAChecksum::plSHAChecksum( uint32_t size, uint8_t *buffer ) +{ + fValid = false; + Start(); + AddTo(size, buffer); + Finish(); +} + +plSHAChecksum::plSHAChecksum() +{ + Clear(); +} + +plSHAChecksum::plSHAChecksum(const plSHAChecksum& rhs) +{ + memcpy(fChecksum, rhs.fChecksum, sizeof(fChecksum)); + fValid = rhs.fValid; +} + +plSHAChecksum::plSHAChecksum(const char* fileName) +{ + CalcFromFile(fileName); +} + +plSHAChecksum::plSHAChecksum(hsStream* stream) +{ + CalcFromStream(stream); +} + +void plSHAChecksum::Clear() +{ + memset(fChecksum, 0, sizeof(fChecksum)); + fValid = false; +} + +void plSHAChecksum::CalcFromFile(const char* fileName) +{ + hsUNIXStream s; + fValid = false; + + if (s.Open(fileName)) { - // yes, it's ugly, but it'll be fast :) - case '0': return 0; - case '1': return 1; - case '2': return 2; - case '3': return 3; - case '4': return 4; - case '5': return 5; - case '6': return 6; - case '7': return 7; - case '8': return 8; - case '9': return 9; + CalcFromStream(&s); + s.Close(); + } +} - case 'a': return 10; - case 'b': return 11; - case 'c': return 12; - case 'd': return 13; - case 'e': return 14; - case 'f': return 15; +void plSHAChecksum::CalcFromStream(hsStream* stream) +{ + uint32_t sPos = stream->GetPosition(); + unsigned loadLen = 1024 * 1024; + Start(); - case 'A': return 10; - case 'B': return 11; - case 'C': return 12; - case 'D': return 13; - case 'E': return 14; - case 'F': return 15; + uint8_t* buf = new uint8_t[loadLen]; + + while (int read = stream->Read(loadLen, buf)) + { + AddTo( read, buf ); } + delete[] buf; - return 0xff; + Finish(); + stream->SetPosition(sPos); } -void plMD5Checksum::SetFromHexString( const char *string ) +void plSHAChecksum::Start() { - const char *ptr; + SHA_Init(&fContext); + fValid = false; +} + +void plSHAChecksum::AddTo(uint32_t size, const uint8_t* buffer) +{ + SHA_Update(&fContext, buffer, size); +} + +void plSHAChecksum::Finish() +{ + SHA_Final(fChecksum, &fContext); + fValid = true; +} + +const char *plSHAChecksum::GetAsHexString() const +{ + const int kHexStringSize = (2 * SHA_DIGEST_LENGTH) + 1; + static char tempString[kHexStringSize]; + + int i; + char* ptr; + + hsAssert(fValid, "Trying to get string version of invalid checksum"); + + for (i = 0, ptr = tempString; i < sizeof(fChecksum); i++, ptr += 2) + sprintf(ptr, "%02x", fChecksum[i]); + + *ptr = 0; + + return tempString; +} + +void plSHAChecksum::SetFromHexString(const char* string) +{ + const char* ptr; int i; + hsAssert(strlen(string) == (2 * SHA_DIGEST_LENGTH), "Invalid string in SHAChecksum Set()"); - hsAssert( strlen( string ) == 2 * MD5_DIGEST_LENGTH, "Invalid string in MD5Checksum Set()" ); + for (i = 0, ptr = string; i < sizeof(fChecksum); i++, ptr += 2) + fChecksum[i] = (IHexCharToInt(ptr[0]) << 4) | IHexCharToInt(ptr[1]); - for( i = 0, ptr = string; i < sizeof( fChecksum ); i++, ptr += 2 ) - fChecksum[ i ] = ( IHexCharToInt( ptr[ 0 ] ) << 4 ) | IHexCharToInt( ptr[ 1 ] ); + fValid = true; +} +void plSHAChecksum::SetValue(uint8_t* checksum) +{ fValid = true; + memcpy(fChecksum, checksum, sizeof(fChecksum)); } -void plMD5Checksum::SetValue(uint8_t* checksum) +bool plSHAChecksum::operator==(const plSHAChecksum& rhs) const +{ + return (fValid && rhs.fValid && memcmp(fChecksum, rhs.fChecksum, sizeof(fChecksum)) == 0); +} + +//============================================================================ + +plSHA1Checksum::plSHA1Checksum( uint32_t size, uint8_t *buffer ) +{ + fValid = false; + Start(); + AddTo(size, buffer); + Finish(); +} + +plSHA1Checksum::plSHA1Checksum() +{ + Clear(); +} + +plSHA1Checksum::plSHA1Checksum(const plSHA1Checksum& rhs) +{ + memcpy(fChecksum, rhs.fChecksum, sizeof(fChecksum)); + fValid = rhs.fValid; +} + +plSHA1Checksum::plSHA1Checksum(const char* fileName) +{ + CalcFromFile(fileName); +} + +plSHA1Checksum::plSHA1Checksum(hsStream* stream) +{ + CalcFromStream(stream); +} + +void plSHA1Checksum::Clear() +{ + memset(fChecksum, 0, sizeof(fChecksum)); + fValid = false; +} + +void plSHA1Checksum::CalcFromFile(const char* fileName) +{ + hsUNIXStream s; + fValid = false; + + if (s.Open(fileName)) + { + CalcFromStream(&s); + s.Close(); + } +} + +void plSHA1Checksum::CalcFromStream(hsStream* stream) +{ + uint32_t sPos = stream->GetPosition(); + unsigned loadLen = 1024 * 1024; + Start(); + + uint8_t* buf = new uint8_t[loadLen]; + + while (int read = stream->Read(loadLen, buf)) + { + AddTo( read, buf ); + } + delete[] buf; + + Finish(); + stream->SetPosition(sPos); +} + +void plSHA1Checksum::Start() +{ + SHA1_Init(&fContext); + fValid = false; +} + +void plSHA1Checksum::AddTo(uint32_t size, const uint8_t* buffer) +{ + SHA1_Update(&fContext, buffer, size); +} + +void plSHA1Checksum::Finish() +{ + SHA1_Final(fChecksum, &fContext); + fValid = true; +} + +const char *plSHA1Checksum::GetAsHexString() const +{ + const int kHexStringSize = (2 * SHA_DIGEST_LENGTH) + 1; + static char tempString[kHexStringSize]; + + int i; + char* ptr; + + hsAssert(fValid, "Trying to get string version of invalid checksum"); + + for (i = 0, ptr = tempString; i < sizeof(fChecksum); i++, ptr += 2) + sprintf(ptr, "%02x", fChecksum[i]); + + *ptr = 0; + + return tempString; +} + +void plSHA1Checksum::SetFromHexString(const char* string) +{ + const char* ptr; + int i; + + hsAssert(strlen(string) == (2 * SHA_DIGEST_LENGTH), "Invalid string in SHA1Checksum Set()"); + + for (i = 0, ptr = string; i < sizeof(fChecksum); i++, ptr += 2) + fChecksum[i] = (IHexCharToInt(ptr[0]) << 4) | IHexCharToInt(ptr[1]); + + fValid = true; +} + +void plSHA1Checksum::SetValue(uint8_t* checksum) { fValid = true; memcpy(fChecksum, checksum, sizeof(fChecksum)); } -bool plMD5Checksum::operator==( const plMD5Checksum &rhs ) const +bool plSHA1Checksum::operator==(const plSHA1Checksum& rhs) const { return (fValid && rhs.fValid && memcmp(fChecksum, rhs.fChecksum, sizeof(fChecksum)) == 0); } + diff --git a/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h b/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h index e4f62990..fed7ce39 100644 --- a/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h +++ b/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h @@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include +#include class plChecksum { @@ -60,46 +61,122 @@ public: class hsStream; -class plMD5Checksum +class plMD5Checksum { protected: - hsBool fValid; MD5_CTX fContext; - uint8_t fChecksum[ MD5_DIGEST_LENGTH ]; - - uint8_t IHexCharToInt( char c ) const; + uint8_t fChecksum[MD5_DIGEST_LENGTH]; public: - - plMD5Checksum( uint32_t size, uint8_t *buffer ); + plMD5Checksum(uint32_t size, uint8_t *buffer); plMD5Checksum(); - plMD5Checksum( const plMD5Checksum &rhs ); - plMD5Checksum( const char *fileName ); - plMD5Checksum( hsStream* stream ); + plMD5Checksum(const plMD5Checksum &rhs); + plMD5Checksum(const char *fileName); + plMD5Checksum(hsStream* stream); - hsBool IsValid( void ) const { return fValid; } + hsBool IsValid() const { return fValid; } void Clear(); - void CalcFromFile( const char *fileName ); - void CalcFromStream( hsStream* stream ); + void CalcFromFile(const char *fileName); + void CalcFromStream(hsStream* stream); - void Start( void ); - void AddTo( uint32_t size, const uint8_t *buffer ); - void Finish( void ); + void Start(); + void AddTo(uint32_t size, const uint8_t *buffer); + void Finish(); - const uint8_t *GetValue( void ) const { return fChecksum; } - uint32_t GetSize( void ) const { return sizeof( fChecksum ); } + const uint8_t *GetValue() const { return fChecksum; } + uint32_t GetSize() const { return sizeof(fChecksum); } // Backdoor for cached checksums (ie, if you loaded it off disk) void SetValue(uint8_t* checksum); - // Note: GetAsHexString() returns a pointer to a static string; do not rely on the contents of this string between calls! - const char *GetAsHexString( void ) const; + // Note: GetAsHexString() returns a pointer to a static string; + // do not rely on the contents of this string between calls! + const char *GetAsHexString() const; void SetFromHexString( const char *string ); - bool operator==( const plMD5Checksum &rhs ) const; - bool operator!=( const plMD5Checksum &rhs ) const { return !operator==( rhs ); } + bool operator==(const plMD5Checksum &rhs) const; + bool operator!=(const plMD5Checksum &rhs) const { return !operator==(rhs); } +}; + +class plSHAChecksum +{ + protected: + hsBool fValid; + SHA_CTX fContext; + uint8_t fChecksum[SHA_DIGEST_LENGTH]; + + public: + plSHAChecksum(uint32_t size, uint8_t* buffer); + plSHAChecksum(); + plSHAChecksum(const plSHAChecksum& rhs); + plSHAChecksum(const char* fileName); + plSHAChecksum(hsStream* stream); + + hsBool IsValid() const { return fValid; } + void Clear(); + + void CalcFromFile(const char* fileName); + void CalcFromStream(hsStream* stream); + + void Start(); + void AddTo(uint32_t size, const uint8_t* buffer); + void Finish(); + + const uint8_t* GetValue() const { return fChecksum; } + uint32_t GetSize() const { return sizeof(fChecksum); } + + // Backdoor for cached checksums (ie, if you loaded it off disk) + void SetValue(uint8_t* checksum); + + // Note: GetAsHexString() returns a pointer to a static string; + // do not rely on the contents of this string between calls! + const char* GetAsHexString() const; + void SetFromHexString(const char* string); + + bool operator==(const plSHAChecksum& rhs) const; + bool operator!=(const plSHAChecksum& rhs) const { return !operator==(rhs); } +}; + +class plSHA1Checksum +{ + protected: + hsBool fValid; + SHA_CTX fContext; + uint8_t fChecksum[SHA_DIGEST_LENGTH]; + + public: + plSHA1Checksum(uint32_t size, uint8_t* buffer); + plSHA1Checksum(); + plSHA1Checksum(const plSHA1Checksum& rhs); + plSHA1Checksum(const char* fileName); + plSHA1Checksum(hsStream* stream); + + hsBool IsValid() const { return fValid; } + void Clear(); + + void CalcFromFile(const char* fileName); + void CalcFromStream(hsStream* stream); + + void Start(); + void AddTo(uint32_t size, const uint8_t* buffer); + void Finish(); + + const uint8_t* GetValue() const { return fChecksum; } + uint32_t GetSize() const { return sizeof(fChecksum); } + + // Backdoor for cached checksums (ie, if you loaded it off disk) + void SetValue(uint8_t* checksum); + + // Note: GetAsHexString() returns a pointer to a static string; + // do not rely on the contents of this string between calls! + const char* GetAsHexString() const; + void SetFromHexString(const char* string); + + bool operator==(const plSHA1Checksum& rhs) const; + bool operator!=(const plSHA1Checksum& rhs) const { return !operator==(rhs); } }; + #endif // PL_CHECKSUM_H From f4878166d59095338835a7f4451c4fc76bb9fa4e Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 11 Feb 2012 21:58:30 -0800 Subject: [PATCH 03/11] Don't use pnUtils for MD5 checksumming. On the other hand, have we ever figured out exactly what this code is supposed to do? Mark added it for something, but it's not really clear what the purpose is. --- .../FeatureLib/pfPython/pyAgeInfoStruct.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp index 7620cdf4..938a9cac 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pyAgeInfoStruct.h" #include "hsStlUtils.h" #include "pnUtils/pnUtCrypt.h" +#include "plEncryption/plChecksum.h" /////////////////////////////////////////////////////////////////////////// @@ -129,9 +130,23 @@ void pyAgeInfoStruct::SetAgeInstanceGuid( const char * guid ) // if it starts with an @ then do a meta kind of GUID std::string curInst = fAgeInfo.GetAgeInstanceName(); std::string y = curInst + guid; - + plUUID instanceGuid; - CryptDigest(kCryptMd5, instanceGuid.fData , y.length(), y.c_str()); + plMD5Checksum hash; + hash.Start(); + hash.AddTo(y.length(), (uint8_t*)y.c_str()); + hash.Finish(); + + const char* md5sum = hash.GetAsHexString(); + plStringStream ss; + for (size_t i = 0; i < 16; i++) { + ss << md5sum[2*i]; + ss << md5sum[(2*i)+1]; + + if (i == 3 || i == 5 || i == 7 || i == 9) + ss << '-'; + } + instanceGuid.FromString(ss.GetString()); fAgeInfo.SetAgeInstanceGuid(&instanceGuid); } else { From d2243c459b82f4f747beb47e666c75387d35cc59 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 11 Feb 2012 22:31:29 -0800 Subject: [PATCH 04/11] Added plSHA project, and clean up pnUtCrypt usage. --- Sources/Plasma/Apps/plClient/winmain.cpp | 15 +--- Sources/Plasma/Apps/plMD5/Main.cpp | 17 +---- Sources/Plasma/Apps/plSHA/CMakeLists.txt | 19 +++++ Sources/Plasma/Apps/plSHA/Main.cpp | 70 +++++++++++++++++++ .../PubUtilLib/plEncryption/plChecksum.h | 9 ++- 5 files changed, 101 insertions(+), 29 deletions(-) create mode 100644 Sources/Plasma/Apps/plSHA/CMakeLists.txt create mode 100644 Sources/Plasma/Apps/plSHA/Main.cpp diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index fd8daf5b..166c20a8 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -989,18 +989,9 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password) PathSplitEmail(wusername, nil, 0, domain, arrsize(domain), nil, 0, nil, 0, 0); if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) { - CryptDigest( - kCryptSha1, - &pLoginParam->namePassHash, - StrLen(password) * sizeof(password[0]), - password - ); - - pLoginParam->namePassHash.data[0] = hsToBE32(pLoginParam->namePassHash.data[0]); - pLoginParam->namePassHash.data[1] = hsToBE32(pLoginParam->namePassHash.data[1]); - pLoginParam->namePassHash.data[2] = hsToBE32(pLoginParam->namePassHash.data[2]); - pLoginParam->namePassHash.data[3] = hsToBE32(pLoginParam->namePassHash.data[3]); - pLoginParam->namePassHash.data[4] = hsToBE32(pLoginParam->namePassHash.data[4]); + plSHA1Checksum shasum(StrLen(password) * sizeof(password[0]), (uint8_t*)password); + + memcpy(pLoginParam->namePassHash, shasum.GetData(), sizeof(ShaDigest)); } else CryptHashPassword(wusername, wpassword, &pLoginParam->namePassHash); diff --git a/Sources/Plasma/Apps/plMD5/Main.cpp b/Sources/Plasma/Apps/plMD5/Main.cpp index 1726c2a4..1da24898 100644 --- a/Sources/Plasma/Apps/plMD5/Main.cpp +++ b/Sources/Plasma/Apps/plMD5/Main.cpp @@ -39,26 +39,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/Apps/plMD5/Main.cpp -* -***/ -#include "pnUtils/pnUtils.h" #include "pnProduct/pnProduct.h" #include "plEncryption/plChecksum.h" #include -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -int CDECL main (int argc, char ** argv) { +int main (int argc, char ** argv) { if (argc < 2) { fprintf(stderr, "ERROR: Please specify filename.\n"); @@ -70,7 +57,7 @@ int CDECL main (int argc, char ** argv) { fprintf(stderr, "ERROR: MD5 failed.\n"); return 1; } - + fprintf(stdout, "%s\n", md5.GetAsHexString()); return 0; } diff --git a/Sources/Plasma/Apps/plSHA/CMakeLists.txt b/Sources/Plasma/Apps/plSHA/CMakeLists.txt new file mode 100644 index 00000000..9c4534f6 --- /dev/null +++ b/Sources/Plasma/Apps/plSHA/CMakeLists.txt @@ -0,0 +1,19 @@ +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") +include_directories(${OPENSSL_INCLUDE_DIR}) + +set(plSHA_SOURCES + Main.cpp +) + +add_executable(plSHA ${plSHA_SOURCES}) +target_link_libraries(plSHA CoreLib pnUtils pnProduct plEncryption) +target_link_libraries(plSHA ${OPENSSL_LIBRARIES}) + +source_group("Source Files" FILES ${plSHA_SOURCES}) diff --git a/Sources/Plasma/Apps/plSHA/Main.cpp b/Sources/Plasma/Apps/plSHA/Main.cpp new file mode 100644 index 00000000..b4b40bd1 --- /dev/null +++ b/Sources/Plasma/Apps/plSHA/Main.cpp @@ -0,0 +1,70 @@ +/*==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 . + +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==*/ + +#include "pnProduct/pnProduct.h" +#include "plEncryption/plChecksum.h" + +#include + +int main (int argc, char** argv) { + + if (argc < 2) { + fprintf(stderr, "ERROR: Please specify filename.\n"); + return 1; + } + + plSHAChecksum sha(argv[1]); + if (!sha.IsValid()) { + fprintf(stderr, "ERROR: SHA failed.\n"); + return 1; + } + + plSHA1Checksum sha1(argv[1]); + if (!sha1.IsValid()) { + fprintf(stderr, "ERROR: SHA1 failed.\n"); + return 1; + } + + fprintf(stdout, "%s\tSHA\n", sha.GetAsHexString()); + fprintf(stdout, "%s\tSHA1\n", sha1.GetAsHexString()); + return 0; +} diff --git a/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h b/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h index fed7ce39..5cb8dc80 100644 --- a/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h +++ b/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h @@ -100,12 +100,17 @@ class plMD5Checksum bool operator!=(const plMD5Checksum &rhs) const { return !operator==(rhs); } }; +/* A bunch of things might store either a SHA or a SHA1 checksum, this provides + * them a way to store the checksum itself, rather than a union of the classes. + */ +typedef uint8_t ShaDigest[SHA_DIGEST_LENGTH]; + class plSHAChecksum { protected: hsBool fValid; SHA_CTX fContext; - uint8_t fChecksum[SHA_DIGEST_LENGTH]; + ShaDigest fChecksum; public: plSHAChecksum(uint32_t size, uint8_t* buffer); @@ -144,7 +149,7 @@ class plSHA1Checksum protected: hsBool fValid; SHA_CTX fContext; - uint8_t fChecksum[SHA_DIGEST_LENGTH]; + ShaDigest fChecksum; public: plSHA1Checksum(uint32_t size, uint8_t* buffer); From 404cd09f1c2654749a8abdf1236fd34c83f6938d Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 11 Feb 2012 23:14:11 -0800 Subject: [PATCH 05/11] Move plEncryption to pnEncryption. --HG-- rename : Sources/Plasma/PubUtilLib/plEncryption/plChecksum.cpp => Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp rename : Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h => Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 2 +- Sources/Plasma/Apps/plClientPatcher/Pch.h | 2 +- Sources/Plasma/Apps/plMD5/CMakeLists.txt | 2 +- Sources/Plasma/Apps/plMD5/Main.cpp | 2 +- .../Plasma/Apps/plPlasmaUpdate/plManifest.cpp | 2 +- Sources/Plasma/Apps/plSHA/CMakeLists.txt | 2 +- Sources/Plasma/Apps/plSHA/Main.cpp | 2 +- .../Plasma/Apps/plUruLauncher/CMakeLists.txt | 2 +- Sources/Plasma/Apps/plUruLauncher/Pch.h | 2 +- .../FeatureLib/pfPython/pyAgeInfoStruct.cpp | 2 +- .../pfSecurePreloader/pfSecurePreloader.cpp | 2 +- Sources/Plasma/NucleusLib/CMakeLists.txt | 1 + .../NucleusLib/pnEncryption/CMakeLists.txt | 17 +++++++++++++++++ .../pnEncryption}/plChecksum.cpp | 0 .../pnEncryption}/plChecksum.h | 0 Sources/Plasma/PubUtilLib/CMakeLists.txt | 1 - .../PubUtilLib/plAgeDescription/plAgeManifest.h | 2 +- .../PubUtilLib/plAgeLoader/plResPatcher.cpp | 2 +- .../PubUtilLib/plEncryption/CMakeLists.txt | 16 ---------------- .../PubUtilLib/plNetClient/plNetClientMgr.h | 2 +- Sources/Tools/MaxMain/CMakeLists.txt | 2 +- Sources/Tools/MaxPlasmaLights/CMakeLists.txt | 2 +- 22 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt rename Sources/Plasma/{PubUtilLib/plEncryption => NucleusLib/pnEncryption}/plChecksum.cpp (100%) rename Sources/Plasma/{PubUtilLib/plEncryption => NucleusLib/pnEncryption}/plChecksum.h (100%) delete mode 100644 Sources/Plasma/PubUtilLib/plEncryption/CMakeLists.txt diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index 5f28cf8c..bb1df50e 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -101,7 +101,6 @@ target_link_libraries(plClient plClientResMgr) target_link_libraries(plClient plCompression) target_link_libraries(plClient plContainer) target_link_libraries(plClient plDrawable) -target_link_libraries(plClient plEncryption) target_link_libraries(plClient plFile) target_link_libraries(plClient plGImage) target_link_libraries(plClient plGLight) @@ -140,6 +139,7 @@ target_link_libraries(plClient pnAsyncCore) target_link_libraries(plClient pnAsyncCoreExe) target_link_libraries(plClient pnCsrNet) target_link_libraries(plClient pnDispatch) +target_link_libraries(plClient pnEncryption) target_link_libraries(plClient pnFactory) target_link_libraries(plClient pnGameMgr) target_link_libraries(plClient pnIni) diff --git a/Sources/Plasma/Apps/plClientPatcher/Pch.h b/Sources/Plasma/Apps/plClientPatcher/Pch.h index 103fca62..6b00160c 100644 --- a/Sources/Plasma/Apps/plClientPatcher/Pch.h +++ b/Sources/Plasma/Apps/plClientPatcher/Pch.h @@ -58,7 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnProduct/pnProduct.h" #include "pnNetCli/pnNetCli.h" #include "plNetGameLib/plNetGameLib.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" #include "plAgeDescription/plAgeManifest.h" #include "plAudioCore/plAudioFileReader.h" diff --git a/Sources/Plasma/Apps/plMD5/CMakeLists.txt b/Sources/Plasma/Apps/plMD5/CMakeLists.txt index c1c3aacb..d83f7c46 100644 --- a/Sources/Plasma/Apps/plMD5/CMakeLists.txt +++ b/Sources/Plasma/Apps/plMD5/CMakeLists.txt @@ -13,7 +13,7 @@ set(plMD5_SOURCES ) add_executable(plMD5 ${plMD5_SOURCES}) -target_link_libraries(plMD5 CoreLib pnUtils pnProduct plEncryption) +target_link_libraries(plMD5 CoreLib pnUtils pnProduct pnEncryption) target_link_libraries(plMD5 ${OPENSSL_LIBRARIES}) source_group("Source Files" FILES ${plMD5_SOURCES}) diff --git a/Sources/Plasma/Apps/plMD5/Main.cpp b/Sources/Plasma/Apps/plMD5/Main.cpp index 1da24898..01f1ef1c 100644 --- a/Sources/Plasma/Apps/plMD5/Main.cpp +++ b/Sources/Plasma/Apps/plMD5/Main.cpp @@ -41,7 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "pnProduct/pnProduct.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" #include diff --git a/Sources/Plasma/Apps/plPlasmaUpdate/plManifest.cpp b/Sources/Plasma/Apps/plPlasmaUpdate/plManifest.cpp index 1b5c7c07..4d1dca94 100644 --- a/Sources/Plasma/Apps/plPlasmaUpdate/plManifest.cpp +++ b/Sources/Plasma/Apps/plPlasmaUpdate/plManifest.cpp @@ -42,7 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "plManifest.h" -#include "../plEncryption/plChecksum.h" +#include "../pnEncryption/plChecksum.h" #include "../plCompression/plZlibStream.h" #include "../plFile/plEncryptedStream.h" #include "../plFile/plFileUtils.h" diff --git a/Sources/Plasma/Apps/plSHA/CMakeLists.txt b/Sources/Plasma/Apps/plSHA/CMakeLists.txt index 9c4534f6..54cce9fc 100644 --- a/Sources/Plasma/Apps/plSHA/CMakeLists.txt +++ b/Sources/Plasma/Apps/plSHA/CMakeLists.txt @@ -13,7 +13,7 @@ set(plSHA_SOURCES ) add_executable(plSHA ${plSHA_SOURCES}) -target_link_libraries(plSHA CoreLib pnUtils pnProduct plEncryption) +target_link_libraries(plSHA CoreLib pnUtils pnProduct pnEncryption) target_link_libraries(plSHA ${OPENSSL_LIBRARIES}) source_group("Source Files" FILES ${plSHA_SOURCES}) diff --git a/Sources/Plasma/Apps/plSHA/Main.cpp b/Sources/Plasma/Apps/plSHA/Main.cpp index b4b40bd1..caa1bafc 100644 --- a/Sources/Plasma/Apps/plSHA/Main.cpp +++ b/Sources/Plasma/Apps/plSHA/Main.cpp @@ -41,7 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "pnProduct/pnProduct.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" #include diff --git a/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt b/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt index 705e4586..404b0a31 100644 --- a/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt +++ b/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt @@ -37,7 +37,6 @@ target_link_libraries(plUruLauncher pfConsoleCore) target_link_libraries(plUruLauncher plAudioCore) target_link_libraries(plUruLauncher plClientPatcher) target_link_libraries(plUruLauncher plCompression) -target_link_libraries(plUruLauncher plEncryption) target_link_libraries(plUruLauncher plFile) target_link_libraries(plUruLauncher plNetClient) target_link_libraries(plUruLauncher plNetClientComm) @@ -47,6 +46,7 @@ target_link_libraries(plUruLauncher plNetTransport) target_link_libraries(plUruLauncher plUnifiedTime) target_link_libraries(plUruLauncher pnAsyncCore) target_link_libraries(plUruLauncher pnAsyncCoreExe) +target_link_libraries(plUruLauncher pnEncryption) target_link_libraries(plUruLauncher pnNetBase) target_link_libraries(plUruLauncher pnNetCli) target_link_libraries(plUruLauncher pnNetCommon) diff --git a/Sources/Plasma/Apps/plUruLauncher/Pch.h b/Sources/Plasma/Apps/plUruLauncher/Pch.h index da3e2321..7c1be92d 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Pch.h +++ b/Sources/Plasma/Apps/plUruLauncher/Pch.h @@ -61,7 +61,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnProduct/pnProduct.h" #include "pnNetCli/pnNetCli.h" #include "plNetGameLib/plNetGameLib.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" #include "plCompression/plZlibStream.h" #include "plClientPatcher/UruPlayer.h" diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp index 938a9cac..43f5805e 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp @@ -42,7 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pyAgeInfoStruct.h" #include "hsStlUtils.h" #include "pnUtils/pnUtCrypt.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" /////////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp index 158069a4..f242afe4 100644 --- a/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp +++ b/Sources/Plasma/FeatureLib/pfSecurePreloader/pfSecurePreloader.cpp @@ -45,7 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStream.h" #include "plgDispatch.h" #include "plCompression/plZlibStream.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" #include "plFile/plFileUtils.h" #include "plFile/plSecureStream.h" #include "plFile/plStreamSource.h" diff --git a/Sources/Plasma/NucleusLib/CMakeLists.txt b/Sources/Plasma/NucleusLib/CMakeLists.txt index cfee5403..1e9f8ade 100644 --- a/Sources/Plasma/NucleusLib/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/CMakeLists.txt @@ -9,6 +9,7 @@ add_subdirectory(pnAsyncCoreExe) #add_subdirectory(pnCsrCli) # Not being used in any current sln add_subdirectory(pnCsrNet) add_subdirectory(pnDispatch) +add_subdirectory(pnEncryption) add_subdirectory(pnFactory) add_subdirectory(pnGameMgr) add_subdirectory(pnIni) diff --git a/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt new file mode 100644 index 00000000..55e7f922 --- /dev/null +++ b/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt @@ -0,0 +1,17 @@ +include_directories("../../CoreLib") +include_directories("../../NucleusLib") +include_directories(${OPENSSL_INCLUDE_DIR}) + +set(pnEncryption_SOURCES + plChecksum.cpp +) + +set(pnEncryption_HEADERS + plChecksum.h +) + +add_library(pnEncryption STATIC ${pnEncryption_SOURCES} ${pnEncryption_HEADERS}) +target_link_libraries(pnEncryption ${OPENSSL_LIBRARIES}) + +source_group("Source Files" FILES ${pnEncryption_SOURCES}) +source_group("Header Files" FILES ${pnEncryption_HEADERS}) diff --git a/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp similarity index 100% rename from Sources/Plasma/PubUtilLib/plEncryption/plChecksum.cpp rename to Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp diff --git a/Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h similarity index 100% rename from Sources/Plasma/PubUtilLib/plEncryption/plChecksum.h rename to Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h diff --git a/Sources/Plasma/PubUtilLib/CMakeLists.txt b/Sources/Plasma/PubUtilLib/CMakeLists.txt index 1b7a1912..01f937bb 100644 --- a/Sources/Plasma/PubUtilLib/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/CMakeLists.txt @@ -11,7 +11,6 @@ add_subdirectory(plCompression) add_subdirectory(plContainer) #add_subdirectory(plDeviceSelector) # Not being used by any current slns add_subdirectory(plDrawable) -add_subdirectory(plEncryption) add_subdirectory(plFile) #add_subdirectory(plGClip) # Not being used by any current slns #add_subdirectory(plGeometry) # Not being used by any current slns diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h index 6c5ef80a..40c47f26 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeManifest.h @@ -55,7 +55,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plUnifiedTime/plUnifiedTime.h" #include "plFile/plInitFileReader.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" //// Small Container Classes for a Single File /////////////////////////////// diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp index c7599db3..44b9e7d3 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp @@ -45,7 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAgeLoader/plAgeLoader.h" #include "plCompression/plZlibStream.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" #include "plFile/plFileUtils.h" #include "plMessage/plResPatcherMsg.h" #include "pnNetBase/pnNbError.h" diff --git a/Sources/Plasma/PubUtilLib/plEncryption/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plEncryption/CMakeLists.txt deleted file mode 100644 index 7acf42ef..00000000 --- a/Sources/Plasma/PubUtilLib/plEncryption/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -include_directories("../../CoreLib") -include_directories("../../NucleusLib") -include_directories("../../PubUtilLib") - -set(plEncryption_SOURCES - plChecksum.cpp -) - -set(plEncryption_HEADERS - plChecksum.h -) - -add_library(plEncryption STATIC ${plEncryption_SOURCES} ${plEncryption_HEADERS}) - -source_group("Source Files" FILES ${plEncryption_SOURCES}) -source_group("Header Files" FILES ${plEncryption_HEADERS}) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h index ce33cab9..b2ac3af3 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h @@ -54,7 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnNetCommon/plNetApp.h" #include "plNetTransport/plNetTransport.h" -#include "plEncryption/plChecksum.h" +#include "pnEncryption/plChecksum.h" #include "plNetCommon/plNetServerSessionInfo.h" #include "plNetClientComm/plNetClientComm.h" #include "plUnifiedTime/plUnifiedTime.h" diff --git a/Sources/Tools/MaxMain/CMakeLists.txt b/Sources/Tools/MaxMain/CMakeLists.txt index 034ac889..2504afab 100644 --- a/Sources/Tools/MaxMain/CMakeLists.txt +++ b/Sources/Tools/MaxMain/CMakeLists.txt @@ -139,7 +139,6 @@ target_link_libraries(MaxMain plCompression) target_link_libraries(MaxMain plContainer) target_link_libraries(MaxMain plClientResMgr) target_link_libraries(MaxMain plDrawable) -target_link_libraries(MaxMain plEncryption) target_link_libraries(MaxMain plFile) target_link_libraries(MaxMain plGImage) target_link_libraries(MaxMain plGLight) @@ -178,6 +177,7 @@ target_link_libraries(MaxMain pnAsyncCore) target_link_libraries(MaxMain pnAsyncCoreExe) target_link_libraries(MaxMain pnCsrNet) target_link_libraries(MaxMain pnDispatch) +target_link_libraries(MaxMain pnEncryption) target_link_libraries(MaxMain pnFactory) target_link_libraries(MaxMain pnGameMgr) target_link_libraries(MaxMain pnIni) diff --git a/Sources/Tools/MaxPlasmaLights/CMakeLists.txt b/Sources/Tools/MaxPlasmaLights/CMakeLists.txt index 62519b06..e53b2711 100644 --- a/Sources/Tools/MaxPlasmaLights/CMakeLists.txt +++ b/Sources/Tools/MaxPlasmaLights/CMakeLists.txt @@ -73,7 +73,6 @@ target_link_libraries(MaxPlasmaLights plAvatar) target_link_libraries(MaxPlasmaLights plCompression) target_link_libraries(MaxPlasmaLights plContainer) target_link_libraries(MaxPlasmaLights plDrawable) -target_link_libraries(MaxPlasmaLights plEncryption) target_link_libraries(MaxPlasmaLights plFile) target_link_libraries(MaxPlasmaLights plGImage) target_link_libraries(MaxPlasmaLights plGLight) @@ -112,6 +111,7 @@ target_link_libraries(MaxPlasmaLights pnAsyncCore) target_link_libraries(MaxPlasmaLights pnAsyncCoreExe) target_link_libraries(MaxPlasmaLights pnCsrNet) target_link_libraries(MaxPlasmaLights pnDispatch) +target_link_libraries(MaxPlasmaLights pnEncryption) target_link_libraries(MaxPlasmaLights pnFactory) target_link_libraries(MaxPlasmaLights pnGameMgr) target_link_libraries(MaxPlasmaLights pnIni) From 1b22f044f075b19d6afc495d5f3994135a36b603 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 11 Feb 2012 23:15:06 -0800 Subject: [PATCH 06/11] Fix conflicting ShaDigest types. --- .../Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp | 65 +++---------------- Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h | 7 +- .../plNetClientComm/plNetClientComm.cpp | 4 +- .../plNetGameLib/Private/plNglAuth.cpp | 4 +- .../plNetGameLib/Private/plNglCsr.cpp | 2 +- 5 files changed, 14 insertions(+), 68 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp index 1b303595..12cd096b 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp @@ -49,7 +49,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtStr.h" #include "pnUtTime.h" -#include #include #include @@ -82,25 +81,6 @@ ShaDigest s_shaSeed; * ***/ -//============================================================================ -void Md5Process ( - void * dest, - unsigned sourceCount, - const unsigned sourceBytes[], - const void * sourcePtrs[] -) { - // initialize digest - MD5_CTX md5; - MD5_Init(&md5); - - // hash data streams - for (unsigned index = 0; index < sourceCount; ++index) - MD5_Update(&md5, sourcePtrs[index], sourceBytes[index]); - - // complete hashing - MD5_Final((unsigned char *)dest, &md5); -} - //============================================================================ void ShaProcess ( void * dest, @@ -120,25 +100,6 @@ void ShaProcess ( SHA_Final((unsigned char *)dest, &sha); } -//============================================================================ -void Sha1Process ( - void * dest, - unsigned sourceCount, - const unsigned sourceBytes[], - const void * sourcePtrs[] -) { - // initialize digest - SHA_CTX sha; - SHA1_Init(&sha); - - // hash data streams - for (unsigned index = 0; index < sourceCount; ++index) - SHA1_Update(&sha, sourcePtrs[index], sourceBytes[index]); - - // complete hashing - SHA1_Final((unsigned char *)dest, &sha); -} - /***************************************************************************** * @@ -208,18 +169,10 @@ void CryptDigest ( const void * sourcePtrs[] // [sourceCount] ) { switch (algorithm) { - case kCryptMd5: - Md5Process(dest, sourceCount, sourceBytes, sourcePtrs); - break; - case kCryptSha: ShaProcess(dest, sourceCount, sourceBytes, sourcePtrs); break; - case kCryptSha1: - Sha1Process(dest, sourceCount, sourceBytes, sourcePtrs); - break; - DEFAULT_FATAL(algorithm); } } @@ -292,21 +245,21 @@ void CryptCreateRandomSeed ( unsigned cur = 0; unsigned end = max(bytes, sizeof(s_shaSeed)); for (; cur < end; ++cur) { - ((uint8_t *) &s_shaSeed)[seedIndex] ^= data[dataIndex]; + s_shaSeed[seedIndex] ^= data[dataIndex]; if (++seedIndex >= sizeof(s_shaSeed)) seedIndex = 0; if (++dataIndex >= bytes) dataIndex = 0; } - s_shaSeed.data[2] ^= (uint32_t) &bytes; - s_shaSeed.data[3] ^= (uint32_t) bytes; - s_shaSeed.data[4] ^= (uint32_t) data; + ((uint32_t*)s_shaSeed)[2] ^= (uint32_t) &bytes; + ((uint32_t*)s_shaSeed)[3] ^= (uint32_t) bytes; + ((uint32_t*)s_shaSeed)[4] ^= (uint32_t) data; } // Hash seed ShaDigest digest; - CryptDigest(kCryptSha, &digest, sizeof(s_shaSeed), &s_shaSeed); + CryptDigest(kCryptSha, &digest, sizeof(s_shaSeed), s_shaSeed); // Update output with contents of digest { @@ -324,11 +277,9 @@ void CryptCreateRandomSeed ( } // Combine seed with digest - s_shaSeed.data[0] ^= digest.data[0]; - s_shaSeed.data[1] ^= digest.data[1]; - s_shaSeed.data[2] ^= digest.data[2]; - s_shaSeed.data[3] ^= digest.data[3]; - s_shaSeed.data[4] ^= digest.data[4]; + for (size_t i = 0; i < SHA_DIGEST_LENGTH; i++) { + s_shaSeed[i] ^= digest[i]; + } } //============================================================================ diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h index fcce7340..7ec9590f 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h @@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "Pch.h" #include "pnUtArray.h" +#include "pnEncryption/plChecksum.h" /***************************************************************************** * @@ -61,17 +62,11 @@ struct CryptKey; enum ECryptAlgorithm { kCryptSha, - kCryptSha1, - kCryptMd5, kCryptRc4, kCryptRsa, kNumCryptAlgorithms }; -struct ShaDigest { - uint32_t data[5]; -}; - /***************************************************************************** * diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 99788d16..326387d7 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -1210,7 +1210,7 @@ void NetCommSetAccountUsernamePassword ( const ShaDigest & namePassHash ) { StrCopy(s_iniAccountUsername, username, arrsize(s_iniAccountUsername)); - s_namePassHash = namePassHash; + memcpy(s_namePassHash, namePassHash, sizeof(ShaDigest)); s_iniReadAccountInfo = false; } @@ -1252,7 +1252,7 @@ void NetCommAuthenticate ( s_iniAccountUsername, arrsize(s_account.accountNameAnsi) ); - s_account.accountNamePassHash = s_namePassHash; + memcpy(s_account.accountNamePassHash, s_namePassHash, sizeof(ShaDigest)); NetCliAuthLoginRequest( s_account.accountName, diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 8008db80..9a1ab597 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -2649,7 +2649,7 @@ bool LoginRequestTrans::Send () { PathSplitEmail(s_accountName, nil, 0, domain, arrsize(domain), nil, 0, nil, 0, 0); if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) { - challengeHash = s_accountNamePassHash; + memcpy(challengeHash, s_accountNamePassHash, sizeof(ShaDigest)); } else { CryptCreateRandomSeed( @@ -5253,7 +5253,7 @@ void NetCliAuthLoginRequest ( if (accountName) StrCopy(s_accountName, accountName, arrsize(s_accountName)); if (accountNamePassHash) - s_accountNamePassHash = *accountNamePassHash; + memcpy(s_accountNamePassHash, *accountNamePassHash, sizeof(ShaDigest)); if (authToken) StrCopy(s_authToken, authToken, arrsize(s_authToken)); if (os) diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp index cdd753f3..b28c012f 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp @@ -633,11 +633,11 @@ LoginRequestTrans::LoginRequestTrans ( FNetCliCsrLoginCallback callback, void * param ) : NetCsrTrans(kCsrLoginTrans) -, m_namePassHash(namePassHash) , m_callback(callback) , m_param(param) { ASSERT(callback); + memcpy(m_namePassHash, namePassHash, sizeof(ShaDigest)); StrCopy(m_csrName, csrName, arrsize(m_csrName)); } From 4a1b36b2843c8fa6482499cbe135ce7c5c1e62bf Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 12 Feb 2012 01:19:22 -0800 Subject: [PATCH 07/11] Move half of the Challenge Hash stuff. --- Sources/Plasma/Apps/plClient/winmain.cpp | 4 +- .../NucleusLib/pnEncryption/CMakeLists.txt | 2 + .../pnEncryption/plChallengeHash.cpp | 78 +++++++++++++++++++ .../NucleusLib/pnEncryption/plChallengeHash.h | 57 ++++++++++++++ .../NucleusLib/pnEncryption/plChecksum.cpp | 12 +-- .../NucleusLib/pnEncryption/plChecksum.h | 18 ++--- .../Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp | 43 ---------- Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h | 13 ---- .../plNetClientComm/plNetClientComm.cpp | 3 +- .../plNetGameLib/Private/plNglAuth.cpp | 22 +++--- .../plNetGameLib/Private/plNglCsr.cpp | 4 +- 11 files changed, 172 insertions(+), 84 deletions(-) create mode 100644 Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp create mode 100644 Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.h diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 166c20a8..4024ee5b 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -994,7 +994,9 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password) memcpy(pLoginParam->namePassHash, shasum.GetData(), sizeof(ShaDigest)); } else - CryptHashPassword(wusername, wpassword, &pLoginParam->namePassHash); + { + CryptHashPassword(_TEMP_CONVERT_FROM_WCHAR_T(wusername), _TEMP_CONVERT_FROM_WCHAR_T(wpassword), pLoginParam->namePassHash); + } } NetCommSetAccountUsernamePassword(wusername, pLoginParam->namePassHash); diff --git a/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt index 55e7f922..b27bffdc 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt @@ -3,10 +3,12 @@ include_directories("../../NucleusLib") include_directories(${OPENSSL_INCLUDE_DIR}) set(pnEncryption_SOURCES + plChallengeHash.cpp plChecksum.cpp ) set(pnEncryption_HEADERS + plChallengeHash.h plChecksum.h ) diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp new file mode 100644 index 00000000..a5d26794 --- /dev/null +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp @@ -0,0 +1,78 @@ +/*==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 . + +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==*/ + +#include "plChallengeHash.h" +#include "pnUtils/pnUtils.h" + +ShaDigest fSeed; + +void CryptCreateRandomSeed(size_t length, uint8_t* data) { +} + +void CryptHashPassword(const plString& username, const plString& password, ShaDigest dest) { + + /* This should be unnecessary once plString has ToLower() */ + wchar_t* w_name = (wchar_t*)_TEMP_CONVERT_TO_WCHAR_T(username); + StrLower(w_name); + + plString buf = password; + buf += _TEMP_CONVERT_FROM_WCHAR_T(w_name); + + plSHAChecksum sum(buf.GetSize() * sizeof(wchar_t), (uint8_t*)_TEMP_CONVERT_TO_WCHAR_T(buf)); + + memcpy(dest, sum.GetValue(), sizeof(ShaDigest)); +} + +void CryptHashPasswordChallenge(uint32_t clientChallenge, uint32_t serverChallenge, ShaDigest namePassHash, ShaDigest challengeHash) { + plSHAChecksum sum; + + sum.Start(); + sum.AddTo(sizeof(uint32_t), (uint8_t*)&clientChallenge); + sum.AddTo(sizeof(uint32_t), (uint8_t*)&serverChallenge); + sum.AddTo(sizeof(ShaDigest), namePassHash); + sum.Finish(); + + memcpy(challengeHash, sum.GetValue(), sizeof(ShaDigest)); +} + +void CryptCreateFastWeakChallenge(uint32_t* challenge, uint32_t val1, uint32_t val2) { +} diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.h b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.h new file mode 100644 index 00000000..10ff930c --- /dev/null +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.h @@ -0,0 +1,57 @@ +/*==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 . + +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==*/ +#ifndef PL_CHALLENGE_HASH_H +#define PL_CHALLENGE_HASH_H + +#include "HeadSpin.h" +#include "plChecksum.h" +#include "plString.h" + +void CryptCreateRandomSeed(size_t length, uint8_t* data); + +void CryptHashPassword(const plString& username, const plString& password, ShaDigest dest); + +void CryptHashPasswordChallenge(uint32_t clientChallenge, uint32_t serverChallenge, ShaDigest namePassHash, ShaDigest challengeHash); + +void CryptCreateFastWeakChallenge(uint32_t* challenge, uint32_t val1, uint32_t val2); + +#endif //PL_CHALLENGE_HASH_H diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp index b7c79c0e..e22b6ee9 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.cpp @@ -104,7 +104,7 @@ plChecksum::plChecksum(unsigned int bufsize, const char* buffer) //============================================================================ -plMD5Checksum::plMD5Checksum( uint32_t size, uint8_t *buffer ) +plMD5Checksum::plMD5Checksum(size_t size, uint8_t *buffer ) { fValid = false; Start(); @@ -173,7 +173,7 @@ void plMD5Checksum::Start() fValid = false; } -void plMD5Checksum::AddTo( uint32_t size, const uint8_t *buffer ) +void plMD5Checksum::AddTo(size_t size, const uint8_t *buffer ) { MD5_Update( &fContext, buffer, size ); } @@ -230,7 +230,7 @@ bool plMD5Checksum::operator==( const plMD5Checksum &rhs ) const //============================================================================ -plSHAChecksum::plSHAChecksum( uint32_t size, uint8_t *buffer ) +plSHAChecksum::plSHAChecksum(size_t size, uint8_t *buffer ) { fValid = false; Start(); @@ -301,7 +301,7 @@ void plSHAChecksum::Start() fValid = false; } -void plSHAChecksum::AddTo(uint32_t size, const uint8_t* buffer) +void plSHAChecksum::AddTo(size_t size, const uint8_t* buffer) { SHA_Update(&fContext, buffer, size); } @@ -356,7 +356,7 @@ bool plSHAChecksum::operator==(const plSHAChecksum& rhs) const //============================================================================ -plSHA1Checksum::plSHA1Checksum( uint32_t size, uint8_t *buffer ) +plSHA1Checksum::plSHA1Checksum(size_t size, uint8_t *buffer ) { fValid = false; Start(); @@ -427,7 +427,7 @@ void plSHA1Checksum::Start() fValid = false; } -void plSHA1Checksum::AddTo(uint32_t size, const uint8_t* buffer) +void plSHA1Checksum::AddTo(size_t size, const uint8_t* buffer) { SHA1_Update(&fContext, buffer, size); } diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h index 5cb8dc80..a42529f1 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChecksum.h @@ -69,7 +69,7 @@ class plMD5Checksum uint8_t fChecksum[MD5_DIGEST_LENGTH]; public: - plMD5Checksum(uint32_t size, uint8_t *buffer); + plMD5Checksum(size_t size, uint8_t *buffer); plMD5Checksum(); plMD5Checksum(const plMD5Checksum &rhs); plMD5Checksum(const char *fileName); @@ -82,11 +82,11 @@ class plMD5Checksum void CalcFromStream(hsStream* stream); void Start(); - void AddTo(uint32_t size, const uint8_t *buffer); + void AddTo(size_t size, const uint8_t *buffer); void Finish(); const uint8_t *GetValue() const { return fChecksum; } - uint32_t GetSize() const { return sizeof(fChecksum); } + size_t GetSize() const { return sizeof(fChecksum); } // Backdoor for cached checksums (ie, if you loaded it off disk) void SetValue(uint8_t* checksum); @@ -113,7 +113,7 @@ class plSHAChecksum ShaDigest fChecksum; public: - plSHAChecksum(uint32_t size, uint8_t* buffer); + plSHAChecksum(size_t size, uint8_t* buffer); plSHAChecksum(); plSHAChecksum(const plSHAChecksum& rhs); plSHAChecksum(const char* fileName); @@ -126,11 +126,11 @@ class plSHAChecksum void CalcFromStream(hsStream* stream); void Start(); - void AddTo(uint32_t size, const uint8_t* buffer); + void AddTo(size_t size, const uint8_t* buffer); void Finish(); const uint8_t* GetValue() const { return fChecksum; } - uint32_t GetSize() const { return sizeof(fChecksum); } + size_t GetSize() const { return sizeof(fChecksum); } // Backdoor for cached checksums (ie, if you loaded it off disk) void SetValue(uint8_t* checksum); @@ -152,7 +152,7 @@ class plSHA1Checksum ShaDigest fChecksum; public: - plSHA1Checksum(uint32_t size, uint8_t* buffer); + plSHA1Checksum(size_t size, uint8_t* buffer); plSHA1Checksum(); plSHA1Checksum(const plSHA1Checksum& rhs); plSHA1Checksum(const char* fileName); @@ -165,11 +165,11 @@ class plSHA1Checksum void CalcFromStream(hsStream* stream); void Start(); - void AddTo(uint32_t size, const uint8_t* buffer); + void AddTo(size_t size, const uint8_t* buffer); void Finish(); const uint8_t* GetValue() const { return fChecksum; } - uint32_t GetSize() const { return sizeof(fChecksum); } + size_t GetSize() const { return sizeof(fChecksum); } // Backdoor for cached checksums (ie, if you loaded it off disk) void SetValue(uint8_t* checksum); diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp index 12cd096b..818ef9d5 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp @@ -282,49 +282,6 @@ void CryptCreateRandomSeed ( } } -//============================================================================ -void CryptHashPassword ( - const wchar_t username[], - const wchar_t password[], - ShaDigest * namePassHash -) { - unsigned passlen = StrLen(password); - unsigned userlen = StrLen(username); - - wchar_t * buffer = (wchar_t*)malloc(sizeof(wchar_t) * (passlen + userlen)); - StrCopy(buffer, password, passlen); - StrCopy(buffer + passlen, username, userlen); - StrLower(buffer + passlen); // lowercase the username - - CryptDigest( - kCryptSha, - namePassHash, - (userlen + passlen) * sizeof(buffer[0]), - buffer - ); - - free(buffer); -} - -//============================================================================ -void CryptHashPasswordChallenge ( - unsigned clientChallenge, - unsigned serverChallenge, - const ShaDigest & namePassHash, - ShaDigest * challengeHash -) { -#pragma pack(push, 1) - struct { - uint32_t clientChallenge; - uint32_t serverChallenge; - ShaDigest namePassHash; - } buffer; -#pragma pack(pop) - buffer.clientChallenge = clientChallenge; - buffer.serverChallenge = serverChallenge; - buffer.namePassHash = namePassHash; - CryptDigest(kCryptSha, challengeHash, sizeof(buffer), &buffer); -} //============================================================================ void CryptCreateFastWeakChallenge ( diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h index 7ec9590f..eab9e465 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h @@ -124,19 +124,6 @@ void CryptCreateRandomSeed ( uint8_t * data ); -void CryptHashPassword ( - const wchar_t username[], - const wchar_t password[], - ShaDigest * namePassHash -); - -void CryptHashPasswordChallenge ( - unsigned clientChallenge, - unsigned serverChallenge, - const ShaDigest & namePassHash, - ShaDigest * challengeHash -); - void CryptCreateFastWeakChallenge ( unsigned * challenge, unsigned val1, diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 326387d7..bfeed522 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -52,6 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnNetCli/pnNetCli.h" #include "plNetGameLib/plNetGameLib.h" #include "pnIni/pnIni.h" +#include "pnEncryption/plChallengeHash.h" #include "plMessage/plNetCommMsgs.h" #include "plMessage/plNetClientMgrMsg.h" @@ -775,7 +776,7 @@ static void IReadNetIni() { L"" ); - CryptHashPassword(s_iniAccountUsername, password, &s_namePassHash); + CryptHashPassword(_TEMP_CONVERT_FROM_WCHAR_T(s_iniAccountUsername), _TEMP_CONVERT_FROM_WCHAR_T(password), s_namePassHash); } else { StrCopy(s_iniStartupAgeName, L"StartUp", arrsize(s_iniStartupAgeName)); diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 9a1ab597..a2819c91 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -48,6 +48,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "../Pch.h" #pragma hdrstop +#include "pnEncryption/plChallengeHash.h" + namespace Ngl { namespace Auth { /***************************************************************************** * @@ -2661,7 +2663,7 @@ bool LoginRequestTrans::Send () { clientChallenge, s_active->serverChallenge, s_accountNamePassHash, - &challengeHash + challengeHash ); } @@ -2818,9 +2820,9 @@ AccountCreateRequestTrans::AccountCreateRequestTrans ( StrCopy(m_accountName, accountName, arrsize(m_accountName)); CryptHashPassword( - m_accountName, - password, - &m_namePassHash + _TEMP_CONVERT_FROM_WCHAR_T(m_accountName), + _TEMP_CONVERT_FROM_WCHAR_T(password), + m_namePassHash ); } @@ -2888,9 +2890,9 @@ AccountCreateFromKeyRequestTrans::AccountCreateFromKeyRequestTrans ( StrCopy(m_accountName, accountName, arrsize(m_accountName)); CryptHashPassword( - m_accountName, - password, - &m_namePassHash + _TEMP_CONVERT_FROM_WCHAR_T(m_accountName), + _TEMP_CONVERT_FROM_WCHAR_T(password), + m_namePassHash ); } @@ -3186,9 +3188,9 @@ AccountChangePasswordRequestTrans::AccountChangePasswordRequestTrans ( StrCopy(m_accountName, accountName, arrsize(m_accountName)); CryptHashPassword( - m_accountName, - password, - &m_namePassHash + _TEMP_CONVERT_FROM_WCHAR_T(m_accountName), + _TEMP_CONVERT_FROM_WCHAR_T(password), + m_namePassHash ); } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp index b28c012f..7c84e206 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp @@ -48,6 +48,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "../Pch.h" #pragma hdrstop +#include "pnEncryption/plChallengeHash.h" + namespace Ngl { namespace Csr { /***************************************************************************** @@ -659,7 +661,7 @@ bool LoginRequestTrans::Send () { clientChallenge, s_active->serverChallenge, m_namePassHash, - &challengeHash + challengeHash ); const uintptr_t msg[] = { From 7a5d61f7c816e9e75c97117cbd314f819f9ceb88 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 12 Feb 2012 15:23:02 -0800 Subject: [PATCH 08/11] Move plRandom into pnEncryption. --HG-- rename : Sources/Plasma/PubUtilLib/plMath/plRandom.h => Sources/Plasma/NucleusLib/pnEncryption/plRandom.h --- Sources/Plasma/FeatureLib/pfAnimation/pfObjectFlocker.cpp | 2 +- Sources/Plasma/FeatureLib/pfAnimation/plBlower.h | 2 +- Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt | 1 + .../{PubUtilLib/plMath => NucleusLib/pnEncryption}/plRandom.h | 0 Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.cpp | 2 +- Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp | 2 +- Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp | 2 +- Sources/Plasma/PubUtilLib/plAvatar/plAvatarMgr.cpp | 2 +- Sources/Plasma/PubUtilLib/plDrawable/plDynaBulletMgr.cpp | 2 +- Sources/Plasma/PubUtilLib/plDrawable/plDynaDecalMgr.cpp | 2 +- Sources/Plasma/PubUtilLib/plDrawable/plDynaFootMgr.cpp | 2 +- Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgr.cpp | 2 +- Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgrVS.cpp | 2 +- Sources/Plasma/PubUtilLib/plDrawable/plDynaTorpedoMgr.cpp | 2 +- Sources/Plasma/PubUtilLib/plDrawable/plDynaWakeMgr.cpp | 2 +- Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h | 2 +- Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt | 1 - Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEffect.cpp | 2 +- .../Plasma/PubUtilLib/plParticleSystem/plParticleGenerator.cpp | 2 +- Sources/Tools/MaxComponent/plClusterComponent.cpp | 2 +- Sources/Tools/MaxComponent/plObjectFlockerComponent.cpp | 2 +- Sources/Tools/MaxConvert/plDistributor.h | 2 +- 22 files changed, 20 insertions(+), 20 deletions(-) rename Sources/Plasma/{PubUtilLib/plMath => NucleusLib/pnEncryption}/plRandom.h (100%) diff --git a/Sources/Plasma/FeatureLib/pfAnimation/pfObjectFlocker.cpp b/Sources/Plasma/FeatureLib/pfAnimation/pfObjectFlocker.cpp index 63b45a86..e2b457ee 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/pfObjectFlocker.cpp +++ b/Sources/Plasma/FeatureLib/pfAnimation/pfObjectFlocker.cpp @@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMessage/plAgeLoadedMsg.h" #include "pnSceneObject/plSceneObject.h" #include "hsTimer.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "pnMessage/plEnableMsg.h" #include "plMessage/plAnimCmdMsg.h" #include "plMessage/plLoadCloneMsg.h" diff --git a/Sources/Plasma/FeatureLib/pfAnimation/plBlower.h b/Sources/Plasma/FeatureLib/pfAnimation/plBlower.h index e8318e0b..d23d95ae 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/plBlower.h +++ b/Sources/Plasma/FeatureLib/pfAnimation/plBlower.h @@ -45,7 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnModifier/plSingleModifier.h" #include "hsGeometry3.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "hsTemplates.h" class plSceneObject; diff --git a/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt index b27bffdc..349b3d42 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt @@ -10,6 +10,7 @@ set(pnEncryption_SOURCES set(pnEncryption_HEADERS plChallengeHash.h plChecksum.h + plRandom.h ) add_library(pnEncryption STATIC ${pnEncryption_SOURCES} ${pnEncryption_HEADERS}) diff --git a/Sources/Plasma/PubUtilLib/plMath/plRandom.h b/Sources/Plasma/NucleusLib/pnEncryption/plRandom.h similarity index 100% rename from Sources/Plasma/PubUtilLib/plMath/plRandom.h rename to Sources/Plasma/NucleusLib/pnEncryption/plRandom.h diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.cpp index 27d6cfcb..9fd821ed 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.cpp @@ -55,7 +55,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plPipeline/plDebugText.h" #include "pnSceneObject/plCoordinateInterface.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "plNetClient/plNetClientMgr.h" #include "plNetTransport/plNetTransportMember.h" diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp index 34581ae7..7dd2ecca 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp @@ -73,7 +73,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnSceneObject/plCoordinateInterface.h" #include "plInputCore/plAvatarInputInterface.h" #include "plInputCore/plInputDevice.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "plPipeline/plDebugText.h" #include "plNetClient/plNetLinkingMgr.h" diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp index b271b04e..83a2da7e 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp @@ -73,7 +73,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plDrawable/plSpaceTree.h" #include "plSurface/hsGMaterial.h" #include "plSurface/plLayer.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "plSDL/plSDL.h" #include "plVault/plVault.h" #include "plResMgr/plKeyFinder.h" diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarMgr.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarMgr.cpp index 07e4e982..51fb0198 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarMgr.cpp @@ -74,7 +74,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plModifier/plSpawnModifier.h" #include "plModifier/plMaintainersMarkerModifier.h" #include "plVault/plDniCoordinateInfo.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "pnMessage/plPlayerPageMsg.h" #include "pnMessage/plWarpMsg.h" diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDynaBulletMgr.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDynaBulletMgr.cpp index dd0a39bf..9757768b 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDynaBulletMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDynaBulletMgr.cpp @@ -58,7 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsFastMath.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" static plRandom sRand; diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDynaDecalMgr.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDynaDecalMgr.cpp index 380f79a5..e159da44 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDynaDecalMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDynaDecalMgr.cpp @@ -75,7 +75,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnMessage/plTimeMsg.h" #include "plgDispatch.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "hsFastMath.h" #include "hsStream.h" diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDynaFootMgr.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDynaFootMgr.cpp index 776f6a10..f0a1b9db 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDynaFootMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDynaFootMgr.cpp @@ -60,7 +60,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAvatar/plArmatureMod.h" #include "plAvatar/plAvBrainHuman.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" static plRandom sRand; static const uint32_t kNumPrintIDs = 2; diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgr.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgr.cpp index 1f41a0d9..36d7909d 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgr.cpp @@ -61,7 +61,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAvatar/plAvBrainHuman.h" #include "plAvatar/plArmatureMod.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" static plRandom sRand; #include "plTweak.h" diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgrVS.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgrVS.cpp index a2bf1374..bdf94371 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgrVS.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDynaRippleMgrVS.cpp @@ -68,7 +68,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAvatar/plAvBrainHuman.h" #include "plAvatar/plArmatureMod.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" static plRandom sRand; #include "plTweak.h" diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDynaTorpedoMgr.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDynaTorpedoMgr.cpp index 4e567102..1cf3fe3c 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDynaTorpedoMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDynaTorpedoMgr.cpp @@ -54,7 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsTimer.h" #include "plTweak.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" static const uint32_t kNumPrintIDs = 0; diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDynaWakeMgr.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDynaWakeMgr.cpp index 9751aa80..f80b530b 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDynaWakeMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDynaWakeMgr.cpp @@ -64,7 +64,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plInterp/plAnimPath.h" #include "hsFastMath.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" static plRandom sRand; diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h b/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h index 90207cf8..17bec842 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h +++ b/Sources/Plasma/PubUtilLib/plDrawable/plWaveSet7.h @@ -46,7 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsGeometry3.h" #include "hsTemplates.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "hsBounds.h" #include "plFixedWaterState7.h" diff --git a/Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt index 36f68520..5be16a99 100644 --- a/Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt @@ -14,7 +14,6 @@ set(plMath_HEADERS hsRadixSort.h hsSearchVersion.h plAvg.h - plRandom.h plTriUtils.h ) diff --git a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEffect.cpp b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEffect.cpp index 3997259c..3ccc1f2a 100644 --- a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEffect.cpp +++ b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEffect.cpp @@ -49,7 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsResMgr.h" #include "plPipeline.h" #include "hsFastMath.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "plParticleSystem.h" #include "plMessage/plParticleUpdateMsg.h" diff --git a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleGenerator.cpp b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleGenerator.cpp index 40b6a271..f5a5c632 100644 --- a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleGenerator.cpp +++ b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleGenerator.cpp @@ -52,7 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMessage/plParticleUpdateMsg.h" #include "plInterp/plController.h" #include "hsResMgr.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" static const float DEFAULT_INVERSE_MASS = 1.f; diff --git a/Sources/Tools/MaxComponent/plClusterComponent.cpp b/Sources/Tools/MaxComponent/plClusterComponent.cpp index 24326bce..5981210a 100644 --- a/Sources/Tools/MaxComponent/plClusterComponent.cpp +++ b/Sources/Tools/MaxComponent/plClusterComponent.cpp @@ -57,7 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsBitVector.h" #include "plMath/hsRadixSort.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "pfAnimation/plBlower.h" #include "plDicer.h" diff --git a/Sources/Tools/MaxComponent/plObjectFlockerComponent.cpp b/Sources/Tools/MaxComponent/plObjectFlockerComponent.cpp index 03877df1..8fe16d8a 100644 --- a/Sources/Tools/MaxComponent/plObjectFlockerComponent.cpp +++ b/Sources/Tools/MaxComponent/plObjectFlockerComponent.cpp @@ -44,7 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "resource.h" #include "plComponent.h" #include "plComponentReg.h" -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "plObjectFlockerComponent.h" #include "pnKeyedObject/plUoid.h" #include "MaxMain/plMaxNode.h" diff --git a/Sources/Tools/MaxConvert/plDistributor.h b/Sources/Tools/MaxConvert/plDistributor.h index 23143474..3e6d3da7 100644 --- a/Sources/Tools/MaxConvert/plDistributor.h +++ b/Sources/Tools/MaxConvert/plDistributor.h @@ -43,7 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef plDistributor_inc #define plDistributor_inc -#include "plMath/plRandom.h" +#include "pnEncryption/plRandom.h" #include "plDistTree.h" class INode; From 39e8dd1b3cacce023135d1675c9525e55de8ca2a Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 12 Feb 2012 15:23:31 -0800 Subject: [PATCH 09/11] Remove all the Digest stuff from pnUtCrypt. --- .../pnEncryption/plChallengeHash.cpp | 55 +++++++- .../NucleusLib/pnEncryption/plChallengeHash.h | 2 - .../Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp | 128 ------------------ Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h | 35 ----- 4 files changed, 48 insertions(+), 172 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp index a5d26794..3b8c7eb0 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp @@ -45,11 +45,54 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ShaDigest fSeed; -void CryptCreateRandomSeed(size_t length, uint8_t* data) { +void CryptCreateRandomSeed(size_t length, uint8_t* data) +{ + uint32_t seedIdx = 0; + uint32_t dataIdx = 0; + uint32_t cur = 0; + uint32_t end = max(length, sizeof(ShaDigest)); + + // Combine seed with input data + for (; cur < end; cur++) { + fSeed[seedIdx] ^= data[dataIdx]; + + if (++seedIdx >= sizeof(ShaDigest)) + seedIdx = 0; + if (++dataIdx >= length) + dataIdx = 0; + } + + ((uint32_t*)fSeed)[2] ^= (uint32_t)&length; + ((uint32_t*)fSeed)[3] ^= (uint32_t)length; + ((uint32_t*)fSeed)[4] ^= (uint32_t)data; + + // Hash seed + plSHAChecksum sum(sizeof(ShaDigest), (uint8_t*)fSeed); + ShaDigest digest; + memcpy(digest, sum->GetValue(), sizeof(ShaDigest)); + + seedIdx = 0; + dataIdx = 0; + cur = 0; + + // Update output with contents of digest + for (; cur < end; cur++) { + data[dataIdx] ^= digest[seedIdx]; + + if (++seedIdx >= sizeof(ShaDigest)) + seedIdx = 0; + if (++dataIdx >= length) + dataIdx = 0; + } + + // Combine seed with digest + for (size_t i = 0; i < sizeof(ShaDigest); i++) { + fSeed[i] ^= digest[i]; + } } -void CryptHashPassword(const plString& username, const plString& password, ShaDigest dest) { - +void CryptHashPassword(const plString& username, const plString& password, ShaDigest dest) +{ /* This should be unnecessary once plString has ToLower() */ wchar_t* w_name = (wchar_t*)_TEMP_CONVERT_TO_WCHAR_T(username); StrLower(w_name); @@ -62,7 +105,8 @@ void CryptHashPassword(const plString& username, const plString& password, ShaDi memcpy(dest, sum.GetValue(), sizeof(ShaDigest)); } -void CryptHashPasswordChallenge(uint32_t clientChallenge, uint32_t serverChallenge, ShaDigest namePassHash, ShaDigest challengeHash) { +void CryptHashPasswordChallenge(uint32_t clientChallenge, uint32_t serverChallenge, ShaDigest namePassHash, ShaDigest challengeHash) +{ plSHAChecksum sum; sum.Start(); @@ -73,6 +117,3 @@ void CryptHashPasswordChallenge(uint32_t clientChallenge, uint32_t serverChallen memcpy(challengeHash, sum.GetValue(), sizeof(ShaDigest)); } - -void CryptCreateFastWeakChallenge(uint32_t* challenge, uint32_t val1, uint32_t val2) { -} diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.h b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.h index 10ff930c..761d1ccf 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.h +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.h @@ -52,6 +52,4 @@ void CryptHashPassword(const plString& username, const plString& password, ShaDi void CryptHashPasswordChallenge(uint32_t clientChallenge, uint32_t serverChallenge, ShaDigest namePassHash, ShaDigest challengeHash); -void CryptCreateFastWeakChallenge(uint32_t* challenge, uint32_t val1, uint32_t val2); - #endif //PL_CHALLENGE_HASH_H diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp index 818ef9d5..7e54b398 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp @@ -49,7 +49,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtStr.h" #include "pnUtTime.h" -#include #include /***************************************************************************** @@ -72,8 +71,6 @@ struct CryptKey { namespace Crypt { -ShaDigest s_shaSeed; - /***************************************************************************** * @@ -81,26 +78,6 @@ ShaDigest s_shaSeed; * ***/ -//============================================================================ -void ShaProcess ( - void * dest, - unsigned sourceCount, - const unsigned sourceBytes[], - const void * sourcePtrs[] -) { - // initialize digest - SHA_CTX sha; - SHA_Init(&sha); - - // hash data streams - for (unsigned index = 0; index < sourceCount; ++index) - SHA_Update(&sha, sourcePtrs[index], sourceBytes[index]); - - // complete hashing - SHA_Final((unsigned char *)dest, &sha); -} - - /***************************************************************************** * * RC4 @@ -144,39 +121,6 @@ static void Rc4Codec ( * ***/ -//============================================================================ -void CryptDigest ( - ECryptAlgorithm algorithm, - void * dest, // must be sized to the algorithm's digest size - const unsigned sourceBytes, - const void * sourceData -) { - CryptDigest( - algorithm, - dest, - 1, - &sourceBytes, - &sourceData - ); -} - -//============================================================================ -void CryptDigest ( - ECryptAlgorithm algorithm, - void * dest, // must be sized to the algorithm's digest size - unsigned sourceCount, - const unsigned sourceBytes[], // [sourceCount] - const void * sourcePtrs[] // [sourceCount] -) { - switch (algorithm) { - case kCryptSha: - ShaProcess(dest, sourceCount, sourceBytes, sourcePtrs); - break; - - DEFAULT_FATAL(algorithm); - } -} - //============================================================================ CryptKey * CryptKeyCreate ( ECryptAlgorithm algorithm, @@ -231,78 +175,6 @@ unsigned CryptKeyGetBlockSize ( } } -//============================================================================ -void CryptCreateRandomSeed ( - unsigned bytes, - uint8_t * data -) { - COMPILER_ASSERT(SHA_DIGEST_LENGTH == 20); - - // Combine seed with input data - { - unsigned seedIndex = 0; - unsigned dataIndex = 0; - unsigned cur = 0; - unsigned end = max(bytes, sizeof(s_shaSeed)); - for (; cur < end; ++cur) { - s_shaSeed[seedIndex] ^= data[dataIndex]; - if (++seedIndex >= sizeof(s_shaSeed)) - seedIndex = 0; - if (++dataIndex >= bytes) - dataIndex = 0; - } - - ((uint32_t*)s_shaSeed)[2] ^= (uint32_t) &bytes; - ((uint32_t*)s_shaSeed)[3] ^= (uint32_t) bytes; - ((uint32_t*)s_shaSeed)[4] ^= (uint32_t) data; - } - - // Hash seed - ShaDigest digest; - CryptDigest(kCryptSha, &digest, sizeof(s_shaSeed), s_shaSeed); - - // Update output with contents of digest - { - unsigned src = 0; - unsigned dst = 0; - unsigned cur = 0; - unsigned end = max(bytes, sizeof(digest)); - for (; cur < end; ++cur) { - data[dst] ^= ((const uint8_t *) &digest)[src]; - if (++src >= sizeof(digest)) - src = 0; - if (++dst >= bytes) - dst = 0; - } - } - - // Combine seed with digest - for (size_t i = 0; i < SHA_DIGEST_LENGTH; i++) { - s_shaSeed[i] ^= digest[i]; - } -} - - -//============================================================================ -void CryptCreateFastWeakChallenge ( - unsigned * challenge, - unsigned val1, - unsigned val2 -) { - s_shaSeed.data[0] ^= TimeGetMs(); // looping time - s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1); - s_shaSeed.data[0] ^= (unsigned) TimeGetTime(); // global time - s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1); - s_shaSeed.data[0] ^= *challenge; // unknown - s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1); - s_shaSeed.data[0] ^= (unsigned) challenge; // variable address - s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1); - s_shaSeed.data[0] ^= val1; - s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1); - s_shaSeed.data[0] ^= val2; - *challenge = s_shaSeed.data[0]; -} - //============================================================================ void CryptEncrypt ( CryptKey * key, diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h index eab9e465..4b5ed241 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h @@ -61,35 +61,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com struct CryptKey; enum ECryptAlgorithm { - kCryptSha, kCryptRc4, kCryptRsa, kNumCryptAlgorithms }; -/***************************************************************************** -* -* Digest functions -* -***/ - -void CryptDigest ( - ECryptAlgorithm algorithm, - void * dest, // must be sized to the algorithm's digest size - const unsigned sourceBytes, - const void * sourceData -); - -void CryptDigest ( - ECryptAlgorithm algorithm, - void * dest, // must be sized to the algorithm's digest size - unsigned sourceCount, - const unsigned sourceBytes[], // [sourceCount] - const void * sourcePtrs[] // [sourceCount] -); - - /***************************************************************************** * * Key generation @@ -119,18 +96,6 @@ unsigned CryptKeyGetBlockSize ( CryptKey * key ); -void CryptCreateRandomSeed ( - unsigned bytes, - uint8_t * data -); - -void CryptCreateFastWeakChallenge ( - unsigned * challenge, - unsigned val1, - unsigned val2 -); - - /***************************************************************************** * * Encryption and Decryption From ee338c9adf23ba6787046b0130417eab18ae1d81 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 12 Feb 2012 15:26:47 -0800 Subject: [PATCH 10/11] Fix some casting errors. --- Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp index 3b8c7eb0..67128439 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp @@ -62,14 +62,14 @@ void CryptCreateRandomSeed(size_t length, uint8_t* data) dataIdx = 0; } - ((uint32_t*)fSeed)[2] ^= (uint32_t)&length; + ((uint32_t*)fSeed)[2] ^= (uint32_t)((uintptr_t)&length); ((uint32_t*)fSeed)[3] ^= (uint32_t)length; - ((uint32_t*)fSeed)[4] ^= (uint32_t)data; + ((uint32_t*)fSeed)[4] ^= (uint32_t)((uintptr_t)data); // Hash seed plSHAChecksum sum(sizeof(ShaDigest), (uint8_t*)fSeed); ShaDigest digest; - memcpy(digest, sum->GetValue(), sizeof(ShaDigest)); + memcpy(digest, sum.GetValue(), sizeof(ShaDigest)); seedIdx = 0; dataIdx = 0; From e9856161072b547e852843bc62516addc7dbf294 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 12 Feb 2012 18:32:07 -0800 Subject: [PATCH 11/11] Fix errors. --- Sources/Plasma/Apps/plClient/winmain.cpp | 8 +++++--- Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 4024ee5b..f7432f94 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -65,6 +65,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plResMgr/plLocalization.h" #include "plFile/plEncryptedStream.h" +#include "pnEncryption/plChallengeHash.h" + #include "plStatusLog/plStatusLog.h" #include "pnProduct/pnProduct.h" #include "plNetGameLib/plNetGameLib.h" @@ -991,7 +993,7 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password) if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) { plSHA1Checksum shasum(StrLen(password) * sizeof(password[0]), (uint8_t*)password); - memcpy(pLoginParam->namePassHash, shasum.GetData(), sizeof(ShaDigest)); + memcpy(pLoginParam->namePassHash, shasum.GetValue(), sizeof(ShaDigest)); } else { @@ -1022,7 +1024,7 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password) stream->WriteSafeString(pLoginParam->username); stream->Writebool(pLoginParam->remember); if (pLoginParam->remember) - stream->Write(sizeof(pLoginParam->namePassHash.data), pLoginParam->namePassHash.data); + stream->Write(sizeof(pLoginParam->namePassHash), pLoginParam->namePassHash); stream->Close(); delete stream; } @@ -1069,7 +1071,7 @@ static void LoadUserPass (LoginDialogParam *pLoginParam) if (pLoginParam->remember) { - stream->Read(sizeof(pLoginParam->namePassHash.data), pLoginParam->namePassHash.data); + stream->Read(sizeof(pLoginParam->namePassHash), pLoginParam->namePassHash); pLoginParam->focus = IDOK; } else diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp index 422910da..04501fd7 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp @@ -48,6 +48,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "Pch.h" #pragma hdrstop +#include "pnEncryption/plChallengeHash.h" + //#define NCCLI_DEBUGGING #ifdef NCCLI_DEBUGGING # pragma message("Compiling pnNetCli with debugging on")