Skip to content

Commit

Permalink
Merge pull request #29 from yoman07/master
Browse files Browse the repository at this point in the history
Added possibility to set ACCESSIBLE level for iOS
  • Loading branch information
pradeep1991singh authored Aug 27, 2018
2 parents eac08e5 + b23e00a commit eec1d9c
Show file tree
Hide file tree
Showing 9 changed files with 2,485 additions and 883 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ $ react-native link react-native-secure-key-store
## Usage

```javascript
import RNSecureKeyStore from 'react-native-secure-key-store';
import RNSecureKeyStore, {ACCESSIBLE} from "react-native-secure-key-store";

// For storing key
RNSecureKeyStore.set("key1", "value1")
RNSecureKeyStore.set("key1", "value1", {accessible: ACCESSIBLE.ALWAYS_THIS_DEVICE_ONLY})
.then((res) => {
console.log(res);
}, (err) => {
Expand All @@ -76,6 +76,24 @@ RNSecureKeyStore.remove("key1")
```
- For demo app, checkout example directory.

## Options

| Key | Platform | Description | Default |
|---|---|---|---|
|**`accessible`**|iOS only|This dictates when a keychain item is accessible, see possible values in `Keychain.ACCESSIBLE`. |*`Keychain.ACCESSIBLE.WHEN_UNLOCKED`*|

### `Keychain.ACCESSIBLE` enum

| Key | Description |
|-----|-------------|
|**`WHEN_UNLOCKED`**|The data in the keychain item can be accessed only while the device is unlocked by the user.|
|**`AFTER_FIRST_UNLOCK`**|The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user.|
|**`ALWAYS`**|The data in the keychain item can always be accessed regardless of whether the device is locked.|
|**`WHEN_PASSCODE_SET_THIS_DEVICE_ONLY`**|The data in the keychain can only be accessed when the device is unlocked. Only available if a passcode is set on the device. Items with this attribute never migrate to a new device.|
|**`WHEN_UNLOCKED_THIS_DEVICE_ONLY`**|The data in the keychain item can be accessed only while the device is unlocked by the user. Items with this attribute do not migrate to a new device.|
|**`AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY`**|The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user. Items with this attribute never migrate to a new device.|
|**`ALWAYS_THIS_DEVICE_ONLY`**|The data in the keychain item can always be accessed regardless of whether the device is locked. Items with this attribute never migrate to a new device.|

## Testing

For Testing using Jest, add RNSecureKeyStoreMock implementation under your __test__/__mocks__ folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Calendar;
import android.support.annotation.Nullable;
import com.facebook.react.bridge.ReadableMap;

import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
Expand All @@ -51,7 +53,7 @@ public String getName() {
}

@ReactMethod
public void set(String alias, String input, Promise promise) {
public void set(String alias, String input, @Nullable ReadableMap options, Promise promise) {
try {
setCipherText(alias, input);
promise.resolve("stored ciphertext in app storage");
Expand Down
6 changes: 3 additions & 3 deletions example/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import {
View
} from 'react-native';

import RNSecureKeyStore from "react-native-secure-key-store";
import RNSecureKeyStore, {ACCESSIBLE} from "react-native-secure-key-store";

export default class example extends Component {
render() {

RNSecureKeyStore.set("key1", "value1")
RNSecureKeyStore.set("key1", "value1", {accessible: ACCESSIBLE.ALWAYS_THIS_DEVICE_ONLY})
.then((res) => {
console.log(res);
}, (err) => {
console.log(err);
});

RNSecureKeyStore.set("key2", "value2")
RNSecureKeyStore.set("key2", "value2", {accessible: ACCESSIBLE.ALWAYS_THIS_DEVICE_ONLY})
.then((res) => {
console.log(res);
}, (err) => {
Expand Down
Loading

0 comments on commit eec1d9c

Please sign in to comment.