diff --git a/ios/MullvadRustRuntimeTests/MullvadPostQuantum+Stubs.swift b/ios/MullvadRustRuntimeTests/MullvadPostQuantum+Stubs.swift index 683e1ab8de61..284588624d55 100644 --- a/ios/MullvadRustRuntimeTests/MullvadPostQuantum+Stubs.swift +++ b/ios/MullvadRustRuntimeTests/MullvadPostQuantum+Stubs.swift @@ -27,6 +27,19 @@ class NWTCPConnectionStub: NWTCPConnection { } class TunnelProviderStub: TunnelProvider { + func tunnelHandle() throws -> Int32 { + 0 + } + + func wgFuncs() -> MullvadTypes.WgFuncPointers { + return MullvadTypes.WgFuncPointers( + open: { _, _, _ in return 0 }, + close: { _, _ in return 0 }, + receive: { _, _, _, _ in return 0 }, + send: { _, _, _, _ in return 0 } + ) + } + let tcpConnection: NWTCPConnectionStub init(tcpConnection: NWTCPConnectionStub) { @@ -55,15 +68,13 @@ class FailedNegotiatorStub: EphemeralPeerNegotiating { } func startNegotiation( - gatewayIP: IPv4Address, devicePublicKey: WireGuardKitTypes.PublicKey, presharedKey: WireGuardKitTypes.PrivateKey, - peerReceiver packetTunnel: any MullvadTypes.TunnelProvider, - tcpConnection: NWTCPConnection, - peerExchangeTimeout: MullvadTypes.Duration, - enablePostQuantum: Bool, - enableDaita: Bool - ) -> Bool { false } + peerReceiver: any MullvadTypes.TunnelProvider, + ephemeralPeerParams: EphemeralPeerParameters + ) -> Bool { + false + } func cancelKeyNegotiation() { onCancelKeyNegotiation?() @@ -81,15 +92,13 @@ class SuccessfulNegotiatorStub: EphemeralPeerNegotiating { } func startNegotiation( - gatewayIP: IPv4Address, devicePublicKey: WireGuardKitTypes.PublicKey, presharedKey: WireGuardKitTypes.PrivateKey, - peerReceiver packetTunnel: any MullvadTypes.TunnelProvider, - tcpConnection: NWTCPConnection, - peerExchangeTimeout: MullvadTypes.Duration, - enablePostQuantum: Bool, - enableDaita: Bool - ) -> Bool { true } + peerReceiver: any MullvadTypes.TunnelProvider, + ephemeralPeerParams: EphemeralPeerParameters + ) -> Bool { + true + } func cancelKeyNegotiation() { onCancelKeyNegotiation?() diff --git a/ios/PacketTunnelCoreTests/EphemeralPeerExchangingPipelineTests.swift b/ios/PacketTunnelCoreTests/EphemeralPeerExchangingPipelineTests.swift index 2af86eedfe42..bbce8c8b44f7 100644 --- a/ios/PacketTunnelCoreTests/EphemeralPeerExchangingPipelineTests.swift +++ b/ios/PacketTunnelCoreTests/EphemeralPeerExchangingPipelineTests.swift @@ -60,7 +60,7 @@ final class EphemeralPeerExchangingPipelineTests: XCTestCase { ) } - func testSingleHopPostQuantumKeyExchange() throws { + func testSingleHopPostQuantumKeyExchange() async throws { let reconfigurationExpectation = expectation(description: "Tunnel reconfiguration took place") reconfigurationExpectation.expectedFulfillmentCount = 2 @@ -78,11 +78,11 @@ final class EphemeralPeerExchangingPipelineTests: XCTestCase { } keyExchangeActor.delegate = KeyExchangingResultStub(onReceivePostQuantumKey: { preSharedKey, privateKey in - postQuantumKeyExchangingPipeline.receivePostQuantumKey(preSharedKey, ephemeralKey: privateKey) + await postQuantumKeyExchangingPipeline.receivePostQuantumKey(preSharedKey, ephemeralKey: privateKey) }) let connectionState = stubConnectionState(enableMultiHop: false, enablePostQuantum: true, enableDaita: false) - postQuantumKeyExchangingPipeline.startNegotiation(connectionState, privateKey: PrivateKey()) + await postQuantumKeyExchangingPipeline.startNegotiation(connectionState, privateKey: PrivateKey()) wait( for: [reconfigurationExpectation, negotiationSuccessful], @@ -90,7 +90,7 @@ final class EphemeralPeerExchangingPipelineTests: XCTestCase { ) } - func testSingleHopDaitaPeerExchange() throws { + func testSingleHopDaitaPeerExchange() async throws { let reconfigurationExpectation = expectation(description: "Tunnel reconfiguration took place") reconfigurationExpectation.expectedFulfillmentCount = 2 @@ -108,11 +108,11 @@ final class EphemeralPeerExchangingPipelineTests: XCTestCase { } keyExchangeActor.delegate = KeyExchangingResultStub(onReceiveEphemeralPeerPrivateKey: { privateKey in - postQuantumKeyExchangingPipeline.receiveEphemeralPeerPrivateKey(privateKey) + await postQuantumKeyExchangingPipeline.receiveEphemeralPeerPrivateKey(privateKey) }) let connectionState = stubConnectionState(enableMultiHop: false, enablePostQuantum: false, enableDaita: true) - postQuantumKeyExchangingPipeline.startNegotiation(connectionState, privateKey: PrivateKey()) + await postQuantumKeyExchangingPipeline.startNegotiation(connectionState, privateKey: PrivateKey()) wait( for: [reconfigurationExpectation, negotiationSuccessful], @@ -120,7 +120,7 @@ final class EphemeralPeerExchangingPipelineTests: XCTestCase { ) } - func testMultiHopPostQuantumKeyExchange() throws { + func testMultiHopPostQuantumKeyExchange() async throws { let reconfigurationExpectation = expectation(description: "Tunnel reconfiguration took place") reconfigurationExpectation.expectedFulfillmentCount = 3 @@ -138,11 +138,11 @@ final class EphemeralPeerExchangingPipelineTests: XCTestCase { } keyExchangeActor.delegate = KeyExchangingResultStub(onReceivePostQuantumKey: { preSharedKey, privateKey in - postQuantumKeyExchangingPipeline.receivePostQuantumKey(preSharedKey, ephemeralKey: privateKey) + await postQuantumKeyExchangingPipeline.receivePostQuantumKey(preSharedKey, ephemeralKey: privateKey) }) let connectionState = stubConnectionState(enableMultiHop: true, enablePostQuantum: true, enableDaita: false) - postQuantumKeyExchangingPipeline.startNegotiation(connectionState, privateKey: PrivateKey()) + await postQuantumKeyExchangingPipeline.startNegotiation(connectionState, privateKey: PrivateKey()) wait( for: [reconfigurationExpectation, negotiationSuccessful], @@ -150,7 +150,7 @@ final class EphemeralPeerExchangingPipelineTests: XCTestCase { ) } - func testMultiHopDaitaExchange() throws { + func testMultiHopDaitaExchange() async throws { let reconfigurationExpectation = expectation(description: "Tunnel reconfiguration took place") reconfigurationExpectation.expectedFulfillmentCount = 3 @@ -168,11 +168,11 @@ final class EphemeralPeerExchangingPipelineTests: XCTestCase { } keyExchangeActor.delegate = KeyExchangingResultStub(onReceiveEphemeralPeerPrivateKey: { privateKey in - postQuantumKeyExchangingPipeline.receiveEphemeralPeerPrivateKey(privateKey) + await postQuantumKeyExchangingPipeline.receiveEphemeralPeerPrivateKey(privateKey) }) let connectionState = stubConnectionState(enableMultiHop: true, enablePostQuantum: false, enableDaita: true) - postQuantumKeyExchangingPipeline.startNegotiation(connectionState, privateKey: PrivateKey()) + await postQuantumKeyExchangingPipeline.startNegotiation(connectionState, privateKey: PrivateKey()) wait( for: [reconfigurationExpectation, negotiationSuccessful], diff --git a/ios/PacketTunnelCoreTests/Mocks/EphemeralPeerExchangeActorStub.swift b/ios/PacketTunnelCoreTests/Mocks/EphemeralPeerExchangeActorStub.swift index 7f17af56bec8..2f217488200e 100644 --- a/ios/PacketTunnelCoreTests/Mocks/EphemeralPeerExchangeActorStub.swift +++ b/ios/PacketTunnelCoreTests/Mocks/EphemeralPeerExchangeActorStub.swift @@ -22,9 +22,9 @@ final class EphemeralPeerExchangeActorStub: EphemeralPeerExchangeActorProtocol { switch result { case let .success((preSharedKey, ephemeralKey)): if enablePostQuantum { - delegate?.receivePostQuantumKey(preSharedKey, ephemeralKey: ephemeralKey) + Task { await delegate?.receivePostQuantumKey(preSharedKey, ephemeralKey: ephemeralKey) } } else { - delegate?.receiveEphemeralPeerPrivateKey(ephemeralKey) + Task { await delegate?.receiveEphemeralPeerPrivateKey(ephemeralKey) } } case .failure: delegate?.ephemeralPeerExchangeFailed() diff --git a/ios/PacketTunnelCoreTests/Mocks/KeyExchangingResultStub.swift b/ios/PacketTunnelCoreTests/Mocks/KeyExchangingResultStub.swift index 9dc9dca58c82..250524ec0677 100644 --- a/ios/PacketTunnelCoreTests/Mocks/KeyExchangingResultStub.swift +++ b/ios/PacketTunnelCoreTests/Mocks/KeyExchangingResultStub.swift @@ -12,15 +12,15 @@ struct KeyExchangingResultStub: EphemeralPeerReceiving { var onFailure: (() -> Void)? - var onReceivePostQuantumKey: ((PreSharedKey, PrivateKey) -> Void)? - var onReceiveEphemeralPeerPrivateKey: ((PrivateKey) -> Void)? + var onReceivePostQuantumKey: ((PreSharedKey, PrivateKey) async -> Void)? + var onReceiveEphemeralPeerPrivateKey: ((PrivateKey) async -> Void)? - func receivePostQuantumKey(_ key: PreSharedKey, ephemeralKey: PrivateKey) { - onReceivePostQuantumKey?(key, ephemeralKey) + func receivePostQuantumKey(_ key: PreSharedKey, ephemeralKey: PrivateKey) async { + await onReceivePostQuantumKey?(key, ephemeralKey) } - public func receiveEphemeralPeerPrivateKey(_ ephemeralPeerPrivateKey: PrivateKey) { - onReceiveEphemeralPeerPrivateKey?(ephemeralPeerPrivateKey) + public func receiveEphemeralPeerPrivateKey(_ ephemeralPeerPrivateKey: PrivateKey) async { + await onReceiveEphemeralPeerPrivateKey?(ephemeralPeerPrivateKey) } func ephemeralPeerExchangeFailed() { diff --git a/ios/PacketTunnelCoreTests/MultiHopEphemeralPeerExchangerTests.swift b/ios/PacketTunnelCoreTests/MultiHopEphemeralPeerExchangerTests.swift index a4c1d09155ee..c55f5b4d6566 100644 --- a/ios/PacketTunnelCoreTests/MultiHopEphemeralPeerExchangerTests.swift +++ b/ios/PacketTunnelCoreTests/MultiHopEphemeralPeerExchangerTests.swift @@ -59,7 +59,7 @@ final class MultiHopEphemeralPeerExchangerTests: XCTestCase { ) } - func testEphemeralPeerExchangeFailsWhenNegotiationCannotStart() { + func testEphemeralPeerExchangeFailsWhenNegotiationCannotStart() async { let expectedNegotiationFailure = expectation(description: "Negotiation failed.") let reconfigurationExpectation = expectation(description: "Tunnel reconfiguration took place") @@ -88,7 +88,7 @@ final class MultiHopEphemeralPeerExchangerTests: XCTestCase { expectedNegotiationFailure.fulfill() } - multiHopExchanger.start() + await multiHopExchanger.start() wait( for: [expectedNegotiationFailure, reconfigurationExpectation, negotiationSuccessful], @@ -96,7 +96,7 @@ final class MultiHopEphemeralPeerExchangerTests: XCTestCase { ) } - func testEphemeralPeerExchangeSuccessWhenPostQuantumNegotiationStarts() throws { + func testEphemeralPeerExchangeSuccessWhenPostQuantumNegotiationStarts() async throws { let unexpectedNegotiationFailure = expectation(description: "Negotiation failed.") unexpectedNegotiationFailure.isInverted = true @@ -124,9 +124,9 @@ final class MultiHopEphemeralPeerExchangerTests: XCTestCase { } peerExchangeActor.delegate = KeyExchangingResultStub(onReceivePostQuantumKey: { preSharedKey, ephemeralKey in - multiHopPeerExchanger.receivePostQuantumKey(preSharedKey, ephemeralKey: ephemeralKey) + await multiHopPeerExchanger.receivePostQuantumKey(preSharedKey, ephemeralKey: ephemeralKey) }) - multiHopPeerExchanger.start() + await multiHopPeerExchanger.start() wait( for: [unexpectedNegotiationFailure, reconfigurationExpectation, negotiationSuccessful], @@ -134,7 +134,7 @@ final class MultiHopEphemeralPeerExchangerTests: XCTestCase { ) } - func testEphemeralPeerExchangeSuccessWhenDaitaNegotiationStarts() throws { + func testEphemeralPeerExchangeSuccessWhenDaitaNegotiationStarts() async throws { let unexpectedNegotiationFailure = expectation(description: "Negotiation failed.") unexpectedNegotiationFailure.isInverted = true @@ -162,9 +162,9 @@ final class MultiHopEphemeralPeerExchangerTests: XCTestCase { } peerExchangeActor.delegate = KeyExchangingResultStub(onReceiveEphemeralPeerPrivateKey: { ephemeralKey in - multiHopPeerExchanger.receiveEphemeralPeerPrivateKey(ephemeralKey) + await multiHopPeerExchanger.receiveEphemeralPeerPrivateKey(ephemeralKey) }) - multiHopPeerExchanger.start() + await multiHopPeerExchanger.start() wait( for: [unexpectedNegotiationFailure, reconfigurationExpectation, negotiationSuccessful], diff --git a/ios/PacketTunnelCoreTests/SingleHopEphemeralPeerExchangerTests.swift b/ios/PacketTunnelCoreTests/SingleHopEphemeralPeerExchangerTests.swift index 2ce3558fbac6..deb402abeb4a 100644 --- a/ios/PacketTunnelCoreTests/SingleHopEphemeralPeerExchangerTests.swift +++ b/ios/PacketTunnelCoreTests/SingleHopEphemeralPeerExchangerTests.swift @@ -38,7 +38,7 @@ final class SingleHopEphemeralPeerExchangerTests: XCTestCase { exitRelay = SelectedRelay(endpoint: match.endpoint, hostname: match.relay.hostname, location: match.location) } - func testEphemeralPeerExchangeFailsWhenNegotiationCannotStart() { + func testEphemeralPeerExchangeFailsWhenNegotiationCannotStart() async { let expectedNegotiationFailure = expectation(description: "Negotiation failed.") let reconfigurationExpectation = expectation(description: "Tunnel reconfiguration took place") @@ -66,7 +66,7 @@ final class SingleHopEphemeralPeerExchangerTests: XCTestCase { expectedNegotiationFailure.fulfill() } - singleHopPostQuantumKeyExchanging.start() + await singleHopPostQuantumKeyExchanging.start() wait( for: [expectedNegotiationFailure, reconfigurationExpectation, negotiationSuccessful], @@ -74,7 +74,7 @@ final class SingleHopEphemeralPeerExchangerTests: XCTestCase { ) } - func testEphemeralPeerExchangeSuccessWhenPostQuantumNegotiationStarts() throws { + func testEphemeralPeerExchangeSuccessWhenPostQuantumNegotiationStarts() async throws { let unexpectedNegotiationFailure = expectation(description: "Negotiation failed.") unexpectedNegotiationFailure.isInverted = true @@ -101,9 +101,9 @@ final class SingleHopEphemeralPeerExchangerTests: XCTestCase { } keyExchangeActor.delegate = KeyExchangingResultStub(onReceivePostQuantumKey: { preSharedKey, ephemeralKey in - singleHopPostQuantumKeyExchanging.receivePostQuantumKey(preSharedKey, ephemeralKey: ephemeralKey) + await singleHopPostQuantumKeyExchanging.receivePostQuantumKey(preSharedKey, ephemeralKey: ephemeralKey) }) - singleHopPostQuantumKeyExchanging.start() + await singleHopPostQuantumKeyExchanging.start() wait( for: [unexpectedNegotiationFailure, reconfigurationExpectation, negotiationSuccessful], @@ -111,7 +111,7 @@ final class SingleHopEphemeralPeerExchangerTests: XCTestCase { ) } - func testEphemeralPeerExchangeSuccessWhenDaitaNegotiationStarts() throws { + func testEphemeralPeerExchangeSuccessWhenDaitaNegotiationStarts() async throws { let unexpectedNegotiationFailure = expectation(description: "Negotiation failed.") unexpectedNegotiationFailure.isInverted = true @@ -138,9 +138,9 @@ final class SingleHopEphemeralPeerExchangerTests: XCTestCase { } peerExchangeActor.delegate = KeyExchangingResultStub(onReceiveEphemeralPeerPrivateKey: { ephemeralKey in - multiHopPeerExchanger.receiveEphemeralPeerPrivateKey(ephemeralKey) + await multiHopPeerExchanger.receiveEphemeralPeerPrivateKey(ephemeralKey) }) - multiHopPeerExchanger.start() + await multiHopPeerExchanger.start() wait( for: [unexpectedNegotiationFailure, reconfigurationExpectation, negotiationSuccessful],