diff --git a/src/vpk/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs b/src/vpk/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs index 5993c6c1..2e4b8110 100644 --- a/src/vpk/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs +++ b/src/vpk/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs @@ -114,7 +114,7 @@ public class WindowsPackCommandRunner : PackageBuilder return ""; var providedRuntimes = Options.Runtimes.ToLower() - .Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); + .Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); var valid = new string[] { "webview2", @@ -163,7 +163,8 @@ public class WindowsPackCommandRunner : PackageBuilder } #pragma warning restore CS0618 // Type or member is obsolete - throw new UserInfoException($"The framework/runtime dependency '{str}' is not valid. See https://github.com/velopack/velopack/blob/master/docs/bootstrapping.md"); + throw new UserInfoException( + $"The framework/runtime dependency '{str}' is not valid. See https://github.com/velopack/velopack/blob/master/docs/bootstrapping.md"); } foreach (var str in validated) { @@ -184,6 +185,7 @@ public class WindowsPackCommandRunner : PackageBuilder if (Options.Icon != null) { editor.SetExeIcon(Options.Icon); } + editor.Commit(); progress(25); @@ -207,7 +209,8 @@ public class WindowsPackCommandRunner : PackageBuilder File.Delete(Path.Combine(current.FullName, "Squirrel.exe")); // move the stub to the root of the portable package - var stubPath = Path.Combine(current.FullName, + var stubPath = Path.Combine( + current.FullName, Path.GetFileNameWithoutExtension(Options.EntryExecutableName) + "_ExecutionStub.exe"); var stubName = (Options.PackTitle ?? Options.PackId) + ".exe"; File.Move(stubPath, Path.Combine(dir.FullName, stubName)); @@ -285,24 +288,26 @@ public class WindowsPackCommandRunner : PackageBuilder if (File.Exists(dlibPath)) { return dlibPath; } - Log.Info($"Downloading Azure Trusted Signing dlib to '{dlibPath}'"); - var dl = new NuGetDownloader(); - using MemoryStream nupkgStream = new(); - await dl.DownloadPackageToStream("Microsoft.Trusted.Signing.Client", "1.*", nupkgStream, cancellationToken); + throw new NotSupportedException("Azure Trusted Signing is not supported in this version of Velopack."); - nupkgStream.Position = 0; - - string parentDir = NugetUtil.BinDirectory + Path.AltDirectorySeparatorChar + "x64" + Path.AltDirectorySeparatorChar; - - ZipArchive zipPackage = new(nupkgStream); - var entries = zipPackage.Entries.Where(x => x.FullName.StartsWith(parentDir, StringComparison.OrdinalIgnoreCase)); - foreach (var entry in entries) { - var relativePath = entry.FullName.Substring(parentDir.Length); - entry.ExtractToFile(Path.Combine(signToolDirectory, relativePath), true); - } - - return dlibPath; + // Log.Info($"Downloading Azure Trusted Signing dlib to '{dlibPath}'"); + // var dl = new NuGetDownloader(); + // + // using MemoryStream nupkgStream = new(); + // await dl.DownloadPackageToStream("Microsoft.Trusted.Signing.Client", "1.*", nupkgStream, cancellationToken); + // + // nupkgStream.Position = 0; + // + // string parentDir = NugetUtil.BinDirectory + Path.AltDirectorySeparatorChar + "x64" + Path.AltDirectorySeparatorChar; + // + // ZipArchive zipPackage = new(nupkgStream); + // var entries = zipPackage.Entries.Where(x => x.FullName.StartsWith(parentDir, StringComparison.OrdinalIgnoreCase)); + // foreach (var entry in entries) { + // var relativePath = entry.FullName.Substring(parentDir.Length); + // entry.ExtractToFile(Path.Combine(signToolDirectory, relativePath), true); + // } + // return dlibPath; } protected override string[] GetMainExeSearchPaths(string packDirectory, string mainExeName) diff --git a/src/vpk/Velopack.Packaging/HelperFile.cs b/src/vpk/Velopack.Packaging/HelperFile.cs index fe554f71..159bfdec 100644 --- a/src/vpk/Velopack.Packaging/HelperFile.cs +++ b/src/vpk/Velopack.Packaging/HelperFile.cs @@ -71,7 +71,7 @@ public static class HelperFile public static string StubExecutablePath => FindHelperFile("stub.exe"); [SupportedOSPlatform("windows")] - public static string SignToolPath => FindHelperFile("signtool.exe"); + public static string SignToolPath => FindHelperFile("signing\\signtool.exe"); [SupportedOSPlatform("windows")] public const string AzureDlibFileName = "Azure.CodeSigning.Dlib.dll"; diff --git a/test/Velopack.Packaging.Tests/TrustedSigningTests.cs b/test/Velopack.Packaging.Tests/TrustedSigningTests.cs index 6d12bae7..022648b5 100644 --- a/test/Velopack.Packaging.Tests/TrustedSigningTests.cs +++ b/test/Velopack.Packaging.Tests/TrustedSigningTests.cs @@ -1,4 +1,3 @@ -using System.Security.Cryptography.X509Certificates; using Azure.Core; using Azure.Identity; using Velopack.Packaging.Windows; @@ -28,20 +27,20 @@ public class TrustedSigningTests var creds = new ChainedTokenCredential( new AzureCliCredential(), new EnvironmentCredential()); + // var creds = new DefaultAzureCredential(); try { - var token = await creds.GetTokenAsync(new TokenRequestContext([$"{CodeSigningEndpoint}/.default"])); + var token = await creds.GetTokenAsync(new TokenRequestContext([$"https://codesigning.azure.net/.default"])); return token.Token != null; } catch (Exception) { return false; } - } [SkippableFact] public async void CanSignWithTrustedSigning() { - Skip.If(!VelopackRuntimeInfo.IsWindows); - Skip.If(!await IsAuthenticatedForCodeSigningAsync()); + Skip.IfNot(VelopackRuntimeInfo.IsWindows, "Only supported on Windows"); + Skip.IfNot(await IsAuthenticatedForCodeSigningAsync(), "Sign in with az login first"); using var logger = _output.BuildLoggerFor(); using var _ = TempUtil.GetTempDirectory(out var releaseDir); @@ -51,7 +50,9 @@ public class TrustedSigningTests : "ci-" + VelopackRuntimeInfo.SystemOs.GetOsShortName(); string metadataFile = Path.Combine(releaseDir, "metadata.json"); - File.WriteAllText(metadataFile, $$""" + File.WriteAllText( + metadataFile, + $$""" { "Endpoint": "{{CodeSigningEndpoint}}", "CodeSigningAccountName": "velopack-signing-account", @@ -60,7 +61,14 @@ public class TrustedSigningTests """); var id = "AZTrustedSigningApp"; - TestApp.PackTestApp(id, "1.0.0", $"aztrusted-{DateTime.UtcNow.ToLongDateString()}", releaseDir, logger, channel: channel, azureTrustedSignFile: metadataFile); + TestApp.PackTestApp( + id, + "1.0.0", + $"aztrusted-{DateTime.UtcNow.ToLongDateString()}", + releaseDir, + logger, + channel: channel, + azureTrustedSignFile: metadataFile); var files = Directory.EnumerateFiles(releaseDir) .Where(x => PathUtil.FileIsLikelyPEImage(x)) @@ -71,4 +79,4 @@ public class TrustedSigningTests Assert.All(files, x => Assert.True(AuthenticodeTools.IsTrusted(x))); #pragma warning restore CA1416 // Validate platform compatibility } -} +} \ No newline at end of file