Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Plugins/Android/freeRASP.androidlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@
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;

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,
Expand All @@ -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;
}
}
Expand All @@ -46,6 +62,7 @@ public void stopTalsec() {

public void setUnityGameObjectCallback(String gameObjectName) {
this.gameObjectName = gameObjectName;
this.appRaspExecutionState.setGameObjectCallback(this.gameObjectName);
}

@Override
Expand Down Expand Up @@ -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");
}
}
8 changes: 8 additions & 0 deletions Plugins/freeRASP/RASPStatusCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

using System.Collections.Generic;
using UnityEngine;

public interface RASPStatusCallback
{
void onAllChecksFinished();
}
2 changes: 2 additions & 0 deletions Plugins/freeRASP/RASPStatusCallback.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Plugins/freeRASP/Talsec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,13 +121,21 @@ 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
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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Plugins/freeRASP/ThreatDetectedCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public interface ThreatDetectedCallback
void onDevMode();
void onADBEnabled();
void onSystemVPN();
void onMultiInstance();
void onUnsecureWiFi();
void onTimeSpoofing();
void onLocationSpoofing();
}
11 changes: 10 additions & 1 deletion Plugins/iOS/NativeBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import TalsecRuntime
@_silgen_name("send_message_to_unity")
func send_message_to_unity(_ threatType: UnsafePointer<CChar>)

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";
Expand Down Expand Up @@ -40,6 +47,8 @@ extension SecurityThreatCenter: SecurityThreatHandler {
message = "onScreenshot"
case .screenRecording:
message = "screenRecording"
case .timeSpoofing:
message = "onTimeSpoofing"
}

message.withCString { messagePtr in
Expand Down
29 changes: 28 additions & 1 deletion Samples/freeRASPTestApp/Scripts/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
}
Expand Down Expand Up @@ -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");
}

}