Ejemplo n.º 1
0
// ClientCDKey::CreateSymmetricKey
// Creates a symmetric key from product name used to save/load CD-Key to/from
// the registry.  Symmetric key is created via a series of CRCs on the product.
void
ClientCDKey::CreateSymmetricKey(BFSymmetricKey& theSymKeyR) const
{
	WTRACE("ClientCDKey::CreateSymmetricKey");
	WDBG_LL("ClientCDKey::CreateSymmetricKey from product=" << mProduct);
	CRC16     aCRC;
	RawBuffer aBuf;

	// CRC the product and use it as 1st 2 bytes of key
	aCRC.Put(mProduct);
	unsigned short aCheckSum = aCRC.GetCRC();
	WDBG_LL("ClientCDKey::CreateSymmetricKey First CRC=" << aCheckSum);
	makeLittleEndian(aCheckSum);	// WON 3/21/00
	aBuf.assign(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum));

	// CRC each of 1st 3 chars of product and add them to key.
	for (int i=0; (i < 3) && (i < mProduct.size()); i++)
	{
		aCRC.Put(static_cast<unsigned char>(mProduct[i]));
		aCheckSum = aCRC.GetCRC();
		WDBG_LL("ClientCDKey::CreateSymmetricKey Add CRC=" << aCheckSum);
		makeLittleEndian(aCheckSum);	// WON 3/21/00
		aBuf.append(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum));
	}

	// Create the key
	WDBG_LL("ClientCDKey::CreateSymmetricKey Buf=" << aBuf);
	theSymKeyR.Create(aBuf.size(), aBuf.data());
}
Ejemplo n.º 2
0
// Auth1PublicKeyBlock::PackData
// Packs member data into raw buffer in base class.  Returns true on success and
// false on failure.  Makes sure keyList is not empty.  Appends number of keys
// in key list.  For each key, appends key length and the key.
bool
Auth1PublicKeyBlock::PackData()
{
	WTRACE("Auth1PublicKeyBlock::PackData");
	if (! AuthPublicKeyBlockBase::PackData()) return false;

	// KeyList cannot be empty.
	WDBG_LL("Auth1PublicKeyBlock::PackData Validating...");
	if (mKeyList.empty())
	{
		WDBG_LH("Auth1PublicKeyBlock::PackData KeySet is empty, pack fails.");
		return false;
	}

	// Append fixed length data
	WDBG_LL("Auth1PublicKeyBlock::PackData Packing...");
	unsigned short aNumKeys = mKeyList.size();
	makeLittleEndian(aNumKeys);
	mRawBuf.append(reinterpret_cast<unsigned char*>(&aNumKeys), sizeof(aNumKeys));

	// Append each key (length and binary data)
	WDBG_LL("Auth1PublicKeyBlock::PackData Packing keys (" << mKeyList.size() << ')');
	PublicKeyList::iterator anItr(mKeyList.begin());
	for (; anItr != mKeyList.end(); anItr++)
	{
		unsigned short aKeyLen = anItr->GetKeyLen();
		unsigned short tmpKeyLen = getLittleEndian(aKeyLen);
		mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpKeyLen), sizeof(tmpKeyLen));
		mRawBuf.append(anItr->GetKey(), aKeyLen);
	}

	return true;
}
Ejemplo n.º 3
0
// Auth1PrivateKeyBlock::PackData
// Packs member data into raw buffer in base class.  Returns true on success and
// false on failure.  Makes sure keyList is not empty.  Appends number of keys
// in key list.  For each key, appends key length and the key.
bool
Auth1PrivateKeyBlock::PackData()
{
	WTRACE("Auth1PrivateKeyBlock::PackData");
	if (! AuthPublicKeyBlockBase::PackData()) return false;

	// KeyList cannot be empty.
	WDBG_LL("Auth1PrivateKeyBlock::PackData Validating...");
	if (mKeyList.empty())
	{
		WDBG_LH("Auth1PrivateKeyBlock::PackData KeySet is empty, pack fails.");
		return false;
	}

	// Append fixed length data
	WDBG_LL("Auth1PrivateKeyBlock::PackData Packing...");
	unsigned short aNumKeys = mKeyList.size();
	unsigned short tmpNumKeys = getLittleEndian(aNumKeys);
	mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpNumKeys), sizeof(tmpNumKeys));

	// Append each key (length and binary data)
	WDBG_LL("Auth1PrivateKeyBlock::PackData Packing keys (" << mKeyList.size() << ')');
	PrivateKeyList::iterator anItr(mKeyList.begin());
	for (; anItr != mKeyList.end(); anItr++)
	{
		unsigned short aKeyLen = (*anItr)->GetKeyLen();
		unsigned short tmpKeyLen = getLittleEndian(tmpKeyLen);
		mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpKeyLen), sizeof(tmpKeyLen));
		mRawBuf.append((*anItr)->GetKey(), aKeyLen);

        // count and record which BlockId's map to this key.
	    PrivateKeyMap::iterator aMapIter(mKeyMap.begin());
		unsigned short aBlockIDCount=0;
        std::list<unsigned short> aBlockIdList;
        for(; aMapIter != mKeyMap.end(); aMapIter++)
        {
            if( aMapIter->second == *anItr )
            {
                aBlockIDCount++;
                aBlockIdList.push_back( aMapIter->first );
            }
        }

		unsigned short tmpBlockIDCount = getLittleEndian(aBlockIDCount);
		
        // pack BlockId count and BlockIds
		mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpBlockIDCount), sizeof(tmpBlockIDCount));
        while( aBlockIdList.size() )
        {
            unsigned short aBlockId = aBlockIdList.front();
            makeLittleEndian(aBlockId);
		    mRawBuf.append(reinterpret_cast<unsigned char*>(& aBlockId), sizeof(unsigned short));
            aBlockIdList.pop_front();
        }
	}

	return true;
}
Ejemplo n.º 4
0
// Auth1Certificate::UnpackData
// Unpacks member data from raw buffer in base class.  Returns true on success and
// false on failure.  Verifies raw data length, reads memeber data, sets mDatalen.
bool
Auth1Certificate::UnpackData()
{
	WTRACE("Auth1Certificate::UnpackData");
	if (! AuthCertificateBase::UnpackData()) return false;

	// Get data pointer (skip header data)
	WDBG_LL("Auth1Certificate::UnpackData Unpack fixed fields.");
	const unsigned char* aDataP = mRawBuf.data() + mDataLen;

	// Read UserId
	mUserId = *(reinterpret_cast<const unsigned long*>(aDataP));
	makeLittleEndian(mUserId);
	aDataP += sizeof(mUserId);

	// Read CommunityId
	unsigned long aCommunityId = *(reinterpret_cast<const unsigned long*>(aDataP));
	SetCommunityId(aCommunityId);
	makeLittleEndian(aCommunityId);
	aDataP += sizeof(aCommunityId);

	// Read TrustLeve
	unsigned short aTrustLevel = *(reinterpret_cast<const unsigned short*>(aDataP));
	SetTrustLevel(aTrustLevel);
	makeLittleEndian(aTrustLevel);
	aDataP += sizeof(aTrustLevel);

	// Read length of Pubkey and set mDataLen.  Verify there's enough data left
	// to read PubKey
	unsigned short aKeyLen = *(reinterpret_cast<const unsigned short*>(aDataP));
	makeLittleEndian(aKeyLen);
	aDataP   += sizeof(aKeyLen);
	mDataLen += CERT_MINLEN + aKeyLen;
	if (mRawBuf.size() < mDataLen)
	{
		WDBG_LH("Auth1Certificate::UnpackData Raw buf len to short for PubKey read (" << mRawBuf.size() << " < " << (CERT_MINLEN + aKeyLen) << ')');
		return false;
	}

	// Read PubKey
	WDBG_LL("Auth1Certificate::UnpackData Unpack PubKey and set dataLen.");
	mPubKey.Create(aKeyLen, aDataP);
	return true;
}
Ejemplo n.º 5
0
// Auth1PublicKeyBlock::UnpackData
// Unpacks member data from raw buffer in base class.  Returns true on success and
// false on failure.  Reads number of keys and then reads each key in turn.  Will
// abort if buffer size is exceeded.
bool
Auth1PublicKeyBlock::UnpackData()
{
	WTRACE("Auth1PublicKeyBlock::UnpackData");
	if (! AuthPublicKeyBlockBase::UnpackData()) return false;

	// Get data pointer (skip header data)
	WDBG_LL("Auth1PublicKeyBlock::UnpackData Unpack fixed fields.");
	const unsigned char* aDataP = mRawBuf.data() + mDataLen;

	// Read number of keys
	unsigned short aNumKeys = *(reinterpret_cast<const unsigned short*>(aDataP));
	makeLittleEndian(aNumKeys);
	aDataP   += sizeof(aNumKeys);
	mDataLen += BLOCK_MINLEN;

	// Read each key
	int i;
	for (i=0; i < aNumKeys; i++)
	{
		// Make sure key len can be read
		mDataLen += sizeof(unsigned short);
		if (mRawBuf.size() < mDataLen) break;

		// Read key len
		WDBG_LL("Auth1PublicKeyBlock::UnpackData Read key length.");
		unsigned short aKeyLen = *(reinterpret_cast<const unsigned short*>(aDataP));
		makeLittleEndian(aKeyLen);
		aDataP += sizeof(aKeyLen);

		// Make sure key can be read
		mDataLen += aKeyLen;
		if (mRawBuf.size() < mDataLen) break;

		// Read key and add to key set
		WDBG_LL("Auth1PublicKeyBlock::UnpackData Read key.");
		EGPublicKey aKey(aKeyLen, aDataP);
		aDataP += aKeyLen;
		mKeyList.push_back(aKey);
	}

	// Return true if all keys were read
	return (i == aNumKeys);
}