diff --git a/Plugins/Android/freeRASP.androidlib/build.gradle b/Plugins/Android/freeRASP.androidlib/build.gradle index 5033411..76fce8a 100644 --- a/Plugins/Android/freeRASP.androidlib/build.gradle +++ b/Plugins/Android/freeRASP.androidlib/build.gradle @@ -33,7 +33,7 @@ android { dependencies { compileOnly files('libs/unity-classes.jar') // freeRASP SDK - implementation 'com.aheaditec.talsec.security:TalsecSecurity-Community:15.1.0' + implementation 'com.aheaditec.talsec.security:TalsecSecurity-Community-Unity:17.0.1' // test dep implementation("com.google.code.gson:gson:2.13.1") } diff --git a/Plugins/Android/freeRASP.androidlib/src/main/java/com/unity/free/rasp/Controller.java b/Plugins/Android/freeRASP.androidlib/src/main/java/com/unity/free/rasp/Controller.java index c20f8f9..ccc4273 100644 --- a/Plugins/Android/freeRASP.androidlib/src/main/java/com/unity/free/rasp/Controller.java +++ b/Plugins/Android/freeRASP.androidlib/src/main/java/com/unity/free/rasp/Controller.java @@ -6,6 +6,7 @@ import com.aheaditec.talsec_security.security.api.SuspiciousAppInfo; import com.aheaditec.talsec_security.security.api.Talsec; import com.aheaditec.talsec_security.security.api.TalsecConfig; +import com.aheaditec.talsec_security.security.api.TalsecMode; import com.aheaditec.talsec_security.security.api.ThreatListener; import java.util.List; @@ -13,10 +14,25 @@ public class Controller implements ThreatListener.ThreatDetected, ThreatListener.DeviceState { private static final String TAG = Controller.class.getSimpleName(); + + public static class AppRaspExecutionState extends ThreatListener.RaspExecutionState { + private String gameObjectName; + public void setGameObjectCallback(String gameObjectName) { + this.gameObjectName = gameObjectName; + } + @Override + public void onAllChecksFinished() { + UnityPlayer.UnitySendMessage(this.gameObjectName, "scanResult", "onAllChecksFinished"); + } + } + private boolean talSecInitialized; private String gameObjectName; + private AppRaspExecutionState appRaspExecutionState; + public Controller() { talSecInitialized = false; + appRaspExecutionState = new AppRaspExecutionState(); } public void initializeTalsec(Context context, String packageName, @@ -30,9 +46,9 @@ public void initializeTalsec(Context context, String packageName, .watcherMail(watcherEmailAddress) .prod(isProd) .build(); - ThreatListener threatListener = new ThreatListener(this, this); + ThreatListener threatListener = new ThreatListener(this, this, appRaspExecutionState); threatListener.registerListener(context); - Talsec.start(context, config); + Talsec.start(context, config, TalsecMode.BACKGROUND); talSecInitialized = true; } } @@ -46,6 +62,7 @@ public void stopTalsec() { public void setUnityGameObjectCallback(String gameObjectName) { this.gameObjectName = gameObjectName; + this.appRaspExecutionState.setGameObjectCallback(this.gameObjectName); } @Override @@ -126,5 +143,25 @@ public void onADBEnabledDetected() { @Override public void onSystemVPNDetected() { UnityPlayer.UnitySendMessage(this.gameObjectName, "scanResult", "onSystemVPN"); - } + } + + @Override + public void onMultiInstanceDetected() { + UnityPlayer.UnitySendMessage(this.gameObjectName, "scanResult", "onMultiInstance"); + } + + @Override + public void onUnsecureWifiDetected() { + UnityPlayer.UnitySendMessage(this.gameObjectName, "scanResult", "onUnsecureWiFi"); + } + + @Override + public void onTimeSpoofingDetected() { + UnityPlayer.UnitySendMessage(this.gameObjectName, "scanResult", "onTimeSpoofing"); + } + + @Override + public void onLocationSpoofingDetected() { + UnityPlayer.UnitySendMessage(this.gameObjectName, "scanResult", "onLocationSpoofing"); + } } \ No newline at end of file diff --git a/Plugins/freeRASP/RASPStatusCallback.cs b/Plugins/freeRASP/RASPStatusCallback.cs new file mode 100644 index 0000000..3995764 --- /dev/null +++ b/Plugins/freeRASP/RASPStatusCallback.cs @@ -0,0 +1,8 @@ + +using System.Collections.Generic; +using UnityEngine; + +public interface RASPStatusCallback +{ + void onAllChecksFinished(); +} \ No newline at end of file diff --git a/Plugins/freeRASP/RASPStatusCallback.cs.meta b/Plugins/freeRASP/RASPStatusCallback.cs.meta new file mode 100644 index 0000000..e9ca13a --- /dev/null +++ b/Plugins/freeRASP/RASPStatusCallback.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 47088122d18c0454a9047720cdb9b6d2 \ No newline at end of file diff --git a/Plugins/freeRASP/Talsec.cs b/Plugins/freeRASP/Talsec.cs index 510344f..35583ef 100644 --- a/Plugins/freeRASP/Talsec.cs +++ b/Plugins/freeRASP/Talsec.cs @@ -20,6 +20,7 @@ public class TalsecPlugin : MonoBehaviour // Singleton instance private static TalsecPlugin _instance; private ThreatDetectedCallback threatDetectedCallback; + private RASPStatusCallback raspStatusCallback; private AndroidJavaObject javaControllerObject; // Public accessor for the instance @@ -120,6 +121,10 @@ public void setThreatDetectedCallback(ThreatDetectedCallback callback) { this.threatDetectedCallback = callback; } + public void setRASPStatusCallback(RASPStatusCallback callback) { + this.raspStatusCallback = callback; + } + // This method will be called from the native side of the code // both iOS & Android will use this method // hence all the threat types for both platforms are handled here @@ -127,6 +132,10 @@ private void scanResult(string talsecScanResultCallback) { if(this.threatDetectedCallback != null) { switch(talsecScanResultCallback) { + case "onAllChecksFinished": + if(this.raspStatusCallback != null) + this.raspStatusCallback.onAllChecksFinished(); + break; case "onAppIntegrity": this.threatDetectedCallback.onAppIntegrity(); break; @@ -178,6 +187,18 @@ private void scanResult(string talsecScanResultCallback) case "onADBEnabled": this.threatDetectedCallback.onADBEnabled(); break; + case "onMultiInstance": + this.threatDetectedCallback.onMultiInstance(); + break; + case "onUnsecureWiFi": + this.threatDetectedCallback.onUnsecureWiFi(); + break; + case "onTimeSpoofing": + this.threatDetectedCallback.onTimeSpoofing(); + break; + case "onLocationSpoofing": + this.threatDetectedCallback.onLocationSpoofing(); + break; } } } diff --git a/Plugins/freeRASP/ThreatDetectedCallback.cs b/Plugins/freeRASP/ThreatDetectedCallback.cs index 2772998..a0b9c88 100644 --- a/Plugins/freeRASP/ThreatDetectedCallback.cs +++ b/Plugins/freeRASP/ThreatDetectedCallback.cs @@ -21,4 +21,8 @@ public interface ThreatDetectedCallback void onDevMode(); void onADBEnabled(); void onSystemVPN(); + void onMultiInstance(); + void onUnsecureWiFi(); + void onTimeSpoofing(); + void onLocationSpoofing(); } \ No newline at end of file diff --git a/Plugins/iOS/NativeBridge.swift b/Plugins/iOS/NativeBridge.swift index b034e63..e1b1020 100644 --- a/Plugins/iOS/NativeBridge.swift +++ b/Plugins/iOS/NativeBridge.swift @@ -6,7 +6,14 @@ import TalsecRuntime @_silgen_name("send_message_to_unity") func send_message_to_unity(_ threatType: UnsafePointer) -extension SecurityThreatCenter: SecurityThreatHandler { +extension SecurityThreatCenter: SecurityThreatHandler, RaspExecutionState { + + public func onAllChecksFinished() { + "onAllChecksFinished".withCString { messagePtr in + send_message_to_unity(messagePtr) + } + } + public func threatDetected(_ securityThreat: TalsecRuntime.SecurityThreat) { var message = "unknown"; @@ -40,6 +47,8 @@ extension SecurityThreatCenter: SecurityThreatHandler { message = "onScreenshot" case .screenRecording: message = "screenRecording" + case .timeSpoofing: + message = "onTimeSpoofing" } message.withCString { messagePtr in diff --git a/Samples/freeRASPTestApp/Scripts/Game.cs b/Samples/freeRASPTestApp/Scripts/Game.cs index 0c1c488..0db5f47 100644 --- a/Samples/freeRASPTestApp/Scripts/Game.cs +++ b/Samples/freeRASPTestApp/Scripts/Game.cs @@ -3,7 +3,7 @@ using System.Collections; using System.Collections.Generic; -public class Game : MonoBehaviour, ThreatDetectedCallback +public class Game : MonoBehaviour, ThreatDetectedCallback, RASPStatusCallback { // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() @@ -18,11 +18,17 @@ void Start() packageName = "com.unity.freeRASP", signingCertificateHashBase64 = new string[] { "Tmac/QIomCqEGS1jYqy9cMMrqaitVoZLpjXzCMnt55Q=" }, supportedAlternativeStores = new string[] { "com.sec.android.app.samsungapps" } + }, + iosConfig = new IOSConfig + { + appBundleIds = new string[] { "com.unity.freeRASP" }, + appTeamId = "TEAM ID" } }; // set callback TalsecPlugin.Instance.setThreatDetectedCallback(this); + TalsecPlugin.Instance.setRASPStatusCallback(this); // initialize talsec with new unified config TalsecPlugin.Instance.initTalsec(config); } @@ -102,4 +108,25 @@ public void onSystemVPN() { Debug.Log("Unity - System VPN detected"); } + public void onMultiInstance() { + Debug.Log("Unity - Multi instance detected"); + } + + public void onUnsecureWiFi() { + Debug.Log("Unity - Unsecure WiFi detected"); + } + + public void onTimeSpoofing() { + Debug.Log("Unity - Time spoofing detected"); + } + + public void onLocationSpoofing() { + Debug.Log("Unity - Location spoofing detected"); + } + + public void onAllChecksFinished() + { + Debug.Log("Unity - All checks finished"); + } + } \ No newline at end of file