summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBug Magnet <marco.nikic@mullvad.net>2024-01-23 15:08:24 +0100
committerBug Magnet <marco.nikic@mullvad.net>2024-01-23 15:08:24 +0100
commit3a74932c162db828afe3bc54bcd5ba44af0cd657 (patch)
treee1487a35bba657950e51cb670fad48f416024c14
parent14c7cd43130f63462ed3d09e4d4b38bd0a301af2 (diff)
parent986e7d5cbb1645e2f8fbd736248dad816420ab29 (diff)
downloadmullvadvpn-3a74932c162db828afe3bc54bcd5ba44af0cd657.tar.xz
mullvadvpn-3a74932c162db828afe3bc54bcd5ba44af0cd657.zip
Merge branch 'refacorting-socks5-authentication-data-structure-455'
-rw-r--r--ios/MullvadREST/Transport/TransportStrategy.swift15
-rw-r--r--ios/MullvadRESTTests/TransportStrategyTests.swift9
-rw-r--r--ios/MullvadSettings/PersistentAccessMethod.swift19
-rw-r--r--ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/AccessMethodViewModel+Persistent.swift5
-rw-r--r--ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/PersistentProxyConfiguration+ViewModel.swift6
5 files changed, 35 insertions, 19 deletions
diff --git a/ios/MullvadREST/Transport/TransportStrategy.swift b/ios/MullvadREST/Transport/TransportStrategy.swift
index acb132acab..a41139a41d 100644
--- a/ios/MullvadREST/Transport/TransportStrategy.swift
+++ b/ios/MullvadREST/Transport/TransportStrategy.swift
@@ -91,16 +91,11 @@ public class TransportStrategy: Equatable {
cipher: configuration.cipher.rawValue.description
))
case let .socks5(configuration):
- switch configuration.authentication {
- case .noAuthentication:
- return .socks5(configuration: Socks5Configuration(proxyEndpoint: configuration.toAnyIPEndpoint))
- case let .usernamePassword(username, password):
- return .socks5(configuration: Socks5Configuration(
- proxyEndpoint: configuration.toAnyIPEndpoint,
- username: username,
- password: password
- ))
- }
+ return .socks5(configuration: Socks5Configuration(
+ proxyEndpoint: configuration.toAnyIPEndpoint,
+ username: configuration.credential?.username,
+ password: configuration.credential?.password
+ ))
}
}
diff --git a/ios/MullvadRESTTests/TransportStrategyTests.swift b/ios/MullvadRESTTests/TransportStrategyTests.swift
index 9acc9e4437..721cd5b904 100644
--- a/ios/MullvadRESTTests/TransportStrategyTests.swift
+++ b/ios/MullvadRESTTests/TransportStrategyTests.swift
@@ -196,10 +196,11 @@ class TransportStrategyTests: XCTestCase {
func testUsesSocks5WithAuthenticationWhenItReaches() throws {
let username = "user"
let password = "pass"
- let authentication = PersistentProxyConfiguration.SocksAuthentication.usernamePassword(
- username: username,
- password: password
- )
+ let authentication = PersistentProxyConfiguration.SocksAuthentication
+ .authentication(PersistentProxyConfiguration.UserCredential(
+ username: username,
+ password: password
+ ))
let socks5Configuration = PersistentProxyConfiguration.SocksConfiguration(
server: .ipv4(.loopback),
port: 1080,
diff --git a/ios/MullvadSettings/PersistentAccessMethod.swift b/ios/MullvadSettings/PersistentAccessMethod.swift
index ba61988900..6728552375 100644
--- a/ios/MullvadSettings/PersistentAccessMethod.swift
+++ b/ios/MullvadSettings/PersistentAccessMethod.swift
@@ -55,7 +55,17 @@ extension PersistentProxyConfiguration {
/// Socks autentication method.
public enum SocksAuthentication: Codable {
case noAuthentication
- case usernamePassword(username: String, password: String)
+ case authentication(UserCredential)
+ }
+
+ public struct UserCredential: Codable {
+ public let username: String
+ public let password: String
+
+ public init(username: String, password: String) {
+ self.username = username
+ self.password = password
+ }
}
/// Socks v5 proxy configuration.
@@ -75,6 +85,13 @@ extension PersistentProxyConfiguration {
self.authentication = authentication
}
+ public var credential: UserCredential? {
+ guard case let .authentication(credential) = authentication else {
+ return nil
+ }
+ return credential
+ }
+
public var toAnyIPEndpoint: AnyIPEndpoint {
switch server {
case let .ipv4(ip):
diff --git a/ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/AccessMethodViewModel+Persistent.swift b/ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/AccessMethodViewModel+Persistent.swift
index 848986af18..8683e70a1c 100644
--- a/ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/AccessMethodViewModel+Persistent.swift
+++ b/ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/AccessMethodViewModel+Persistent.swift
@@ -87,7 +87,10 @@ extension AccessMethodViewModel.Socks {
context: context
))
} else {
- draftConfiguration.authentication = .usernamePassword(username: username, password: password)
+ draftConfiguration.authentication = .authentication(PersistentProxyConfiguration.UserCredential(
+ username: username,
+ password: password
+ ))
}
}
diff --git a/ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/PersistentProxyConfiguration+ViewModel.swift b/ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/PersistentProxyConfiguration+ViewModel.swift
index 2bb7e763ba..43b1e72489 100644
--- a/ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/PersistentProxyConfiguration+ViewModel.swift
+++ b/ios/MullvadVPN/Coordinators/Settings/APIAccess/Models/PersistentProxyConfiguration+ViewModel.swift
@@ -22,9 +22,9 @@ extension PersistentProxyConfiguration {
)
switch config.authentication {
- case let .usernamePassword(username, password):
- socks.username = username
- socks.password = password
+ case let .authentication(userCredential):
+ socks.username = userCredential.username
+ socks.password = userCredential.password
socks.authenticate = true
case .noAuthentication: