Skip to content

Commit

Permalink
Do not chop extension when zipping mac files (#15438)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmitche authored Jan 21, 2025
1 parent 9a861dd commit e8027a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/Microsoft.DotNet.SignTool.Tests/SignToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ public void SignJustPkgWithoutUnpack()
ValidateGeneratedProject(itemsToSign, strongNameSignInfo, fileSignInfo, s_fileExtensionSignInfo, new[]
{
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "test.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "test.pkg.zip"))}"">
<Authenticode>MacDeveloperHarden</Authenticode>
</FilesToSign>",
});
Expand Down Expand Up @@ -1341,11 +1341,11 @@ public void UnpackAndSignPkg()
</FilesToSign>
",
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "ContainerSigning", "1", "NestedPkg.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "ContainerSigning", "1", "NestedPkg.pkg.zip"))}"">
<Authenticode>MacDeveloperHarden</Authenticode>
</FilesToSign>",
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "test.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "test.pkg.zip"))}"">
<Authenticode>MacDeveloperHarden</Authenticode>
</FilesToSign>",
});
Expand Down Expand Up @@ -1411,16 +1411,16 @@ public void SignAndNotarizePkgFile()
</FilesToSign>
",
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "ContainerSigning", "1", "NestedPkg.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "ContainerSigning", "1", "NestedPkg.pkg.zip"))}"">
<Authenticode>MacDeveloperHarden</Authenticode>
</FilesToSign>",
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "test.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "test.pkg.zip"))}"">
<Authenticode>MacDeveloperHarden</Authenticode>
</FilesToSign>
",
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "test.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "test.pkg.zip"))}"">
<Authenticode>8020</Authenticode>
<MacAppName>com.microsoft.dotnet</MacAppName>
</FilesToSign>",
Expand Down Expand Up @@ -1473,7 +1473,7 @@ public void SignNestedPkgFile()
</FilesToSign>
",
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "NestedPkg.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "NestedPkg.pkg.zip"))}"">
<Authenticode>MacDeveloperHarden</Authenticode>
</FilesToSign>"
});
Expand Down Expand Up @@ -1514,12 +1514,12 @@ public void SignPkgFileWithApp()
</FilesToSign>
",
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "ContainerSigning", "2", "Payload", "test.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "ContainerSigning", "2", "Payload", "test.app.zip"))}"">
<Authenticode>MacDeveloperHarden</Authenticode>
</FilesToSign>
",
$@"
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "WithApp.zip"))}"">
<FilesToSign Include=""{Uri.EscapeDataString(Path.Combine(_tmpDir, "WithApp.pkg.zip"))}"">
<Authenticode>MacDeveloperHarden</Authenticode>
</FilesToSign>"
});
Expand Down
12 changes: 11 additions & 1 deletion src/Microsoft.DotNet.SignTool/src/SignTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Packaging;

namespace Microsoft.DotNet.SignTool
{
Expand Down Expand Up @@ -131,6 +132,8 @@ private void UnzipMacFiles(Dictionary<string, string> zippedOSXFiles)
ZipFile.ExtractToDirectory(item.Value, Path.GetDirectoryName(item.Key), true);
#endif
}

File.Delete(item.Value);
}
}

Expand Down Expand Up @@ -219,7 +222,14 @@ private string GenerateBuildFileContent(IEnumerable<FileSignInfo> filesToSign, D

protected virtual string GetZipFilePath(string fullPath)
{
return Path.Combine(Path.GetDirectoryName(fullPath), Path.GetFileNameWithoutExtension(fullPath) + ".zip");
var zipFilePath = Path.Combine(Path.GetDirectoryName(fullPath), Path.GetFileName(fullPath) + ".zip");
// If the file already exists, it means that the user asked for another file to be signed with a colliding name.
// This is very unlikely. Throw in this case.
if (File.Exists(zipFilePath))
{
throw new NotImplementedException($"The zip file path '{zipFilePath}' already exists.");
}
return zipFilePath;
}

private static void AppendLine(StringBuilder builder, int depth, string text)
Expand Down

0 comments on commit e8027a5

Please sign in to comment.