/****************************************************************************************************
 * @fn      CheckPacketSanity
 *          Initial correctness checks for Host Interface Packet.
 *
 *          Returns OSP_STATUS_OK if sanity checks pass, otherwise returns negative error code.
 ***************************************************************************************************/
static int32_t CheckPacketSanity( const uint8_t *pPacket )
{
    /* Buffer check */
    if (pPacket == NULL)
    {
        return SET_ERROR( OSP_STATUS_NULL_POINTER );
    }

    /* Version check */
    if (!(PACKET_VERSION_1_SUPPORTED) && GetPacketVersion(pPacket))
    {
        return SET_ERROR( OSP_STATUS_UNSUPPORTED_FEATURE );
    }

    return SET_ERROR( OSP_STATUS_OK );
}
Exemple #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