-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement packet capture client and models
- Loading branch information
1 parent
966a56c
commit dc55447
Showing
13 changed files
with
792 additions
and
48 deletions.
There are no files selected for viewing
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
22 changes: 0 additions & 22 deletions
22
ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// SafariApp.swift | ||
// MullvadVPNUITests | ||
// | ||
// Created by Niklas Berglund on 2024-05-31. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
|
||
class SafariApp { | ||
let app = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari") | ||
|
||
func launch() { | ||
app.launch() | ||
} | ||
|
||
@discardableResult func tapAddressBar() -> Self { | ||
app.textFields.firstMatch.tap() | ||
return self | ||
} | ||
|
||
@discardableResult func enterText(_ text: String) -> Self { | ||
app.typeText(text) | ||
return self | ||
} | ||
} |
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,76 @@ | ||
// | ||
// LeakTests.swift | ||
// MullvadVPNUITests | ||
// | ||
// Created by Niklas Berglund on 2024-05-31. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
|
||
class LeakTests: LoggedInWithTimeUITestCase { | ||
override func tearDown() { | ||
FirewallAPIClient().removeRules() | ||
} | ||
|
||
/// Send UDP traffic to a host, connect to relay and make sure while connected to relay no traffic leaked went directly to the host | ||
func testNegativeLeaks() throws { | ||
let testIpAddress = Networking.getAlwaysReachableIPAddress() | ||
FirewallAPIClient().createRule(try FirewallRule.makeBlockAllTrafficRule(toIPAddress: testIpAddress)) | ||
startPacketCapture() | ||
let trafficGenerator = TrafficGenerator(destinationHost: testIpAddress, port: 80) | ||
trafficGenerator.startGeneratingUDPTraffic(interval: 1.0) | ||
|
||
TunnelControlPage(app) | ||
.tapSecureConnectionButton() | ||
|
||
allowAddVPNConfigurationsIfAsked() | ||
|
||
TunnelControlPage(app) | ||
.waitForSecureConnectionLabel() | ||
let connectedDate = Date() | ||
|
||
let relayIPAddress = TunnelControlPage(app) | ||
.getInIPAddressFromConnectionStatus() | ||
|
||
// Keep the tunnel connection for a while | ||
Thread.sleep(forTimeInterval: 5.0) | ||
|
||
app.launch() | ||
TunnelControlPage(app) | ||
.tapDisconnectButton() | ||
let disconnectedDate = Date() | ||
|
||
// Keep the capture open for a while | ||
Thread.sleep(forTimeInterval: 3.0) | ||
trafficGenerator.stopGeneratingUDPTraffic() | ||
|
||
let capturedStreamCollection = stopPacketCapture() | ||
|
||
do { | ||
let relayConnectionDateInterval = try capturedStreamCollection | ||
.getConnectedThroughRelayDateInterval( | ||
relayIPAddress: relayIPAddress | ||
) | ||
|
||
// Get traffic from time window of connection with some leeway | ||
let secondsLeeway = 2.0 | ||
let connectedDateWithLeeway = relayConnectionDateInterval.start.addingTimeInterval(secondsLeeway) | ||
let disconnectedDateWithLeeway = relayConnectionDateInterval.end.addingTimeInterval(-secondsLeeway) | ||
let connectedToRelayDateIntervalWithLeeway = DateInterval( | ||
start: connectedDateWithLeeway, | ||
end: disconnectedDateWithLeeway | ||
) | ||
let connectedThroughRelayStreamCollection = capturedStreamCollection.extractStreamCollectionFrom( | ||
connectedToRelayDateIntervalWithLeeway, | ||
cutOffPacketsOverflow: true | ||
) | ||
|
||
// Treat any traffic to the test IP address during the connected time window as leak | ||
connectedThroughRelayStreamCollection.dontAllowTrafficFromTestDevice(to: testIpAddress) | ||
connectedThroughRelayStreamCollection.verifyDontHaveLeaks() | ||
} catch { | ||
XCTFail("Unexpectedly didn't find any traffic between test device and relay") | ||
} | ||
} | ||
} |
Oops, something went wrong.