2024-03-27 15:53:11 +01:00
|
|
|
//
|
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static let TEST = WebIDEnv(
|
|
|
|
uri: URLComponents(string: "https://test.webid-solutions.de")!,
|
|
|
|
username: Credentials.demoUsernameTest,
|
|
|
|
apiKey: Credentials.demoApiKeyTest,
|
|
|
|
name: "Test",
|
|
|
|
pinningCerts: EWebIDEnv.getPinningCerts(certResourceNames: [
|
2025-02-12 13:25:50 +01:00
|
|
|
"test.webid-solutions.de-valid_until_2026.02.21",
|
|
|
|
"test.webid-solutions.de_2025.02.22"
|
2024-03-27 15:53:11 +01:00
|
|
|
])
|
|
|
|
)
|
|
|
|
|
|
|
|
static let PRODUCTION = WebIDEnv(
|
|
|
|
uri: URLComponents(string: "https://webid-gateway.de")!,
|
|
|
|
username: Credentials.demoUsernameProduction,
|
|
|
|
apiKey: Credentials.demoApiKeyProduction,
|
|
|
|
name: "",
|
|
|
|
pinningCerts: EWebIDEnv.getPinningCerts(certResourceNames: [
|
2025-02-12 13:25:50 +01:00
|
|
|
"webid-gateway.de_valid_until_2025.10.17"
|
2024-03-27 15:53:11 +01:00
|
|
|
])
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|