Skip to content

Commit

Permalink
Try adding Windows and iOS to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Dec 27, 2024
1 parent 0535d93 commit 21e10eb
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 61 deletions.
43 changes: 42 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,46 @@ jobs:
with:
with_linting: true
with_musl: true
ios_scheme_name: swift-wallet-Package
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

windows-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
swift-version:
- 5.9
- 5.10
- 6.0
include:
- { swift-version: 5.9, swift-branch: swift-5.9.2-release, swift-tag: 5.9.2-RELEASE }
- { swift-version: 5.10, swift-branch: swift-5.10.1-release, swift-tag: 5.10.1-RELEASE }
- { swift-version: 6.0, swift-branch: swift-6.0.1-release, swift-tag: 6.0.1-RELEASE }
runs-on: windows-latest
timeout-minutes: 60
steps:
- name: Install Windows Swift toolchain
uses: compnerd/gha-setup-swift@main
with:
branch: ${{ matrix.swift-branch }}
tag: ${{ matrix.swift-tag }}
- name: Download zlib
run: |
curl -L -o zlib.zip https://www.zlib.net/zlib131.zip
mkdir zlib-131
tar -xf zlib.zip -C zlib-131 --strip-components=1
- name: Build and install zlib
run: |
cd zlib-131
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake --install . --prefix ../install
- name: Check out code
uses: actions/checkout@v4
- name: Run unit tests
run: |
swift test -Xcc -I'C:/Program Files (x86)/zlib/include' -Xlinker -L'C:/Program Files (x86)/zlib/lib'
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import PackageDescription
let package = Package(
name: "swift-wallet",
platforms: [
.macOS(.v11)
.macOS(.v11),
.iOS(.v14),
.tvOS(.v14),
.watchOS(.v7),
],
products: [
.library(name: "WalletPasses", targets: ["WalletPasses"]),
Expand Down
64 changes: 34 additions & 30 deletions Sources/WalletOrders/OrderBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,40 @@ public struct OrderBuilder: Sendable {
private func signature(for manifest: Data) throws -> Data {
// Swift Crypto doesn't support encrypted PEM private keys, so we have to use OpenSSL for that.
if let pemPrivateKeyPassword {
guard FileManager.default.fileExists(atPath: self.openSSLURL.path) else {
throw WalletOrdersError.noOpenSSLExecutable
}

let dir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: dir) }

try manifest.write(to: dir.appendingPathComponent("manifest.json"))
try self.pemWWDRCertificate.write(to: dir.appendingPathComponent("wwdr.pem"), atomically: true, encoding: .utf8)
try self.pemCertificate.write(to: dir.appendingPathComponent("certificate.pem"), atomically: true, encoding: .utf8)
try self.pemPrivateKey.write(to: dir.appendingPathComponent("private.pem"), atomically: true, encoding: .utf8)

let process = Process()
process.currentDirectoryURL = dir
process.executableURL = self.openSSLURL
process.arguments = [
"smime", "-binary", "-sign",
"-certfile", dir.appendingPathComponent("wwdr.pem").path,
"-signer", dir.appendingPathComponent("certificate.pem").path,
"-inkey", dir.appendingPathComponent("private.pem").path,
"-in", dir.appendingPathComponent("manifest.json").path,
"-out", dir.appendingPathComponent("signature").path,
"-outform", "DER",
"-passin", "pass:\(pemPrivateKeyPassword)",
]
try process.run()
process.waitUntilExit()

return try Data(contentsOf: dir.appendingPathComponent("signature"))
#if !os(macOS) && !os(Linux) && !os(Windows)
throw WalletPassesError.noOpenSSLExecutable
#else
guard FileManager.default.fileExists(atPath: self.openSSLURL.path) else {
throw WalletOrdersError.noOpenSSLExecutable
}

let dir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: dir) }

try manifest.write(to: dir.appendingPathComponent("manifest.json"))
try self.pemWWDRCertificate.write(to: dir.appendingPathComponent("wwdr.pem"), atomically: true, encoding: .utf8)
try self.pemCertificate.write(to: dir.appendingPathComponent("certificate.pem"), atomically: true, encoding: .utf8)
try self.pemPrivateKey.write(to: dir.appendingPathComponent("private.pem"), atomically: true, encoding: .utf8)

let process = Process()
process.currentDirectoryURL = dir
process.executableURL = self.openSSLURL
process.arguments = [
"smime", "-binary", "-sign",
"-certfile", dir.appendingPathComponent("wwdr.pem").path,
"-signer", dir.appendingPathComponent("certificate.pem").path,
"-inkey", dir.appendingPathComponent("private.pem").path,
"-in", dir.appendingPathComponent("manifest.json").path,
"-out", dir.appendingPathComponent("signature").path,
"-outform", "DER",
"-passin", "pass:\(pemPrivateKeyPassword)",
]
try process.run()
process.waitUntilExit()

return try Data(contentsOf: dir.appendingPathComponent("signature"))
#endif
} else {
let signature = try CMS.sign(
manifest,
Expand Down
62 changes: 33 additions & 29 deletions Sources/WalletPasses/PassBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,36 +60,40 @@ public struct PassBuilder: Sendable {
public func signature(for manifest: Data) throws -> Data {
// Swift Crypto doesn't support encrypted PEM private keys, so we have to use OpenSSL for that.
if let pemPrivateKeyPassword {
guard FileManager.default.fileExists(atPath: self.openSSLURL.path) else {
#if !os(macOS) && !os(Linux) && !os(Windows)
throw WalletPassesError.noOpenSSLExecutable
}

let dir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: dir) }

try manifest.write(to: dir.appendingPathComponent("manifest.json"))
try self.pemWWDRCertificate.write(to: dir.appendingPathComponent("wwdr.pem"), atomically: true, encoding: .utf8)
try self.pemCertificate.write(to: dir.appendingPathComponent("certificate.pem"), atomically: true, encoding: .utf8)
try self.pemPrivateKey.write(to: dir.appendingPathComponent("private.pem"), atomically: true, encoding: .utf8)

let process = Process()
process.currentDirectoryURL = dir
process.executableURL = self.openSSLURL
process.arguments = [
"smime", "-binary", "-sign",
"-certfile", dir.appendingPathComponent("wwdr.pem").path,
"-signer", dir.appendingPathComponent("certificate.pem").path,
"-inkey", dir.appendingPathComponent("private.pem").path,
"-in", dir.appendingPathComponent("manifest.json").path,
"-out", dir.appendingPathComponent("signature").path,
"-outform", "DER",
"-passin", "pass:\(pemPrivateKeyPassword)",
]
try process.run()
process.waitUntilExit()

return try Data(contentsOf: dir.appendingPathComponent("signature"))
#else
guard FileManager.default.fileExists(atPath: self.openSSLURL.path) else {
throw WalletPassesError.noOpenSSLExecutable
}

let dir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: dir) }

try manifest.write(to: dir.appendingPathComponent("manifest.json"))
try self.pemWWDRCertificate.write(to: dir.appendingPathComponent("wwdr.pem"), atomically: true, encoding: .utf8)
try self.pemCertificate.write(to: dir.appendingPathComponent("certificate.pem"), atomically: true, encoding: .utf8)
try self.pemPrivateKey.write(to: dir.appendingPathComponent("private.pem"), atomically: true, encoding: .utf8)

let process = Process()
process.currentDirectoryURL = dir
process.executableURL = self.openSSLURL
process.arguments = [
"smime", "-binary", "-sign",
"-certfile", dir.appendingPathComponent("wwdr.pem").path,
"-signer", dir.appendingPathComponent("certificate.pem").path,
"-inkey", dir.appendingPathComponent("private.pem").path,
"-in", dir.appendingPathComponent("manifest.json").path,
"-out", dir.appendingPathComponent("signature").path,
"-outform", "DER",
"-passin", "pass:\(pemPrivateKeyPassword)",
]
try process.run()
process.waitUntilExit()

return try Data(contentsOf: dir.appendingPathComponent("signature"))
#endif
} else {
let signature = try CMS.sign(
manifest,
Expand Down
2 changes: 2 additions & 0 deletions Tests/WalletPassesTests/WalletPassesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct WalletPassesTests {
#expect(bundle != nil)
}

@available(macOS 11.0, Windows 10, *)
@Test("Build Pass with Encrypted Key")
func buildEncrypted() throws {
let builder = PassBuilder(
Expand Down Expand Up @@ -78,6 +79,7 @@ struct WalletPassesTests {
}
}

@available(macOS 11.0, Windows 10, *)
@Test("Build Pass without OpenSSL")
func buildWithoutOpenSSL() throws {
let builder = PassBuilder(
Expand Down

0 comments on commit 21e10eb

Please sign in to comment.