Changeset 1832
- Timestamp:
- 2/12/2010 8:39:59 AM (3 years ago)
- Location:
- trunk/eraser6
- Files:
-
- 1 deleted
- 3 edited
-
Eraser.Manager/EntropySource.cs (modified) (2 diffs)
-
Eraser.Util/Eraser.Util.csproj (modified) (1 diff)
-
Eraser.Util/NativeMethods/AdvApi.cs (deleted)
-
Eraser.Util/Security.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Manager/EntropySource.cs
r1802 r1832 271 271 //Ticks since start up 272 272 result.AddRange(StructToBuffer(Environment.TickCount)); 273 274 //CryptGenRandom275 byte[] cryptGenRandom = new byte[160];276 if (Security.Randomise(cryptGenRandom))277 result.AddRange(cryptGenRandom);278 279 273 return result.ToArray(); 280 274 } … … 293 287 result.AddRange(netApiStats); 294 288 295 #if false 296 //Get disk I/O statistics for all the hard drives 297 try 298 { 299 for (int drive = 0; ; ++drive) 300 { 301 //Try to open the drive. 302 StreamInfo info = new StreamInfo(string.Format(CultureInfo.InvariantCulture, 303 "\\\\.\\PhysicalDrive{0}", drive)); 304 using (FileStream stream = info.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) 305 { 306 SafeFileHandle device = stream.SafeFileHandle; 307 KernelApi.DiskPerformanceInfo diskPerformance = 308 KernelApi.QueryDiskPerformanceInfo(device); 309 if (diskPerformance != null) 310 { 311 result.AddRange(StructToBuffer(diskPerformance.BytesRead)); 312 result.AddRange(StructToBuffer(diskPerformance.BytesWritten)); 313 result.AddRange(StructToBuffer(diskPerformance.IdleTime)); 314 result.AddRange(StructToBuffer(diskPerformance.QueryTime)); 315 result.AddRange(StructToBuffer(diskPerformance.QueueDepth)); 316 result.AddRange(StructToBuffer(diskPerformance.ReadCount)); 317 result.AddRange(StructToBuffer(diskPerformance.ReadTime)); 318 result.AddRange(StructToBuffer(diskPerformance.SplitCount)); 319 result.AddRange(StructToBuffer(diskPerformance.StorageDeviceNumber)); 320 result.AddRange(Encoding.UTF8.GetBytes(diskPerformance.StorageManagerName)); 321 result.AddRange(StructToBuffer(diskPerformance.WriteCount)); 322 result.AddRange(StructToBuffer(diskPerformance.WriteTime)); 323 } 324 } 325 } 326 } 327 catch (FileNotFoundException) 328 { 329 } 330 catch (UnauthorizedAccessException) 331 { 289 #false 290 foreach (VolumeInfo info in VolumeInfo.Volumes) 291 { 292 /*DiskPerformanceInfo performance = info.Performance; 293 result.AddRange(StructToBuffer(performance.BytesRead)); 294 result.AddRange(StructToBuffer(performance.BytesWritten)); 295 result.AddRange(StructToBuffer(performance.IdleTime)); 296 result.AddRange(StructToBuffer(performance.QueryTime)); 297 result.AddRange(StructToBuffer(performance.QueueDepth)); 298 result.AddRange(StructToBuffer(performance.ReadCount)); 299 result.AddRange(StructToBuffer(performance.ReadTime)); 300 result.AddRange(StructToBuffer(performance.SplitCount)); 301 result.AddRange(StructToBuffer(performance.WriteCount)); 302 result.AddRange(StructToBuffer(performance.WriteTime));*/ 332 303 } 333 304 #endif 334 //Finally, our good friend CryptGenRandom()335 byte[] cryptGenRandom = new byte[1536];336 if (Security.Randomise(cryptGenRandom))337 result.AddRange(cryptGenRandom);338 305 339 306 return result.ToArray(); -
trunk/eraser6/Eraser.Util/Eraser.Util.csproj
r1802 r1832 76 76 <Compile Include="BlackBox.cs" /> 77 77 <Compile Include="Localisation.cs" /> 78 <Compile Include="NativeMethods\AdvApi.cs" />79 78 <Compile Include="NativeMethods\Kernel.cs" /> 80 79 <Compile Include="NativeMethods\MsCorEE.cs" /> -
trunk/eraser6/Eraser.Util/Security.cs
r1802 r1832 92 92 out wasVerified) && wasVerified; 93 93 } 94 95 /// <summary>96 /// Randomises the provided buffer using CryptGenRandom.97 /// </summary>98 /// <param name="cryptGenRandom">The buffer which receives the random99 /// data. The contents of this buffer can also be used as a random100 /// seed.</param>101 /// <returns>True if the operation suceeded.</returns>102 public static bool Randomise(byte[] buffer)103 {104 return CryptApi.CryptGenRandom(buffer);105 }106 }107 108 internal sealed class CryptApi : IDisposable109 {110 /// <summary>111 /// Constructor.112 /// </summary>113 private CryptApi()114 {115 /* Intel i8xx (82802 Firmware Hub Device) hardware random number generator */116 const string IntelDefaultProvider = "Intel Hardware Cryptographic Service Provider";117 118 handle = new SafeCryptHandle();119 if (NativeMethods.CryptAcquireContext(out handle, null,120 IntelDefaultProvider, NativeMethods.PROV_INTEL_SEC, 0))121 {122 return;123 }124 else if (NativeMethods.CryptAcquireContext(out handle, null,125 null, NativeMethods.PROV_RSA_FULL, 0))126 {127 return;128 }129 else if (Marshal.GetLastWin32Error() == NativeMethods.NTE_BAD_KEYSET)130 {131 //Default keyset doesn't exist, attempt to create a new one132 if (NativeMethods.CryptAcquireContext(out handle, null, null,133 NativeMethods.PROV_RSA_FULL, NativeMethods.CRYPT_NEWKEYSET))134 {135 return;136 }137 }138 139 throw new NotSupportedException("Unable to acquire a cryptographic service provider.");140 }141 142 #region IDisposable Members143 ~CryptApi()144 {145 Dispose(false);146 }147 148 private void Dispose(bool disposing)149 {150 //If we already have run Dispose, then handle will be null.151 if (handle == null)152 return;153 154 if (disposing)155 handle.Close();156 157 //Don't run Dispose again.158 handle = null;159 }160 161 public void Dispose()162 {163 Dispose(true);164 GC.SuppressFinalize(this);165 }166 #endregion167 168 /// <summary>169 /// The GenRandom function fills a buffer with cryptographically random bytes.170 /// </summary>171 /// <param name="buffer">Buffer to receive the returned data. This buffer172 /// must be at least dwLen bytes in length.173 ///174 /// Optionally, the application can fill this buffer with data to use as175 /// an auxiliary random seed.</param>176 public static bool CryptGenRandom(byte[] buffer)177 {178 return NativeMethods.CryptGenRandom(instance.handle, (uint)buffer.Length, buffer);179 }180 181 /// <summary>182 /// The HCRYPTPROV handle.183 /// </summary>184 private SafeCryptHandle handle;185 186 /// <summary>187 /// The global CryptAPI instance.188 /// </summary>189 private static CryptApi instance = new CryptApi();190 }191 192 internal class SafeCryptHandle : SafeHandleZeroOrMinusOneIsInvalid193 {194 public SafeCryptHandle()195 : base(true)196 {197 }198 199 protected override bool ReleaseHandle()200 {201 NativeMethods.CryptReleaseContext(handle, 0u);202 handle = IntPtr.Zero;203 return true;204 }205 94 } 206 95 }
Note: See TracChangeset
for help on using the changeset viewer.
