Skip to content

Commit 31a6d71

Browse files
fix: Avoid Keychain's errSecInteractionNotAllowed error on iOS 15
For iOS 15, on SecureStorage's init method, if ProtectedData is unavailable, add an observer for the UIApplicationProtectedDataDidBecomeAvailable notification that re-triggers init when it becomes available.
1 parent c580031 commit 31a6d71

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
2.6.8-OS12 - 2022-04-14
5+
------------------
6+
7+
- Fix: For iOS 15, on the `init` method, if ProtectedData is unavailable, add an observer for the `UIApplicationProtectedDataDidBecomeAvailable` notification that re-triggers `init` when it becomes available. (RMET-1417)
8+
49
2.6.8-OS11 - 2022-04-12
510
------------------
611

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-secure-storage",
3-
"version": "2.6.8-OS11",
3+
"version": "2.6.8-OS12",
44
"description": "Secure storage plugin for iOS & Android",
55
"author": "Yiorgis Gozadinos <ggozad@crypho.com>",
66
"contributors": [

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
id="cordova-plugin-secure-storage"
5-
version="2.6.8-OS11">
5+
version="2.6.8-OS12">
66

77
<name>SecureStorage</name>
88
<author>Crypho AS</author>

src/ios/SecureStorage.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,37 @@
44
#import <Cordova/CDV.h>
55
#import "SAMKeychain.h"
66

7+
@interface SecureStorage ()
8+
9+
/// This local property is used to store the command to execute when SecureStorage tries to access Keychain without Protected Data Access being available. It's included as a fix for the iOS 15 pre-warm functionality.
10+
@property(nonatomic, strong) CDVInvokedUrlCommand *savedCommand API_AVAILABLE(ios(15));
11+
12+
@end
13+
714
@implementation SecureStorage
815

16+
/// Method triggered when the `UIApplicationProtectedDataDidBecomeAvailable` notification is trigged.
17+
- (void)dataBecameAvailableNotification:(NSNotification *)notification API_AVAILABLE(ios(15))
18+
{
19+
// Re-triggers the `init` method as before, using the stored command
20+
[self init:self.savedCommand];
21+
}
22+
923
- (void)init:(CDVInvokedUrlCommand*)command
1024
{
25+
if (@available(iOS 15, *)) {
26+
// if Protected Data Acess is not yet available, the app observes the `dataBecomeAvailableNotification:`, so that the method resumes when the notification is triggered
27+
if (!UIApplication.sharedApplication.isProtectedDataAvailable) {
28+
self.savedCommand = command;
29+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(dataBecameAvailableNotification:) name:UIApplicationProtectedDataDidBecomeAvailable object:nil];
30+
return;
31+
}
32+
33+
// all good, we can remove what was added and proceed.
34+
self.savedCommand = nil;
35+
[NSNotificationCenter.defaultCenter removeObserver:self name:UIApplicationProtectedDataDidBecomeAvailable object:nil];
36+
}
37+
1138
CFTypeRef accessibility;
1239
NSString *keychainAccessibility;
1340
NSDictionary *keychainAccesssibilityMapping;

0 commit comments

Comments
 (0)