9
0

65 lines
2.1 KiB
Swift
Raw Normal View History

//
// Created by WebID Solutions GmbH | www.webid-solutions.de.
// See the file "LICENSE" for the full license governing this code.
//
import Foundation
class EWebIDEnv {
struct WebIDEnv: Equatable {
let uri: URLComponents
let username: String
let apiKey: String
let name: String
let pinningCerts: [SecCertificate]
static func == (lhs: WebIDEnv, rhs: WebIDEnv) -> Bool {
return (lhs.uri == rhs.uri && lhs.name == rhs.name)
}
static func != (lhs: WebIDEnv, rhs: WebIDEnv) -> Bool {
return (!(lhs == rhs))
}
}
// one environment (here PRODUCTION) has to have an actionIdPrefix= nil, all other environments != nil
static let TEST = WebIDEnv(
uri: URLComponents(string: "https://test.webid-solutions.de")!,
username: Credentials.demoUsernameTest,
apiKey: Credentials.demoApiKeyTest,
name: "Test",
pinningCerts: EWebIDEnv.getPinningCerts(certResourceNames: [
"test.webid-solutions.de_2025.02.22",
"test.webid-solutions.de_2024.02.27"
])
)
static let PRODUCTION = WebIDEnv(
uri: URLComponents(string: "https://webid-gateway.de")!,
username: Credentials.demoUsernameProduction,
apiKey: Credentials.demoApiKeyProduction,
name: "",
pinningCerts: EWebIDEnv.getPinningCerts(certResourceNames: [
"webid-gateway.de_2024.11.02",
"webid-gateway.de_2023.12.01"
])
)
static func getPinningCerts(certResourceNames: [String]) -> [SecCertificate] {
var certificates: [SecCertificate] = []
for certResourceName in certResourceNames {
let url = Bundle.main.url(
forResource: certResourceName,
withExtension: "cer"
)!
let localCertificate = try! Data(contentsOf: url) as CFData
if let certificate = SecCertificateCreateWithData(
nil,
localCertificate
) {
certificates.append(certificate)
}
}
return certificates
}
}