Esempio n. 1
0
void ConfigurationMapper::enumerate(const std::string& key, Keys& range) const
{
	std::string cKey(key);
	if (!cKey.empty()) cKey += '.';
	std::string::size_type keyLen = cKey.length();
	if (keyLen < _toPrefix.length())
	{
		if (_toPrefix.compare(0, keyLen, cKey) == 0)
		{
			std::string::size_type pos = _toPrefix.find_first_of('.', keyLen);
			poco_assert_dbg(pos != std::string::npos);
			range.push_back(_toPrefix.substr(keyLen, pos - keyLen));
		}
	}
	else
	{
		std::string translatedKey;
		if (cKey == _toPrefix)
		{
			translatedKey = _fromPrefix;
			if (!translatedKey.empty())
				translatedKey.resize(translatedKey.length() - 1);
		}
		else translatedKey = translateKey(key);
		_pConfig->enumerate(translatedKey, range);
	}
}
Esempio n. 2
0
int wmain(int argc, wchar_t* argv[])
{
	wchar_t buf[_MAX_PATH] = L"";
	setlocale(LC_ALL, "");
	c2lib::Init(argc, argv);
	// レジストリ //
	if(0){
		//HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir
		CRegKey cKey(L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
		ExpandEnvironmentStrings(cKey.GetValue(L"WallPaperDir").ToString().c_str(), buf, _countof(buf));
		printf("%ls\n", buf);
	}
	// シェル //
	if(1){
//		CShellFolder s(L"D:\\_tmp");
		CShellFolder s(L"::MyComputer");
		CEnumIdList list = s.CreateEnumIDList();
		while(1){
			CItemIdList item = list.CreateNextIDList();
			if(!item.IsValid())break;
			std::wstring strName = s.GetDisplayNameOfItem(item);//item.GetPath();
			std::wstring strPath = item.GetPath();
			wprintf(L"[%ls] [%ls]\n", strName.c_str(), strPath.c_str());
		}
	}
	return 0;
}
static void encodePrivateKeyHeader(const CssmData &inBlob, CFDataRef certificate, FVPrivateKeyHeader &outHeader)
{
	CssmClient::CL cl(gGuidAppleX509CL);
	const CssmData cert(const_cast<UInt8 *>(CFDataGetBytePtr(certificate)), CFDataGetLength(certificate));
	CSSM_KEY_PTR key;
	if (CSSM_RETURN rv = CSSM_CL_CertGetKeyInfo(cl->handle(), &cert, &key))
		CssmError::throwMe(rv);
	
	Security::CssmClient::CSP fCSP(gGuidAppleCSP);

	// Set it up so the cl is used to free key and key->KeyData
	// CssmAutoData _keyData(cl.allocator());
	// _keyData.set(CssmData::overlay(key->KeyData));
	CssmAutoData _key(cl.allocator());
	_key.set(reinterpret_cast<uint8 *>(key), sizeof(*key));
	CssmClient::Key cKey(fCSP, *key);
	
	/* Given a CSSM_KEY_PTR in any format, obtain the SHA-1 hash of the 
		* associated key blob. 
		* Key is specified in CSSM_CSP_CreatePassThroughContext.
		* Hash is allocated by the CSP, in the App's memory, and returned
		* in *outData. */
	CssmClient::PassThrough passThrough(fCSP);
	passThrough.key(key);
	void *outData;
	passThrough(CSSM_APPLECSP_KEYDIGEST, NULL, &outData);
	CssmData *cssmData = reinterpret_cast<CssmData *>(outData);
	
	assert(cssmData->Length <= sizeof(outHeader.publicKeyHash));
	outHeader.publicKeyHashSize = (uint32_t)cssmData->Length;
	memcpy(outHeader.publicKeyHash, cssmData->Data, cssmData->Length);
	fCSP.allocator().free(cssmData->Data);
	fCSP.allocator().free(cssmData);
	
	/* Now encrypt the blob with the public key. */
    CssmClient::Encrypt encrypt(fCSP, key->KeyHeader.AlgorithmId);
	encrypt.key(cKey);
	CssmData clearBuf(outHeader.encryptedBlob, sizeof(outHeader.encryptedBlob));
	CssmAutoData remData(fCSP.allocator());
	encrypt.padding(CSSM_PADDING_PKCS1);
	
	outHeader.encryptedBlobSize = (uint32_t)encrypt.encrypt(inBlob, clearBuf, remData.get());
	if (outHeader.encryptedBlobSize > sizeof(outHeader.encryptedBlob))
		secinfo("FDERecovery", "encodePrivateKeyHeader: encrypted blob too big: %d", outHeader.encryptedBlobSize);
}