expo-secure-store 12.7.0 β†’ 12.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,13 @@
10
10
 
11
11
  ### πŸ’‘ Others
12
12
 
13
+ ## 12.8.0 β€” 2023-12-12
14
+
15
+ ### πŸŽ‰ New features
16
+
17
+ - [iOS] Added possibility to store values that require authentication and ones that don't under the same `keychainService`. ([#23841](https://github.com/expo/expo/pull/23841) by [@behenate](https://github.com/behenate))
18
+ - [iOS] Added synchronous functions for storing and retrieving values from the store. ([#23841](https://github.com/expo/expo/pull/23841) by [@behenate](https://github.com/behenate))
19
+
13
20
  ## 12.7.0 β€” 2023-11-14
14
21
 
15
22
  ### πŸ›  Breaking changes
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '12.7.0'
6
+ version = '12.8.0'
7
7
 
8
8
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
9
9
  if (expoModulesCorePlugin.exists()) {
@@ -94,7 +94,7 @@ android {
94
94
  namespace "expo.modules.securestore"
95
95
  defaultConfig {
96
96
  versionCode 17
97
- versionName '12.7.0'
97
+ versionName '12.8.0'
98
98
  }
99
99
  }
100
100
 
@@ -17,20 +17,22 @@ public final class SecureStoreModule: Module {
17
17
  ])
18
18
 
19
19
  AsyncFunction("getValueWithKeyAsync") { (key: String, options: SecureStoreOptions) -> String? in
20
- guard let key = validate(for: key) else {
21
- throw InvalidKeyException()
22
- }
20
+ return try get(with: key, options: options)
21
+ }
23
22
 
24
- let data = try searchKeyChain(with: key, options: options)
23
+ Function("getValueWithKeySync") { (key: String, options: SecureStoreOptions) -> String? in
24
+ return try get(with: key, options: options)
25
+ }
25
26
 
26
- guard let data = data else {
27
- return nil
27
+ AsyncFunction("setValueWithKeyAsync") { (value: String, key: String, options: SecureStoreOptions) -> Bool in
28
+ guard let key = validate(for: key) else {
29
+ throw InvalidKeyException()
28
30
  }
29
31
 
30
- return String(data: data, encoding: .utf8)
32
+ return try set(value: value, with: key, options: options)
31
33
  }
32
34
 
33
- AsyncFunction("setValueWithKeyAsync") { (value: String, key: String, options: SecureStoreOptions) -> Bool in
35
+ Function("setValueWithKeySync") {(value: String, key: String, options: SecureStoreOptions) -> Bool in
34
36
  guard let key = validate(for: key) else {
35
37
  throw InvalidKeyException()
36
38
  }
@@ -39,33 +41,61 @@ public final class SecureStoreModule: Module {
39
41
  }
40
42
 
41
43
  AsyncFunction("deleteValueWithKeyAsync") { (key: String, options: SecureStoreOptions) in
42
- let searchDictionary = query(with: key, options: options)
43
- SecItemDelete(searchDictionary as CFDictionary)
44
+ let noAuthSearchDictionary = query(with: key, options: options, requireAuthentication: false)
45
+ let authSearchDictionary = query(with: key, options: options, requireAuthentication: true)
46
+ let legacySearchDictionary = query(with: key, options: options)
47
+
48
+ SecItemDelete(legacySearchDictionary as CFDictionary)
49
+ SecItemDelete(authSearchDictionary as CFDictionary)
50
+ SecItemDelete(noAuthSearchDictionary as CFDictionary)
44
51
  }
45
52
  }
46
53
 
54
+ private func get(with key: String, options: SecureStoreOptions) throws -> String? {
55
+ guard let key = validate(for: key) else {
56
+ throw InvalidKeyException()
57
+ }
58
+
59
+ if let unauthenticatedItem = try searchKeyChain(with: key, options: options, requireAuthentication: false) {
60
+ return String(data: unauthenticatedItem, encoding: .utf8)
61
+ }
62
+
63
+ if let authenticatedItem = try searchKeyChain(with: key, options: options, requireAuthentication: true) {
64
+ return String(data: authenticatedItem, encoding: .utf8)
65
+ }
66
+
67
+ if let legacyItem = try searchKeyChain(with: key, options: options) {
68
+ return String(data: legacyItem, encoding: .utf8)
69
+ }
70
+
71
+ return nil
72
+ }
73
+
47
74
  private func set(value: String, with key: String, options: SecureStoreOptions) throws -> Bool {
48
- var query = query(with: key, options: options)
75
+ var setItemQuery = query(with: key, options: options, requireAuthentication: options.requireAuthentication)
49
76
 
50
77
  let valueData = value.data(using: .utf8)
51
- query[kSecValueData as String] = valueData
78
+ setItemQuery[kSecValueData as String] = valueData
52
79
 
53
80
  let accessibility = attributeWith(options: options)
54
81
 
55
82
  if !options.requireAuthentication {
56
- query[kSecAttrAccessible as String] = accessibility
83
+ setItemQuery[kSecAttrAccessible as String] = accessibility
57
84
  } else {
58
85
  guard let _ = Bundle.main.infoDictionary?["NSFaceIDUsageDescription"] as? String else {
59
86
  throw MissingPlistKeyException()
60
87
  }
61
88
  let accessOptions = SecAccessControlCreateWithFlags(kCFAllocatorDefault, accessibility, SecAccessControlCreateFlags.biometryCurrentSet, nil)
62
- query[kSecAttrAccessControl as String] = accessOptions
89
+ setItemQuery[kSecAttrAccessControl as String] = accessOptions
63
90
  }
64
91
 
65
- let status = SecItemAdd(query as CFDictionary, nil)
92
+ let status = SecItemAdd(setItemQuery as CFDictionary, nil)
66
93
 
67
94
  switch status {
68
95
  case errSecSuccess:
96
+ // On success we want to remove the other key alias and legacy key (if they exist) to avoid conflicts during reads
97
+ SecItemDelete(query(with: key, options: options) as CFDictionary)
98
+ SecItemDelete(query(with: key, options: options, requireAuthentication: !options.requireAuthentication) as CFDictionary)
69
99
  return true
70
100
  case errSecDuplicateItem:
71
101
  return try update(value: value, with: key, options: options)
@@ -75,7 +105,7 @@ public final class SecureStoreModule: Module {
75
105
  }
76
106
 
77
107
  private func update(value: String, with key: String, options: SecureStoreOptions) throws -> Bool {
78
- var query = query(with: key, options: options)
108
+ var query = query(with: key, options: options, requireAuthentication: options.requireAuthentication)
79
109
 
80
110
  let valueData = value.data(using: .utf8)
81
111
  let updateDictionary = [kSecValueData as String: valueData]
@@ -93,8 +123,8 @@ public final class SecureStoreModule: Module {
93
123
  }
94
124
  }
95
125
 
96
- private func searchKeyChain(with key: String, options: SecureStoreOptions) throws -> Data? {
97
- var query = query(with: key, options: options)
126
+ private func searchKeyChain(with key: String, options: SecureStoreOptions, requireAuthentication: Bool? = nil) throws -> Data? {
127
+ var query = query(with: key, options: options, requireAuthentication: requireAuthentication)
98
128
 
99
129
  query[kSecMatchLimit as String] = kSecMatchLimitOne
100
130
  query[kSecReturnData as String] = kCFBooleanTrue
@@ -119,8 +149,12 @@ public final class SecureStoreModule: Module {
119
149
  }
120
150
  }
121
151
 
122
- private func query(with key: String, options: SecureStoreOptions) -> [String: Any] {
123
- let service = options.keychainService ?? "app"
152
+ private func query(with key: String, options: SecureStoreOptions, requireAuthentication: Bool? = nil) -> [String: Any] {
153
+ var service = options.keychainService ?? "app"
154
+ if let requireAuthentication {
155
+ service.append(":\(requireAuthentication ? "auth" : "no-auth")")
156
+ }
157
+
124
158
  let encodedKey = Data(key.utf8)
125
159
 
126
160
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-secure-store",
3
- "version": "12.7.0",
3
+ "version": "12.8.0",
4
4
  "description": "Provides a way to encrypt and securely store key–value pairs locally on the device.",
5
5
  "main": "build/SecureStore.js",
6
6
  "types": "build/SecureStore.d.ts",
@@ -42,5 +42,5 @@
42
42
  "peerDependencies": {
43
43
  "expo": "*"
44
44
  },
45
- "gitHead": "3142a086578deffd8704a8f1b6f0f661527d836c"
45
+ "gitHead": "6aca7ce098ddc667776a3d7cf612adbb985e264a"
46
46
  }