Skip to content

Add missing timestamper cert to the newer catalog signing APIs - #4061

Merged
Mike Richmond (mirichmo) merged 2 commits into
PowerShell:masterfrom
PaulHigin:GetAuthSigFix
Jun 27, 2017
Merged

Add missing timestamper cert to the newer catalog signing APIs#4061
Mike Richmond (mirichmo) merged 2 commits into
PowerShell:masterfrom
PaulHigin:GetAuthSigFix

Conversation

@PaulHigin

@PaulHigin Paul Higinbotham (PaulHigin) commented Jun 20, 2017

Copy link
Copy Markdown
Contributor

This fixes Issue #4060

Code to obtain the file signature time stamp cert was missing from the newer catalog signing APIs, with the result that Get-AuthenticodeSignature would not include the time stamp cert in the Signature object.

Fix is to refactor and use the older API code for obtaining this.

I didn't add a test for this because no catalog signing tests are in GitHub yet and porting them will be a separate work item.

}
}

Diagnostics.Assert(((error == 0) && (signature != null)) || (error != 0), "GetSignatureFromWintrustData: general crypto failure");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question about this case, will sync offline

@PaulHigin Paul Higinbotham (PaulHigin) changed the title Fixed missing functionality to add timestamper cert for the newer catalog signing APIs Add missing timestamper cert to the newer catalog signing APIs Jun 22, 2017
}

[ArchitectureSensitive]
private static bool TryGetProviderSigner(IntPtr wvtStateData, ref IntPtr pProvSigner, ref X509Certificate2 timestamperCert)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me both pProvSigner and timestamperCert are better to be an out parameter instead of a ref parameter.

else
{
signature = new Signature(filename, error, cert);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the parameters pProvSigner and timestamperCert are changed to out parameters, you can use the new language feature in C# for out parameters:

if (int.TryParse(input, out int result))
    WriteLine(result);
else
    WriteLine("Could not parse input");

So this code block can be rewritten to:

if (TryGetProviderSigner(phStateData, out IntPtr pProvSigner, out X509Certificate2 timestamperCert) && timestamperCert != null)
{
    signature = new Signature(filename, error, cert, timestamperCert);
}
else
{
    signature = new Signature(filename, error, cert);
}

X509Certificate2 signerCert = null;
IntPtr pProvSigner = IntPtr.Zero;
X509Certificate2 timestamperCert = null;
if (TryGetProviderSigner(wtd.hWVTStateData, ref pProvSigner, ref timestamperCert))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Once change to out parameters, you can use the new feature in C# to make the code cleaner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Will change.

@mirichmo

Copy link
Copy Markdown
Member

I created issue #4087 to document the lack of tests

@PaulHigin

Copy link
Copy Markdown
Contributor Author

Mike Richmond (@mirichmo) Is there anything preventing this from being merged? I also need to port this to internal branches. Thanks!

@mirichmo
Mike Richmond (mirichmo) merged commit 2ee9705 into PowerShell:master Jun 27, 2017
@PaulHigin
Paul Higinbotham (PaulHigin) deleted the GetAuthSigFix branch June 27, 2017 22:02
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
…t-AuthenticodeSignature (PowerShell#4061)

* Fixed missing functionality to add timestamper cert for the newer catalog signing APIs for Get-AuthenticodeSignature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue-Bug Issue has been identified as a bug in the product OS-Windows WG-Cmdlets general cmdlet issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants