Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions Sources/LinuxPlatform/Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,7 @@ public struct Linux: Platform {
throw SwiftlyError(message: msg)
}

let tmpFile = self.getTempFilePath()
try await fs.create(.mode(0o600), file: tmpFile, contents: nil)
try await fs.withTemporary(files: tmpFile) {
try await ctx.httpClient.getGpgKeys().download(to: tmpFile)
if let mockedHomeDir = ctx.mockedHomeDir {
try await sys.gpg()._import(key: tmpFile).run(environment: .inherit.updating(["GNUPGHOME": (mockedHomeDir / ".gnupg").string]), quiet: true)
} else {
try await sys.gpg()._import(key: tmpFile).run(quiet: true)
}
}
try await self.importGpgKeys(ctx)
}

guard let manager = manager else {
Expand Down Expand Up @@ -430,6 +421,9 @@ public struct Linux: Platform {
public func verifyToolchainSignature(
_ ctx: SwiftlyCoreContext, toolchainFile: ToolchainFile, archive: FilePath, verbose: Bool
) async throws {
// Ensure GPG keys are imported before attempting signature verification
try await self.importGpgKeys(ctx)

if verbose {
await ctx.message("Downloading toolchain signature...")
}
Expand All @@ -452,9 +446,28 @@ public struct Linux: Platform {
}
}

/// Import Swift.org GPG keys for signature verification
private func importGpgKeys(_ ctx: SwiftlyCoreContext) async throws {
let tmpFile = self.getTempFilePath()
try await fs.create(.mode(0o600), file: tmpFile, contents: nil)
try await fs.withTemporary(files: tmpFile) {
try await ctx.httpClient.getGpgKeys().download(to: tmpFile)
if let mockedHomeDir = ctx.mockedHomeDir {
var env = ProcessInfo.processInfo.environment
env["GNUPGHOME"] = (mockedHomeDir / ".gnupg").string
try await sys.gpg()._import(key: tmpFile).run(environment: .init(env), quiet: true)
Copy link
Member

Choose a reason for hiding this comment

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

issue (blocking): Since updating to swift-subprocess the environment handling is more explicit in that it can be precisely encoded that the environment should be inherited with specific overrides. This line becomes the following:

try await sys.gpg()._import(key: tmpFile).run(environment: .inherit.updating(["GNUPGHOME": (mockedHomeDir / ".gnupg").string]), quiet: true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed the change

} else {
try await sys.gpg()._import(key: tmpFile).run(quiet: true)
}
}
}

public func verifySwiftlySignature(
_ ctx: SwiftlyCoreContext, archiveDownloadURL: URL, archive: FilePath, verbose: Bool
) async throws {
// Ensure GPG keys are imported before attempting signature verification
try await self.importGpgKeys(ctx)

if verbose {
await ctx.message("Downloading swiftly signature...")
}
Expand Down
Loading