Skip to content

Commit 99d010b

Browse files
authored
Merge pull request #115 from star-collector/keystore
Updated keystore branch
2 parents d4e6eea + d5f5d0a commit 99d010b

65 files changed

Lines changed: 34850 additions & 4322 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ example/node_modules
3838

3939
android/build/
4040
android/local.properties
41+
android.yml
42+
*.iml

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example/

README.md

Lines changed: 110 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
[![npm version](https://badge.fury.io/js/react-native-sensitive-info.svg)](https://badge.fury.io/js/react-native-sensitive-info)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5+
[![Open Source Love](https://badges.frapsoft.com/os/v2/open-source.png?v=103)](https://github.com/ellerbrock/open-source-badges/)
6+
57

68
**react-native-sensitive-info** is the next generation of [react-native-get-shared-prefs](https://www.npmjs.com/package/react-native-get-shared-prefs).
79

810
# Introduction
911

10-
`react-native-sensitive-info` manages all data stored in Android Shared Preferences and iOS Keychain. You can set and get all key/value using simple methods.
12+
`react-native-sensitive-info` manages all data stored in Android Shared Preferences, iOS Keychain and Windows Credentials. You can set and get all key/value using simple methods.
1113

1214

1315
| RN SensitiveInfo Version | Description |
@@ -19,7 +21,7 @@
1921

2022
Install `react-native-sensitive-info` using:
2123

22-
``npm i -S react-native-sensitive-info``
24+
``npm i -S react-native-sensitive-info`` or ``yarn add react-native-sensitive-info``
2325

2426
## Linking project
2527

@@ -31,6 +33,13 @@ Install `react-native-sensitive-info` using:
3133

3234
#### iOS
3335

36+
If you are using Cocoapods add the following line to your Podfile:
37+
```ruby
38+
pod 'react-native-sensitive-info', path: "../node_modules/react-native-sensitive-info"
39+
```
40+
41+
otherwise follow those steps:
42+
3443
In XCode, in the project navigator:
3544

3645
* Right click Libraries
@@ -46,6 +55,10 @@ In XCode, in the project navigator, select your project.
4655

4756
Run your project (Cmd+R)
4857

58+
#### macos (https://github.com/ptmt/react-native-macos)
59+
60+
Same steps as iOS but change the Base SDK to macOS in Libraries/RNSensitiveInfo.xcodeproj.
61+
4962
#### Android
5063

5164
Go to `settings.gradle` inside your android project folder and paste this lines there:
@@ -76,23 +89,53 @@ protected List<ReactPackage> getPackages() {
7689

7790
Sync gradle and go :)
7891

79-
# Changelog
92+
#### Windows
8093

81-
## Since version >= 5.0.0
94+
* Open the solution in Visual Studio for your Windows apps.
8295

83-
We introduced **Android Keystore** security into our library. Also, we've fixed some issues and updated example.
96+
* Right click your in the Explorer and click Add > Existing Project....
8497

85-
Thanks to all contributors who helped us on our journey :)
98+
* Navigate to ./<app-name>/node_modules/react-native-sensitive-info/windows/RNSensitiveInfo/RNSensitiveInfo/ and add RNSensitiveInfo.csproj.
8699

87-
## Since version >= 3.0.0
100+
* Right click on your React Native Windows app under your solutions directory and click Add > Reference....
101+
102+
* Check the RNSensitiveInfo you just added and press Ok
103+
104+
* Open MainPage.cs in your app
105+
106+
```
107+
using RNSqlite2;
108+
109+
get
110+
{
111+
return new List<IReactPackage>
112+
{
113+
new MainReactPackage(),
114+
new RNSensitiveInfoPackage(),
115+
};
116+
}
117+
```
118+
119+
120+
### Expo
121+
122+
As noted by by [@Palisand](https://github.com/Palisand) in [this issue](https://github.com/mCodex/react-native-sensitive-info/issues/50#issuecomment-334583668), it's not possible to use this module with Expo, unless your project is detached. The same is true for any modules with native code, it's not an issue with `react-native-sensitive-info`. You may want to try [SecureStore](https://docs.expo.io/versions/latest/sdk/securestore.html) from Expo itself.
123+
124+
# Methods
88125

89126
We unified our library's methods to bring more efficiency and simplify the usability for other developers. We hope that you enjoy it. :)
90127

91-
`setItem(key, value, options)`: You can insert data into shared preferences & keychain using this method.
128+
`isHardwareDetected()`: resolves to a boolean that indicates the detection of fingerprint hardware
129+
130+
`hasEnrolledFingerprints()`: resolves to a boolean that indicates the enrollment status of fingerprints on the device
131+
132+
`isSensorAvailable`: resolves to a boolean that indicates the overall availability of fingerprint sensor (a combination of the previous two methods)
133+
134+
`setItem(key, value, options)`: You can insert data into shared preferences & keychain using this promise method.
92135

93136
`getItem(key, options)`: This promise will get value from given key.
94137

95-
`deleteItem(key, options)`: (New method since this version) It will delete value from given key
138+
`deleteItem(key, options)`: It will delete value from given key
96139

97140
`getAllItems(options)`: Will retrieve all keys and values from Shared Preferences & Keychain
98141

@@ -105,9 +148,43 @@ keychainService: 'myKeychain',
105148
encrypt: true});
106149
```
107150

108-
But if you prefer to not use it, our default sharedPreferencesName is: **shared_preferences** and keychainService is: **app**
151+
If you used Android's getDefaultSharedPreferences in your project the shared preference's name that you are looking for is: **com.mypackage.MyApp_preferences**. On the other hand if you used iOS's Keychain the default service is: **app** which is our default too.
152+
153+
### Android Specific Options
109154

110-
If you used Android's getDefaultSharedPreferences in your project the shared preference's name that you are looking for is: **com.mypackage.MyApp_preferences**. In other hands if you used iOS's Keychain the default service is: **app** which is our default too.
155+
#### showModal & strings
156+
157+
When passing in `touchID` and `showModal` (Android only) options as `true`, an Android native prompt will show up asking for user's authentication. This behavior is similar to that of iOS.
158+
159+
You can control strings associated with a modal prompt via `strings` option:
160+
```javascript
161+
strings: {
162+
header: 'Sign in',
163+
description: 'Place finger to authenticate',
164+
hint: 'Touch',
165+
success: 'Fingerprint recognized',
166+
notRecognized: 'Fingerprint not recognized, try again',
167+
cancel: 'Cancel',
168+
cancelled: 'Authentication was cancelled', // reject error message
169+
}
170+
```
171+
172+
### iOS Specific Options
173+
174+
#### kSecAccessControl
175+
176+
When passing in the `touchID` option as `true`, you can also set `kSecAccessControl`. For example:
177+
178+
```javascript
179+
SInfo.setItem('key1', 'value1', {
180+
keychainService: 'myKeychain',
181+
kSecAccessControl: 'kSecAccessControlTouchIDCurrentSet',
182+
sharedPreferencesName: 'mySharedPrefs',
183+
touchID: true,
184+
});
185+
```
186+
187+
Note: By default `kSecAccessControl` will get set to `kSecAccessControlUserPresence`.
111188

112189
# How to use?
113190

@@ -118,29 +195,45 @@ import SInfo from 'react-native-sensitive-info';
118195

119196
SInfo.setItem('key1', 'value1', {
120197
sharedPreferencesName: 'mySharedPrefs',
121-
keychainService: 'myKeychain',
122-
encrypt: true
123-
});
198+
keychainService: 'myKeychain'
199+
}).then((value) =>
200+
console.log(value) //value 1
201+
);
124202

125-
SInfo.setItem('key2', 'value2');
203+
SInfo.setItem('key2', 'value2', {});
126204

127205
SInfo.getItem('key1', {
128206
sharedPreferencesName: 'mySharedPrefs',
129207
keychainService: 'myKeychain'}).then(value => {
130208
console.log(value) //value1
131209
});
132210

133-
SInfo.getItem('key2').then(value => {
211+
SInfo.getItem('key2',{}).then(value => {
134212
console.log(value) //value2
135213
});
136214

137215
SInfo.getAllItems({
138216
sharedPreferencesName: 'mySharedPrefs',
139217
keychainService: 'myKeychain'}).then(values => {
140-
console.log(values) //value1
218+
console.log(values) //value1, value2
141219
});
142220
```
143221

222+
# Protect your item with fingerprint
223+
As jailbroken device can access your iOS Keychain/ Android shared preference and key store in plain text, it is necessary to add another layer of protection so even jailbreaking won't leak your data (like refresh_token or bank account password).
224+
- for iOS it is implemented though [Access Control](https://developer.apple.com/documentation/security/secaccesscontrol). Everytime when app wants to access the protected keychain item, a prompt by iOS will show up. Only when authentication success will the app get the keychain item.
225+
- for Android it is implemented though [FingerprintManager](https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html) + Keystore. Keystore has a function called `setUserAuthenticationRequired` which makes Keystore requires user authentication before getting value. However Android doesn't nicely user to scan their finger, it just throws error. Here is where FingerprintManager comes in. However (AGAIN) FingerprintManager doesn't show prompt for you, so you need to build UI yourself to let user to know that it is time to scan fingerprint.
226+
227+
**The example in the repo shows how to use this feature and how to build some Android UI based on callbacks.**
228+
229+
**NOTE: fingerprint will only work with Android 6.0 and above.**
230+
231+
HELP NEEDED: It will be nice if someone can build an Android native prompt to make Android touch as easy to use as iOS. Maybe we can borrow some code from [google's example](https://github.com/googlesamples/android-FingerprintDialog)
232+
233+
# Use with redux-persist
234+
235+
If you would like to use [redux-persist](https://github.com/rt2zz/redux-persist) to store information from your Redux state into secure storage, you can use [redux-persist-sensitive-storage](https://github.com/CodingZeal/redux-persist-sensitive-storage), which provides a custom storage back-end for redux-persist that uses react-native-sensitive-info.
236+
144237
# Contributing
145238

146239
Pull requests are always welcome :)

android/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 25
5-
buildToolsVersion "25.0.3"
4+
compileSdkVersion rootProject.ext.compileSdkVersion
5+
buildToolsVersion rootProject.ext.buildToolsVersion
66

77
defaultConfig {
8-
minSdkVersion 16
9-
targetSdkVersion 25
8+
minSdkVersion rootProject.ext.minSdkVersion
9+
targetSdkVersion rootProject.ext.targetSdkVersion
1010
versionCode 1
1111
versionName "1.0"
1212
ndk {
1313
abiFilters "armeabi-v7a", "x86"
1414
}
1515
}
1616
lintOptions {
17-
warning 'InvalidPackage'
17+
warning 'InvalidPackage'
1818
}
1919
}
2020

2121
dependencies {
22-
compile 'com.facebook.react:react-native:0.20.1'
22+
implementation 'com.facebook.react:react-native:+'
2323
}
52.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue May 16 10:45:51 BRT 2017
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

0 commit comments

Comments
 (0)