Changeset 1552
- Timestamp:
- 1/18/2010 5:32:15 AM (3 years ago)
- Location:
- branches/eraser6/CodeReview
- Files:
-
- 1 deleted
- 4 edited
- 1 moved
-
Eraser.Manager/DirectExecutor.cs (modified) (1 diff)
-
Eraser.Manager/EntropySource.cs (modified) (1 diff)
-
Eraser.Manager/Plugins.cs (modified) (1 diff)
-
Eraser.Util/Eraser.Util.csproj (modified) (2 diffs)
-
Eraser.Util/MsCorEEApi.cs (deleted)
-
Eraser.Util/Security.cs (moved) (moved from branches/eraser6/CodeReview/Eraser.Util/AdvApi.cs) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Manager/DirectExecutor.cs
r1515 r1552 327 327 { 328 328 //Check for sufficient privileges to run the unused space erasure. 329 if (! AdvApi.IsAdministrator())329 if (!Security.IsAdministrator()) 330 330 { 331 331 if (Environment.OSVersion.Platform == PlatformID.Win32NT && -
branches/eraser6/CodeReview/Eraser.Manager/EntropySource.cs
r1551 r1552 360 360 //CryptGenRandom 361 361 byte[] cryptGenRandom = new byte[160]; 362 if ( CryptApi.CryptGenRandom(cryptGenRandom))362 if (Security.Randomise(cryptGenRandom)) 363 363 result.AddRange(cryptGenRandom); 364 364 -
branches/eraser6/CodeReview/Eraser.Manager/Plugins.cs
r1528 r1552 212 212 IDictionary<Guid, bool> approvals = ManagerLibrary.Settings.PluginApprovals; 213 213 if ((reflectAssembly.GetName().GetPublicKey().Length == 0 || 214 ! MsCorEEApi.VerifyStrongName(filePath) ||214 !Security.VerifyStrongName(filePath) || 215 215 instance.AssemblyAuthenticode == null) && 216 216 !approvals.ContainsKey(instance.AssemblyInfo.Guid)) -
branches/eraser6/CodeReview/Eraser.Util/Eraser.Util.csproj
r1551 r1552 49 49 <Link>Version.cs</Link> 50 50 </Compile> 51 <Compile Include=" AdvApi.cs" />51 <Compile Include="Security.cs" /> 52 52 <Compile Include="ExtensionMethods\IO.cs" /> 53 53 <Compile Include="Localisation.cs" /> 54 <Compile Include="MsCorEEApi.cs" />55 54 <Compile Include="NativeMethods\AdvApi.cs" /> 56 55 <Compile Include="NativeMethods\Kernel.cs" /> … … 76 75 <Compile Include="Properties\AssemblyInfo.cs" /> 77 76 <Compile Include="UserApi.cs" /> 78 <Compile Include="WintrustApi.cs" />79 77 </ItemGroup> 80 78 <ItemGroup> -
branches/eraser6/CodeReview/Eraser.Util/Security.cs
r1543 r1552 29 29 namespace Eraser.Util 30 30 { 31 public static class AdvApi31 public static class Security 32 32 { 33 33 /// <summary> … … 90 90 } 91 91 } 92 } 93 94 public sealed class CryptApi : IDisposable 92 93 /// <summary> 94 /// Verifies the Authenticode signature in a file. 95 /// </summary> 96 /// <param name="pathToFile">The file to verify.</param> 97 /// <returns>True if the file contains a valid Authenticode certificate.</returns> 98 public static bool VerifyAuthenticode(string pathToFile) 99 { 100 IntPtr unionPointer = IntPtr.Zero; 101 102 try 103 { 104 NativeMethods.WINTRUST_FILE_INFO fileinfo = new NativeMethods.WINTRUST_FILE_INFO(); 105 fileinfo.cbStruct = (uint)Marshal.SizeOf(typeof(NativeMethods.WINTRUST_FILE_INFO)); 106 fileinfo.pcwszFilePath = pathToFile; 107 108 NativeMethods.WINTRUST_DATA data = new NativeMethods.WINTRUST_DATA(); 109 data.cbStruct = (uint)Marshal.SizeOf(typeof(NativeMethods.WINTRUST_DATA)); 110 data.dwUIChoice = NativeMethods.WINTRUST_DATA.UIChoices.WTD_UI_NONE; 111 data.fdwRevocationChecks = NativeMethods.WINTRUST_DATA.RevocationChecks.WTD_REVOKE_NONE; 112 data.dwUnionChoice = NativeMethods.WINTRUST_DATA.UnionChoices.WTD_CHOICE_FILE; 113 unionPointer = data.pUnion = Marshal.AllocHGlobal((int)fileinfo.cbStruct); 114 Marshal.StructureToPtr(fileinfo, data.pUnion, false); 115 116 Guid guid = NativeMethods.WINTRUST_ACTION_GENERIC_VERIFY_V2; 117 return NativeMethods.WinVerifyTrust(IntPtr.Zero, ref guid, ref data) == 0; 118 } 119 finally 120 { 121 if (unionPointer != IntPtr.Zero) 122 Marshal.FreeHGlobal(unionPointer); 123 } 124 } 125 126 /// <summary> 127 /// Gets a value indicating whether the assembly manifest at the supplied 128 /// path contains a strong name signature. 129 /// </summary> 130 /// <param name="assemblyPath">The path to the portable executable (.exe or 131 /// .dll) file for the assembly to be verified.</param> 132 /// <returns>True if the verification was successful; otherwise, false.</returns> 133 /// <remarks>VerifyStrongName is a utility function to check the validity 134 /// of an assembly, taking into account registry settings.</remarks> 135 public static bool VerifyStrongName(string assemblyPath) 136 { 137 bool wasVerified = false; 138 return NativeMethods.StrongNameSignatureVerificationEx(assemblyPath, false, 139 out wasVerified) && wasVerified; 140 } 141 142 /// <summary> 143 /// Randomises the provided buffer using CryptGenRandom. 144 /// </summary> 145 /// <param name="cryptGenRandom">The buffer which receives the random 146 /// data. The contents of this buffer can also be used as a random 147 /// seed.</param> 148 /// <returns>True if the operation suceeded.</returns> 149 public static bool Randomise(byte[] buffer) 150 { 151 return CryptApi.CryptGenRandom(buffer); 152 } 153 } 154 155 internal sealed class CryptApi : IDisposable 95 156 { 96 157 /// <summary>
Note: See TracChangeset
for help on using the changeset viewer.
