summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/AccessMethodRepository
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2023-12-22 14:27:35 +0100
committerEmīls <emils@mullvad.net>2023-12-22 14:27:35 +0100
commit19b1e3ffc70eaba054b7e6e697c3dc16859c5381 (patch)
tree5e30920c506dd35a74bd3b5213066bee0e5c7883 /ios/MullvadVPN/AccessMethodRepository
parent9d71eccc2f3507928b833f969c952347c7a76d4c (diff)
parent12a6969b45a9c7bdea0e408567ec309922e549d7 (diff)
downloadmullvadvpn-19b1e3ffc70eaba054b7e6e697c3dc16859c5381.tar.xz
mullvadvpn-19b1e3ffc70eaba054b7e6e697c3dc16859c5381.zip
Merge branch 'moving-users-access-methods-configuration-into-ios-420'
Diffstat (limited to 'ios/MullvadVPN/AccessMethodRepository')
-rw-r--r--ios/MullvadVPN/AccessMethodRepository/AccessMethodRepositoryProtocol.swift36
-rw-r--r--ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift124
-rw-r--r--ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTester.swift1
-rw-r--r--ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTesterProtocol.swift1
-rw-r--r--ios/MullvadVPN/AccessMethodRepository/ShadowsocksCipher.swift48
5 files changed, 2 insertions, 208 deletions
diff --git a/ios/MullvadVPN/AccessMethodRepository/AccessMethodRepositoryProtocol.swift b/ios/MullvadVPN/AccessMethodRepository/AccessMethodRepositoryProtocol.swift
deleted file mode 100644
index 213f524bcc..0000000000
--- a/ios/MullvadVPN/AccessMethodRepository/AccessMethodRepositoryProtocol.swift
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// AccessMethodRepositoryProtocol.swift
-// MullvadVPN
-//
-// Created by pronebird on 28/11/2023.
-// Copyright © 2023 Mullvad VPN AB. All rights reserved.
-//
-
-import Combine
-import Foundation
-
-protocol AccessMethodRepositoryProtocol {
- /// Publisher that propagates a snapshot of persistent store upon modifications.
- var publisher: PassthroughSubject<[PersistentAccessMethod], Never> { get }
-
- /// Add new access method.
- /// - Parameter method: persistent access method model.
- func add(_ method: PersistentAccessMethod)
-
- /// Persist modified access method locating existing entry by id.
- /// - Parameter method: persistent access method model.
- func update(_ method: PersistentAccessMethod)
-
- /// Delete access method by id.
- /// - Parameter id: an access method id.
- func delete(id: UUID)
-
- /// Fetch access method by id.
- /// - Parameter id: an access method id.
- /// - Returns: a persistent access method model upon success, otherwise `nil`.
- func fetch(by id: UUID) -> PersistentAccessMethod?
-
- /// Fetch all access method from the persistent store.
- /// - Returns: an array of all persistent access method.
- func fetchAll() -> [PersistentAccessMethod]
-}
diff --git a/ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift b/ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift
deleted file mode 100644
index b5d5ef2947..0000000000
--- a/ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift
+++ /dev/null
@@ -1,124 +0,0 @@
-//
-// PersistentAccessMethod.swift
-// MullvadVPN
-//
-// Created by pronebird on 15/11/2023.
-// Copyright © 2023 Mullvad VPN AB. All rights reserved.
-//
-
-import Foundation
-import MullvadTypes
-import Network
-
-/// Persistent access method model.
-struct PersistentAccessMethod: Identifiable, Codable {
- /// The unique identifier used for referencing the access method entry in a persistent store.
- var id: UUID
-
- /// The user-defined name for access method.
- var name: String
-
- /// The flag indicating whether configuration is enabled.
- var isEnabled: Bool
-
- /// Proxy configuration.
- var proxyConfiguration: PersistentProxyConfiguration
-}
-
-/// Persistent proxy configuration.
-enum PersistentProxyConfiguration: Codable {
- /// Direct communication without proxy.
- case direct
-
- /// Communication over bridges.
- case bridges
-
- /// Communication over shadowsocks.
- case shadowsocks(ShadowsocksConfiguration)
-
- /// Communication over socks5 proxy.
- case socks5(SocksConfiguration)
-}
-
-extension PersistentProxyConfiguration {
- /// Socks autentication method.
- enum SocksAuthentication: Codable {
- case noAuthentication
- case usernamePassword(username: String, password: String)
- }
-
- /// Socks v5 proxy configuration.
- struct SocksConfiguration: Codable {
- /// Proxy server address.
- var server: AnyIPAddress
-
- /// Proxy server port.
- var port: UInt16
-
- /// Authentication method.
- var authentication: SocksAuthentication
- }
-
- /// Shadowsocks configuration.
- struct ShadowsocksConfiguration: Codable {
- /// Server address.
- var server: AnyIPAddress
-
- /// Server port.
- var port: UInt16
-
- /// Server password.
- var password: String
-
- /// Server cipher.
- var cipher: ShadowsocksCipher
- }
-}
-
-extension PersistentAccessMethod {
- /// A kind of access method.
- var kind: AccessMethodKind {
- switch proxyConfiguration {
- case .direct:
- .direct
- case .bridges:
- .bridges
- case .shadowsocks:
- .shadowsocks
- case .socks5:
- .socks5
- }
- }
-}
-
-/// A kind of API access method.
-enum AccessMethodKind: Equatable, Hashable, CaseIterable {
- /// Direct communication.
- case direct
-
- /// Communication over bridges.
- case bridges
-
- /// Communication over shadowsocks.
- case shadowsocks
-
- /// Communication over socks v5 proxy.
- case socks5
-}
-
-extension AccessMethodKind {
- /// Returns `true` if the method is permanent and cannot be deleted.
- var isPermanent: Bool {
- switch self {
- case .direct, .bridges:
- true
- case .shadowsocks, .socks5:
- false
- }
- }
-
- /// Returns all access method kinds that can be added by user.
- static var allUserDefinedKinds: [AccessMethodKind] {
- allCases.filter { !$0.isPermanent }
- }
-}
diff --git a/ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTester.swift b/ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTester.swift
index bf9ad5f03a..95f6b302f7 100644
--- a/ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTester.swift
+++ b/ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTester.swift
@@ -8,6 +8,7 @@
import Combine
import Foundation
+import MullvadSettings
/// A concrete implementation of an access method proxy configuration.
class ProxyConfigurationTester: ProxyConfigurationTesterProtocol {
diff --git a/ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTesterProtocol.swift b/ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTesterProtocol.swift
index 3ee795cbf9..b01d817d61 100644
--- a/ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTesterProtocol.swift
+++ b/ios/MullvadVPN/AccessMethodRepository/ProxyConfigurationTesterProtocol.swift
@@ -7,6 +7,7 @@
//
import Foundation
+import MullvadSettings
/// Type implementing access method proxy configuration testing.
protocol ProxyConfigurationTesterProtocol {
diff --git a/ios/MullvadVPN/AccessMethodRepository/ShadowsocksCipher.swift b/ios/MullvadVPN/AccessMethodRepository/ShadowsocksCipher.swift
deleted file mode 100644
index 8610bf33c1..0000000000
--- a/ios/MullvadVPN/AccessMethodRepository/ShadowsocksCipher.swift
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-// ShadowsocksCipher.swift
-// MullvadVPN
-//
-// Created by pronebird on 13/11/2023.
-// Copyright © 2023 Mullvad VPN AB. All rights reserved.
-//
-
-import Foundation
-
-/// Type representing a shadowsocks cipher.
-struct ShadowsocksCipher: RawRepresentable, CustomStringConvertible, Equatable, Hashable, Codable {
- let rawValue: String
-
- var description: String {
- rawValue
- }
-
- /// Default cipher.
- static let `default` = ShadowsocksCipher(rawValue: "chacha20")
-
- /// All supported ciphers.
- static let supportedCiphers = supportedCipherIdentifiers.map { ShadowsocksCipher(rawValue: $0) }
-}
-
-private let supportedCipherIdentifiers = [
- // Stream ciphers.
- "aes-128-cfb",
- "aes-128-cfb1",
- "aes-128-cfb8",
- "aes-128-cfb128",
- "aes-256-cfb",
- "aes-256-cfb1",
- "aes-256-cfb8",
- "aes-256-cfb128",
- "rc4",
- "rc4-md5",
- "chacha20",
- "salsa20",
- "chacha20-ietf",
- // AEAD ciphers.
- "aes-128-gcm",
- "aes-256-gcm",
- "chacha20-ietf-poly1305",
- "xchacha20-ietf-poly1305",
- "aes-128-pmac-siv",
- "aes-256-pmac-siv",
-]