Пример #1
0
CryptManager::CryptManager()
{
	//
	// generate keys if none are available
	//
	if( PREFSMAN->m_bSignProfileData )
	{
		if( !DoesFileExist(PRIVATE_KEY_PATH) || !DoesFileExist(PUBLIC_KEY_PATH) )
		{
			LOG->Warn( "Public and/or Private keys missing. Profile data cannot be signed." );
			FlushDirCache();
		}
	}
}
Пример #2
0
void CryptoTest()
{
	PREFSMAN = new PrefsManager; /* CRYPTMAN needs PREFSMAN */
	PREFSMAN->m_bSignProfileData.Set( true );

	CRYPTMAN = new CryptManager;

	g_TestFile = "hello world";
	g_TestFilename = "file";
	FlushDirCache();

	do {
		g_BytesUntilError = -1;
		CRYPTMAN->SignFileToFile( "test/file", "output" );

		FlushDirCache();

		if( !CRYPTMAN->VerifyFileWithFile( "test/file", "output" ) )
			Fail( "Crypto: VerifyFileWithFile failed");
	} while(false);


	/* Write error check. */
	do {
		g_BytesUntilError = 5;
		CRYPTMAN->SignFileToFile( "test/file", "output" );
	} while(false);

	/* Read error check. */
	do {
		g_BytesUntilError = 5;
		CRYPTMAN->SignFileToFile( "output", "test/file" );
	} while(false);

	delete PREFSMAN;
	delete CRYPTMAN;
}
Пример #3
0
// this is the diary of a mad man
bool GetUSBDeviceList(vector<USBDevice> &pDevList)
{
	FlushDirCache();

	std::map< CString, vector<CString> > sDevInterfaceList;
	vector<CString> sDirList;
	GetDirListing( "/rootfs/sys/bus/usb/devices/", sDirList, true, false );
	for (unsigned i = 0; i < sDirList.size(); i++)
	{
		CString sDirEntry = sDirList[i];
		vector<CString> components;

		if (sDirEntry.substr(0, 3) == "usb") continue;

		split( sDirEntry, ":", components, true );
		if ( components.size() < 2 ) continue;

		if ( ! IsADirectory( "/rootfs/sys/bus/usb/devices/" + components[0] ) ) continue;

		// I win --infamouspat
		sDevInterfaceList[components[0]].push_back(components[1]);

	}

	map< CString, vector<CString> >::iterator iter;
 
	for(iter = sDevInterfaceList.begin(); iter != sDevInterfaceList.end(); iter++)
	{
		USBDevice newDev;
		CString sDevName = iter->first;
		vector<CString> sDevChildren = iter->second;
		
		if ( newDev.Load(sDevName, sDevChildren) )
			pDevList.push_back(newDev);
	}

	return true;
}
Пример #4
0
CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex )
{
	//
	// Find a file name for the screenshot
	//
	FlushDirCache();

	vector<CString> files;
	GetDirListing( sDir + "screen*", files, false, false );
	sort( files.begin(), files.end() );

	/* Files should be of the form "screen######.xxx".  Ignore the extension; find
	 * the last file of this form, and use the next number.  This way, we don't
	 * write the same screenshot number for different formats (screen00011.bmp,
	 * screen00011.jpg), and we always increase from the end, so if screen00003.jpg
	 * is deleted, we won't fill in the hole (which makes screenshots hard to find). */
	if( iIndex == -1 ) 
	{
		iIndex = 0;

		for( int i = files.size()-1; i >= 0; --i )
		{
			static Regex re( "^screen([0-9]{5})\\....$" );
			vector<CString> matches;
			if( !re.Compare( files[i], matches ) )
				continue;

			ASSERT( matches.size() == 1 );
			iIndex = atoi( matches[0] )+1;
			break;
		}
	}

	//
	// Save the screenshot
	//
	/* If writing lossy to a memcard, use SAVE_LOSSY_LOW_QUAL, so we don't eat up
	 * lots of space with screenshots. */
	RageDisplay::GraphicsFileFormat fmt;
	if( bSaveCompressed && MEMCARDMAN->PathIsMemCard(sDir) )
		fmt = RageDisplay::SAVE_LOSSY_LOW_QUAL;
	else if( bSaveCompressed )
		fmt = RageDisplay::SAVE_LOSSY_HIGH_QUAL;
	else
		fmt = RageDisplay::SAVE_LOSSLESS;

	CString sFileName = ssprintf( "screen%05d.%s",iIndex,bSaveCompressed ? "jpg" : "bmp" );
	CString sPath = sDir+sFileName;
	bool bResult = DISPLAY->SaveScreenshot( sPath, fmt );
	if( !bResult )
	{
		SCREENMAN->PlayInvalidSound();
		return "";
	}

	SCREENMAN->PlayScreenshotSound();

	// We wrote a new file, and SignFile won't pick it up unless we invalidate
	// the Dir cache.  There's got to be a better way of doing this than 
	// thowing out all the cache. -Chris
	FlushDirCache();

	if( PREFSMAN->m_bSignProfileData && bMakeSignature )
		CryptManager::SignFileToFile( sPath );

	return sFileName;
}
Пример #5
0
void ScreenPackages::HTTPUpdate()
{
	if( !m_bIsDownloading )
		return;

	int BytesGot=0;
	//Keep this as a code block
	//as there may be need to "if" it out some time.
	/* If you need a conditional for a large block of code, stick it in
	 * a function and return. */
	while(1)
	{
		char Buffer[1024];
		int iSize = m_wSocket.ReadData( Buffer, 1024 );
		if( iSize <= 0 )
			break;

		m_sBUFFER.append( Buffer, iSize );
		BytesGot += iSize;
	}

	if( !m_bGotHeader )
	{
		m_sStatus = "Waiting for header.";
		//We don't know if we are using unix-style or dos-style
		size_t iHeaderEnd = FindEndOfHeaders( m_sBUFFER );
		if( iHeaderEnd == m_sBUFFER.npos )
			return;

		// "HTTP/1.1 200 OK"
		size_t i = m_sBUFFER.find(" ");
		size_t j = m_sBUFFER.find(" ",i+1);
		size_t k = m_sBUFFER.find("\n",j+1);
		if ( i == string::npos || j == string::npos || k == string::npos )
		{
			m_iResponseCode = -100;
			m_sResponseName = "Malformed response.";
			return;
		}
		m_iResponseCode = atoi(m_sBUFFER.substr(i+1,j-i).c_str());
		m_sResponseName = m_sBUFFER.substr( j+1, k-j );

		i = m_sBUFFER.find("Content-Length:");
		j = m_sBUFFER.find("\n", i+1 );

		if( i != string::npos )
			m_iTotalBytes = atoi(m_sBUFFER.substr(i+16,j-i).c_str());
		else
			m_iTotalBytes = -1;	//We don't know, so go until disconnect

		m_bGotHeader = true;
		m_sBUFFER.erase( 0, iHeaderEnd );
	}

	if( m_bIsPackage )
	{
		m_iDownloaded += m_sBUFFER.length();
		m_fOutputFile.Write( m_sBUFFER );
		m_sBUFFER = "";
	}
	else
	{
		m_iDownloaded = m_sBUFFER.length();
	}

	if ( ( m_iTotalBytes <= m_iDownloaded && m_iTotalBytes != -1 ) ||
					//We have the full doc. (And we knew how big it was)
		( m_iTotalBytes == -1 && 
			( m_wSocket.state == EzSockets::skERROR || m_wSocket.state == EzSockets::skDISCONNECTED ) ) )
				//We didn't know how big it was, and were disconnected
				//So that means we have it all.
	{
		m_wSocket.close();
		m_bIsDownloading = false;
		m_bGotHeader=false;
		m_sStatus = ssprintf( "Done;%dB", int(m_iDownloaded) );

		if( m_iResponseCode < 200 || m_iResponseCode >= 400 )
		{
			m_sStatus = ssprintf( "%ld", m_iResponseCode ) + m_sResponseName;
		}
		else
		{
			if( m_bIsPackage && m_iResponseCode < 300 )
			{
				m_fOutputFile.Close();
				FlushDirCache();
				RefreshPackages();
				m_iDownloaded = 0;
			}
			else
				HTMLParse();
		}
	}
}