Exemplo n.º 1
0
// This decodes a packet to see if we like it
int DecodeArmoredAuthString(const unsigned char *PacketInput, unsigned char *DataOutputSixteen)
{
#ifdef WCS_BUILD_DEMO
return(0);
#else // !WCS_BUILD_DEMO
#ifdef WCS_BUILD_RTX
unsigned char EBuf[48], NBuf[48];

// we publicly decode with the easy E/N combo, keeping the hard D/N pair elsewhere (in the authorize tool)
memcpy(EBuf, AUTH_KEY_E, 48);
memcpy(NBuf, AUTH_KEY_N, 48);

//clear output buffer
memset(DataOutputSixteen, 0, 16);


if(DecryptPacket(PacketInput, DataOutputSixteen, EBuf, NBuf))
	{
	return(1);
	} // if
#endif // WCS_BUILD_RTX

return(0);
#endif // !WCS_BUILD_DEMO
} // DecodeArmoredAuthString
Exemplo n.º 2
0
// returns true if Check is successful
// generic binary file signature checking
bool CheckDependentBinaryFileSignature(const char *InputSig, const char *FileNameAndPath)
{
// must be explicitly cleared to succeed
bool SigInvalid = true;

// Handle repeated calls via caching
// (avoids expensive RSA decryption and file reads for MD5 calculation for
// sequential calls for the same object)
if(PreviousSigValid)
	{
	if(PreviousCachedSigText[0])
		{
		if(!strcmp(InputSig, PreviousCachedSigText))
			{
			if(!strcmp(FileNameAndPath, PreviousCachedFileText))
				{
				return(PreviousSigSuccess);
				} // if
			} // if
		} // if
	} // if

if(InputSig && InputSig[0] && FileNameAndPath && FileNameAndPath[0])
	{
	unsigned char NVWMD5Sixteen[17], SigSixteen[17];
	int PacketVersion = 0, MaxLength = 0;
	PacketVersion = GetPacketVersion((unsigned char *)InputSig);
	if(PacketVersion == 1) MaxLength = 0;
	if(PacketVersion == 2) MaxLength = 16384;
	if(CalcHashOfFileFromName(FileNameAndPath, NVWMD5Sixteen, MaxLength, 1)) // calculate hash using binary method (allow ECW hash)
		{
		unsigned char DBuf[48], NBuf[48];

		// Try VNS2 signature first
		memcpy(DBuf, NV_KEY_VNS_D, 48);
		memcpy(NBuf, NV_KEY_VNS_N, 48);
		// this makes debugging easier
		NVWMD5Sixteen[16] = SigSixteen[16] = 0;
		if(DecryptPacket((unsigned char *)InputSig, SigSixteen, DBuf, NBuf))
			{
			// update cache
			strcpy(PreviousCachedSigText, InputSig);
			strcpy(PreviousCachedFileText, FileNameAndPath);
			PreviousSigValid = 1;

			if(memcmp(NVWMD5Sixteen, SigSixteen, 16))
				{
				PreviousSigSuccess = 0;
				//UserMessageOK(NVW_NATUREVIEW_NAMETEXT, "Signatures differ!", REQUESTER_ICON_EXCLAMATION);
				} // if
			else
				{
				SigInvalid = false;
				PreviousSigSuccess = 1;
				//UserMessageOK(NVW_NATUREVIEW_NAMETEXT, "Signatures match!");
				} // else
			} // if
		// if that fails, try WCS6
		if(SigInvalid)
			{
			memcpy(DBuf, NV_KEY_WCS_D, 48);
			memcpy(NBuf, NV_KEY_WCS_N, 48);
			// this makes debugging easier
			NVWMD5Sixteen[16] = SigSixteen[16] = 0;
			if(DecryptPacket((unsigned char *)InputSig, SigSixteen, DBuf, NBuf))
				{
				// update cache
				strcpy(PreviousCachedSigText, InputSig);
				strcpy(PreviousCachedFileText, FileNameAndPath);
				PreviousSigValid = 1;

				if(memcmp(NVWMD5Sixteen, SigSixteen, 16))
					{
					PreviousSigSuccess = 0;
					//UserMessageOK(NVW_NATUREVIEW_NAMETEXT, "Signatures differ!", REQUESTER_ICON_EXCLAMATION);
					} // if
				else
					{
					SigInvalid = false;
					PreviousSigSuccess = 1;
					//UserMessageOK(NVW_NATUREVIEW_NAMETEXT, "Signatures match!");
					} // else
				} // if
			} // if
		} // if
	} // if

return(!SigInvalid);
} // CheckDependentBinaryFileSignature
Exemplo n.º 3
0
bool CheckNVWFileSignature(const char *FileNameAndPath)
{
bool SigInvalid = false;

#ifdef NV_CHECK_SIGNATURES
// check signatures

// SigInvalid must be successfully cleared to proceed
SigInvalid = true;
if(MasterScene.CheckSig())
	{
	unsigned char NVWMD5Sixteen[17], SigSixteen[17];
	if(CalcModifiedHashOfNVWFileFromName(FileNameAndPath, NVWMD5Sixteen))
		{
		unsigned char DBuf[48], NBuf[48];

		// Try VNS2 signature
		memcpy(DBuf, NV_KEY_VNS_D, 48);
		memcpy(NBuf, NV_KEY_VNS_N, 48);
		// this makes debugging easier
		NVWMD5Sixteen[16] = SigSixteen[16] = 0;
		if(DecryptPacket((unsigned char *)MasterScene.GetSig(), SigSixteen, DBuf, NBuf))
			{
			if(memcmp(NVWMD5Sixteen, SigSixteen, 16))
				{
				//UserMessageOK(NVW_NATUREVIEW_NAMETEXT, "Signatures differ!", REQUESTER_ICON_EXCLAMATION);
				} // if
			else
				{
				SigInvalid = false;
				//UserMessageOK(NVW_NATUREVIEW_NAMETEXT, "Signatures match!");
				} // else
			} // if

		// if that fails, try WCS6
		if(SigInvalid)
			{
			memcpy(DBuf, NV_KEY_WCS_D, 48);
			memcpy(NBuf, NV_KEY_WCS_N, 48);
			// this makes debugging easier
			NVWMD5Sixteen[16] = SigSixteen[16] = 0;
			if(DecryptPacket((unsigned char *)MasterScene.GetSig(), SigSixteen, DBuf, NBuf))
				{
				if(memcmp(NVWMD5Sixteen, SigSixteen, 16))
					{
					//UserMessageOK(NVW_NATUREVIEW_NAMETEXT, "Signatures differ!", REQUESTER_ICON_EXCLAMATION);
					} // if
				else
					{
					SigInvalid = false;
					//UserMessageOK(NVW_NATUREVIEW_NAMETEXT, "Signatures match!");
					} // else
				} // if
			}

		} // if
	} // if
#endif // NV_CHECK_SIGNATURES

return(SigInvalid);
} // CheckNVWFileSignature
Exemplo n.º 4
0
void KOSocket::OnRead()
{
    Packet pkt;

    for (;;)
    {
        if (m_remaining == 0)
        {
            if (GetReadBuffer().GetSize() < 5)
                return; //check for opcode as well

            uint16 header = 0;
            GetReadBuffer().Read(&header, 2);
            if (header != 0x55aa)
            {
                TRACE("%s: Got packet without header 0x55AA, got 0x%X\n", GetRemoteIP().c_str(), header);
                goto error_handler;
            }

            GetReadBuffer().Read(&m_remaining, 2);
            if (m_remaining == 0)
            {
                TRACE("%s: Got packet without an opcode, this should never happen.\n", GetRemoteIP().c_str());
                goto error_handler;
            }
        }

        if (m_remaining > GetReadBuffer().GetAllocatedSize())
        {
            TRACE("%s: Packet received which was %u bytes in size, maximum of %u.\n", GetRemoteIP().c_str(), m_remaining, GetReadBuffer().GetAllocatedSize());
            goto error_handler;
        }

        if (m_remaining > GetReadBuffer().GetSize())
        {
            if (m_readTries > 4)
            {
                TRACE("%s: packet fragmentation count is over 4, disconnecting as they're probably up to something bad\n", GetRemoteIP().c_str());
                goto error_handler;
            }
            m_readTries++;
            return;
        }

        uint8 *in_stream = new uint8[m_remaining];

        m_readTries = 0;
        GetReadBuffer().Read(in_stream, m_remaining);

        uint16 footer = 0;
        GetReadBuffer().Read(&footer, 2);

        if (footer != 0xaa55
                || !DecryptPacket(in_stream, pkt))
        {
            TRACE("%s: Footer invalid (%X) or failed to decrypt.\n", GetRemoteIP().c_str(), footer);
            delete [] in_stream;
            goto error_handler;
        }

        delete [] in_stream;

        if (!HandlePacket(pkt))
        {

            TRACE("%s: Handler for packet %X returned false\n", GetRemoteIP().c_str(), pkt.GetOpcode());
#ifndef _DEBUG
            goto error_handler;
#endif
        }

        m_remaining = 0;
    }

    return;

error_handler:
    GetReadBuffer().Remove(GetReadBuffer().GetSize());
    Disconnect();
}