@@ -9,134 +9,100 @@ import com.aheaditec.talsec_security.security.api.Talsec
99import com.aheaditec.talsec_security.security.api.TalsecConfig
1010import 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+ }
0 commit comments