Skip to content

Commit

Permalink
[ios][secure-store] Backport to sdk49 (expo#23278)
Browse files Browse the repository at this point in the history
# Why
Backports expo#23275

# How


# Test Plan


# Checklist
  • Loading branch information
alanjhughes authored Jul 3, 2023
1 parent b31f747 commit 99eab64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ internal class InvalidKeyException: Exception {
}
}

internal class MissingPlistKeyException: Exception {
override var reason: String {
"You must set `NSFaceIDUsageDescription` in your Info.plist file to use the `requireAuthentication` option"
}
}

internal class KeyChainException: GenericException<OSStatus> {
override var reason: String {
switch param {
Expand Down
7 changes: 5 additions & 2 deletions ios/versioned/sdk49/ExpoSecureStore/SecureStoreModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class SecureStoreModule: Module {
}

AsyncFunction("deleteValueWithKeyAsync") { (key: String, options: SecureStoreOptions) in
var searchDictionary = query(with: key, options: options)
let searchDictionary = query(with: key, options: options)
SecItemDelete(searchDictionary as CFDictionary)
}
}
Expand All @@ -55,6 +55,9 @@ public final class SecureStoreModule: Module {
if !options.requireAuthentication {
query[kSecAttrAccessible as String] = accessibility
} else {
guard let _ = Bundle.main.infoDictionary?["NSFaceIDUsageDescription"] as? String else {
throw MissingPlistKeyException()
}
let accessOptions = SecAccessControlCreateWithFlags(kCFAllocatorDefault, accessibility, SecAccessControlCreateFlags.biometryCurrentSet, nil)
query[kSecAttrAccessControl as String] = accessOptions
}
Expand Down Expand Up @@ -119,7 +122,7 @@ public final class SecureStoreModule: Module {

private func query(with key: String, options: SecureStoreOptions) -> [String: Any] {
let service = options.keychainService ?? "app"
let encodedKey = key.data(using: .utf8)
let encodedKey = Data(key.utf8)

return [
kSecClass as String: kSecClassGenericPassword,
Expand Down

0 comments on commit 99eab64

Please sign in to comment.