2014-08-10 22:44:04 +01:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading ;
using System.IO ;
namespace USB_Lockdown
{
class authentication
{
internal static Thread authenticationThread ;
internal static Thread deviceScanner ;
internal static void startScanning ( )
{
Thread authenticationThread = new Thread ( beginAuthentication ) ;
}
internal static void beginAuthentication ( )
{
2014-08-13 16:06:50 +01:00
deviceScan . calculateHash ( ) ;
2014-08-10 22:44:04 +01:00
Thread deviceScanner = new Thread ( deviceScan . scanDevices ) ;
deviceScanner . Join ( ) ; //the thread will exit when a valid drive has been found
2014-08-13 16:06:50 +01:00
//code here to unlock computer and stuff
2014-08-10 22:44:04 +01:00
}
}
class deviceScan
{
internal static DriveInfo validDrive ;
internal static DriveInfo [ ] driveListing ;
private static bool driveFound = false ;
2014-08-13 16:06:50 +01:00
internal static string originalHash ;
2014-08-10 22:44:04 +01:00
2014-08-13 16:06:50 +01:00
internal static void calculateHash ( )
{
//decide how to do this!
2014-08-10 22:44:04 +01:00
2014-08-13 16:06:50 +01:00
}
2014-08-10 22:44:04 +01:00
internal static void scanDevices ( )
{
while ( ! driveFound ) {
driveListing = DriveInfo . GetDrives ( ) ;
foreach ( DriveInfo currentDrive in driveListing )
{
2014-08-13 16:06:50 +01:00
try { string driveName = currentDrive . VolumeLabel ; string driveLabel = currentDrive . Name ; }
catch { }
2014-08-10 22:44:04 +01:00
if ( File . Exists ( currentDrive . Name + "\\LockDown.config" ) ) // the first check for a valid drive. Could be something else, but this is a lightweight test to be done first!
{
2014-08-11 17:28:31 +01:00
if ( driveValidate ( currentDrive ) ) //runs the full validation of the drive
2014-08-10 22:44:04 +01:00
{
validDrive = currentDrive ;
driveFound = true ;
break ;
}
}
}
}
}
internal static bool driveValidate ( DriveInfo drive ) {
2014-08-13 16:06:50 +01:00
if ( ! checkHash ( drive ) ) {
return false ;
}
return true ;
}
2014-08-10 22:44:04 +01:00
2014-08-13 16:06:50 +01:00
private static bool checkHash ( DriveInfo drive )
{
string fileName = drive . Name + "" ;
if ( ! File . Exists ( fileName ) ) { return false ; }
using ( BinaryReader reader = new BinaryReader ( File . Open ( fileName , FileMode . Open ) ) )
{
string hashFromDrive = reader . ReadString ( ) ;
if ( hashFromDrive ! = )
}
2014-08-10 22:44:04 +01:00
return true ;
}
2014-08-13 16:06:50 +01:00
2014-08-10 22:44:04 +01:00
internal static void resetValues ( )
{
validDrive = null ;
driveListing = null ;
driveFound = false ;
}
}
}