native-packages 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +5 -1
- data/README.md +3 -1
- data/docs/_guides/distribution-recipes.md +3 -1
- data/docs/_guides/getting-started.md +2 -2
- data/docs/_guides/github-actions.md +6 -4
- data/docs/_guides/multi-platform.md +1 -1
- data/docs/_guides/native-recipes.md +6 -2
- data/docs/_guides/omarchy.md +131 -0
- data/docs/_guides/prereleases.md +1 -1
- data/docs/_guides/release-signing.md +4 -4
- data/docs/_guides/windows-signing.md +259 -0
- data/docs/_reference/commands.md +29 -1
- data/docs/_reference/configuration.md +28 -1
- data/docs/_reference/platforms.md +40 -5
- data/docs/_reference/troubleshooting.md +22 -2
- data/docs/releasing.md +2 -2
- data/examples/native-packages-all-formats.yaml +1 -1
- data/examples/native-packages.yaml +1 -1
- data/lib/native_packages/appimage.rb +119 -8
- data/lib/native_packages/build.rb +35 -12
- data/lib/native_packages/cli.rb +19 -2
- data/lib/native_packages/configuration.rb +17 -2
- data/lib/native_packages/omarchy.rb +140 -0
- data/lib/native_packages/support.rb +1 -1
- data/lib/native_packages/windows_signing.rb +284 -0
- metadata +5 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "build"
|
|
4
|
+
|
|
5
|
+
module NativePackages
|
|
6
|
+
# Writes a first Omarchy recipe (omacom/omarchy-pkgs) from the app's AUR -bin
|
|
7
|
+
# templates. Omarchy's bot then opens every later version bump itself, from
|
|
8
|
+
# the upstream declaration in .omarchy/package.json, so this runs once.
|
|
9
|
+
class Omarchy
|
|
10
|
+
include Support
|
|
11
|
+
ARCHITECTURES = %w[x86_64 aarch64].freeze
|
|
12
|
+
# The policy RawMakase and superwhisper-bin use: hourly, self-merging updates that wait a day
|
|
13
|
+
# after each GitHub release and go to every channel at once.
|
|
14
|
+
POLICY = { "source" => "local", "auto_merge" => true, "release_ring" => "fast", "min_release_age" => "24h" }.freeze
|
|
15
|
+
PROBE = "999.0.0"
|
|
16
|
+
# Releases are tagged vMAJOR.MINOR.PATCH; the watch must match the whole tag.
|
|
17
|
+
TAG_PATTERN = "v(?P<version>[0-9]+(?:\\.[0-9]+)*)"
|
|
18
|
+
|
|
19
|
+
attr_reader :configuration, :root
|
|
20
|
+
|
|
21
|
+
def initialize(configuration)
|
|
22
|
+
@configuration = configuration
|
|
23
|
+
@root = configuration.root
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def recipe(checkout, release:, package: nil)
|
|
27
|
+
configuration.validate
|
|
28
|
+
version = version_arg(release)
|
|
29
|
+
name = package || bin_package
|
|
30
|
+
templates = configuration.data.fetch("templates").select { |path, _| path.start_with?("arch/#{name}/") }
|
|
31
|
+
raise Error, "no template for arch/#{name}/PKGBUILD" unless templates.key?("arch/#{name}/PKGBUILD")
|
|
32
|
+
checkout = Pathname.new(checkout).expand_path
|
|
33
|
+
raise Error, "#{checkout} is not an omarchy-pkgs checkout (no pkgbuilds/)" unless (checkout / "pkgbuilds").directory?
|
|
34
|
+
destination = checkout / "pkgbuilds" / name
|
|
35
|
+
raise Error, "#{destination} exists; after the first PR Omarchy's bot updates it" if destination.exist? || destination.symlink?
|
|
36
|
+
|
|
37
|
+
build = Build.new(configuration)
|
|
38
|
+
metadata = build.metadata(version, release: true).merge("PKGREL" => 1)
|
|
39
|
+
checksums = build.release_checksums(metadata)
|
|
40
|
+
configuration.data.fetch("assets").each_key do |key|
|
|
41
|
+
digest = checksums[metadata.fetch("#{key}_FILE")]
|
|
42
|
+
metadata["#{key}_SHA256"] = digest if digest
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
Dir.mktmpdir(".#{name}-", checkout / "pkgbuilds") do |temporary|
|
|
46
|
+
staging = Pathname.new(temporary) / name
|
|
47
|
+
templates.each do |path, source|
|
|
48
|
+
template = root / relative_path(source)
|
|
49
|
+
content = render(template.binread, metadata)
|
|
50
|
+
content = follow_pkgver(content, version) if File.basename(path) == "PKGBUILD"
|
|
51
|
+
write(staging / relative_path(path).relative_path_from(Pathname.new("arch/#{name}")), content, executable: template.executable?)
|
|
52
|
+
end
|
|
53
|
+
upstream = declaration(staging, name, version, checksums)
|
|
54
|
+
write(staging / ".omarchy/package.json", JSON.pretty_generate(POLICY.merge("upstream" => upstream)) + "\n")
|
|
55
|
+
staging.rename(destination)
|
|
56
|
+
end
|
|
57
|
+
puts "Wrote #{destination}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# The one AUR binary recipe, unless the caller names it.
|
|
61
|
+
def bin_package
|
|
62
|
+
names = configuration.data.fetch("templates").keys.filter_map { |path| path[%r{\Aarch/([^/]+-bin)/PKGBUILD\z}, 1] }
|
|
63
|
+
raise Error, "no arch/NAME-bin/PKGBUILD template; add one or pass --package" if names.empty?
|
|
64
|
+
raise Error, "several -bin templates (#{names.join(', ')}); pass --package" if names.length > 1
|
|
65
|
+
names.first
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Omarchy's bot rewrites only pkgver, pkgrel and the checksums, so every
|
|
69
|
+
# source URL has to be written in terms of pkgver.
|
|
70
|
+
def follow_pkgver(content, version)
|
|
71
|
+
literal = /(?<![0-9.])#{Regexp.escape(version)}(?![0-9])/
|
|
72
|
+
content.gsub(/^source(?:_[A-Za-z0-9_]+)?=\(.*?\)/m) { |array| array.gsub(literal, "${pkgver}") }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def declaration(staging, name, version, checksums)
|
|
76
|
+
pkgbuild = staging / "PKGBUILD"
|
|
77
|
+
run "bash", "-n", pkgbuild
|
|
78
|
+
upstream = configuration.project.upstream
|
|
79
|
+
sources = {}
|
|
80
|
+
architectures = nil
|
|
81
|
+
ARCHITECTURES.each do |arch|
|
|
82
|
+
recipe = inspect_recipe(pkgbuild, arch)
|
|
83
|
+
architectures ||= recipe.fetch("arch")
|
|
84
|
+
raise Error, "PKGBUILD pkgname must be #{name}" unless recipe.fetch("pkgname") == [name]
|
|
85
|
+
raise Error, "PKGBUILD pkgver must be #{version}" unless recipe.fetch("pkgver") == [version]
|
|
86
|
+
unless !architectures.empty? && (architectures - ARCHITECTURES).empty?
|
|
87
|
+
raise Error, "PKGBUILD arch must list x86_64 and/or aarch64"
|
|
88
|
+
end
|
|
89
|
+
if recipe.fetch("source").any? { |entry| entry.split("::", 2).last.match?(%r{\A[a-z+]+://}) }
|
|
90
|
+
raise Error, "move downloads into source_<arch>: each architecture downloads its own release assets"
|
|
91
|
+
end
|
|
92
|
+
next unless architectures.include?(arch)
|
|
93
|
+
|
|
94
|
+
urls = recipe.fetch("source_#{arch}").map { |entry| entry.split("::", 2).last }
|
|
95
|
+
sums = recipe.fetch("sha256sums_#{arch}")
|
|
96
|
+
raise Error, "source_#{arch} must download the release assets" if urls.empty?
|
|
97
|
+
raise Error, "sha256sums_#{arch} must match source_#{arch}" unless sums.length == urls.length
|
|
98
|
+
prefix = "#{upstream}/releases/download/v#{version}/"
|
|
99
|
+
urls.each_with_index do |url, index|
|
|
100
|
+
raise Error, "source_#{arch} leaves a variable unexpanded; use double quotes: #{url}" if url.include?("$")
|
|
101
|
+
raise Error, "source_#{arch} must come from #{prefix}: #{url}" unless url.start_with?(prefix)
|
|
102
|
+
file = url.delete_prefix(prefix)
|
|
103
|
+
raise Error, "#{file} is not listed in the release checksums" unless checksums.key?(file)
|
|
104
|
+
raise Error, "sha256sums_#{arch} disagrees with the release checksums for #{file}" unless sums[index] == checksums.fetch(file)
|
|
105
|
+
end
|
|
106
|
+
sources[arch] = urls
|
|
107
|
+
end
|
|
108
|
+
# Prove the URLs move with pkgver, as they will when the bot bumps it.
|
|
109
|
+
probe = staging / "PKGBUILD.probe"
|
|
110
|
+
probe.write(pkgbuild.read.sub(/^pkgver=.*$/, "pkgver=#{PROBE}"))
|
|
111
|
+
begin
|
|
112
|
+
sources.each do |arch, urls|
|
|
113
|
+
moved = inspect_recipe(probe, arch).fetch("source_#{arch}").map { |entry| entry.split("::", 2).last }
|
|
114
|
+
raise Error, "source_#{arch} does not follow pkgver" unless moved == urls.map { |url| url.gsub(version, PROBE) }
|
|
115
|
+
end
|
|
116
|
+
ensure
|
|
117
|
+
probe.delete
|
|
118
|
+
end
|
|
119
|
+
# The watch takes each new tag's SHA-256 from the digest GitHub reports
|
|
120
|
+
# for the asset at that exact URL, which is why every source above must
|
|
121
|
+
# be a release download and match the release's own checksums.
|
|
122
|
+
{ "watch" => { "github" => configuration.data.fetch("release").fetch("repository"), "pattern" => TAG_PATTERN } }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Source the recipe the way omarchy-pkgs' tooling does: CARCH set and
|
|
126
|
+
# nothing else from the environment.
|
|
127
|
+
def inspect_recipe(path, arch)
|
|
128
|
+
script = <<~'BASH'
|
|
129
|
+
source "$1" >/dev/null
|
|
130
|
+
emit() { printf '%s' "$1"; shift; printf '\t%s' "$@"; printf '\n'; }
|
|
131
|
+
emit pkgname "${pkgname[@]}"; emit pkgver "$pkgver"; emit arch "${arch[@]}"; emit source "${source[@]}"
|
|
132
|
+
for name in source_x86_64 source_aarch64 sha256sums_x86_64 sha256sums_aarch64; do
|
|
133
|
+
declare -n values="$name"; emit "$name" "${values[@]}"; unset -n values
|
|
134
|
+
done
|
|
135
|
+
BASH
|
|
136
|
+
output = capture("env", "-i", "PATH=/usr/bin:/bin", "CARCH=#{arch}", "bash", "-c", script, "bash", path.basename, chdir: path.dirname)
|
|
137
|
+
output.lines.to_h { |line| key, *values = line.chomp.split("\t", -1); [key, values.reject(&:empty?)] }
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NativePackages
|
|
4
|
+
# Authenticode signing through Azure Artifact Signing (formerly Trusted
|
|
5
|
+
# Signing). The configuration opts in; the account coordinates come from the
|
|
6
|
+
# environment, and Azure authentication from an existing Azure CLI sign-in
|
|
7
|
+
# (`az login`, or azure/login with OIDC in CI). No secret is read or stored.
|
|
8
|
+
class WindowsSigning
|
|
9
|
+
include Support
|
|
10
|
+
PROVIDER = "azure-artifact-signing"
|
|
11
|
+
KEYS = %w[provider description description_url publisher].freeze
|
|
12
|
+
VARIABLES = %w[AZURE_SIGNING_ENDPOINT AZURE_SIGNING_ACCOUNT AZURE_SIGNING_PROFILE].freeze
|
|
13
|
+
TIMESTAMP = "http://timestamp.acs.microsoft.com"
|
|
14
|
+
# Every DefaultAzureCredential source except the Azure CLI's, so a stray
|
|
15
|
+
# client secret or cached account can never sign in its place.
|
|
16
|
+
EXCLUDED_CREDENTIALS = %w[EnvironmentCredential WorkloadIdentityCredential ManagedIdentityCredential
|
|
17
|
+
SharedTokenCacheCredential VisualStudioCredential VisualStudioCodeCredential AzurePowerShellCredential
|
|
18
|
+
AzureDeveloperCliCredential InteractiveBrowserCredential].freeze
|
|
19
|
+
# The versions azure/artifact-signing-action 2.0.0 installs, pinned by hash.
|
|
20
|
+
TOOLS = {
|
|
21
|
+
"signtool" => { "package" => "microsoft.windows.sdk.buildtools", "version" => "10.0.26100.4188",
|
|
22
|
+
"sha256" => "180deb372659029864c10a0c04787833234d64aacd1d2c0661d2c00295d8e022",
|
|
23
|
+
"directory" => "bin/10.0.26100.0/x64", "file" => "signtool.exe", "override" => "NATIVE_PACKAGES_SIGNTOOL" },
|
|
24
|
+
"dlib" => { "package" => "microsoft.artifactsigning.client", "version" => "1.0.128",
|
|
25
|
+
"sha256" => "74bd7d27e6ce1051409c38d9b46bc8df0400ecd643d51ffbf2ac00869061e40b",
|
|
26
|
+
"directory" => "bin/x64", "file" => "Azure.CodeSigning.Dlib.dll", "override" => "NATIVE_PACKAGES_ARTIFACT_SIGNING_DLIB" }
|
|
27
|
+
}.freeze
|
|
28
|
+
# Command lines on Windows hold 32,767 characters; leave room for options.
|
|
29
|
+
BATCH_CHARACTERS = 16_000
|
|
30
|
+
SIGNATURES = <<~'POWERSHELL'
|
|
31
|
+
$ErrorActionPreference = 'Stop'
|
|
32
|
+
$simple = [System.Security.Cryptography.X509Certificates.X509NameType]::SimpleName
|
|
33
|
+
$paths = @(Get-Content -LiteralPath $env:NATIVE_PACKAGES_SIGNATURE_LIST -Encoding UTF8)
|
|
34
|
+
$result = @(foreach ($line in $paths) {
|
|
35
|
+
# Plain strings: lines from Get-Content carry note properties that
|
|
36
|
+
# ConvertTo-Json would otherwise write out as an object.
|
|
37
|
+
$path = [string]$line
|
|
38
|
+
$signature = Get-AuthenticodeSignature -LiteralPath $path
|
|
39
|
+
$certificate = $signature.SignerCertificate
|
|
40
|
+
$publisher = $null
|
|
41
|
+
$subject = $null
|
|
42
|
+
if ($certificate) {
|
|
43
|
+
$publisher = $certificate.GetNameInfo($simple, $false)
|
|
44
|
+
$subject = $certificate.Subject
|
|
45
|
+
}
|
|
46
|
+
[pscustomobject]@{ path = $path; status = [string]$signature.Status; message = [string]$signature.StatusMessage;
|
|
47
|
+
publisher = $publisher; subject = $subject; timestamped = [bool]$signature.TimeStamperCertificate }
|
|
48
|
+
})
|
|
49
|
+
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes((ConvertTo-Json -InputObject $result -Compress -Depth 3)))
|
|
50
|
+
POWERSHELL
|
|
51
|
+
|
|
52
|
+
# Only the tool's own directory leaves the NuGet package (a ZIP file).
|
|
53
|
+
EXTRACT = <<~'POWERSHELL'
|
|
54
|
+
$ErrorActionPreference = 'Stop'
|
|
55
|
+
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
56
|
+
$prefix = $env:NATIVE_PACKAGES_PREFIX + '/'
|
|
57
|
+
$zip = [System.IO.Compression.ZipFile]::OpenRead($env:NATIVE_PACKAGES_ARCHIVE)
|
|
58
|
+
try {
|
|
59
|
+
foreach ($entry in $zip.Entries) {
|
|
60
|
+
if (-not $entry.FullName.StartsWith($prefix) -or -not $entry.Name -or $entry.FullName.Contains('..')) { continue }
|
|
61
|
+
$target = Join-Path $env:NATIVE_PACKAGES_DESTINATION $entry.FullName
|
|
62
|
+
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $target) | Out-Null
|
|
63
|
+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target, $true)
|
|
64
|
+
}
|
|
65
|
+
} finally {
|
|
66
|
+
$zip.Dispose()
|
|
67
|
+
}
|
|
68
|
+
POWERSHELL
|
|
69
|
+
|
|
70
|
+
attr_reader :root, :settings
|
|
71
|
+
|
|
72
|
+
def self.validate(data)
|
|
73
|
+
windows = data.fetch("windows", {})
|
|
74
|
+
raise Error, "windows: expected a mapping" unless windows.is_a?(Hash)
|
|
75
|
+
unknown = windows.keys - %w[signing]
|
|
76
|
+
raise Error, "windows: unknown fields #{unknown.join(', ')}" unless unknown.empty?
|
|
77
|
+
return unless windows.key?("signing")
|
|
78
|
+
signing = windows["signing"]
|
|
79
|
+
raise Error, "windows.signing: expected a mapping" unless signing.is_a?(Hash)
|
|
80
|
+
unknown = signing.keys - KEYS
|
|
81
|
+
raise Error, "windows.signing: unknown fields #{unknown.join(', ')}" unless unknown.empty?
|
|
82
|
+
raise Error, "windows.signing.provider: use #{PROVIDER}" unless signing["provider"] == PROVIDER
|
|
83
|
+
%w[description publisher].each do |key|
|
|
84
|
+
next unless signing.key?(key)
|
|
85
|
+
raise Error, "windows.signing.#{key}: expected a nonempty string" unless signing[key].is_a?(String) && !signing[key].strip.empty?
|
|
86
|
+
end
|
|
87
|
+
if signing.key?("description_url") && !(signing["description_url"].is_a?(String) && %r{\Ahttps://\S+\z}.match?(signing["description_url"]))
|
|
88
|
+
raise Error, "windows.signing.description_url: expected an https:// URL"
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def initialize(configuration, environment = ENV)
|
|
93
|
+
@root = configuration.root
|
|
94
|
+
self.class.validate(configuration.data)
|
|
95
|
+
@settings = configuration.data.fetch("windows", {}).fetch("signing", nil)
|
|
96
|
+
@environment = environment
|
|
97
|
+
@values = VARIABLES.to_h { |name| [name, environment[name].to_s.strip] }
|
|
98
|
+
@description = settings && settings.fetch("description", configuration.name)
|
|
99
|
+
@description_url = settings && (settings["description_url"] || configuration.data.fetch("nfpm")["homepage"])
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def configured? = !settings.nil?
|
|
103
|
+
def enabled? = configured? && @values.values.any? { |value| !value.empty? }
|
|
104
|
+
def state = !configured? ? "off" : enabled? ? "enabled" : "off: #{VARIABLES.join(', ')} not set"
|
|
105
|
+
|
|
106
|
+
def doctor
|
|
107
|
+
return unless enabled?
|
|
108
|
+
missing = @values.select { |_, value| value.empty? }.keys
|
|
109
|
+
raise Error, "incomplete Azure Artifact Signing settings: set #{missing.join(', ')}" unless missing.empty?
|
|
110
|
+
unless %r{\Ahttps://[a-z0-9-]+\.codesigning\.azure\.net/?\z}.match?(@values.fetch("AZURE_SIGNING_ENDPOINT"))
|
|
111
|
+
raise Error, "AZURE_SIGNING_ENDPOINT must be an Artifact Signing endpoint such as https://weu.codesigning.azure.net/"
|
|
112
|
+
end
|
|
113
|
+
%w[AZURE_SIGNING_ACCOUNT AZURE_SIGNING_PROFILE].each do |name|
|
|
114
|
+
raise Error, "#{name} must be a name, not a path or URL" unless /\A[A-Za-z0-9][A-Za-z0-9-]*\z/.match?(@values.fetch(name))
|
|
115
|
+
end
|
|
116
|
+
raise Error, "Windows signing must run on Windows" unless NativeRecipe.host == "windows"
|
|
117
|
+
tools = %w[powershell az]
|
|
118
|
+
tools << "curl" if TOOLS.values.any? { |tool| @environment[tool.fetch("override")].to_s.empty? }
|
|
119
|
+
missing_tools = tools.reject { |tool| available?(tool) }
|
|
120
|
+
raise Error, "install required Windows signing tools: #{missing_tools.join(', ')}" unless missing_tools.empty?
|
|
121
|
+
TOOLS.each_value do |tool|
|
|
122
|
+
path = @environment[tool.fetch("override")].to_s
|
|
123
|
+
raise Error, "#{tool.fetch('override')} does not name a file: #{path}" unless path.empty? || File.file?(path)
|
|
124
|
+
end
|
|
125
|
+
begin
|
|
126
|
+
execute "az", "account", "show", "--output", "none"
|
|
127
|
+
rescue Error
|
|
128
|
+
raise Error, "sign in to Azure before signing: az login, or azure/login with OIDC in GitHub Actions"
|
|
129
|
+
end
|
|
130
|
+
nil
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def with_identity
|
|
134
|
+
doctor
|
|
135
|
+
return yield(nil) unless enabled?
|
|
136
|
+
Dir.mktmpdir("native-packages-windows-signing-") do |directory|
|
|
137
|
+
directory = Pathname.new(directory)
|
|
138
|
+
@signtool = tool("signtool", directory)
|
|
139
|
+
@dlib = tool("dlib", directory)
|
|
140
|
+
@metadata = directory / "metadata.json"
|
|
141
|
+
write(@metadata, JSON.pretty_generate("Endpoint" => @values.fetch("AZURE_SIGNING_ENDPOINT"),
|
|
142
|
+
"CodeSigningAccountName" => @values.fetch("AZURE_SIGNING_ACCOUNT"),
|
|
143
|
+
"CertificateProfileName" => @values.fetch("AZURE_SIGNING_PROFILE"),
|
|
144
|
+
"ExcludeCredentials" => EXCLUDED_CREDENTIALS) + "\n")
|
|
145
|
+
yield self
|
|
146
|
+
ensure
|
|
147
|
+
@signtool = @dlib = @metadata = nil
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# A package recipe gets a signed copy of its input. Code that already
|
|
152
|
+
# carries a valid signature, ours from sign-windows or a vendor's, stays.
|
|
153
|
+
def sign_payload(payload)
|
|
154
|
+
binaries = NativeRecipe.new(root).tree(payload).filter_map do |relative, kind, *|
|
|
155
|
+
path = payload / relative
|
|
156
|
+
path if kind == "file" && portable_executable?(path)
|
|
157
|
+
end
|
|
158
|
+
unsigned = signatures(binaries).reject { |record| record.fetch("status") == "Valid" }.map { |record| Pathname.new(record.fetch("path")) }
|
|
159
|
+
sign(unsigned) unless unsigned.empty?
|
|
160
|
+
puts "Signed #{unsigned.length} of #{binaries.length} Windows binaries in the package input."
|
|
161
|
+
unsigned.length
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def sign_package(package)
|
|
165
|
+
record = sign([package]).first
|
|
166
|
+
{ "signature" => "authenticode", "provider" => PROVIDER, "publisher" => record.fetch("publisher"),
|
|
167
|
+
"timestamped" => true }
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Signs files in place, in as few SignTool calls as fit a command line,
|
|
171
|
+
# then checks every signature.
|
|
172
|
+
def sign(paths)
|
|
173
|
+
paths = paths.map { |path| Pathname.new(path).expand_path(root) }
|
|
174
|
+
paths.each { |path| raise Error, "not a regular file: #{path}" unless path.file? && !path.symlink? }
|
|
175
|
+
batches = paths.each_with_object([[]]) do |path, groups|
|
|
176
|
+
length = groups.last.sum { |item| item.to_s.length + 3 } + path.to_s.length + 3
|
|
177
|
+
groups << [] if !groups.last.empty? && length > BATCH_CHARACTERS
|
|
178
|
+
groups.last << path
|
|
179
|
+
end
|
|
180
|
+
batches.each do |batch|
|
|
181
|
+
arguments = [@signtool, "sign", "/v", "/fd", "SHA256", "/tr", TIMESTAMP, "/td", "SHA256",
|
|
182
|
+
"/dlib", @dlib, "/dmdf", @metadata, "/d", @description]
|
|
183
|
+
arguments += ["/du", @description_url] if @description_url
|
|
184
|
+
output = signtool(*arguments, *batch)
|
|
185
|
+
puts output unless output.empty?
|
|
186
|
+
end
|
|
187
|
+
verify(paths)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def verify(paths)
|
|
191
|
+
signatures(paths).map do |record|
|
|
192
|
+
path = record.fetch("path")
|
|
193
|
+
unless record.fetch("status") == "Valid" && record.fetch("timestamped")
|
|
194
|
+
raise Error, "#{path} is not validly signed and timestamped: #{record.fetch('status')} #{record.fetch('message')}".strip
|
|
195
|
+
end
|
|
196
|
+
if settings["publisher"] && record.fetch("publisher") != settings["publisher"]
|
|
197
|
+
raise Error, "#{path} is signed by #{record.fetch('publisher').inspect}, not windows.signing.publisher #{settings['publisher'].inspect}"
|
|
198
|
+
end
|
|
199
|
+
puts "#{File.basename(path)}: signed by #{record.fetch('subject')}, timestamped"
|
|
200
|
+
record
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def signatures(paths)
|
|
205
|
+
return [] if paths.empty?
|
|
206
|
+
records = Dir.mktmpdir("native-packages-signatures-") do |directory|
|
|
207
|
+
list = Pathname.new(directory) / "files.txt"
|
|
208
|
+
write(list, paths.map { |path| Pathname.new(path).expand_path(root).to_s }.join("\n") + "\n")
|
|
209
|
+
JSON.parse(powershell(SIGNATURES, "NATIVE_PACKAGES_SIGNATURE_LIST" => list.to_s).strip.unpack1("m0").force_encoding(Encoding::UTF_8))
|
|
210
|
+
end
|
|
211
|
+
raise Error, "unexpected signature report" unless records.is_a?(Array) && records.length == paths.length
|
|
212
|
+
records
|
|
213
|
+
rescue ArgumentError, JSON::ParserError
|
|
214
|
+
raise Error, "could not read Authenticode signatures"
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# `native-packages sign-windows FILE...`: explicit, so it never skips.
|
|
218
|
+
def sign_files(paths)
|
|
219
|
+
raise Error, "add windows.signing to the configuration to sign Windows files" unless configured?
|
|
220
|
+
raise Error, "set #{VARIABLES.join(', ')} to sign Windows files" unless enabled?
|
|
221
|
+
raise Error, "sign-windows needs at least one file" if paths.empty?
|
|
222
|
+
with_identity { |signing| signing.sign(paths) }
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def portable_executable?(path)
|
|
226
|
+
File.open(path, "rb") do |file|
|
|
227
|
+
next false unless file.size >= 64 && file.read(2) == "MZ"
|
|
228
|
+
file.seek(0x3c)
|
|
229
|
+
offset = file.read(4).unpack1("L<")
|
|
230
|
+
next false unless offset >= 64 && offset + 4 <= file.size
|
|
231
|
+
file.seek(offset)
|
|
232
|
+
file.read(4) == "PE\0\0"
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# SignTool and the Artifact Signing client from nuget.org, hash-checked on
|
|
237
|
+
# every use, or local copies named by the override variables.
|
|
238
|
+
def tool(name, directory)
|
|
239
|
+
tool = TOOLS.fetch(name)
|
|
240
|
+
override = @environment[tool.fetch("override")].to_s
|
|
241
|
+
return Pathname.new(override).expand_path unless override.empty?
|
|
242
|
+
package, version = tool.values_at("package", "version")
|
|
243
|
+
archive = cache_directory / "#{package}.#{version}.nupkg"
|
|
244
|
+
download("https://api.nuget.org/v3-flatcontainer/#{package}/#{version}/#{package}.#{version}.nupkg", archive)
|
|
245
|
+
unless sha256(archive) == tool.fetch("sha256")
|
|
246
|
+
archive.delete
|
|
247
|
+
raise Error, "#{package} #{version} from nuget.org does not match its pinned SHA-256"
|
|
248
|
+
end
|
|
249
|
+
destination = directory / name
|
|
250
|
+
destination.mkpath
|
|
251
|
+
powershell(EXTRACT, "NATIVE_PACKAGES_ARCHIVE" => archive.to_s, "NATIVE_PACKAGES_PREFIX" => tool.fetch("directory"),
|
|
252
|
+
"NATIVE_PACKAGES_DESTINATION" => destination.to_s)
|
|
253
|
+
path = destination / tool.fetch("directory") / tool.fetch("file")
|
|
254
|
+
raise Error, "#{package} #{version} has no #{tool.fetch('file')}" unless path.file?
|
|
255
|
+
path
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def cache_directory
|
|
259
|
+
base = @environment["LOCALAPPDATA"].to_s.empty? ? File.join(Dir.home, ".cache") : @environment["LOCALAPPDATA"]
|
|
260
|
+
Pathname.new(base) / "native-packages/windows-signing"
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# SignTool and the Artifact Signing client report failures on standard
|
|
264
|
+
# output, so a failure shows both streams.
|
|
265
|
+
def signtool(*arguments)
|
|
266
|
+
output, status = Open3.capture2e(*arguments.map(&:to_s), chdir: root.to_s, binmode: true)
|
|
267
|
+
raise Error, "SignTool failed:\n#{output.strip}" unless status.success?
|
|
268
|
+
output.strip
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Windows PowerShell started from PowerShell 7 inherits a module path
|
|
272
|
+
# where its own Microsoft.PowerShell.Security cannot load; without one, it
|
|
273
|
+
# uses its default.
|
|
274
|
+
def powershell(script, env)
|
|
275
|
+
encoded = [script.encode(Encoding::UTF_16LE)].pack("m0")
|
|
276
|
+
execute("powershell", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", encoded,
|
|
277
|
+
env: env.merge("PSModulePath" => nil))
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def execute(*arguments, env: {})
|
|
281
|
+
capture(*arguments, env: env)
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: native-packages
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Carmine Paolino
|
|
@@ -27,9 +27,11 @@ files:
|
|
|
27
27
|
- docs/_guides/github-actions.md
|
|
28
28
|
- docs/_guides/multi-platform.md
|
|
29
29
|
- docs/_guides/native-recipes.md
|
|
30
|
+
- docs/_guides/omarchy.md
|
|
30
31
|
- docs/_guides/prereleases.md
|
|
31
32
|
- docs/_guides/publishing.md
|
|
32
33
|
- docs/_guides/release-signing.md
|
|
34
|
+
- docs/_guides/windows-signing.md
|
|
33
35
|
- docs/_reference/commands.md
|
|
34
36
|
- docs/_reference/configuration.md
|
|
35
37
|
- docs/_reference/platforms.md
|
|
@@ -59,11 +61,13 @@ files:
|
|
|
59
61
|
- lib/native_packages/inspection.rb
|
|
60
62
|
- lib/native_packages/macos_signing.rb
|
|
61
63
|
- lib/native_packages/native_recipe.rb
|
|
64
|
+
- lib/native_packages/omarchy.rb
|
|
62
65
|
- lib/native_packages/project.rb
|
|
63
66
|
- lib/native_packages/release_signing.rb
|
|
64
67
|
- lib/native_packages/repositories.rb
|
|
65
68
|
- lib/native_packages/scaffold.rb
|
|
66
69
|
- lib/native_packages/support.rb
|
|
70
|
+
- lib/native_packages/windows_signing.rb
|
|
67
71
|
homepage: https://github.com/crmne/native-packages
|
|
68
72
|
licenses:
|
|
69
73
|
- MIT
|