Skip to content

Commit 134d5a8

Browse files
committed
update
1 parent 56c9e67 commit 134d5a8

6 files changed

Lines changed: 161 additions & 162 deletions

File tree

FreeRASPDemoApp/app/build.gradle

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
plugins {
2-
id 'com.android.application'
3-
id 'kotlin-android'
2+
alias(libs.plugins.android.application)
43
}
54

65
android {
6+
namespace "com.aheaditec.talsec.demoapp"
7+
78
defaultConfig {
89
applicationId "com.aheaditec.talsec.demoapp"
910
minSdkVersion 23
1011
compileSdkVersion 36
1112
targetSdkVersion 36
1213
versionCode 1
1314
versionName "1.0"
14-
15-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1615
}
1716

1817
buildTypes {
@@ -23,24 +22,15 @@ android {
2322
}
2423

2524
compileOptions {
26-
sourceCompatibility JavaVersion.VERSION_1_8
27-
targetCompatibility JavaVersion.VERSION_1_8
28-
}
29-
30-
kotlinOptions {
31-
jvmTarget = '1.8'
25+
sourceCompatibility JavaVersion.VERSION_17
26+
targetCompatibility JavaVersion.VERSION_17
3227
}
33-
34-
namespace "com.aheaditec.talsec.demoapp"
3528
}
3629

3730
dependencies {
3831
// freeRASP SDK
39-
implementation 'com.aheaditec.talsec.security:TalsecSecurity-Community:18.0.1'
32+
implementation libs.talsec.security
4033

41-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
42-
implementation 'androidx.core:core-ktx:1.17.0'
43-
implementation 'androidx.appcompat:appcompat:1.7.1'
44-
implementation 'com.google.android.material:material:1.13.0'
45-
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
46-
}
34+
implementation libs.kotlin.stdlib
35+
implementation libs.bundles.androidx
36+
}

FreeRASPDemoApp/app/src/main/java/com/aheaditec/talsec/demoapp/TalsecApplication.kt

Lines changed: 123 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -9,134 +9,100 @@ import com.aheaditec.talsec_security.security.api.Talsec
99
import com.aheaditec.talsec_security.security.api.TalsecConfig
1010
import com.aheaditec.talsec_security.security.api.ThreatListener
1111

