Skip to content

Commit

Permalink
improved validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleinrotti committed Oct 11, 2024
1 parent 262c85c commit a8e0afd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Signer/FileObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class FileObject
{
public string Name { get; set; }
public string Path { get; set; }
public bool Trusted { get; set; }
public bool Valid { get; set; }

public string FullPath
{
Expand Down
34 changes: 20 additions & 14 deletions src/Signer/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ public static IEnumerable<string> FileSearchPattern
public static async Task<List<FileObject>> ScanDirectory(string folder, ParallelOptions parallelOptions, Action<int, int> progressCallback)
{
var fileObjects = new ConcurrentBag<FileObject>();
var task = Task.Run(() =>
var fileCount = 0;
await Task.Run(() =>
{
IEnumerable<string> files = null;
try
{
files = SearchFiles(folder, FileSearchPattern);
fileCount = files.Count();
}
catch (UnauthorizedAccessException ex)
{
System.Windows.MessageBox.Show(ex.Message);
return;
}
var fileCount = files.Count();
var progressCount = 0;
Parallel.ForEach(files, parallelOptions, file =>
{
Expand All @@ -62,7 +63,6 @@ public static async Task<List<FileObject>> ScanDirectory(string folder, Parallel
progressCallback(fileCount, progressCount++);
});
});
await task;
return fileObjects.ToList();
}

Expand All @@ -86,7 +86,7 @@ private static FileObject InspectFile(string file)
Name = Path.GetFileName(file),
Path = Path.GetDirectoryName(file)
};
obj.Signed = Signed(file, ref obj);
CheckSigned(ref obj);
return obj;
}

Expand All @@ -99,21 +99,27 @@ private static IEnumerable<string> SearchFiles(string path, IEnumerable<string>
);
}

private static bool Signed(string path, ref FileObject fileObject)
private static void CheckSigned(ref FileObject fileObject)
{
var inspector = new FileInspector(path);
var inspector = new FileInspector(fileObject.FullPath);
var result = inspector.Validate();
if (result == SignatureCheckResult.Valid || result == SignatureCheckResult.UntrustedRoot)
if (result == SignatureCheckResult.Valid)
{
fileObject.Signed = true;
fileObject.Valid = true;
}
else if (result == SignatureCheckResult.NoSignature)
{
fileObject.Signatures = inspector.GetSignatures();
if (result == SignatureCheckResult.UntrustedRoot)
fileObject.Trusted = false;
else
fileObject.Trusted = true;
return true;
fileObject.Signed = false;
fileObject.Valid = false;
return;
}
else
return false;
{
fileObject.Signed = true;
fileObject.Valid = false;
}
fileObject.Signatures = inspector.GetSignatures();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Signer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<GridViewColumn DisplayMemberBinding="{Binding Path=Path}" Header="Path" Width="150" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Filename" Width="180" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Signed}" Header="Signed" Width="Auto" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Trusted}" Header="Trusted" Width="Auto" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Valid}" Header="Valid" />
</GridView>
</ListView.View>
<ListView.ContextMenu>
Expand Down

0 comments on commit a8e0afd

Please sign in to comment.