bool WinRegistryConfiguration::getRaw(const std::string& key, std::string& value) const
{
	std::string keyName;
	std::string fullPath = _rootPath + ConvertToRegFormat(key, keyName);
	WinRegistryKey aKey(fullPath);
	bool exists = aKey.exists(keyName);
	if (exists)
	{
		WinRegistryKey::Type type = aKey.type(keyName);

		switch (type)
		{
		case WinRegistryKey::REGT_STRING:
			value = aKey.getString(keyName);
			break;
		case WinRegistryKey::REGT_STRING_EXPAND:
			value = aKey.getStringExpand(keyName);
			break;
		case WinRegistryKey::REGT_DWORD:
			value = Poco::NumberFormatter::format(aKey.getInt(keyName));
			break;
		default:
			exists = false;
		}
	}
	return exists;
}
void WinRegistryConfiguration::setRaw(const std::string& key, const std::string& value)
{
	std::string keyName;
	std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
	WinRegistryKey aKey(fullPath);
	aKey.setString(keyName, value);
}
Пример #3
0
// ClientCDKey::Load
// Loads CD-Key from WON standard location in registry.  Entry is registry must be
// the enrypted binary form.  Calls Init(RawBuffer).
bool
ClientCDKey::Load()
{
	WTRACE("ClientCDKey::Load");
	WDBG_LM("ClientCDKey::Load Loading key from registry.");

	// Open registry key
	RegKey aRegKey(REG_CDKEY_PATH, HKEY_LOCAL_MACHINE);
	if (! aRegKey.IsOpen())
	{
		WDBG_LH("ClientCDKey::Load Fail open registry key: " << REG_CDKEY_PATH);
		mValidity = Invalid;
		return false;
	}

	// Fetch key from registry for value product
	unsigned char* aBufP = NULL;
	unsigned long  aLen  = 0;
	if (aRegKey.GetValue(mProduct, aBufP, aLen) != RegKey::Ok)
	{
		WDBG_LH("ClientCDKey::Load Fail fetch key value for product=" << mProduct);
		mValidity = Invalid;
		return false;
	}

	// Build buffer and call Init(RawBuffer)
	RawBuffer aKey(aBufP, aLen);
	delete aBufP;
	return Init(aKey);
}
// EGPublicKey::CopyFromPrivateKey
// Copies public key from a private key.  Existing key (if any) is replaced.  This
// method takes the binary rep of the private key and drops the private portion
// to generate the public key.
void
EGPublicKey::CopyFromPrivateKey(const EGPrivateKey& theKeyR)
{
	ClearLocal();

	try
	{
		ByteQueue aPrivQueue;
		aPrivQueue.Put(theKeyR.GetKey(), theKeyR.GetKeyLen());
		aPrivQueue.Close();

		ElGamalVerifier aKey(aPrivQueue);
		ByteQueue       aPubQueue;
		aKey.DEREncode(aPubQueue);
		aPubQueue.Close();

		AllocKeyBuf(aPubQueue.MaxRetrieveable());
		aPubQueue.Get(mKey, mKeyLen);
	}
	catch (Exception& anEx)
	{
		WDBG_AH("EGPublicKey::CopyFromPrivateKey Caught CryptoLib exception: " << anEx.what());
#ifndef _WONCRYPT_NOEXCEPTIONS
		throw WONCrypt::CryptException(WONCommon::ExCryptoLib, __LINE__, __FILE__, anEx.what());
#else
		Invalidate();
#endif
	}
}
Пример #5
0
bool
Vertex::isInNeighbour(Vertex* putNeighbr)
{
	string aKey(putNeighbr->getName());
	bool found=false;
	if(inNeighbours.find(aKey)!=inNeighbours.end())
	{
		found=true;
	}
	return found;
}
Пример #6
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);
}
void WinRegistryConfiguration::enumerate(const std::string& key, Keys& range) const
{
	if (key.empty())
	{
		// return all root level keys
		range.push_back("HKEY_CLASSES_ROOT");
		range.push_back("HKEY_CURRENT_CONFIG");
		range.push_back("HKEY_CURRENT_USER");
		range.push_back("HKEY_LOCAL_MACHINE");
		range.push_back("HKEY_PERFORMANCE_DATA");
		range.push_back("HKEY_USERS");
	}
	else
	{
		std::string keyName;
		std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
		WinRegistryKey aKey(fullPath);
		aKey.values(range);
		aKey.subKeys(range);
	}
}
Пример #8
0
// WON_AuthFamilyBuffer::Pack
// Pack into raw form and sign with specified raw private key.
int
WON_AuthFamilyBuffer::Pack(const unsigned char* thePrivKeyP, unsigned short theLen)
{
    EGPrivateKey aKey(theLen, thePrivKeyP);
    return (mBufP->Pack(aKey) ? RETURN_TRUE : RETURN_FALSE);
}
Пример #9
0
// WON_AuthFamilyBuffer::Verify
// Veriy signature using specified raw public key.
int
WON_AuthFamilyBuffer::Verify(const unsigned char* thePubKeyP, unsigned short theLen) const
{
    EGPublicKey aKey(theLen, thePubKeyP);
    return (mBufP->Verify(aKey) ? RETURN_TRUE : RETURN_FALSE);
}
void
WON_AuthCertificate1::SetPublicKey(const unsigned char* theKeyP, unsigned short theLen)
{
	EGPublicKey aKey(theLen, theKeyP);
	mCertP->SetPublicKey(aKey);
}