Updated the OpenGroupAPI to always use authentication and default to blinded when no capabilities are present

This commit is contained in:
Morgan Pretty 2022-10-24 15:24:46 +11:00
parent 1b350cf422
commit 301ae76b0f
4 changed files with 3 additions and 20 deletions

View file

@ -190,7 +190,6 @@ public enum OpenGroupAPI {
_ db: Database,
server: String,
requests: [BatchRequestInfoType],
authenticated: Bool = true,
using dependencies: SMKDependencies = SMKDependencies()
) -> Promise<[Endpoint: (OnionRequestResponseInfoType, Codable?)]> {
let requestBody: BatchRequest = requests.map { $0.toSubRequest() }
@ -205,7 +204,6 @@ public enum OpenGroupAPI {
endpoint: Endpoint.sequence,
body: requestBody
),
authenticated: authenticated,
using: dependencies
)
.decoded(as: responseTypes, on: OpenGroupAPI.workQueue, using: dependencies)
@ -229,7 +227,6 @@ public enum OpenGroupAPI {
public static func capabilities(
_ db: Database,
server: String,
authenticated: Bool = true,
using dependencies: SMKDependencies = SMKDependencies()
) -> Promise<(OnionRequestResponseInfoType, Capabilities)> {
return OpenGroupAPI
@ -239,7 +236,6 @@ public enum OpenGroupAPI {
server: server,
endpoint: .capabilities
),
authenticated: authenticated,
using: dependencies
)
.decoded(as: Capabilities.self, on: OpenGroupAPI.workQueue, using: dependencies)
@ -325,7 +321,6 @@ public enum OpenGroupAPI {
_ db: Database,
for roomToken: String,
on server: String,
authenticated: Bool = true,
using dependencies: SMKDependencies = SMKDependencies()
) -> Promise<(capabilities: (info: OnionRequestResponseInfoType, data: Capabilities), room: (info: OnionRequestResponseInfoType, data: Room))> {
let requestResponseType: [BatchRequestInfoType] = [
@ -353,7 +348,6 @@ public enum OpenGroupAPI {
db,
server: server,
requests: requestResponseType,
authenticated: authenticated,
using: dependencies
)
.map { (response: [Endpoint: (OnionRequestResponseInfoType, Codable?)]) -> (capabilities: (OnionRequestResponseInfoType, Capabilities), room: (OnionRequestResponseInfoType, Room)) in
@ -391,7 +385,6 @@ public enum OpenGroupAPI {
public static func capabilitiesAndRooms(
_ db: Database,
on server: String,
authenticated: Bool = true,
using dependencies: SMKDependencies = SMKDependencies()
) -> Promise<(capabilities: (info: OnionRequestResponseInfoType, data: Capabilities), rooms: (info: OnionRequestResponseInfoType, data: [Room]))> {
let requestResponseType: [BatchRequestInfoType] = [
@ -419,7 +412,6 @@ public enum OpenGroupAPI {
db,
server: server,
requests: requestResponseType,
authenticated: authenticated,
using: dependencies
)
.map { (response: [Endpoint: (OnionRequestResponseInfoType, Codable?)]) -> (capabilities: (OnionRequestResponseInfoType, Capabilities), rooms: (OnionRequestResponseInfoType, [Room])) in
@ -1286,8 +1278,8 @@ public enum OpenGroupAPI {
.fetchSet(db))
.defaulting(to: [])
// Check if the server supports blinded keys, if so then sign using the blinded key
if capabilities.contains(.blind) {
// If we have no capabilities or if the server supports blinded keys then sign using the blinded key
if capabilities.isEmpty || capabilities.contains(.blind) {
guard let blindedKeyPair: Box.KeyPair = dependencies.sodium.blindedKeyPair(serverPublicKey: serverPublicKey, edKeyPair: userEdKeyPair, genericHash: dependencies.genericHash) else {
return nil
}
@ -1394,7 +1386,6 @@ public enum OpenGroupAPI {
private static func send<T: Encodable>(
_ db: Database,
request: Request<T, Endpoint>,
authenticated: Bool = true,
using dependencies: SMKDependencies = SMKDependencies()
) -> Promise<(OnionRequestResponseInfoType, Data?)> {
let urlRequest: URLRequest
@ -1414,11 +1405,6 @@ public enum OpenGroupAPI {
guard let publicKey: String = maybePublicKey else { return Promise(error: OpenGroupAPIError.noPublicKey) }
// If we don't want to authenticate the request then send it immediately
guard authenticated else {
return dependencies.onionApi.sendOnionRequest(urlRequest, to: request.server, with: publicKey)
}
// Attempt to sign the request with the new auth
guard let signedRequest: URLRequest = sign(db, request: urlRequest, for: request.server, with: publicKey, using: dependencies) else {
return Promise(error: OpenGroupAPIError.signingFailed)

View file

@ -252,7 +252,6 @@ public final class OpenGroupManager: NSObject {
db,
for: roomToken,
on: targetServer,
authenticated: false,
using: dependencies
)
}
@ -935,7 +934,6 @@ public final class OpenGroupManager: NSObject {
OpenGroupAPI.capabilitiesAndRooms(
db,
on: OpenGroupAPI.defaultServer,
authenticated: false,
using: dependencies
)
}

View file

@ -361,7 +361,7 @@ public final class MessageSender {
.defaulting(to: [])
// If the server doesn't support blinding then go with an unblinded id
guard capabilities.contains(.blind) else {
guard capabilities.isEmpty || capabilities.contains(.blind) else {
return SessionId(.unblinded, publicKey: userEdKeyPair.publicKey).hexString
}
guard let blindedKeyPair: Box.KeyPair = dependencies.sodium.blindedKeyPair(serverPublicKey: openGroup.publicKey, edKeyPair: userEdKeyPair, genericHash: dependencies.genericHash) else {

View file

@ -213,7 +213,6 @@ extension OpenGroupAPI {
OpenGroupAPI.capabilities(
db,
server: server,
authenticated: false,
using: dependencies
)
}