-
Notifications
You must be signed in to change notification settings - Fork 89
KM-17461: decouple VPN permission grant from server list availability #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
48 changes: 48 additions & 0 deletions
48
LocalPackages/PIALibrary/Sources/PIALibrary/WebServices/Server+PermissionPlaceholder.swift
This file contains hidden or 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,48 @@ | ||
| // | ||
| // Server+PermissionPlaceholder.swift | ||
| // PIALibrary | ||
| // | ||
| // Copyright © 2026 Private Internet Access, Inc. | ||
| // | ||
| // This file is part of the Private Internet Access iOS Client. | ||
| // | ||
| // The Private Internet Access iOS Client is free software: you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License as published by the Free | ||
| // Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
| // | ||
| // The Private Internet Access iOS Client is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| // details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along with the Private | ||
| // Internet Access iOS Client. If not, see <https://www.gnu.org/licenses/>. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| extension Server { | ||
|
|
||
| /// Placeholder server used exclusively to obtain the one-time OS VPN permission | ||
| /// (`NEVPNManager.saveToPreferences()`) when the real server list has not been | ||
| /// downloaded yet — e.g. right after a fresh signup, when logout wiped the cache. | ||
| /// | ||
| /// The saved configuration is inert: `connect()` always re-resolves the real | ||
| /// `targetServer` and re-saves the profile before starting the tunnel, so this | ||
| /// endpoint is never actually dialed. | ||
| /// | ||
| /// The hostname uses the RFC 6761 reserved `.invalid` TLD: it can never resolve | ||
| /// and never collides with PIA-domain checks such as `needsMigrationToGEN4()`. | ||
| /// Computed (not `static let`) because `Server` is a mutable class — each access | ||
| /// returns a fresh instance instead of a shared, mutable process-wide one. | ||
| static var vpnPermissionPlaceholder: Server { | ||
| Server( | ||
| serial: "", | ||
| name: "VPN Permission Placeholder", | ||
| country: "us", | ||
| hostname: "vpn-permission-placeholder.invalid", | ||
| pingAddress: nil, | ||
| regionIdentifier: "vpn-permission-placeholder" | ||
| ) | ||
| } | ||
| } |
111 changes: 111 additions & 0 deletions
111
LocalPackages/PIALibrary/Tests/PIALibraryTests/VPNPermissionPlaceholderTests.swift
This file contains hidden or 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,111 @@ | ||
| // | ||
| // VPNPermissionPlaceholderTests.swift | ||
| // PIALibraryTests | ||
| // | ||
| // Copyright © 2026 Private Internet Access, Inc. | ||
| // | ||
| // This file is part of the Private Internet Access iOS Client. | ||
| // | ||
| // The Private Internet Access iOS Client is free software: you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License as published by the Free | ||
| // Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
| // | ||
| // The Private Internet Access iOS Client is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| // details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along with the Private | ||
| // Internet Access iOS Client. If not, see <https://www.gnu.org/licenses/>. | ||
| // | ||
|
|
||
| // PIATunnelProfile and PIAWGTunnelProfile are only declared for iOS. | ||
| #if os(iOS) | ||
|
|
||
| import TunnelKitCore | ||
| import TunnelKitOpenVPN | ||
| import XCTest | ||
|
|
||
| @testable import PIALibrary | ||
|
|
||
| /// Locks the invariant behind the VPN-permission placeholder (KM-17461): a profile | ||
| /// generated from `Server.vpnPermissionPlaceholder` must always carry a non-empty | ||
| /// `serverAddress`, so the OS profile save that grants the one-time VPN permission | ||
| /// cannot fail or persist an empty endpoint when the server list is unavailable. | ||
| class VPNPermissionPlaceholderTests: XCTestCase { | ||
|
|
||
| private var previousLastServerCN: String? | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
|
|
||
| Client.database = Client.Database(group: "group.com.privateinternetaccess") | ||
| Client.providers.accountProvider = MockAccountProvider() | ||
| Client.providers.vpnProvider = MockVPNProvider() | ||
|
|
||
| // generatedProtocol persists lastServerCN as a side effect; keep other | ||
| // tests isolated from the placeholder's empty CN. | ||
| previousLastServerCN = Client.database.plain.lastServerCN | ||
| } | ||
|
|
||
| override func tearDown() { | ||
| Client.database.plain.lastServerCN = previousLastServerCN | ||
| super.tearDown() | ||
| } | ||
|
|
||
| private func makeConfiguration(customConfiguration: VPNCustomConfiguration? = nil) -> VPNConfiguration { | ||
| VPNConfiguration( | ||
| name: "PIA Test", | ||
| username: "p0000000", | ||
| passwordReference: Data(), | ||
| server: .vpnPermissionPlaceholder, | ||
| isOnDemand: false, | ||
| disconnectsOnSleep: false, | ||
| customConfiguration: customConfiguration, | ||
| leakProtection: false, | ||
| allowLocalDeviceAccess: false | ||
| ) | ||
| } | ||
|
|
||
| /// Mirrors the session configuration the app passes in production | ||
| /// (`AppConfiguration.VPN.piaDefaultConfigurationBuilder`), so the test walks the | ||
| /// real `endpointProtocols` / `bestAddressForOVPN(tcp:)` branch and not just the | ||
| /// trivial no-custom-configuration path. | ||
| private func makeOpenVPNConfiguration() -> OpenVPNProvider.Configuration { | ||
| var sessionBuilder = OpenVPN.ConfigurationBuilder() | ||
| sessionBuilder.cipher = .aes128gcm | ||
| sessionBuilder.digest = .sha256 | ||
| sessionBuilder.endpointProtocols = [ | ||
| EndpointProtocol(.udp, 8080), | ||
| EndpointProtocol(.tcp, 443) | ||
| ] | ||
| sessionBuilder.usesPIAPatches = true | ||
| return OpenVPNProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()).build() | ||
| } | ||
|
|
||
| func testPlaceholderServerHasNonEmptyHostname() { | ||
| XCTAssertFalse(Server.vpnPermissionPlaceholder.hostname.isEmpty) | ||
| // RFC 6761 reserved TLD: never resolves, never matches PIA-domain checks | ||
| // such as needsMigrationToGEN4(). | ||
| XCTAssertTrue(Server.vpnPermissionPlaceholder.hostname.hasSuffix(".invalid")) | ||
| XCTAssertFalse(Server.vpnPermissionPlaceholder.hostname.contains("privateinternetaccess.com")) | ||
| } | ||
|
|
||
| func testWireGuardGeneratedProtocolFallsBackToPlaceholderHostname() throws { | ||
| let profile = PIAWGTunnelProfile(bundleIdentifier: "com.test.wg-tunnel") | ||
| let proto = try profile.generatedProtocol(withConfiguration: makeConfiguration()) | ||
|
|
||
| XCTAssertEqual(proto.serverAddress, Server.vpnPermissionPlaceholder.hostname) | ||
| } | ||
|
|
||
| func testOpenVPNGeneratedProtocolFallsBackToPlaceholderHostname() { | ||
| let profile = PIATunnelProfile(bundleIdentifier: "com.test.ovpn-tunnel") | ||
| let configuration = makeConfiguration(customConfiguration: makeOpenVPNConfiguration()) | ||
| let proto = profile.generatedProtocol(withConfiguration: configuration) | ||
|
|
||
| XCTAssertEqual(proto.serverAddress, Server.vpnPermissionPlaceholder.hostname) | ||
| XCTAssertNotEqual(proto.serverAddress, "") | ||
| } | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.