-
Notifications
You must be signed in to change notification settings - Fork 64
Verify signatures of toolchains before installing #94
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7f6d94e
wip validate signatures
patrickfreed 9ed01cd
finish validate signatures
patrickfreed e85675d
add --no-import-pgp-keys option to swiftly-install, update tests
patrickfreed 2e7b47e
use curl instead of wget
patrickfreed 410f297
fix format
patrickfreed 62d695d
remove --no-progress-meter option from curl command
patrickfreed 75fff7c
properly account for apt-get cleanup
patrickfreed c0f8e72
remove dead code
patrickfreed 023e04c
switch flag to --verify/--no-verify
patrickfreed 4a403d0
fail to install if gpg not installed, Swift keys not imported
patrickfreed ba9b028
ensure keys are imported on rhel and amazonlinux2
patrickfreed 1ae11ed
check gpg requirements before downloading the toolchain tarball
patrickfreed 2236517
use verify + inversion for update, fix help string
patrickfreed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,5 +141,76 @@ public struct Linux: Platform { | |
| FileManager.default.temporaryDirectory.appendingPathComponent("swiftly-\(UUID())") | ||
| } | ||
|
|
||
| public func verifySignature(httpClient: SwiftlyHTTPClient, archiveDownloadURL: URL, archive: URL) async throws { | ||
| guard (try? self.runProgram("gpg", "--version", quiet: true)) != nil else { | ||
| SwiftlyCore.print("gpg not installed, skipping signature verification.") | ||
| return | ||
| } | ||
|
|
||
| let foundKeys = (try? self.runProgram( | ||
| "gpg", | ||
| "--list-keys", | ||
| "[email protected]", | ||
| "[email protected]", | ||
| quiet: true | ||
| )) != nil | ||
| guard foundKeys else { | ||
| SwiftlyCore.print("Swift PGP keys not imported, skipping signature verification.") | ||
adam-fowler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SwiftlyCore.print("To enable verification, import the keys from https://swift.org/keys/all-keys.asc") | ||
adam-fowler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return | ||
| } | ||
|
|
||
| SwiftlyCore.print("Refreshing Swift PGP keys...") | ||
| do { | ||
| try self.runProgram( | ||
| "gpg", | ||
| "--quiet", | ||
| "--keyserver", | ||
| "hkp://keyserver.ubuntu.com", | ||
| "--refresh-keys", | ||
| "Swift" | ||
| ) | ||
| } catch { | ||
| throw Error(message: "Failed to refresh PGP keys: \(error)") | ||
| } | ||
patrickfreed marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| SwiftlyCore.print("Downloading toolchain signature...") | ||
| let sigFile = self.getTempFilePath() | ||
| FileManager.default.createFile(atPath: sigFile.path, contents: nil) | ||
| defer { | ||
| try? FileManager.default.removeItem(at: sigFile) | ||
| } | ||
|
|
||
| try await httpClient.downloadFile( | ||
| url: archiveDownloadURL.appendingPathExtension("sig"), | ||
| to: sigFile | ||
| ) | ||
|
|
||
| SwiftlyCore.print("Verifying toolchain signature...") | ||
| do { | ||
| try self.runProgram("gpg", "--verify", sigFile.path, archive.path) | ||
| } catch { | ||
| throw Error(message: "Toolchain signature verification failed: \(error)") | ||
| } | ||
| } | ||
|
|
||
| private func runProgram(_ args: String..., quiet: Bool = false) throws { | ||
| let process = Process() | ||
| process.executableURL = URL(fileURLWithPath: "/usr/bin/env") | ||
| process.arguments = args | ||
|
|
||
| if quiet { | ||
| process.standardOutput = nil | ||
| process.standardError = nil | ||
| } | ||
|
|
||
| try process.run() | ||
| process.waitUntilExit() | ||
|
|
||
| guard process.terminationStatus == 0 else { | ||
| throw Error(message: "\(args.first!) exited with non-zero status: \(process.terminationStatus)") | ||
| } | ||
| } | ||
|
|
||
| public static let currentPlatform: any Platform = Linux() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| ARG base_image=amazonlinux:2 | ||
| FROM $base_image | ||
|
|
||
| RUN yum install -y curl util-linux | ||
| RUN yum install -y curl util-linux gpg | ||
| RUN echo 'export PATH="$HOME/.local/bin:$PATH"' >> $HOME/.profile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| ARG base_image=redhat/ubi9:latest | ||
| FROM $base_image | ||
|
|
||
| RUN yum install --allowerasing -y curl gcc-c++ | ||
| RUN yum install --allowerasing -y curl gcc-c++ gpg | ||
| RUN echo 'export PATH="$HOME/.local/bin:$PATH"' >> $HOME/.profile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.