12-
class TalsecApplication : Application(), ThreatListener.ThreatDetected {
12+
class TalsecApplication : Application() {
1313

14-
override fun onCreate() {
15-
super.onCreate()
16-
17-
// Uncomment the following Log.e(...) to get your expectedSigningCertificateHashBase64
18-
// Copy the result from logcat and assign to expectedSigningCertificateHashBase64
19-
// Log.e("SigningCertificateHash", Utils.computeSigningCertificateHash(this))
20-
21-
val config = TalsecConfig.Builder(
22-
expectedPackageName,
23-
expectedSigningCertificateHashBase64)
24-
.watcherMail(watcherMail)
25-
.supportedAlternativeStores(supportedAlternativeStores)
26-
.prod(isProd)
27-
.killOnBypass(true) // determines if the app should be killed within the SDK if the callbacks are hooked/modified by an attacker
28-
.build()
29-
30-
ThreatListener(this, deviceStateListener, raspExecutionStateListener).registerListener(this)
31-
Talsec.start(this, config)
32-
33-
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
34-
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
35-
Talsec.blockScreenCapture(activity, false)
36-
}
37-
38-
override fun onActivityStarted(activity: Activity) {}
39-
40-
override fun onActivityResumed(activity: Activity) {
41-
ScreenProtector.INSTANCE.registerScreenCallbacks(activity)
42-
}
43-
44-
override fun onActivityPaused(activity: Activity) {
45-
ScreenProtector.INSTANCE.unregisterScreenCallbacks(activity)
46-
}
47-
48-
override fun onActivityStopped(activity: Activity) {}
49-
50-
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
51-
52-
override fun onActivityDestroyed(activity: Activity) {}
53-
})
54-
}
14+
// Listener for security threat detection events (root, debugger, emulator, tampering, etc.)
15+
private val threatDetected = object : ThreatListener.ThreatDetected() {
16+
override fun onRootDetected() {
17+
// Set your reaction
18+
println("onRootDetected")
19+
}
5520

56-
override fun onRootDetected() {
57-
// Set your reaction
58-
println("onRootDetected")
59-
}
21+
override fun onDebuggerDetected() {
22+
// Set your reaction
23+
// Triggered only in release build
24+
println("onDebuggerDetected")
25+
}
6026

61-
override fun onDebuggerDetected() {
62-
// Set your reaction
63-
// Triggered only in release build
64-
println("onDebuggerDetected")
65-
}
27+
override fun onEmulatorDetected() {
28+
// Set your reaction
29+
// Triggered only in release build
30+
println("onEmulatorDetected")
31+
}
6632

67-
override fun onEmulatorDetected() {
68-
// Set your reaction
69-
// Triggered only in release build
70-
println("onEmulatorDetected")
71-
}
33+
override fun onTamperDetected() {
34+
// Set your reaction
35+
// Triggered only in release build
36+
println("onTamperDetected")
37+
}
7238

73-
override fun onTamperDetected() {
74-
// Set your reaction
75-
// Triggered only in release build
76-
println("onTamperDetected")
77-
}
39+
override fun onUntrustedInstallationSourceDetected() {
40+
// Set your reaction
41+
// Triggered only in release build
42+
println("onUntrustedInstallationSourceDetected")
43+
}
7844

79-
override fun onUntrustedInstallationSourceDetected() {
80-
// Set your reaction
81-
// Triggered only in release build
82-
println("onUntrustedInstallationSourceDetected")
83-
}
45+
override fun onHookDetected() {
46+
// Set your reaction
47+
println("onHookDetected")
48+
}
8449

85-
override fun onHookDetected() {
86-
// Set your reaction
87-
println("onHookDetected")
88-
}
50+
override fun onDeviceBindingDetected() {
51+
// Set your reaction
52+
println("onDeviceBindingDetected")
53+
}
8954

90-
override fun onDeviceBindingDetected() {
91-
// Set your reaction
92-
println("onDeviceBindingDetected")
93-
}
55+
override fun onObfuscationIssuesDetected() {
56+
// Set your reaction
57+
println("onObfuscationIssuesDetected")
58+
}
9459

95-
override fun onObfuscationIssuesDetected() {
96-
// Set your reaction
97-
println("onObfuscationIssuesDetected")
98-
}
60+
override fun onMalwareDetected(suspiciousApps: List<SuspiciousAppInfo>) {
61+
// Set your reaction
62+
println("onMalwareDetected")
63+
suspiciousApps.forEach {
64+
println("Suspicious app: ${it.packageInfo.packageName}, reason: ${it.reason}")
65+
}
66+
}
9967

100-
override fun onMalwareDetected(suspiciousApps: List<SuspiciousAppInfo>) {
101-
// Set your reaction
102-
println("onMalwareDetected")
103-
suspiciousApps.forEach {
104-
println("Suspicious app: ${it.packageInfo.packageName}, reason: ${it.reason}")
68+
override fun onAutomationDetected() {
69+
// Set your reaction
70+
println("onAutomationDetected")
10571
}
106-
}
10772

108-
override fun onScreenshotDetected() {
109-
// Set your reaction
110-
println("onScreenshotDetected")
111-
}
73+
override fun onScreenshotDetected() {
74+
// Set your reaction
75+
println("onScreenshotDetected")
76+
}
11277

113-
override fun onScreenRecordingDetected() {
114-
// Set your reaction
115-
println("onScreenRecordingDetected")
116-
}
78+
override fun onScreenRecordingDetected() {
79+
// Set your reaction
80+
println("onScreenRecordingDetected")
81+
}
11782

118-
override fun onMultiInstanceDetected() {
119-
// Set your reaction
120-
println("onMultiInstanceDetected")
121-
}
83+
override fun onMultiInstanceDetected() {
84+
// Set your reaction
85+
println("onMultiInstanceDetected")
86+
}
12287

123-
override fun onUnsecureWifiDetected() {
124-
// Set your reaction
125-
println("onUnsecureWifiDetected")
126-
}
88+
override fun onUnsecureWifiDetected() {
89+
// Set your reaction
90+
println("onUnsecureWifiDetected")
91+
}
12792

128-
override fun onTimeSpoofingDetected() {
129-
// Set your reaction
130-
println("onTimeSpoofingDetected")
131-
}
93+
override fun onTimeSpoofingDetected() {
94+
// Set your reaction
95+
println("onTimeSpoofingDetected")
96+
}
13297

133-
override fun onLocationSpoofingDetected() {
134-
// Set your reaction
135-
println("onLocationSpoofingDetected")
98+
override fun onLocationSpoofingDetected() {
99+
// Set your reaction
100+
println("onLocationSpoofingDetected")
101+
}
136102
}
137103

138104
// This is optional. Use only if you are interested in device state information like device lock and HW backed keystore state
139-
private val deviceStateListener = object : ThreatListener.DeviceState {
105+
private val deviceState = object : ThreatListener.DeviceState() {
140106
override fun onUnlockedDeviceDetected() {
141107
// Set your reaction
142108
println("onUnlockedDeviceDetected")
@@ -164,23 +130,64 @@ class TalsecApplication : Application(), ThreatListener.ThreatDetected {
164130
}
165131

166132
// This is optional. Use only if you are interested in RASP execution state information
167-
private val raspExecutionStateListener = object : ThreatListener.RaspExecutionState() {
133+
private val raspExecutionState = object : ThreatListener.RaspExecutionState() {
168134
override fun onAllChecksFinished() {
169135
println("onAllChecksFinished")
170136
}
171137
}
172138

173-
companion object {
174-
private const val expectedPackageName = "com.aheaditec.talsec.demoapp" // Don't use Context.getPackageName!
175-
private val expectedSigningCertificateHashBase64 = arrayOf(
139+
override fun onCreate() {
140+
super.onCreate()
141+
142+
// Uncomment the following Log.e(...) to get your expectedSigningCertificateHashBase64
143+
// Copy the result from logcat and assign to expectedSigningCertificateHashBase64
144+
// Log.e("SigningCertificateHash", Utils.computeSigningCertificateHash(this))
145+
146+
val config = TalsecConfig.Builder(EXPECTED_PACKAGE_NAME, EXPECTED_SIGNING_CERTIFICATE_HASH_BASE64)
147+
.watcherMail(WATCHER_MAIL)
148+
.supportedAlternativeStores(SUPPORTED_ALTERNATIVE_STORES)
149+
.prod(IS_PROD)
150+
.killOnBypass(true) // determines if the app should be killed within the SDK if the callbacks are hooked/modified by an attacker
151+
.build()
152+
153+
ThreatListener(threatDetected, deviceState, raspExecutionState).registerListener(this)
154+
Talsec.start(this, config)
155+
156+
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
157+
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
158+
Talsec.blockScreenCapture(activity, false)
159+
}
160+
161+
override fun onActivityStarted(activity: Activity) {}
162+
163+
override fun onActivityResumed(activity: Activity) {
164+
ScreenProtector.INSTANCE.registerScreenCallbacks(activity)
165+
}
166+
167+
override fun onActivityPaused(activity: Activity) {
168+
ScreenProtector.INSTANCE.unregisterScreenCallbacks(activity)
169+
}
170+
171+
override fun onActivityStopped(activity: Activity) {}
172+
173+
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
174+
175+
override fun onActivityDestroyed(activity: Activity) {}
176+
})
177+
}
178+
179+
180+
private companion object {
181+
private const val EXPECTED_PACKAGE_NAME = "com.aheaditec.talsec.demoapp" // Don't use Context.getPackageName!
182+
private val EXPECTED_SIGNING_CERTIFICATE_HASH_BASE64 = arrayOf(
176183
"mVr/qQLO8DKTwqlL+B1qigl9NoBnbiUs8b4c2Ewcz0k=",
177184
"cVr/qQLO8DKTwqlL+B1qigl9NoBnbiUs8b4c2Ewcz0m="
178185
) // Replace with your release (!) signing certificate hashes
179-
private const val watcherMail = "john@example.com" // for Alerts and Reports
180-
private val supportedAlternativeStores = arrayOf(
186+
private const val WATCHER_MAIL = "john@example.com" // for Alerts and Reports
187+
private val SUPPORTED_ALTERNATIVE_STORES = arrayOf(
181188
// Google Play Store and Huawei AppGallery are supported out of the box, you can pass empty array or null or add other stores like the Samsung's one:
182189
"com.sec.android.app.samsungapps" // Samsung Store
183190
)
184-
private const val isProd = true
191+
private const val IS_PROD = true
185192
}
186-
}
193+
}

FreeRASPDemoApp/build.gradle

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
buildscript {
3-
ext.kotlin_version = "2.0.21"
4-
repositories {
5-
google()
6-
mavenCentral()
7-
}
8-
dependencies {
9-
classpath 'com.android.tools.build:gradle:8.13.2'
10-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
12-
// NOTE: Do not place your application dependencies here; they belong
13-
// in the individual module build.gradle files
14-
}
15-
}
16-
17-
allprojects {
18-
repositories {
19-
google()
20-
mavenCentral()
21-
maven { url "https://europe-west3-maven.pkg.dev/talsec-artifact-repository/freerasp" }
22-
maven { url 'https://jitpack.io' }
23-
}
2+
plugins {
3+
alias(libs.plugins.android.application) apply false
244
}
255

26-
task clean(type: Delete) {
6+
// noinspection GrDeprecatedAPIUsage
7+
tasks.register('clean', Delete) {
278
delete rootProject.buildDir
28-
}
9+
}

FreeRASPDemoApp/gradle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ android.useAndroidX=true
1818
# Automatically convert third-party libraries to use AndroidX
1919
android.enableJetifier=true
2020
# Kotlin code style for this project: "official" or "obsolete":
21-
kotlin.code.style=official
21+
kotlin.code.style=official
22+
# Temporary compatibility settings for AGP 9.0 migration
23+
android.builtInKotlin=true
24+
android.newDsl=false
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
5-
zipStorePath=wrapper/dists
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)