1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 19:29:09 +00:00

Integrate SecurePreloader into pfPatcher

This commit is contained in:
2013-11-25 11:55:29 -05:00
parent 9d162a7a32
commit 3299267976
26 changed files with 241 additions and 742 deletions

View File

@ -45,12 +45,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plgDispatch.h"
#include "plAgeLoader/plAgeLoader.h"
#include "plFile/plEncryptedStream.h"
#include "plFile/plStreamSource.h"
#include "plFile/plSecureStream.h"
#include "plMessage/plResPatcherMsg.h"
#include "pfPatcher/pfPatcher.h"
#include "plProgressMgr/plProgressMgr.h"
#include "plResMgr/plResManager.h"
extern bool gDataServerLocal;
bool gSkipPreload = false;
/////////////////////////////////////////////////////////////////////////////
@ -98,6 +102,21 @@ void plResPatcher::OnFileDownloaded(const plFileName& file)
}
}
bool plResPatcher::OnGameCodeDiscovered(const plFileName& file, hsStream* stream)
{
plSecureStream* ss = new plSecureStream(false, plStreamSource::GetInstance()->GetEncryptionKey());
if (ss->Open(stream)) {
plStreamSource::GetInstance()->InsertFile(file, ss);
// SecureStream will hold a decrypted buffer...
stream->Close();
delete stream;
} else
plStreamSource::GetInstance()->InsertFile(file, stream);
return true; // ASSume success for now...
}
void plResPatcher::OnProgressTick(uint64_t dl, uint64_t total, const plString& msg)
{
if (dl && total) {
@ -121,6 +140,14 @@ pfPatcher* plResPatcher::CreatePatcher()
patcher->OnFileDownloadBegin(std::bind(&plResPatcher::OnFileDownloadBegin, this, std::placeholders::_1));
patcher->OnFileDownloaded(std::bind(&plResPatcher::OnFileDownloaded, this, std::placeholders::_1));
patcher->OnProgressTick(std::bind(&plResPatcher::OnProgressTick, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
// sneaky hax: do the old SecurePreloader thing.... except here
if (!fRequestedGameCode && !gSkipPreload) {
patcher->OnGameCodeDiscovery(std::bind(&plResPatcher::OnGameCodeDiscovered, this, std::placeholders::_1, std::placeholders::_2));
patcher->RequestGameCode();
fRequestedGameCode = true;
}
return patcher;
}
@ -133,7 +160,7 @@ void plResPatcher::InitProgress()
/////////////////////////////////////////////////////////////////////////////
plResPatcher::plResPatcher()
: fProgress(nullptr) { }
: fProgress(nullptr), fRequestedGameCode(false) { }
plResPatcher::~plResPatcher()
{

View File

@ -58,12 +58,14 @@ class plResPatcher
{
plOperationProgress* fProgress;
static plResPatcher* fInstance;
bool fRequestedGameCode;
friend class plAgeLoader;
void OnCompletion(ENetError, const plString& msg);
void OnFileDownloadBegin(const plFileName& file);
void OnFileDownloaded(const plFileName& file);
bool OnGameCodeDiscovered(const plFileName& file, class hsStream* stream);
void OnProgressTick(uint64_t dl, uint64_t total, const plString& msg);
class pfPatcher* CreatePatcher();

View File

@ -667,17 +667,13 @@ bool plSecureStream::IsSecureFile(const plFileName& fileName)
hsStream* plSecureStream::OpenSecureFile(const plFileName& fileName, const uint32_t flags /* = kRequireEncryption */, uint32_t* key /* = nil */)
{
bool requireEncryption = flags & kRequireEncryption;
#ifndef PLASMA_EXTERNAL_RELEASE
requireEncryption = false;
#endif
bool deleteOnExit = flags & kDeleteOnExit;
bool isEncrypted = IsSecureFile(fileName);
hsStream* s = nil;
hsStream* s = nullptr;
if (isEncrypted)
s = new plSecureStream(deleteOnExit, key);
else if (!requireEncryption) // If this isn't an external release, let them use unencrypted data
else if (!requireEncryption)
s = new hsUNIXStream;
if (s)

View File

@ -40,7 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include <string>
#include "HeadSpin.h"
#include "plStreamSource.h"
#include "plSecureStream.h"
#include "plEncryptedStream.h"
@ -49,8 +49,15 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
# include <wctype.h>
#endif
plStreamSource::plStreamSource()
{
memset(fServerKey, 0, arrsize(fServerKey));
}
void plStreamSource::ICleanup()
{
hsTempMutexLock lock(fMutex);
// loop through all the file data records, and delete the streams
decltype(fFileData.begin()) curData;
for (curData = fFileData.begin(); curData != fFileData.end(); curData++)
@ -65,6 +72,8 @@ void plStreamSource::ICleanup()
hsStream* plStreamSource::GetFile(const plFileName& filename)
{
hsTempMutexLock lock(fMutex);
plFileName sFilename = filename.Normalize('/');
if (fFileData.find(sFilename) == fFileData.end())
{
@ -78,14 +87,15 @@ hsStream* plStreamSource::GetFile(const plFileName& filename)
fFileData[sFilename].fExt = sFilename.GetFileExt();
if (plSecureStream::IsSecureFile(filename))
{
uint32_t encryptionKey[4];
if (!plSecureStream::GetSecureEncryptionKey(filename, encryptionKey, 4))
{
FATAL("Hey camper... You need an NTD key file!");
return nil;
}
hsStream* ss = nullptr;
fFileData[sFilename].fStream = plSecureStream::OpenSecureFile(filename, 0, encryptionKey);
uint32_t encryptionKey[4];
if (plSecureStream::GetSecureEncryptionKey(filename, encryptionKey, 4))
ss = plSecureStream::OpenSecureFile(filename, 0, encryptionKey);
else
ss = plSecureStream::OpenSecureFile(filename, 0, fServerKey);
fFileData[sFilename].fStream = ss;
hsAssert(ss, "failed to open a SecureStream for a disc file!");
}
else // otherwise it is an encrypted or plain stream, this call handles both
fFileData[sFilename].fStream = plEncryptedStream::OpenEncryptedFile(filename);
@ -102,6 +112,7 @@ std::vector<plFileName> plStreamSource::GetListOfNames(const plFileName& dir, co
{
plFileName sDir = dir.Normalize('/');
hsAssert(ext.CharAt(0) != '.', "Don't add a dot");
hsTempMutexLock lock(fMutex);
// loop through all the file data records, and create the list
std::vector<plFileName> retVal;
@ -131,6 +142,7 @@ bool plStreamSource::InsertFile(const plFileName& filename, hsStream* stream)
{
plFileName sFilename = filename.Normalize('/');
hsTempMutexLock lock(fMutex);
if (fFileData.find(sFilename) != fFileData.end())
return false; // duplicate entry, return failure

View File

@ -43,8 +43,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plStreamSource_h_inc
#include <map>
#include <string>
#include "hsStream.h"
#include "hsThread.h"
// A class for holding and accessing file streams. The preloader will insert
// files in here once they are loaded. In internal builds, if a requested file
@ -60,10 +60,12 @@ private:
hsStream* fStream; // we own this pointer, so clean it up
};
std::map<plFileName, fileData, plFileName::less_i> fFileData; // key is filename
hsMutex fMutex;
uint32_t fServerKey[4];
void ICleanup(); // closes all file pointers and cleans up after itself
plStreamSource() {}
plStreamSource();
public:
~plStreamSource() {ICleanup();}
@ -77,6 +79,9 @@ public:
// For other classes to insert files (takes ownership of the stream if successful)
bool InsertFile(const plFileName& filename, hsStream* stream);
/** Gets a pointer to our encryption key */
uint32_t* GetEncryptionKey() { return fServerKey; }
// Instance handling
static plStreamSource* GetInstance();
};

View File

@ -98,7 +98,6 @@ set(plMessage_HEADERS
plOneShotMsg.h
plParticleUpdateMsg.h
plPickedMsg.h
plPreloaderMsg.h
plRenderMsg.h
plRenderRequestMsg.h
plReplaceGeometryMsg.h

View File

@ -319,9 +319,6 @@ REGISTER_CREATABLE(plNetCommPublicAgeListMsg);
REGISTER_CREATABLE(plNetCommPublicAgeMsg);
REGISTER_CREATABLE(plNetCommRegisterAgeMsg);
#include "plPreloaderMsg.h"
REGISTER_CREATABLE(plPreloaderMsg);
#include "plNetClientMgrMsg.h"
REGISTER_CREATABLE(plNetClientMgrMsg);

View File

@ -1,67 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/PubUtilLib/plMessage/plPreloaderMsg.h
*
***/
#ifndef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLMESSAGE_PLPRELOADERMSG_H
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLMESSAGE_PLPRELOADERMSG_H
#include "pnMessage/plMessage.h"
class plPreloaderMsg : public plMessage {
public:
bool fSuccess;
plPreloaderMsg () { SetBCastFlag(kBCastByExactType); }
CLASSNAME_REGISTER(plPreloaderMsg);
GETINTERFACE_ANY(plPreloaderMsg, plMessage);
void Read (hsStream* stream, hsResMgr* ) { FATAL("plPreloaderMsg::Read"); }
void Write (hsStream* stream, hsResMgr* ) { FATAL("plPreloaderMsg::Write"); }
};
#endif // PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLMESSAGE_PLPRELOADERMSG_H

View File

@ -60,6 +60,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plVault/plVault.h"
#include "plMessage/plAccountUpdateMsg.h"
#include "plNetClient/plNetClientMgr.h"
#include "plFile/plStreamSource.h"
#include "pfMessage/pfKIMsg.h"
@ -414,6 +415,9 @@ static void INetCliAuthLoginRequestCallback (
if (!wantsStartUpAge && 0 == StrCmpI(s_players[i].playerName, s_iniStartupPlayerName, (unsigned)-1))
s_player = &s_players[i];
}
// store this server's encryption key for posterity
NetCliAuthGetEncryptionKey(plStreamSource::GetInstance()->GetEncryptionKey(), 4);
}
else
s_account.accountUuid = kNilUuid;