From f33baaa584ea29a845890017aafcee2d58b76988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Mon, 20 May 2024 14:36:59 +0100 Subject: [PATCH 1/5] fix: iOS/macOS readAll --- .../ios/Classes/FlutterSecureStorage.swift | 66 +++++++++---------- .../SwiftFlutterSecureStoragePlugin.swift | 60 ++++++++--------- .../macos/Classes/FlutterSecureStorage.swift | 4 +- .../Classes/FlutterSecureStoragePlugin.swift | 2 +- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift b/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift index b2c3fbe7..7829aba9 100644 --- a/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift +++ b/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift @@ -12,7 +12,7 @@ class FlutterSecureStorage{ guard let accessibility = accessibility else { return kSecAttrAccessibleWhenUnlocked } - + switch accessibility { case "passcode": return kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly @@ -34,32 +34,32 @@ class FlutterSecureStorage{ kSecClass : kSecClassGenericPassword, kSecAttrAccessible : parseAccessibleAttr(accessibility: accessibility), ] - + if (key != nil) { keychainQuery[kSecAttrAccount] = key } - + if (groupId != nil) { keychainQuery[kSecAttrAccessGroup] = groupId } - + if (accountName != nil) { keychainQuery[kSecAttrService] = accountName } - + if (synchronizable != nil) { keychainQuery[kSecAttrSynchronizable] = synchronizable } - + if (returnData != nil) { keychainQuery[kSecReturnData] = returnData } return keychainQuery } - - internal func containsKey(key: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> Result { + + internal func containsKey(key: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> Result { let keychainQuery = baseQuery(key: key, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: false) - + let status = SecItemCopyMatching(keychainQuery as CFDictionary, nil) switch status { case errSecSuccess: @@ -70,26 +70,26 @@ class FlutterSecureStorage{ return .failure(OSSecError(status: status)) } } - - internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { - var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: true) - + + internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { + var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) + keychainQuery[kSecMatchLimit] = kSecMatchLimitAll keychainQuery[kSecReturnAttributes] = true - + var ref: AnyObject? let status = SecItemCopyMatching( keychainQuery as CFDictionary, &ref ) - + if (status == errSecItemNotFound) { // readAll() returns all elements, so return nil if the items does not exist return FlutterSecureStorageResponse(status: errSecSuccess, value: nil) } var results: [String: String] = [:] - + if (status == noErr) { (ref as! NSArray).forEach { item in let key: String = (item as! NSDictionary)[kSecAttrAccount] as! String @@ -97,13 +97,13 @@ class FlutterSecureStorage{ results[key] = value } } - + return FlutterSecureStorageResponse(status: status, value: results) } - + internal func read(key: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { let keychainQuery = baseQuery(key: key, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) - + var ref: AnyObject? let status = SecItemCopyMatching( keychainQuery as CFDictionary, @@ -114,28 +114,28 @@ class FlutterSecureStorage{ if (status == errSecItemNotFound) { return FlutterSecureStorageResponse(status: errSecSuccess, value: nil) } - + var value: String? = nil - + if (status == noErr) { value = String(data: ref as! Data, encoding: .utf8) } return FlutterSecureStorageResponse(status: status, value: value) } - + internal func deleteAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { let keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: nil) let status = SecItemDelete(keychainQuery as CFDictionary) - + if (status == errSecItemNotFound) { // deleteAll() deletes all items, so return nil if the items does not exist return FlutterSecureStorageResponse(status: errSecSuccess, value: nil) } - + return FlutterSecureStorageResponse(status: status, value: nil) } - + internal func delete(key: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { let keychainQuery = baseQuery(key: key, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) let status = SecItemDelete(keychainQuery as CFDictionary) @@ -144,11 +144,11 @@ class FlutterSecureStorage{ if (status == errSecItemNotFound) { return FlutterSecureStorageResponse(status: errSecSuccess, value: nil) } - + return FlutterSecureStorageResponse(status: status, value: nil) } - - internal func write(key: String, value: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { + + internal func write(key: String, value: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { var keyExists: Bool = false switch containsKey(key: key, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility) { @@ -163,24 +163,24 @@ class FlutterSecureStorage{ if (keyExists) { let attrAccessible = parseAccessibleAttr(accessibility: accessibility) - + let update: [CFString: Any?] = [ kSecValueData: value.data(using: String.Encoding.utf8), kSecAttrAccessible: attrAccessible, kSecAttrSynchronizable: synchronizable ] - + let status = SecItemUpdate(keychainQuery as CFDictionary, update as CFDictionary) - + return FlutterSecureStorageResponse(status: status, value: nil) } else { keychainQuery[kSecValueData] = value.data(using: String.Encoding.utf8) - + let status = SecItemAdd(keychainQuery as CFDictionary, nil) return FlutterSecureStorageResponse(status: status, value: nil) } - } + } } struct FlutterSecureStorageResponse { diff --git a/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift b/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift index bca7d5bf..c913d9db 100644 --- a/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift +++ b/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift @@ -9,7 +9,7 @@ import Flutter import UIKit public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterStreamHandler { - + private let flutterSecureStorageManager: FlutterSecureStorage = FlutterSecureStorage() private var secStoreAvailabilitySink: FlutterEventSink? @@ -21,7 +21,7 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt registrar.addApplicationDelegate(instance) eventChannel.setStreamHandler(instance) } - + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { func handleResult(_ value: Any?) { DispatchQueue.main.async { @@ -75,79 +75,79 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt self.secStoreAvailabilitySink = eventSink return nil } - + public func onCancel(withArguments arguments: Any?) -> FlutterError? { self.secStoreAvailabilitySink = nil return nil } - + private func read(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) if (values.key == nil) { result(FlutterError.init(code: "Missing Parameter", message: "write requires key parameter", details: nil)) return } - + let response = flutterSecureStorageManager.read(key: values.key!, groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) handleResponse(response, result) } - + private func write(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { if (!((call.arguments as! [String : Any?])["value"] is String)){ result(FlutterError.init(code: "Invalid Parameter", message: "key parameter must be String", details: nil)) return; } - + let values = parseCall(call) if (values.key == nil) { result(FlutterError.init(code: "Missing Parameter", message: "write requires key parameter", details: nil)) return } - + if (values.value == nil) { result(FlutterError.init(code: "Missing Parameter", message: "write requires value parameter", details: nil)) return } - + let response = flutterSecureStorageManager.write(key: values.key!, value: values.value!, groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) - + handleResponse(response, result) } - + private func delete(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) if (values.key == nil) { result(FlutterError.init(code: "Missing Parameter", message: "delete requires key parameter", details: nil)) return } - + let response = flutterSecureStorageManager.delete(key: values.key!, groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) - + handleResponse(response, result) } - + private func deleteAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) let response = flutterSecureStorageManager.deleteAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) - + handleResponse(response, result) } - + private func readAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) - let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) - + let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) + handleResponse(response, result) } - + private func containsKey(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) if (values.key == nil) { result(FlutterError.init(code: "Missing Parameter", message: "containsKey requires key parameter", details: nil)) } - + let response = flutterSecureStorageManager.containsKey(key: values.key!, groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) - + switch response { case .success(let exists): result(exists) @@ -168,27 +168,27 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt break; } } - + private func parseCall(_ call: FlutterMethodCall) -> FlutterSecureStorageRequest { let arguments = call.arguments as! [String : Any?] let options = arguments["options"] as! [String : Any?] - + let accountName = options["accountName"] as? String let groupId = options["groupId"] as? String let synchronizableString = options["synchronizable"] as? String - + let synchronizable: Bool = synchronizableString != nil ? Bool(synchronizableString!)! : false - + let key = arguments["key"] as? String let accessibility = options["accessibility"] as? String let value = arguments["value"] as? String - + return FlutterSecureStorageRequest( accountName: accountName, groupId: groupId, synchronizable: synchronizable, - accessibility: accessibility, - key: key, + accessibility: accessibility, + key: key, value: value ) } @@ -215,7 +215,7 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt result(response.value) } } - + struct FlutterSecureStorageRequest { var accountName: String? var groupId: String? @@ -224,5 +224,5 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt var key: String? var value: String? } - + } diff --git a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift index 6f2943d5..90823186 100644 --- a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift +++ b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift @@ -74,8 +74,8 @@ class FlutterSecureStorage{ } } - internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { - var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: true) + internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { + var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) keychainQuery[kSecMatchLimit] = kSecMatchLimitAll keychainQuery[kSecReturnAttributes] = true diff --git a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift index a9a2e512..320bf609 100644 --- a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift +++ b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift @@ -99,7 +99,7 @@ public class FlutterSecureStoragePlugin: NSObject, FlutterPlugin { private func readAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) - let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) + let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) handleResponse(response, result) } From 656e4ea0e0d86206490fb96ecd7a2de7d62eddbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Mon, 20 May 2024 15:01:15 +0100 Subject: [PATCH 2/5] chore: revert IntelliJ auto-format --- .../ios/Classes/FlutterSecureStorage.swift | 66 +++++++++---------- .../SwiftFlutterSecureStoragePlugin.swift | 60 ++++++++--------- .../macos/Classes/FlutterSecureStorage.swift | 4 +- .../Classes/FlutterSecureStoragePlugin.swift | 2 +- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift b/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift index 7829aba9..b2c3fbe7 100644 --- a/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift +++ b/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift @@ -12,7 +12,7 @@ class FlutterSecureStorage{ guard let accessibility = accessibility else { return kSecAttrAccessibleWhenUnlocked } - + switch accessibility { case "passcode": return kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly @@ -34,32 +34,32 @@ class FlutterSecureStorage{ kSecClass : kSecClassGenericPassword, kSecAttrAccessible : parseAccessibleAttr(accessibility: accessibility), ] - + if (key != nil) { keychainQuery[kSecAttrAccount] = key } - + if (groupId != nil) { keychainQuery[kSecAttrAccessGroup] = groupId } - + if (accountName != nil) { keychainQuery[kSecAttrService] = accountName } - + if (synchronizable != nil) { keychainQuery[kSecAttrSynchronizable] = synchronizable } - + if (returnData != nil) { keychainQuery[kSecReturnData] = returnData } return keychainQuery } - - internal func containsKey(key: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> Result { + + internal func containsKey(key: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> Result { let keychainQuery = baseQuery(key: key, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: false) - + let status = SecItemCopyMatching(keychainQuery as CFDictionary, nil) switch status { case errSecSuccess: @@ -70,26 +70,26 @@ class FlutterSecureStorage{ return .failure(OSSecError(status: status)) } } - - internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { - var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) - + + internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { + var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: true) + keychainQuery[kSecMatchLimit] = kSecMatchLimitAll keychainQuery[kSecReturnAttributes] = true - + var ref: AnyObject? let status = SecItemCopyMatching( keychainQuery as CFDictionary, &ref ) - + if (status == errSecItemNotFound) { // readAll() returns all elements, so return nil if the items does not exist return FlutterSecureStorageResponse(status: errSecSuccess, value: nil) } var results: [String: String] = [:] - + if (status == noErr) { (ref as! NSArray).forEach { item in let key: String = (item as! NSDictionary)[kSecAttrAccount] as! String @@ -97,13 +97,13 @@ class FlutterSecureStorage{ results[key] = value } } - + return FlutterSecureStorageResponse(status: status, value: results) } - + internal func read(key: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { let keychainQuery = baseQuery(key: key, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) - + var ref: AnyObject? let status = SecItemCopyMatching( keychainQuery as CFDictionary, @@ -114,28 +114,28 @@ class FlutterSecureStorage{ if (status == errSecItemNotFound) { return FlutterSecureStorageResponse(status: errSecSuccess, value: nil) } - + var value: String? = nil - + if (status == noErr) { value = String(data: ref as! Data, encoding: .utf8) } return FlutterSecureStorageResponse(status: status, value: value) } - + internal func deleteAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { let keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: nil) let status = SecItemDelete(keychainQuery as CFDictionary) - + if (status == errSecItemNotFound) { // deleteAll() deletes all items, so return nil if the items does not exist return FlutterSecureStorageResponse(status: errSecSuccess, value: nil) } - + return FlutterSecureStorageResponse(status: status, value: nil) } - + internal func delete(key: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { let keychainQuery = baseQuery(key: key, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) let status = SecItemDelete(keychainQuery as CFDictionary) @@ -144,11 +144,11 @@ class FlutterSecureStorage{ if (status == errSecItemNotFound) { return FlutterSecureStorageResponse(status: errSecSuccess, value: nil) } - + return FlutterSecureStorageResponse(status: status, value: nil) } - - internal func write(key: String, value: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { + + internal func write(key: String, value: String, groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { var keyExists: Bool = false switch containsKey(key: key, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility) { @@ -163,24 +163,24 @@ class FlutterSecureStorage{ if (keyExists) { let attrAccessible = parseAccessibleAttr(accessibility: accessibility) - + let update: [CFString: Any?] = [ kSecValueData: value.data(using: String.Encoding.utf8), kSecAttrAccessible: attrAccessible, kSecAttrSynchronizable: synchronizable ] - + let status = SecItemUpdate(keychainQuery as CFDictionary, update as CFDictionary) - + return FlutterSecureStorageResponse(status: status, value: nil) } else { keychainQuery[kSecValueData] = value.data(using: String.Encoding.utf8) - + let status = SecItemAdd(keychainQuery as CFDictionary, nil) return FlutterSecureStorageResponse(status: status, value: nil) } - } + } } struct FlutterSecureStorageResponse { diff --git a/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift b/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift index c913d9db..bca7d5bf 100644 --- a/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift +++ b/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift @@ -9,7 +9,7 @@ import Flutter import UIKit public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterStreamHandler { - + private let flutterSecureStorageManager: FlutterSecureStorage = FlutterSecureStorage() private var secStoreAvailabilitySink: FlutterEventSink? @@ -21,7 +21,7 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt registrar.addApplicationDelegate(instance) eventChannel.setStreamHandler(instance) } - + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { func handleResult(_ value: Any?) { DispatchQueue.main.async { @@ -75,79 +75,79 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt self.secStoreAvailabilitySink = eventSink return nil } - + public func onCancel(withArguments arguments: Any?) -> FlutterError? { self.secStoreAvailabilitySink = nil return nil } - + private func read(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) if (values.key == nil) { result(FlutterError.init(code: "Missing Parameter", message: "write requires key parameter", details: nil)) return } - + let response = flutterSecureStorageManager.read(key: values.key!, groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) handleResponse(response, result) } - + private func write(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { if (!((call.arguments as! [String : Any?])["value"] is String)){ result(FlutterError.init(code: "Invalid Parameter", message: "key parameter must be String", details: nil)) return; } - + let values = parseCall(call) if (values.key == nil) { result(FlutterError.init(code: "Missing Parameter", message: "write requires key parameter", details: nil)) return } - + if (values.value == nil) { result(FlutterError.init(code: "Missing Parameter", message: "write requires value parameter", details: nil)) return } - + let response = flutterSecureStorageManager.write(key: values.key!, value: values.value!, groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) - + handleResponse(response, result) } - + private func delete(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) if (values.key == nil) { result(FlutterError.init(code: "Missing Parameter", message: "delete requires key parameter", details: nil)) return } - + let response = flutterSecureStorageManager.delete(key: values.key!, groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) - + handleResponse(response, result) } - + private func deleteAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) let response = flutterSecureStorageManager.deleteAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) - + handleResponse(response, result) } - + private func readAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) - let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) - + let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) + handleResponse(response, result) } - + private func containsKey(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) if (values.key == nil) { result(FlutterError.init(code: "Missing Parameter", message: "containsKey requires key parameter", details: nil)) } - + let response = flutterSecureStorageManager.containsKey(key: values.key!, groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) - + switch response { case .success(let exists): result(exists) @@ -168,27 +168,27 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt break; } } - + private func parseCall(_ call: FlutterMethodCall) -> FlutterSecureStorageRequest { let arguments = call.arguments as! [String : Any?] let options = arguments["options"] as! [String : Any?] - + let accountName = options["accountName"] as? String let groupId = options["groupId"] as? String let synchronizableString = options["synchronizable"] as? String - + let synchronizable: Bool = synchronizableString != nil ? Bool(synchronizableString!)! : false - + let key = arguments["key"] as? String let accessibility = options["accessibility"] as? String let value = arguments["value"] as? String - + return FlutterSecureStorageRequest( accountName: accountName, groupId: groupId, synchronizable: synchronizable, - accessibility: accessibility, - key: key, + accessibility: accessibility, + key: key, value: value ) } @@ -215,7 +215,7 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt result(response.value) } } - + struct FlutterSecureStorageRequest { var accountName: String? var groupId: String? @@ -224,5 +224,5 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt var key: String? var value: String? } - + } diff --git a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift index 90823186..6f2943d5 100644 --- a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift +++ b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift @@ -74,8 +74,8 @@ class FlutterSecureStorage{ } } - internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { - var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) + internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { + var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: true) keychainQuery[kSecMatchLimit] = kSecMatchLimitAll keychainQuery[kSecReturnAttributes] = true diff --git a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift index 320bf609..a9a2e512 100644 --- a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift +++ b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift @@ -99,7 +99,7 @@ public class FlutterSecureStoragePlugin: NSObject, FlutterPlugin { private func readAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) - let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) + let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) handleResponse(response, result) } From 3a835309c7af3e479825706fb75bf42bb53835aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Mon, 20 May 2024 15:07:19 +0100 Subject: [PATCH 3/5] chore: re-apply fix --- flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift | 4 ++-- .../ios/Classes/SwiftFlutterSecureStoragePlugin.swift | 2 +- .../macos/Classes/FlutterSecureStorage.swift | 4 ++-- .../macos/Classes/FlutterSecureStoragePlugin.swift | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift b/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift index b2c3fbe7..58a31a6c 100644 --- a/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift +++ b/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift @@ -71,8 +71,8 @@ class FlutterSecureStorage{ } } - internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { - var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: true) + internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { + var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) keychainQuery[kSecMatchLimit] = kSecMatchLimitAll keychainQuery[kSecReturnAttributes] = true diff --git a/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift b/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift index bca7d5bf..58ce07e1 100644 --- a/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift +++ b/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift @@ -135,7 +135,7 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt private func readAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) - let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) + let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) handleResponse(response, result) } diff --git a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift index 6f2943d5..90823186 100644 --- a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift +++ b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift @@ -74,8 +74,8 @@ class FlutterSecureStorage{ } } - internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { - var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: true) + internal func readAll(groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { + var keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: true) keychainQuery[kSecMatchLimit] = kSecMatchLimitAll keychainQuery[kSecReturnAttributes] = true diff --git a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift index a9a2e512..320bf609 100644 --- a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift +++ b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift @@ -99,7 +99,7 @@ public class FlutterSecureStoragePlugin: NSObject, FlutterPlugin { private func readAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) - let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) + let response = flutterSecureStorageManager.readAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) handleResponse(response, result) } From 76505cd66ca3c3b91d536f4c98fe41cf17319657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Tue, 21 May 2024 08:35:06 +0100 Subject: [PATCH 4/5] fix: fix iOS/macOS deleteAll --- flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift | 4 ++-- .../ios/Classes/SwiftFlutterSecureStoragePlugin.swift | 2 +- .../macos/Classes/FlutterSecureStorage.swift | 4 ++-- .../macos/Classes/FlutterSecureStoragePlugin.swift | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift b/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift index 58a31a6c..3bfd118f 100644 --- a/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift +++ b/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift @@ -124,8 +124,8 @@ class FlutterSecureStorage{ return FlutterSecureStorageResponse(status: status, value: value) } - internal func deleteAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { - let keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: nil) + internal func deleteAll(groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { + let keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: nil) let status = SecItemDelete(keychainQuery as CFDictionary) if (status == errSecItemNotFound) { diff --git a/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift b/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift index 58ce07e1..894870de 100644 --- a/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift +++ b/flutter_secure_storage/ios/Classes/SwiftFlutterSecureStoragePlugin.swift @@ -128,7 +128,7 @@ public class SwiftFlutterSecureStoragePlugin: NSObject, FlutterPlugin, FlutterSt private func deleteAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) - let response = flutterSecureStorageManager.deleteAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) + let response = flutterSecureStorageManager.deleteAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) handleResponse(response, result) } diff --git a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift index 90823186..e4e429c7 100644 --- a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift +++ b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift @@ -127,8 +127,8 @@ class FlutterSecureStorage{ return FlutterSecureStorageResponse(status: status, value: value) } - internal func deleteAll(groupId: String?, accountName: String?, synchronizable: Bool?) -> FlutterSecureStorageResponse { - let keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: nil, returnData: nil) + internal func deleteAll(groupId: String?, accountName: String?, synchronizable: Bool?, accessibility: String?) -> FlutterSecureStorageResponse { + let keychainQuery = baseQuery(key: nil, groupId: groupId, accountName: accountName, synchronizable: synchronizable, accessibility: accessibility, returnData: nil) let status = SecItemDelete(keychainQuery as CFDictionary) if (status == errSecItemNotFound) { diff --git a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift index 320bf609..1740e9d2 100644 --- a/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift +++ b/flutter_secure_storage_macos/macos/Classes/FlutterSecureStoragePlugin.swift @@ -92,7 +92,7 @@ public class FlutterSecureStoragePlugin: NSObject, FlutterPlugin { private func deleteAll(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { let values = parseCall(call) - let response = flutterSecureStorageManager.deleteAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable) + let response = flutterSecureStorageManager.deleteAll(groupId: values.groupId, accountName: values.accountName, synchronizable: values.synchronizable, accessibility: values.accessibility) handleResponse(response, result) } From cb30953edc029dc4059b72700270b4cd3a3afade Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Wed, 22 May 2024 08:50:42 +0200 Subject: [PATCH 5/5] release of v9.2.2 --- flutter_secure_storage/CHANGELOG.md | 3 +++ flutter_secure_storage/pubspec.yaml | 4 ++-- flutter_secure_storage_macos/CHANGELOG.md | 3 +++ flutter_secure_storage_macos/pubspec.yaml | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/flutter_secure_storage/CHANGELOG.md b/flutter_secure_storage/CHANGELOG.md index 1c18024e..d5e2c9e2 100644 --- a/flutter_secure_storage/CHANGELOG.md +++ b/flutter_secure_storage/CHANGELOG.md @@ -1,3 +1,6 @@ +## 9.2.2 +[iOS, macOS] Fixed an issue which caused the readAll and deleteAll to not work properly. + ## 9.2.1 * Fix async race condition bug in storage operations. * [macOS] Return nil on macOS if key is not found diff --git a/flutter_secure_storage/pubspec.yaml b/flutter_secure_storage/pubspec.yaml index dc3f3d62..cdbe465d 100644 --- a/flutter_secure_storage/pubspec.yaml +++ b/flutter_secure_storage/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_secure_storage description: Flutter Secure Storage provides API to store data in secure storage. Keychain is used in iOS, KeyStore based solution is used in Android. -version: 9.2.1 +version: 9.2.2 repository: https://github.com/mogol/flutter_secure_storage/tree/develop/flutter_secure_storage environment: @@ -32,7 +32,7 @@ dependencies: # validation, so we set a ^ constraint. # https://github.com/flutter/flutter/issues/46264 flutter_secure_storage_linux: ^1.2.1 - flutter_secure_storage_macos: ^3.1.1 + flutter_secure_storage_macos: ^3.1.2 flutter_secure_storage_platform_interface: ^1.1.2 flutter_secure_storage_web: ^1.2.1 flutter_secure_storage_windows: ^3.1.2 diff --git a/flutter_secure_storage_macos/CHANGELOG.md b/flutter_secure_storage_macos/CHANGELOG.md index 3130bb7c..1e96c43b 100644 --- a/flutter_secure_storage_macos/CHANGELOG.md +++ b/flutter_secure_storage_macos/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.1.2 +Fixed an issue which caused the readAll and deleteAll to not work properly. + ## 3.1.1 Fixed an issue which caused a platform exception when the key does not exists in the keychain. diff --git a/flutter_secure_storage_macos/pubspec.yaml b/flutter_secure_storage_macos/pubspec.yaml index 3c690378..6118cbdd 100644 --- a/flutter_secure_storage_macos/pubspec.yaml +++ b/flutter_secure_storage_macos/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_secure_storage_macos description: macOS implementation of flutter_secure_storage repository: https://github.com/mogol/flutter_secure_storage -version: 3.1.1 +version: 3.1.2 environment: sdk: ">=2.12.0 <4.0.0" @@ -10,7 +10,7 @@ environment: dependencies: flutter: sdk: flutter - flutter_secure_storage_platform_interface: ^1.1.1 + flutter_secure_storage_platform_interface: ^1.1.2 flutter: plugin: