-
-
Save tompsota/e0198fdb90ff69c407b70f99b9322240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useFreeRasp } from 'freerasp-react-native'; | |
import React, { useEffect, useState } from 'react'; | |
import { androidChecks, commonChecks, iosChecks } from './checks'; | |
import { Platform, View } from 'react-native'; | |
import { Text } from '@react-native-material/core'; | |
export const WhoIsIn = () => { | |
const [appChecks, setAppChecks] = useState([ | |
...commonChecks, | |
...(Platform.OS === 'ios' ? iosChecks : androidChecks), | |
]); | |
const [isCompromised, setIsCompromised] = useState(false); | |
const isRelease = !__DEV__ ? true : false; | |
const config = { | |
androidConfig: { | |
packageName: 'com.test', | |
certificateHashes: ['r********************************8='], | |
supportedAlternativeStores: [], | |
}, | |
iosConfig: { | |
appBundleId: 'com.test', | |
appTeamId: '********', | |
}, | |
watcherMail: '****@****.com', | |
isProd: isRelease, | |
}; | |
console.log('is release', isRelease); | |
const actions = { | |
// Android & iOS | |
privilegedAccess: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Privileged Access' | |
? { ...threat, status: isRelease ? 'nok' : 'ok' } | |
: threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'privilegedAccess' }); | |
}, | |
// Android & iOS | |
debug: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Debug' | |
? { ...threat, status: isRelease ? 'nok' : 'ok' } | |
: threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'debug' }); | |
}, | |
// Android & iOS | |
simulator: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Simulator' | |
? { ...threat, status: isRelease ? 'nok' : 'ok' } | |
: threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'simulator' }); | |
}, | |
// Android & iOS | |
appIntegrity: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'App Integrity' | |
? { ...threat, status: isRelease ? 'nok' : 'ok' } | |
: threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'appIntegrity' }); | |
}, | |
// Android & iOS | |
unofficialStore: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Unofficial Store' | |
? { ...threat, status: isRelease ? 'nok' : 'ok' } | |
: threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'unofficialStore' }); | |
}, | |
// Android & iOS | |
hooks: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Hooks' ? { ...threat, status: 'nok' } : threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'hooks' }); | |
}, | |
// Android & iOS | |
deviceBinding: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Device Binding' | |
? { ...threat, status: 'nok' } | |
: threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'deviceBinding' }); | |
}, | |
// Android & iOS | |
secureHardwareNotAvailable: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Secure Hardware Not Available' | |
? { ...threat, status: isRelease ? 'nok' : 'ok' } | |
: threat | |
) | |
); | |
console.log('Security Threat Detected', { | |
type: 'secureHardwareNotAvailable', | |
}); | |
}, | |
// Android & iOS | |
passcode: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Passcode' ? { ...threat, status: 'ok' } : threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'passcode' }); | |
}, | |
// iOS only | |
deviceID: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Device ID' ? { ...threat, status: 'ok' } : threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'deviceID' }); | |
}, | |
// Android only | |
obfuscationIssues: () => { | |
setAppChecks((currentState) => | |
currentState.map((threat) => | |
threat.name === 'Obfuscation Issues' | |
? { ...threat, status: 'nok' } | |
: threat | |
) | |
); | |
console.log('Security Threat Detected', { type: 'obfuscationIssues' }); | |
}, | |
}; | |
const checkWhoIsIn = () => { | |
const isNokAvailable = appChecks.some((element) => { | |
if (element.status === 'nok') { | |
return true; | |
} | |
return false; | |
}); | |
return isNokAvailable; | |
}; | |
useEffect(() => { | |
setIsCompromised(checkWhoIsIn()); | |
console.log(JSON.stringify(appChecks)); | |
// eslint-disable-next-line react-hooks/exhaustive-deps | |
}, [appChecks]); | |
useFreeRasp(config, actions); | |
if (!isCompromised) { | |
console.log('not compromised'); | |
return null; | |
} | |
console.log('compromised'); | |
return ( | |
<View> | |
<Text>Access Denied</Text> | |
</View> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment