From 532a2fb1fe3bee959295806cdd0da1b42d8627c2 Mon Sep 17 00:00:00 2001 From: King <47607185+DarkGamerYT@users.noreply.github.com> Date: Fri, 15 Aug 2025 01:13:42 +0100 Subject: [PATCH 1/3] fix(PlayKeychain): a crash when storing dictionary --- PlayTools/MysticRunes/PlayedApple.swift | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/PlayTools/MysticRunes/PlayedApple.swift b/PlayTools/MysticRunes/PlayedApple.swift index 5a4a7b4e..0db42157 100644 --- a/PlayTools/MysticRunes/PlayedApple.swift +++ b/PlayTools/MysticRunes/PlayedApple.swift @@ -33,6 +33,7 @@ public class PlayKeychain: NSObject { debugLogger("Wrote keychain item to db") // Place v_Data in the result guard let vData = attributes["v_Data"] as? CFTypeRef else { + result?.pointee = nil return errSecSuccess } @@ -49,15 +50,25 @@ public class PlayKeychain: NSObject { } if attributes["class"] as? String == "keys" { - // kSecAttrKeyType is stored as `type` in the dictionary - // kSecAttrKeyClass is stored as `kcls` in the dictionary - let keyAttributes = [ - kSecAttrKeyType: attributes["type"] as! CFString, // swiftlint:disable:this force_cast - kSecAttrKeyClass: attributes["kcls"] as! CFString // swiftlint:disable:this force_cast - ] - let keyData = vData as! Data // swiftlint:disable:this force_cast - let key = SecKeyCreateWithData(keyData as CFData, keyAttributes as CFDictionary, nil) - result?.pointee = Unmanaged.passRetained(key!) + if let keyDataValue = vData as? Data { + // kSecAttrKeyType is stored as `type` in the dictionary + // kSecAttrKeyClass is stored as `kcls` in the dictionary + let keyAttributesDictionary = [ + kSecAttrKeyType: attributes["type"] as? String + ?? (attributes[kSecAttrKeyType as String] as? String), + kSecAttrKeyClass: attributes["kcls"] as? String + ?? (attributes[kSecAttrKeyType as String] as? String) + ] + if let key = SecKeyCreateWithData( + keyDataValue as CFData, + keyAttributesDictionary as CFDictionary, + nil + ) { + result?.pointee = Unmanaged.passRetained(key) + return errSecSuccess + } + } + result?.pointee = nil return errSecSuccess } result?.pointee = Unmanaged.passRetained(vData) From ae5adaf2ef2bdf61e478e7c93d7b7f0ef567abce Mon Sep 17 00:00:00 2001 From: King <47607185+DarkGamerYT@users.noreply.github.com> Date: Fri, 12 Sep 2025 13:14:01 +0100 Subject: [PATCH 2/3] Update PlayedApple.swift --- PlayTools/MysticRunes/PlayedApple.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/PlayTools/MysticRunes/PlayedApple.swift b/PlayTools/MysticRunes/PlayedApple.swift index 0db42157..44f1f147 100644 --- a/PlayTools/MysticRunes/PlayedApple.swift +++ b/PlayTools/MysticRunes/PlayedApple.swift @@ -33,7 +33,6 @@ public class PlayKeychain: NSObject { debugLogger("Wrote keychain item to db") // Place v_Data in the result guard let vData = attributes["v_Data"] as? CFTypeRef else { - result?.pointee = nil return errSecSuccess } @@ -68,7 +67,6 @@ public class PlayKeychain: NSObject { return errSecSuccess } } - result?.pointee = nil return errSecSuccess } result?.pointee = Unmanaged.passRetained(vData) From c5f63112bd77d9f2f3fe26d771c3f8f99a65834e Mon Sep 17 00:00:00 2001 From: King <47607185+DarkGamerYT@users.noreply.github.com> Date: Fri, 12 Sep 2025 17:57:23 +0100 Subject: [PATCH 3/3] Update PlayedApple.swift --- PlayTools/MysticRunes/PlayedApple.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlayTools/MysticRunes/PlayedApple.swift b/PlayTools/MysticRunes/PlayedApple.swift index 44f1f147..a1fd3c79 100644 --- a/PlayTools/MysticRunes/PlayedApple.swift +++ b/PlayTools/MysticRunes/PlayedApple.swift @@ -67,7 +67,7 @@ public class PlayKeychain: NSObject { return errSecSuccess } } - return errSecSuccess + return errSecBadReq } result?.pointee = Unmanaged.passRetained(vData) return errSecSuccess