react-native-device-defense 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +236 -0
- package/android/build.gradle +90 -0
- package/android/proguard-rules.pro +28 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/cpp/CMakeLists.txt +45 -0
- package/android/src/main/cpp/device-security.cpp +314 -0
- package/android/src/main/java/vn/osp/security/DebugDetection.kt +131 -0
- package/android/src/main/java/vn/osp/security/DeviceSecurityModule.kt +277 -0
- package/android/src/main/java/vn/osp/security/DeviceSecurityPackage.kt +58 -0
- package/android/src/main/java/vn/osp/security/EmulatorDetection.kt +204 -0
- package/android/src/main/java/vn/osp/security/HookDetection.kt +270 -0
- package/android/src/main/java/vn/osp/security/NativeSecurityCheck.kt +66 -0
- package/android/src/main/java/vn/osp/security/RootDetection.kt +349 -0
- package/lib/commonjs/NativeDeviceSecurity.js +9 -0
- package/lib/commonjs/NativeDeviceSecurity.js.map +1 -0
- package/lib/commonjs/api.js +213 -0
- package/lib/commonjs/api.js.map +1 -0
- package/lib/commonjs/components/SecurityBlockedScreen.js +177 -0
- package/lib/commonjs/components/SecurityBlockedScreen.js.map +1 -0
- package/lib/commonjs/components/index.js +13 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/hooks/index.js +13 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/hooks/useDeviceSecurity.js +81 -0
- package/lib/commonjs/hooks/useDeviceSecurity.js.map +1 -0
- package/lib/commonjs/index.js +48 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/NativeDeviceSecurity.js +3 -0
- package/lib/module/NativeDeviceSecurity.js.map +1 -0
- package/lib/module/api.js +206 -0
- package/lib/module/api.js.map +1 -0
- package/lib/module/components/SecurityBlockedScreen.js +169 -0
- package/lib/module/components/SecurityBlockedScreen.js.map +1 -0
- package/lib/module/components/index.js +2 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/hooks/index.js +2 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useDeviceSecurity.js +73 -0
- package/lib/module/hooks/useDeviceSecurity.js.map +1 -0
- package/lib/module/index.js +21 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/NativeDeviceSecurity.d.ts +16 -0
- package/lib/typescript/NativeDeviceSecurity.d.ts.map +1 -0
- package/lib/typescript/api.d.ts +55 -0
- package/lib/typescript/api.d.ts.map +1 -0
- package/lib/typescript/components/SecurityBlockedScreen.d.ts +23 -0
- package/lib/typescript/components/SecurityBlockedScreen.d.ts.map +1 -0
- package/lib/typescript/components/index.d.ts +2 -0
- package/lib/typescript/components/index.d.ts.map +1 -0
- package/lib/typescript/hooks/index.d.ts +3 -0
- package/lib/typescript/hooks/index.d.ts.map +1 -0
- package/lib/typescript/hooks/useDeviceSecurity.d.ts +7 -0
- package/lib/typescript/hooks/useDeviceSecurity.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +12 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +81 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +72 -0
- package/react-native-device-security.podspec +18 -0
- package/src/NativeDeviceSecurity.ts +33 -0
- package/src/api.ts +225 -0
- package/src/components/SecurityBlockedScreen.tsx +204 -0
- package/src/components/index.ts +1 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useDeviceSecurity.ts +91 -0
- package/src/index.ts +27 -0
- package/src/types.ts +95 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook for device security
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
6
|
+
import { Platform } from 'react-native';
|
|
7
|
+
import deviceSecurity from '../api';
|
|
8
|
+
import type {
|
|
9
|
+
SecurityStatus,
|
|
10
|
+
UseDeviceSecurityOptions,
|
|
11
|
+
UseDeviceSecurityReturn,
|
|
12
|
+
} from '../types';
|
|
13
|
+
|
|
14
|
+
export function useDeviceSecurity(
|
|
15
|
+
options: UseDeviceSecurityOptions = {},
|
|
16
|
+
): UseDeviceSecurityReturn {
|
|
17
|
+
const {
|
|
18
|
+
onSecurityThreat,
|
|
19
|
+
blockOnThreat = false,
|
|
20
|
+
blockOptions,
|
|
21
|
+
checkInterval = 0,
|
|
22
|
+
} = options;
|
|
23
|
+
|
|
24
|
+
const [isSecure, setIsSecure] = useState<boolean | null>(null);
|
|
25
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
26
|
+
const [securityStatus, setSecurityStatus] = useState<SecurityStatus | null>(
|
|
27
|
+
null,
|
|
28
|
+
);
|
|
29
|
+
const [error, setError] = useState<Error | null>(null);
|
|
30
|
+
|
|
31
|
+
const checkSecurity = useCallback(async () => {
|
|
32
|
+
if (Platform.OS !== 'android') {
|
|
33
|
+
setIsSecure(true);
|
|
34
|
+
setIsLoading(false);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
setIsLoading(true);
|
|
40
|
+
setError(null);
|
|
41
|
+
|
|
42
|
+
const status = await deviceSecurity.getSecurityStatus();
|
|
43
|
+
setSecurityStatus(status);
|
|
44
|
+
setIsSecure(status.isSecure);
|
|
45
|
+
|
|
46
|
+
// Handle security threats
|
|
47
|
+
if (!status.isSecure) {
|
|
48
|
+
// Call callback for each threat
|
|
49
|
+
for (const threat of status.threats) {
|
|
50
|
+
onSecurityThreat?.(threat, status);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Block if requested
|
|
54
|
+
if (blockOnThreat) {
|
|
55
|
+
deviceSecurity.blockOnSecurityThreat(blockOptions);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
const errorObj =
|
|
60
|
+
err instanceof Error ? err : new Error('Security check failed');
|
|
61
|
+
setError(errorObj);
|
|
62
|
+
setIsSecure(false);
|
|
63
|
+
} finally {
|
|
64
|
+
setIsLoading(false);
|
|
65
|
+
}
|
|
66
|
+
}, [onSecurityThreat, blockOnThreat, blockOptions]);
|
|
67
|
+
|
|
68
|
+
const recheck = useCallback(async () => {
|
|
69
|
+
await checkSecurity();
|
|
70
|
+
}, [checkSecurity]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
checkSecurity();
|
|
74
|
+
|
|
75
|
+
// Set up interval if specified
|
|
76
|
+
if (checkInterval > 0) {
|
|
77
|
+
const intervalId = setInterval(checkSecurity, checkInterval);
|
|
78
|
+
return () => clearInterval(intervalId);
|
|
79
|
+
}
|
|
80
|
+
}, [checkSecurity, checkInterval]);
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
isSecure,
|
|
84
|
+
isLoading,
|
|
85
|
+
securityStatus,
|
|
86
|
+
error,
|
|
87
|
+
recheck,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default useDeviceSecurity;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-native-device-security
|
|
3
|
+
*
|
|
4
|
+
* Main exports for the library
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Main API
|
|
8
|
+
export { default as DeviceSecurity, DeviceSecurity as DeviceSecurityClass } from './api';
|
|
9
|
+
export { default } from './api';
|
|
10
|
+
|
|
11
|
+
// Native module spec
|
|
12
|
+
export { default as NativeDeviceSecurity } from './NativeDeviceSecurity';
|
|
13
|
+
|
|
14
|
+
// Hooks
|
|
15
|
+
export { useDeviceSecurity } from './hooks';
|
|
16
|
+
|
|
17
|
+
// Components
|
|
18
|
+
export { SecurityBlockedScreen } from './components';
|
|
19
|
+
|
|
20
|
+
// Types
|
|
21
|
+
export type {
|
|
22
|
+
SecurityStatus,
|
|
23
|
+
SecurityThreat,
|
|
24
|
+
BlockOnSecurityThreatOptions,
|
|
25
|
+
UseDeviceSecurityOptions,
|
|
26
|
+
UseDeviceSecurityReturn,
|
|
27
|
+
} from './types';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security threat types
|
|
3
|
+
*/
|
|
4
|
+
export type SecurityThreat =
|
|
5
|
+
| 'root_detected'
|
|
6
|
+
| 'root_beer_detected'
|
|
7
|
+
| 'native_root_detected'
|
|
8
|
+
| 'dangerous_bins_detected'
|
|
9
|
+
| 'root_apps_detected'
|
|
10
|
+
| 'system_props_modified'
|
|
11
|
+
| 'frida_detected'
|
|
12
|
+
| 'xposed_detected'
|
|
13
|
+
| 'magisk_detected'
|
|
14
|
+
| 'debugger_detected'
|
|
15
|
+
| 'emulator_detected';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Detailed security status
|
|
19
|
+
*/
|
|
20
|
+
export interface SecurityStatus {
|
|
21
|
+
/** Overall security status */
|
|
22
|
+
isSecure: boolean;
|
|
23
|
+
/** List of detected threats */
|
|
24
|
+
threats: SecurityThreat[];
|
|
25
|
+
/** Device is rooted */
|
|
26
|
+
isRooted: boolean;
|
|
27
|
+
/** RootBeer library detected root */
|
|
28
|
+
hasRootBeerDetected: boolean;
|
|
29
|
+
/** Native C++ detection found root */
|
|
30
|
+
hasNativeRootDetected: boolean;
|
|
31
|
+
/** Dangerous binaries found */
|
|
32
|
+
hasDangerousBins: boolean;
|
|
33
|
+
/** Root management apps found */
|
|
34
|
+
hasRootApps: boolean;
|
|
35
|
+
/** System properties modified */
|
|
36
|
+
hasSystemPropsModified: boolean;
|
|
37
|
+
/** Frida framework detected */
|
|
38
|
+
hasFrida: boolean;
|
|
39
|
+
/** Xposed framework detected */
|
|
40
|
+
hasXposed: boolean;
|
|
41
|
+
/** Magisk detected */
|
|
42
|
+
hasMagisk: boolean;
|
|
43
|
+
/** Debugger is attached */
|
|
44
|
+
isDebuggable: boolean;
|
|
45
|
+
/** Running on emulator */
|
|
46
|
+
isEmulator: boolean;
|
|
47
|
+
/** Additional details about detection */
|
|
48
|
+
details?: Record<string, boolean | string | number>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Options for blocking on security threat
|
|
53
|
+
*/
|
|
54
|
+
export interface BlockOnSecurityThreatOptions {
|
|
55
|
+
/** Show alert to user when blocked */
|
|
56
|
+
showAlert?: boolean;
|
|
57
|
+
/** Custom alert title (default: 'Security Warning') */
|
|
58
|
+
alertTitle?: string;
|
|
59
|
+
/** Custom alert message */
|
|
60
|
+
alertMessage?: string;
|
|
61
|
+
/** Alert button text (default: 'OK') */
|
|
62
|
+
alertButtonText?: string;
|
|
63
|
+
/** Callback when app is blocked */
|
|
64
|
+
onBlocked?: (status: SecurityStatus) => void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Hook options
|
|
69
|
+
*/
|
|
70
|
+
export interface UseDeviceSecurityOptions {
|
|
71
|
+
/** Callback when security threat detected */
|
|
72
|
+
onSecurityThreat?: (threat: SecurityThreat, status: SecurityStatus) => void;
|
|
73
|
+
/** Block app when threat detected */
|
|
74
|
+
blockOnThreat?: boolean;
|
|
75
|
+
/** Custom block options */
|
|
76
|
+
blockOptions?: BlockOnSecurityThreatOptions;
|
|
77
|
+
/** Check interval in ms (default: 0 - check once) */
|
|
78
|
+
checkInterval?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Hook return value
|
|
83
|
+
*/
|
|
84
|
+
export interface UseDeviceSecurityReturn {
|
|
85
|
+
/** Device is secure */
|
|
86
|
+
isSecure: boolean | null;
|
|
87
|
+
/** Loading state */
|
|
88
|
+
isLoading: boolean;
|
|
89
|
+
/** Security status details */
|
|
90
|
+
securityStatus: SecurityStatus | null;
|
|
91
|
+
/** Error if any */
|
|
92
|
+
error: Error | null;
|
|
93
|
+
/** Manually re-check security */
|
|
94
|
+
recheck: () => Promise<void>;
|
|
95
|
+
}
|