mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 16:42:44 +02:00
CrossSigningService: Add method to setup cross-signing without authentication.
This commit is contained in:
@@ -16,6 +16,23 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
enum CrossSigningServiceError: Int, Error {
|
||||
case authenticationRequired
|
||||
case unknown
|
||||
}
|
||||
|
||||
extension CrossSigningServiceError: CustomNSError {
|
||||
public static let errorDomain = "CrossSigningService"
|
||||
|
||||
public var errorCode: Int {
|
||||
return Int(rawValue)
|
||||
}
|
||||
|
||||
public var errorUserInfo: [String: Any] {
|
||||
return [:]
|
||||
}
|
||||
}
|
||||
|
||||
@objcMembers
|
||||
final class CrossSigningService: NSObject {
|
||||
|
||||
@@ -63,4 +80,37 @@ final class CrossSigningService: NSObject {
|
||||
let path = "\(kMXAPIPrefixPathUnstable)/keys/device_signing/upload"
|
||||
return AuthenticationSessionParameters(path: path, httpMethod: "POST")
|
||||
}
|
||||
|
||||
/// Setup cross-signing without authentication. Useful when a grace period is enabled.
|
||||
@discardableResult
|
||||
func setupCrossSigningWithoutAuthentication(for session: MXSession, success: @escaping (() -> Void), failure: @escaping ((Error) -> Void)) -> MXHTTPOperation? {
|
||||
|
||||
guard let crossSigning = session.crypto.crossSigning else {
|
||||
failure(CrossSigningServiceError.unknown)
|
||||
return nil
|
||||
}
|
||||
|
||||
let authenticationSessionService = AuthenticationSessionService(session: session)
|
||||
self.authenticationSessionService = authenticationSessionService
|
||||
|
||||
let authenticationSessionParameters = self.setupCrossSigningAuthenticationSessionParameters()
|
||||
|
||||
return authenticationSessionService.authenticationSession(for: authenticationSessionParameters) { result in
|
||||
switch result {
|
||||
case .success(let authenticationSessionResult):
|
||||
switch authenticationSessionResult {
|
||||
case .authenticationNeeded:
|
||||
failure(CrossSigningServiceError.authenticationRequired)
|
||||
case .authenticationNotNeeded:
|
||||
crossSigning.setup(withAuthParams: [:]) {
|
||||
success()
|
||||
} failure: { error in
|
||||
failure(error)
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
failure(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user