Skip to content
Open
Changes from all 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
31 changes: 21 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,26 @@ 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 {
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)
}
}
}

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