Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-AuthenticodeSignature: Add embedded cert opt #23846

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Microsoft.PowerShell.Security/security/SignatureCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ protected override void ProcessRecord()
[OutputType(typeof(Signature))]
public sealed class GetAuthenticodeSignatureCommand : SignatureCommandsBase
{
/// <summary>
/// Property that sets the switch parameter that decides whether to retrieve embedded signatures only or
/// also signatures inside a catalogue file.
/// </summary>
[Parameter(ParameterSetName = "ByPath")]
[Parameter(ParameterSetName = "ByLiteralPath")]
public SwitchParameter EmbeddedSignature { get; set; }

/// <summary>
/// Initializes a new instance of the GetSignatureCommand class.
/// </summary>
Expand All @@ -279,7 +287,7 @@ public sealed class GetAuthenticodeSignatureCommand : SignatureCommandsBase
/// </returns>
protected override Signature PerformAction(string filePath)
{
return SignatureHelper.GetSignature(filePath, null);
return SignatureHelper.GetSignature(filePath, null, embeddedSignatureOnly: EmbeddedSignature);
}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions src/System.Management.Automation/security/Authenticode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ internal static class SignatureHelper
/// </summary>
/// <param name="fileName">Name of file to check.</param>
/// <param name="fileContent">Content of file to check.</param>
/// <param name="embeddedSignatureOnly">
/// Get the embedded signature in the provided file rather than one inside a .cat file.
/// </param>
/// <returns>Signature object.</returns>
/// <exception cref="System.ArgumentException">
/// Thrown if argument fileName is empty.
Expand All @@ -275,11 +278,14 @@ internal static class SignatureHelper
/// <exception cref="System.IO.FileNotFoundException">
/// Thrown if the file specified by argument fileName is not found.
/// </exception>
internal static Signature GetSignature(string fileName, byte[] fileContent)
internal static Signature GetSignature(
string fileName,
byte[] fileContent,
bool embeddedSignatureOnly = false)
{
Signature signature = null;

if (fileContent == null)
if (!embeddedSignatureOnly && fileContent == null)
{
// First, try to get the signature from the latest dotNet signing API.
signature = GetSignatureFromMSSecurityExtensions(fileName);
Expand Down
Loading