UNPKG

react-native-malwarelytics

Version:

Malwarelytics for React Native protects your banking or fintech app from a broad range of mobile security threats with an industry-leading mobile threat intelligence solution.

325 lines (297 loc) 9.3 kB
// // Copyright 2023 Wultra s.r.o. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions // and limitations under the License. // import { wrapNativeCall } from "./internal/MalwarelyticsModule"; import { Platform } from "react-native"; import { MalwarelyticsError } from "./MalwarelyticsError"; /** * Malwarelytics RASP module. */ export class MalwarelyticsRasp { constructor(eventHelper) { this.eventHelper = eventHelper; this.module = eventHelper.module; } /** * Instance of EventHelper shared with Malwarelytics class. */ /** * Instance of native module interface. */ /** * Object representing a subscription to RASP events. */ /** * Set listener for RASP events. * @param listener Listener implementation. */ async setRaspListener(listener) { this.raspEventsSubscription?.remove(); this.raspEventsSubscription = await this.eventHelper.addListener('Malwarelytics.RASP', data => { //console.log(`${Platform.OS}: RASP event: ${JSON.stringify(data)}`) const m = data; switch (m.type) { // Apple + Android case "DEBUGGER": listener.debuggerDetected(m.payload); break; case "REPACKAGED": listener.repackagingDetected(m.payload); break; case "SYSTEM_INTEGRITY": listener.systemIntegrityCompromised(m.payload); break; case "HTTP_PROXY": listener.httpProxyDetected(m.payload); break; case "SCREEN_SHARING": listener.screenSharingDetected(m.payload); break; case "EMULATOR": listener.emulatorDetected(m.payload); break; case "VPN": listener.vpnDetected(m.payload); break; case "APP_PRESENCE": listener.appPresenceChangeDetected(m.payload); break; // Android specific case "SCREEN_READER": listener.screenReaderDetected(m.payload); break; case "TAPJACKING": listener.tapjackingDetected(m.payload); break; case "ADB_STATUS": listener.adbStatusDetected(m.payload); break; case "ACTIVE_CALL": listener.activeCallDetected(m.payload); break; // Apple specific case "SCREENSHOT": listener.userScreenshotDetected(); break; case "REVERSE_TOOLS": listener.reverseEngineeringToolsDetected(); break; case "DEVICE_PASSCODE": listener.systemPasscodeConfigurationChanged(m.payload); break; case "DEVICE_BIOMETRY": listener.systemBiometryConfigurationChanged(m.payload); break; case "ON_CALL": listener.isOnCallChanged(m.payload); break; default: console.warn(`${Platform.OS}: Unsupported RASP event ${m.type}`); break; } }); } /** * Remove RASP listener previously set by `setRaspListener()` method. */ removeRaspListener() { this.raspEventsSubscription?.remove(); this.raspEventsSubscription = undefined; } // Android + Apple /** * Get information about Jailbreak or Root presence on the device. */ getSystemIntegrityInfo() { return this.getRaspInfo("SYSTEM_INTEGRITY"); } /** * Get information whether app is running in emulator. You can use `getEmulatorInfo()` method to get more details * about the emulator type. */ async isRunningInEmulator() { return (await this.getEmulatorInfo()).isEmulator; } /** * Get information whether debugger is connected. */ isDebuggerConnected() { return this.getRaspInfo("DEBUGGER"); } /** * Get detailed information about debugger detection. */ getDebuggerInfo() { return this.getRaspAndroidInfo("DEBUGGER_INFO"); } /** * Get information about application repackaging. */ getRepackagingInfo() { return this.getRaspInfo("REPACKAGED"); } /** * Get information about HTTP proxy configured on the system. */ getHttpProxyInfo() { return this.getRaspInfo("HTTP_PROXY"); } /** * Get information whether app is running in emulator. */ getEmulatorInfo() { return this.getRaspInfo("EMULATOR"); } /** * Get information about active screen sharing or screen capturing. */ getScreenSharingInfo() { return this.getRaspInfo("SCREEN_SHARING"); } /** * Get information about active VPN connection. */ isVpnActive() { return this.getRaspInfo("VPN"); } /** * Get information about the active phone call. */ isOnCall() { return this.getRaspInfo("ON_CALL"); } /** * Obtain information about app presence. */ getAppPresenceInfo() { return this.getRaspInfo("APP_PRESENCE"); } // Apple specific /** * Apple specific: Get information whether reverse engineering tools are present on the device. */ isReverseEngineeringToolsPresent() { return this.getRaspAppleInfo("REVERSE_TOOLS"); } /** * Apple specific: Get information about enabled passcode in the system (device lock) */ isSystemPasscodeEnabled() { return this.getRaspAppleInfo("DEVICE_PASSCODE"); } /** * Apple specific: Get information about biometry enrolled by the user in the system. */ isSystemBiometryEnabled() { return this.getRaspAppleInfo("DEVICE_BIOMETRY"); } // Android specific /** * Android specific: Get information about tapjacking. */ getTapjackingInfo() { return this.getRaspAndroidInfo("TAPJACKING"); } /** * Android specific: Get information about connected ADB. */ getAdbStatus() { return this.getRaspAndroidInfo("ADB_STATUS"); } /** * Android specific: Check if system screen lock (PIN or pattern) is being used to prevent * unauthorized usage of the device by other people. It does not check if the device is currently locked. */ isScreenLockEnabled() { return this.getRaspAndroidInfo("SCREEN_LOCK"); } /** * Android specific: Check if Play Protect is enabled on the device. `undefined` value indicates that there was * a problem obtaining the information. */ isPlayProtectEnabled() { return this.getRaspAndroidInfo("PLAY_PROTECT"); } /** * Android specific: Get information about screen readers. */ getScreenReaderInfo() { return this.getRaspAndroidInfo("SCREEN_READER"); } /** * Android specific: Check if any not allowed screen reader is enabled on the device. Allowed screen readers are configured * in `MalwarelyticsAndroidRaspScreenReadersConfig.allowedScreenReaders`. */ isNotAllowedScreenReaderEnabled() { return this.getRaspAndroidInfo("NA_SCREEN_READER"); } /** * Android specific: Check if there's a bad app that is able to create a system overlay. A bad app is one that * has a treat index same or higher than `MalwarelyticsAndroidRaspTapjackingConfig.blockSensitivity`. */ isBadTapjackingCapableAppPresent() { return this.getRaspAndroidInfo("TAPJACKING_APP_PRESENT"); } /** * Android specific: Check if developer options are enabled on the device. */ isDeveloperOptionsEnabled() { return this.getRaspAndroidInfo("DEVELOPER_MODE"); } /** * Android specific: Obtain information about biometry on the device. */ getBiometryInfo() { return this.getRaspAndroidInfo("BIOMETRY"); } /** * Android specific: Obtain information about active call. */ getActiveCallInfo() { return this.getRaspAndroidInfo("ACTIVE_CALL"); } // Private methods /** * Acquire typed information about RASP detection. * @param messageType RASP message to get. * @returns Value returned from native code. */ async getRaspInfo(messageType) { return await wrapNativeCall(this.module, module => module.getRaspInfo(messageType)); } /** * Acquire typed information about RASP detection. This function fails if called on non-Apple platform. * @param messageType RASP message to get. * @returns Value returned from native code. */ getRaspAppleInfo(messageType) { if (Platform.OS != "ios") { return Promise.reject(new MalwarelyticsError("METHOD_NOT_SUPPORTED", "This method is supported only on Apple platforms")); } return this.getRaspInfo(messageType); } /** * Acquire typed information about RASP detection. This function fails if called on non-Android platform. * @param messageType RASP message to get. * @returns Value returned from native code. */ getRaspAndroidInfo(messageType) { if (Platform.OS != "android") { return Promise.reject(new MalwarelyticsError("METHOD_NOT_SUPPORTED", "This method is supported only on Android platform")); } return this.getRaspInfo(messageType); } } //# sourceMappingURL=MalwarelyticsRasp.js.map