Browse Source

swap rn secure key store dependency for rn keychain

pull/1/head
Tim Glasgow 2 years ago
parent
commit
c89e86a61f
  1. 43
      changeme/__mock__/mockKeyStore.js
  2. 2
      changeme/jest.config.js
  3. 22
      changeme/package-lock.json
  4. 2
      changeme/package.json
  5. 4
      changeme/src/realm/DbInit.js
  6. 19
      changeme/src/services/Keystore.js

43
changeme/__mock__/mockKeyStore.js

@ -1,32 +1,29 @@
class MockKeyStore {
async remove(key) {
if (key === 'notakey') {
throw ('Key not found');
}
return true;
}
async set(key, value) { export async function resetInternetCredentials(key) {
if (key === 'savefailed'){ if (key === 'notakey') {
throw ('Failed to save key'); throw ('Key not found');
}
return true;
} }
return true;
}
async get(key) { export async function setInternetCredentials(key, value, placeholder) {
if (key === 'isNull'){ if (key === 'savefailed'){
return null; throw ('Failed to save key');
} else if (key === 'negTest') {
return '-1';
} else if (key === 'notakey') {
throw ('Key not found');
} else {
return '1234567890';
}
} }
return true;
} }
export default RNSecureKeyStore = new MockKeyStore(); export async function getInternetCredentials(key) {
if (key === 'isNull'){
return false;
} else if (key === 'negTest') {
return {username: '-1'};
} else if (key === 'notakey') {
throw ('Key not found');
} else {
return {username: '1234567890'};
}
}
export const ACCESSIBLE = { export const ACCESSIBLE = {
AFTER_FIRST_UNLOCK :'AccessibleAfterFirstUnlock', AFTER_FIRST_UNLOCK :'AccessibleAfterFirstUnlock',

2
changeme/jest.config.js

@ -6,7 +6,7 @@ module.exports = {
moduleDirectories: ['node_modules', 'src'], moduleDirectories: ['node_modules', 'src'],
moduleNameMapper: { moduleNameMapper: {
// '@react-native-firebase/messaging: '<rootDir>/__mock__/mockFirebase.js', // '@react-native-firebase/messaging: '<rootDir>/__mock__/mockFirebase.js',
'react-native-secure-key-store': '<rootDir>/__mock__/mockKeyStore.js', 'react-native-keychain': '<rootDir>/__mock__/mockKeyStore.js',
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mock__/file.js', '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mock__/file.js',
'^(realm)': '<rootDir>/__mock__/mockRealmObject' '^(realm)': '<rootDir>/__mock__/mockRealmObject'
}, },

22
changeme/package-lock.json

@ -15,9 +15,9 @@
"react-native": "0.69.2", "react-native": "0.69.2",
"react-native-gesture-handler": "^2.5.0", "react-native-gesture-handler": "^2.5.0",
"react-native-get-random-values": "^1.8.0", "react-native-get-random-values": "^1.8.0",
"react-native-keychain": "^8.1.1",
"react-native-safe-area-context": "^4.3.1", "react-native-safe-area-context": "^4.3.1",
"react-native-screens": "^3.15.0", "react-native-screens": "^3.15.0",
"react-native-secure-key-store": "^2.0.9",
"react-native-vector-icons": "^9.2.0", "react-native-vector-icons": "^9.2.0",
"react-redux": "^8.0.2", "react-redux": "^8.0.2",
"realm": "^10.19.5", "realm": "^10.19.5",
@ -14507,6 +14507,11 @@
"resolved": "https://registry.npmjs.org/react-native-gradle-plugin/-/react-native-gradle-plugin-0.0.7.tgz", "resolved": "https://registry.npmjs.org/react-native-gradle-plugin/-/react-native-gradle-plugin-0.0.7.tgz",
"integrity": "sha512-+4JpbIx42zGTONhBTIXSyfyHICHC29VTvhkkoUOJAh/XHPEixpuBduYgf6Y4y9wsN1ARlQhBBoptTvXvAFQf5g==" "integrity": "sha512-+4JpbIx42zGTONhBTIXSyfyHICHC29VTvhkkoUOJAh/XHPEixpuBduYgf6Y4y9wsN1ARlQhBBoptTvXvAFQf5g=="
}, },
"node_modules/react-native-keychain": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/react-native-keychain/-/react-native-keychain-8.1.1.tgz",
"integrity": "sha512-8fxgeHKwGcL657eAYpdBTkDIxNhbIHI+kyyO0Yac2dgVAN184JoIwQcW2z6snahwDaCObQOu0biLFHnsH+4KSg=="
},
"node_modules/react-native-safe-area-context": { "node_modules/react-native-safe-area-context": {
"version": "4.3.1", "version": "4.3.1",
"resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-4.3.1.tgz", "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-4.3.1.tgz",
@ -14540,11 +14545,6 @@
"react": "^17.0.0" "react": "^17.0.0"
} }
}, },
"node_modules/react-native-secure-key-store": {
"version": "2.0.9",
"resolved": "https://registry.npmjs.org/react-native-secure-key-store/-/react-native-secure-key-store-2.0.9.tgz",
"integrity": "sha512-9qi1rOlv4qNSpJIjqcIB7d0EQSwo2Yho8NVBT/Jc9NeYibDLHdArLXl8jn8H6nlf+8alk/bXqr4rPINrCTtmog=="
},
"node_modules/react-native-vector-icons": { "node_modules/react-native-vector-icons": {
"version": "9.2.0", "version": "9.2.0",
"resolved": "https://registry.npmjs.org/react-native-vector-icons/-/react-native-vector-icons-9.2.0.tgz", "resolved": "https://registry.npmjs.org/react-native-vector-icons/-/react-native-vector-icons-9.2.0.tgz",
@ -28080,6 +28080,11 @@
"resolved": "https://registry.npmjs.org/react-native-gradle-plugin/-/react-native-gradle-plugin-0.0.7.tgz", "resolved": "https://registry.npmjs.org/react-native-gradle-plugin/-/react-native-gradle-plugin-0.0.7.tgz",
"integrity": "sha512-+4JpbIx42zGTONhBTIXSyfyHICHC29VTvhkkoUOJAh/XHPEixpuBduYgf6Y4y9wsN1ARlQhBBoptTvXvAFQf5g==" "integrity": "sha512-+4JpbIx42zGTONhBTIXSyfyHICHC29VTvhkkoUOJAh/XHPEixpuBduYgf6Y4y9wsN1ARlQhBBoptTvXvAFQf5g=="
}, },
"react-native-keychain": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/react-native-keychain/-/react-native-keychain-8.1.1.tgz",
"integrity": "sha512-8fxgeHKwGcL657eAYpdBTkDIxNhbIHI+kyyO0Yac2dgVAN184JoIwQcW2z6snahwDaCObQOu0biLFHnsH+4KSg=="
},
"react-native-safe-area-context": { "react-native-safe-area-context": {
"version": "4.3.1", "version": "4.3.1",
"resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-4.3.1.tgz", "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-4.3.1.tgz",
@ -28103,11 +28108,6 @@
} }
} }
}, },
"react-native-secure-key-store": {
"version": "2.0.9",
"resolved": "https://registry.npmjs.org/react-native-secure-key-store/-/react-native-secure-key-store-2.0.9.tgz",
"integrity": "sha512-9qi1rOlv4qNSpJIjqcIB7d0EQSwo2Yho8NVBT/Jc9NeYibDLHdArLXl8jn8H6nlf+8alk/bXqr4rPINrCTtmog=="
},
"react-native-vector-icons": { "react-native-vector-icons": {
"version": "9.2.0", "version": "9.2.0",
"resolved": "https://registry.npmjs.org/react-native-vector-icons/-/react-native-vector-icons-9.2.0.tgz", "resolved": "https://registry.npmjs.org/react-native-vector-icons/-/react-native-vector-icons-9.2.0.tgz",

2
changeme/package.json

@ -27,9 +27,9 @@
"react-native": "0.69.2", "react-native": "0.69.2",
"react-native-gesture-handler": "^2.5.0", "react-native-gesture-handler": "^2.5.0",
"react-native-get-random-values": "^1.8.0", "react-native-get-random-values": "^1.8.0",
"react-native-keychain": "^8.1.1",
"react-native-safe-area-context": "^4.3.1", "react-native-safe-area-context": "^4.3.1",
"react-native-screens": "^3.15.0", "react-native-screens": "^3.15.0",
"react-native-secure-key-store": "^2.0.9",
"react-native-vector-icons": "^9.2.0", "react-native-vector-icons": "^9.2.0",
"react-redux": "^8.0.2", "react-redux": "^8.0.2",
"realm": "^10.19.5", "realm": "^10.19.5",

4
changeme/src/realm/DbInit.js

@ -20,14 +20,14 @@ export async function initDB(dbKeyRef = 'appDB', dbLocation = Realm.defaultPath)
try { try {
let fromStore = await KeyStore.getKey(dbKeyRef); let fromStore = await KeyStore.getKey(dbKeyRef);
if (fromStore === null) { if (fromStore === false) {
let newKey = generateKey(); let newKey = generateKey();
await KeyStore.setKey(dbKeyRef, newKey); await KeyStore.setKey(dbKeyRef, newKey);
fromStore = await KeyStore.getKey(dbKeyRef); fromStore = await KeyStore.getKey(dbKeyRef);
} }
let dbKey = new Uint8Array(64); let dbKey = new Uint8Array(64);
if (fromStore !== null){ if (fromStore !== false){
for (let i = 0; i < 64; ++i){ for (let i = 0; i < 64; ++i){
dbKey[i] = fromStore.charAt(i); dbKey[i] = fromStore.charAt(i);
} }

19
changeme/src/services/Keystore.js

@ -1,8 +1,13 @@
import RNSecureKeyStore, {ACCESSIBLE} from 'react-native-secure-key-store'; import {
setInternetCredentials,
getInternetCredentials,
resetInternetCredentials,
ACCESSIBLE
} from "react-native-keychain";
export async function removeKey(key) { export async function removeKey(key) {
let outcome = null; let outcome = null;
await RNSecureKeyStore.remove(key).then( await resetInternetCredentials(key).then(
(res) => { (res) => {
outcome = true; outcome = true;
}, },
@ -16,7 +21,7 @@ export async function removeKey(key) {
export async function setKey(key, value) { export async function setKey(key, value) {
let outcome = null; let outcome = null;
await RNSecureKeyStore.set(key, value, { await setInternetCredentials(key, value, 'none', {
accessible: ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY, accessible: ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
}).then( }).then(
(res) => { (res) => {
@ -32,9 +37,13 @@ export async function setKey(key, value) {
export async function getKey(key) { export async function getKey(key) {
let value = null; let value = null;
await RNSecureKeyStore.get(key).then( await getInternetCredentials(key).then(
(res) => { (res) => {
value = res; if (res === false) {
value = false;
} else {
value = res.username;
}
}, },
(err) => { (err) => {
value = null; value = null;

Loading…
Cancel
Save