Skip to content

Commit ad37a49

Browse files
Merge pull request #16 from tombailey/master
Potential fix for issue #14
2 parents 2e308a4 + 26e9975 commit ad37a49

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

android/src/main/java/com/reactlibrary/securekeystore/RNSecureKeyStoreModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private PublicKey getOrCreatePublicKey(String alias) throws GeneralSecurityExcep
6666
KeyStore keyStore = KeyStore.getInstance(getKeyStore());
6767
keyStore.load(null);
6868

69-
if (!keyStore.containsAlias(alias)) {
69+
if (!keyStore.containsAlias(alias) || keyStore.getCertificate(alias) == null) {
7070
Log.i(Constants.TAG, "no existing asymmetric keys for alias");
7171

7272
Calendar start = Calendar.getInstance();
@@ -125,7 +125,6 @@ private SecretKey getOrCreateSecretKey(String alias) throws GeneralSecurityExcep
125125
keyGenerator.init(256);
126126
SecretKey secretKey = keyGenerator.generateKey();
127127
PublicKey publicKey = getOrCreatePublicKey(alias);
128-
129128
Storage.writeValues(getContext(), Constants.SKS_KEY_FILENAME + alias,
130129
encryptRsaPlainText(publicKey, secretKey.getEncoded()));
131130

@@ -143,6 +142,9 @@ private void setCipherText(String alias, String input) throws GeneralSecurityExc
143142
public void get(String alias, Promise promise) {
144143
try {
145144
promise.resolve(getPlainText(alias));
145+
} catch (FileNotFoundException fnfe) {
146+
fnfe.printStackTrace();
147+
promise.reject("404", "{\"code\":404,\"api-level\":" + Build.VERSION.SDK_INT + ",\"message\":" + fnfe.getMessage() + "}", fnfe);
146148
} catch (Exception e) {
147149
e.printStackTrace();
148150
Log.e(Constants.TAG, "Exception: " + e.getMessage());

ios/RNSecureKeyStore.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ - (void)handleAppUninstallation
153153
NSString *value = [self searchKeychainCopyMatching:key];
154154
if (value == nil) {
155155
NSString* errorMessage = @"{\"message\":\"key does not present\"}";
156-
reject(@"1", errorMessage, secureKeyStoreError(errorMessage));
156+
reject(@"404", errorMessage, secureKeyStoreError(errorMessage));
157157
} else {
158158
resolve(value);
159159
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"name": "react-native-secure-key-store",
33
"version": "1.0.8",
4-
"description":
5-
"React Native Library for securely storing keys to iOS and Android devices in KeyChain and KeyStore respectively.",
4+
"description": "React Native Library for securely storing keys to iOS and Android devices in KeyChain and KeyStore respectively.",
65
"main": "index.js",
76
"scripts": {
87
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)