From 6bf8011e12dbc95f914ac21dd4712d12b0bf3a25 Mon Sep 17 00:00:00 2001 From: Mikhail Churbanov Date: Tue, 24 Jul 2018 22:25:30 +0300 Subject: [PATCH 1/3] Fixed 'swift test' issues and updated podspec --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Example/Tests/Configuration.swift | 1 + ProxyResolver.podspec | 13 +++---------- 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/Tests/Configuration.swift b/Example/Tests/Configuration.swift index 9c7417b..6c5ef26 100644 --- a/Example/Tests/Configuration.swift +++ b/Example/Tests/Configuration.swift @@ -6,6 +6,7 @@ // Copyright © 2018 CocoaPods. All rights reserved. // +import Foundation @testable import ProxyResolver typealias ProxyConfigDict = [CFString: AnyObject] diff --git a/ProxyResolver.podspec b/ProxyResolver.podspec index 27acbff..d524bfb 100644 --- a/ProxyResolver.podspec +++ b/ProxyResolver.podspec @@ -8,15 +8,9 @@ Pod::Spec.new do |s| s.name = 'ProxyResolver' - s.version = '0.3.0' + s.version = '0.3.1' s.summary = 'Simple resolution of user proxy settings for macOS' -# This description is used to generate tags and improve search results. -# * Think: What does it do? Why did you write it? What is the focus? -# * Try to keep it short, snappy and to the point. -# * Write the description between the DESC delimiters below. -# * Finally, don't worry about the indent, CocoaPods strips it! - s.description = <<-DESC ProxyResolver allows simply resolve the actual proxy information from users system configuration and could be used for setting up Stream-based connections, @@ -24,13 +18,12 @@ Pod::Spec.new do |s| DESC s.homepage = 'https://github.com/rinold/ProxyResolver' - # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'rinold' => 'mihail.churbanov@gmail.com' } s.source = { :git => 'https://github.com/rinold/ProxyResolver.git', :tag => s.version.to_s } - # s.social_media_url = 'https://twitter.com/' + s.social_media_url = 'https://twitter.com/rinold_nn' - s.platform = :osx + s.ios.deployment_target = "10.0" s.osx.deployment_target = "10.10" s.source_files = 'ProxyResolver/Classes/**/*' From fb4e8171a909dd4a7c8de745140a90c109d6e1a3 Mon Sep 17 00:00:00 2001 From: Mikhail Churbanov Date: Tue, 24 Jul 2018 22:25:59 +0300 Subject: [PATCH 2/3] Moved keychain credentials out of Resolver --- ProxyResolver/Classes/ProxyResolver.swift | 48 ++++++++++++----------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/ProxyResolver/Classes/ProxyResolver.swift b/ProxyResolver/Classes/ProxyResolver.swift index 69bbd17..2614906 100644 --- a/ProxyResolver/Classes/ProxyResolver.swift +++ b/ProxyResolver/Classes/ProxyResolver.swift @@ -21,13 +21,37 @@ public struct Credentials { public let password: String } +extension Credentials { + public static func get(for host: String) -> Credentials? { + let query: [String: Any] = [kSecClass as String: kSecClassInternetPassword, + kSecAttrServer as String: host, + kSecMatchLimit as String: kSecMatchLimitOne, + kSecReturnAttributes as String: true, + kSecReturnData as String: true] + + var item: CFTypeRef? + let status = SecItemCopyMatching(query as CFDictionary, &item) + guard status == errSecSuccess else { return nil } + + guard let existingItem = item as? [String : Any], + let passwordData = existingItem[kSecValueData as String] as? Data, + let password = String(data: passwordData, encoding: .utf8), + let account = existingItem[kSecAttrAccount as String] as? String + else { + return nil + } + + return Credentials(username: account, password: password) + } +} + public struct Proxy { public let type: ProxyType public let host: String public let port: UInt32 public var credentials: Credentials? { - return ProxyResolver.getCredentials(for: host) + return Credentials.get(for: host) } } @@ -284,26 +308,4 @@ public final class ProxyResolver { return urlComponents.url } - class func getCredentials(for host: String) -> Credentials? { - let query: [String: Any] = [kSecClass as String: kSecClassInternetPassword, - kSecAttrServer as String: host, - kSecMatchLimit as String: kSecMatchLimitOne, - kSecReturnAttributes as String: true, - kSecReturnData as String: true] - - var item: CFTypeRef? - let status = SecItemCopyMatching(query as CFDictionary, &item) - guard status == errSecSuccess else { return nil } - - guard let existingItem = item as? [String : Any], - let passwordData = existingItem[kSecValueData as String] as? Data, - let password = String(data: passwordData, encoding: .utf8), - let account = existingItem[kSecAttrAccount as String] as? String - else { - return nil - } - - return Credentials(username: account, password: password) - } - } From 8c63550f98ab47f1ae138d2d00b8dca578166809 Mon Sep 17 00:00:00 2001 From: Mikhail Churbanov Date: Tue, 24 Jul 2018 22:49:54 +0300 Subject: [PATCH 3/3] Allow changing config after init --- ProxyResolver/Classes/ProxyResolver.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProxyResolver/Classes/ProxyResolver.swift b/ProxyResolver/Classes/ProxyResolver.swift index 2614906..aad6cfc 100644 --- a/ProxyResolver/Classes/ProxyResolver.swift +++ b/ProxyResolver/Classes/ProxyResolver.swift @@ -116,7 +116,7 @@ public protocol ProxyResolverDelegate: class { public final class ProxyResolver { - private let config: ProxyResolverConfig + public var config: ProxyResolverConfig public weak var delegate: ProxyResolverDelegate?