-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from johannes-schliephake/develop
v1.1
- Loading branch information
Showing
78 changed files
with
503 additions
and
124 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions
100
App/Assets.xcassets/AppIcon-debug.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"filename" : "60@2x.png", | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "83.5x83.5" | ||
}, | ||
{ | ||
"filename" : "1024@1x.png", | ||
"idiom" : "ios-marketing", | ||
"scale" : "1x", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Foundation | ||
|
||
|
||
struct Configuration { | ||
|
||
static let shortVersionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String | ||
static let appService = Bundle.main.object(forInfoDictionaryKey: "AppService") as! String | ||
static let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String | ||
static let appKeychain = Bundle.main.object(forInfoDictionaryKey: "AppKeychain") as! String | ||
static let clientName = "\(Bundle.main.infoDictionary?["CFBundleName"] as! String) (iOS)" | ||
static let isTestEnvironment = ProcessInfo.processInfo.environment["TEST"] == "true" | ||
static let userDefaults = UserDefaults(suiteName: Configuration.appGroup)! | ||
|
||
private init() {} | ||
|
||
} |
121 changes: 121 additions & 0 deletions
121
Shared/Controllers/Global/AuthenticationChallengeController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import CryptoKit | ||
import WebKit | ||
import Combine | ||
|
||
|
||
final class AuthenticationChallengeController: NSObject, ObservableObject { | ||
|
||
static let `default` = AuthenticationChallengeController() | ||
|
||
@Published var certificateConfirmationRequests = [CertificateConfirmationRequest]() | ||
|
||
private var acceptedCertificateHash: String? { | ||
didSet { | ||
guard let acceptedCertificateHash = acceptedCertificateHash else { | ||
Keychain.default.remove(key: "acceptedCertificateHash") | ||
return | ||
} | ||
Keychain.default.store(key: "acceptedCertificateHash", value: acceptedCertificateHash) | ||
} | ||
} | ||
private var subscriptions = Set<AnyCancellable>() | ||
|
||
override private init() { | ||
super.init() | ||
|
||
acceptedCertificateHash = Keychain.default.load(key: "acceptedCertificateHash") | ||
CredentialsController.default.$credentials.sink(receiveValue: clearAcceptedCertificateHash).store(in: &subscriptions) | ||
} | ||
|
||
func clearAcceptedCertificateHash(credentials: Credentials? = nil) { | ||
guard credentials == nil else { | ||
return | ||
} | ||
acceptedCertificateHash = nil | ||
} | ||
|
||
func accept(certificateHash: String) { | ||
acceptedCertificateHash = certificateHash | ||
|
||
let acceptedCertificateConfirmationRequests = certificateConfirmationRequests.filter { $0.hash == certificateHash } | ||
certificateConfirmationRequests.removeAll { acceptedCertificateConfirmationRequests.contains($0) } | ||
acceptedCertificateConfirmationRequests.forEach { $0.accept() } | ||
} | ||
|
||
func deny(certificateHash: String) { | ||
CredentialsController.default.logout() | ||
|
||
let deniedCertificateConfirmationRequests = certificateConfirmationRequests.filter { $0.hash == certificateHash } | ||
certificateConfirmationRequests.removeAll { deniedCertificateConfirmationRequests.contains($0) } | ||
deniedCertificateConfirmationRequests.forEach { $0.deny() } | ||
} | ||
|
||
private func handler(didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { | ||
/// Check certificate and calculate SHA-256 if invalid | ||
guard let serverTrust = challenge.protectionSpace.serverTrust else { | ||
completionHandler(.performDefaultHandling, nil) | ||
return | ||
} | ||
if SecTrustEvaluateWithError(serverTrust, nil) { | ||
completionHandler(.performDefaultHandling, nil) | ||
return | ||
} | ||
guard let certificate = SecTrustGetCertificateAtIndex(serverTrust, 0) else { | ||
completionHandler(.performDefaultHandling, nil) | ||
return | ||
} | ||
let certificateData = SecCertificateCopyData(certificate) as Data | ||
let certificateHash = SHA256.hash(data: certificateData).map { String(format: "%02X", $0) }.joined(separator: ":") | ||
|
||
/// Check certificate hash against accepted hash | ||
if certificateHash == acceptedCertificateHash { | ||
completionHandler(.useCredential, URLCredential(trust: serverTrust)) | ||
return | ||
} | ||
|
||
/// Add data needed for certificate confirmation | ||
let certificateConfirmationRequest = CertificateConfirmationRequest(hash: certificateHash, accept: { | ||
completionHandler(.useCredential, URLCredential(trust: serverTrust)) | ||
}, deny: { | ||
completionHandler(.performDefaultHandling, nil) | ||
}) | ||
certificateConfirmationRequests.append(certificateConfirmationRequest) | ||
} | ||
|
||
} | ||
|
||
|
||
extension AuthenticationChallengeController { | ||
|
||
struct CertificateConfirmationRequest: Identifiable, Equatable { | ||
|
||
let id = UUID() | ||
let hash: String | ||
let accept: () -> Void | ||
let deny: () -> Void | ||
|
||
static func ==(lhs: CertificateConfirmationRequest, rhs: CertificateConfirmationRequest) -> Bool { | ||
lhs.id == rhs.id | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
extension AuthenticationChallengeController: URLSessionDelegate { | ||
|
||
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { | ||
handler(didReceive: challenge, completionHandler: completionHandler) | ||
} | ||
|
||
} | ||
|
||
|
||
extension AuthenticationChallengeController: WKNavigationDelegate { | ||
|
||
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { | ||
handler(didReceive: challenge, completionHandler: completionHandler) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.