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

Enable signing validation of .pkg files using SignCheck #15489

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ellahathaway
Copy link
Member

@ellahathaway ellahathaway commented Feb 6, 2025

@ellahathaway
Copy link
Member Author

ellahathaway commented Feb 7, 2025

Current output from test run is:

[File] test.pkg, Signed: True [Error] Timestamp (2/7/2025 6:54:02 PM) outside validity period (2/1/2027 10:12:15 PM to 2/1/2027 10:12:15 PM)., Timestamp (2/7/2025 6:54:02 PM) outside validity period (2/1/2027 10:12:15 PM to 2/1/2027 10:12:15 PM)., Timestamp (2/7/2025 6:54:02 PM) outside validity period (2/9/2035 9:40:36 PM to 2/9/2035 9:40:36 PM).
  [File] 6741a098e863e0ff41f9bddf2c67747dbd9adde100e3deca6e308852287baddd.pkg, Signed: False, Virtual path: test.pkg/NestedPkg.pkg, Full Name: NestedPkg.pkg [Error] Timestamp (2/7/2025 6:54:02 PM) outside validity period (2/1/2027 10:12:15 PM to 2/1/2027 10:12:15 PM)., Timestamp (2/7/2025 6:54:02 PM) outside validity period (2/1/2027 10:12:15 PM to 2/1/2027 10:12:15 PM)., Timestamp (2/7/2025 6:54:02 PM) outside validity period (2/9/2035 9:40:36 PM to 2/9/2035 9:40:36 PM).

Need to figure out two things:

  • Why the timestamp is outside of the validity period - fixed
  • Why the NestedPkg.pkg is listed as being not-signed. - pinged @mmitche offline. I don't think that the lack of pkg signature here is related to these code changes, so I'm going to publish this PR now.

@@ -1,7 +1,7 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>

<Import Project="..\DefaultVersions.Generated.props"/>
Copy link
Member

Choose a reason for hiding this comment

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

This looks suspect. IIRC, the generated file contains the just built versions of the tooling packages. Without this, you end up with N-1, I think?

Copy link
Member Author

@ellahathaway ellahathaway Feb 11, 2025

Choose a reason for hiding this comment

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

DefaultVersions.props imports DefaultVersions.Generated.props, so I was thinking that this would still allow us to end up with the "just build" versions of the tooling packages. But I think you're right, this would just import the N-1 versions.

The reason that I switched the imported project was to get access to MicrosoftDotNetMacOsPkgVersion which is in DefaultVersions.props and not DefaultVersions.Generated.props. That said, I should be able to add the pkg version prop to generated content specified in the _GenerateSdkVersionFile target, which should make the prop available in DefaultVersions.Generated.props

@@ -25,7 +25,7 @@ public static string Run(string command, string arguments = "", string workingDi
process.Start();
output = process.StandardOutput.ReadToEnd();
process.WaitForExit(60000); // 60 seconds
if (process.ExitCode != 0)
if (process.ExitCode != 0 && throwOnError)
Copy link
Member

@mmitche mmitche Feb 11, 2025

Choose a reason for hiding this comment

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

I would suggest refactoring this to return the exit code (or bool) from the method, with an out parameter for stdout/stderr, then allow the caller to decide whether to throw or not.

@@ -9,7 +9,6 @@
<IsPackable>true</IsPackable>
<Description>The MacOsPkg tool is used for unpacking and packing MacOS .pkg files and nested .app bundles.</Description>
<PackageTags>Arcade Build Tool MacOS Pkg</PackageTags>
<DevelopmentDependency>false</DevelopmentDependency>
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing you're doing this so that SigningValidation ends up with a package ref to this, and it gets restored? This kind of makes me think we should factor out the MacOsPkg functionality into a library, with a command line tool that uses the library. Then you can avoid passing around the path to the pkg tooling and just redist the library with the task.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. I think that this would be better done in a separate PR, so I'll work on those changes first then update this PR later.

foreach (var path in Directory.EnumerateFiles(extractionPath, "*.*", SearchOption.AllDirectories))
{
var relativePath = path.Substring(extractionPath.Length + 1).Replace(Path.DirectorySeparatorChar, '/');
using var stream = (Stream)File.Open(path, FileMode.Open);
Copy link
Member

Choose a reason for hiding this comment

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

I thiiink this is okay but I am not sure. The using statement means that the stream would be disposed at the end of the for loop iteration. It doesn't look like the entry.Content member ends up getting used outside of the current iteration.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. I looked more closely at the way that SignTool does this, and I think the method there is better... it opens the stream, yield returns the entry, then closes the stream. That feels a lot safer.

I'm going to open a separate PR that includes this change, along with other modifications to the ArchiveVerifier logic that have been included in this current PR.

protected virtual IEnumerable<ArchiveEntry> ExtractArchiveEntries(string archivePath, string extractionPath)
{
ZipFile.ExtractToDirectory(archivePath, extractionPath);
foreach (var path in Directory.EnumerateFiles(extractionPath, "*.*", SearchOption.AllDirectories))
Copy link
Member

Choose a reason for hiding this comment

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

The end of method is common with PkgVerifier.ExtractArchiveEntries. Pull out to a common helper?

@ellahathaway
Copy link
Member Author

Converting this to a draft PR. There are a few things to do first that will clean up the logic in this PR:

  • Refactor the ArchiveVerifier. This will allow other package types to inherit the classes in a more concise way.
  • Break the MacOsPkg tool up into a cli tool and a library

@ellahathaway ellahathaway marked this pull request as draft February 11, 2025 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable signing validation of .pkg files using SignCheck
2 participants