25-3/12/1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:Tripz/constant/api_key.dart';
|
||||
import 'package:Tripz/controller/functions/sss.dart';
|
||||
import 'package:Tripz/env/env.dart';
|
||||
@@ -28,6 +29,7 @@ import '../../print.dart';
|
||||
import '../functions/encrypt_decrypt.dart';
|
||||
import '../functions/package_info.dart';
|
||||
import '../functions/secure_storage.dart';
|
||||
import '../functions/securty_check.dart';
|
||||
|
||||
class LoginController extends GetxController {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
@@ -86,7 +88,14 @@ class LoginController extends GetxController {
|
||||
}
|
||||
|
||||
getJwtWallet() async {
|
||||
await SecurityHelper.performSecurityChecks();
|
||||
final random = Random();
|
||||
|
||||
if (random.nextBool()) {
|
||||
await SecurityHelper.performSecurityChecks();
|
||||
} else {
|
||||
await SecurityChecks.isDeviceRootedFromNative(Get.context!);
|
||||
}
|
||||
|
||||
String fingerPrint = DeviceHelper.getDeviceFingerprint().toString();
|
||||
dev = Platform.isAndroid ? 'android' : 'ios';
|
||||
var payload = {
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jailbreak_root_detection/jailbreak_root_detection.dart';
|
||||
@@ -246,37 +247,64 @@ class SecurityHelper {
|
||||
}
|
||||
|
||||
/// Deletes all app data
|
||||
static Future<void> clearAllData() async {
|
||||
//await storage.deleteAll(); // What's 'storage'? Be specific. Likely GetStorage as well.
|
||||
await box.erase(); // Clear GetStorage data
|
||||
exit(0); // This will terminate the app. Be VERY careful with this.
|
||||
}
|
||||
|
||||
static void _showSecurityWarning() {
|
||||
// Show a dialog, navigate to an error screen, etc.
|
||||
// Example using Get.dialog (if you use GetX):
|
||||
// Use an RxInt to track the remaining seconds. This is the KEY!
|
||||
RxInt secondsRemaining = 10.obs;
|
||||
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: Text("Security Warning".tr), // Or use localized string
|
||||
content: Text(
|
||||
"Potential security risks detected. The application may not function correctly."
|
||||
.tr), //Or use localized string
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await storage.deleteAll();
|
||||
await box.erase();
|
||||
Get.back(); // Close the dialog
|
||||
// Or, if you really must, exit the app (but give the user a chance!)
|
||||
exit(0);
|
||||
},
|
||||
child: Text("OK"), // Or use a localized string
|
||||
),
|
||||
],
|
||||
CupertinoAlertDialog(
|
||||
title: Text("Security Warning".tr),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Obx(() => Text(
|
||||
"Potential security risks detected. The application will close in @seconds seconds."
|
||||
.trParams({
|
||||
// Use trParams for placeholders
|
||||
'seconds': secondsRemaining.value.toString(),
|
||||
}),
|
||||
// Wrap the Text widget in Obx
|
||||
)),
|
||||
SizedBox(height: 24), // More spacing before the progress bar
|
||||
Obx(() => SizedBox(
|
||||
width: double.infinity, // Make progress bar full width
|
||||
child: CupertinoActivityIndicator(
|
||||
// in case of loading
|
||||
radius: 15,
|
||||
animating: true,
|
||||
))),
|
||||
SizedBox(height: 8),
|
||||
Obx(() => ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8), // Rounded corners
|
||||
child: LinearProgressIndicator(
|
||||
value: secondsRemaining.value / 10,
|
||||
backgroundColor: Colors.grey.shade300, // Lighter background
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
CupertinoColors.systemRed), // iOS-style red
|
||||
minHeight: 8, // Slightly thicker progress bar
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
barrierDismissible: false, // Prevent closing by tapping outside
|
||||
barrierDismissible: false,
|
||||
);
|
||||
|
||||
Timer.periodic(Duration(seconds: 1), (timer) {
|
||||
secondsRemaining.value--;
|
||||
if (secondsRemaining.value <= 0) {
|
||||
timer.cancel();
|
||||
// Get.back();
|
||||
_clearDataAndExit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static Future<void> _clearDataAndExit() async {
|
||||
await storage.deleteAll();
|
||||
await box.erase();
|
||||
exit(0); // Exit the app
|
||||
print('exit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,6 +341,7 @@ class DeviceHelper {
|
||||
|
||||
// Generate and return the encrypted fingerprint
|
||||
final String fingerprint = '${deviceId}_${deviceModel}_$osVersion';
|
||||
// print(EncryptionHelper.instance.encryptData(fingerprint));
|
||||
return EncryptionHelper.instance.encryptData(fingerprint);
|
||||
} catch (e) {
|
||||
throw Exception('Failed to generate device fingerprint');
|
||||
|
||||
46
lib/controller/functions/securty_check.dart
Normal file
46
lib/controller/functions/securty_check.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class SecurityChecks {
|
||||
static const platform = MethodChannel(
|
||||
'com.mobileapp.store.ride/security'); // Choose a unique channel name
|
||||
|
||||
static Future<bool> isDeviceCompromised() async {
|
||||
try {
|
||||
final bool result = await platform
|
||||
.invokeMethod('isNativeRooted'); // Invoke the native method
|
||||
return result;
|
||||
} on PlatformException catch (e) {
|
||||
print("Failed to check security status: ${e.message}");
|
||||
return true; // Treat platform errors as a compromised device (for safety)
|
||||
}
|
||||
}
|
||||
|
||||
static isDeviceRootedFromNative(BuildContext context) async {
|
||||
bool compromised = await isDeviceCompromised();
|
||||
if (compromised) {
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text("Security Warning".tr),
|
||||
content: Text(
|
||||
"Your device appears to be compromised. The app will now close."
|
||||
.tr),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
SystemNavigator.pop(); // Close the app
|
||||
},
|
||||
child: Text("OK"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Continue with normal app flow
|
||||
print("Device is secure.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:Tripz/controller/auth/login_controller.dart';
|
||||
import 'package:Tripz/views/widgets/mydialoug.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:Tripz/constant/box_name.dart';
|
||||
import 'package:Tripz/main.dart';
|
||||
@@ -20,6 +23,7 @@ import '../../../controller/functions/crud.dart';
|
||||
import '../../../controller/functions/encrypt_decrypt.dart';
|
||||
import '../../../controller/functions/package_info.dart';
|
||||
import '../../../controller/functions/secure_storage.dart';
|
||||
import '../../../controller/functions/securty_check.dart';
|
||||
import '../../../controller/functions/tts.dart';
|
||||
import '../../../controller/home/map_passenger_controller.dart';
|
||||
import '../../../controller/home/vip_waitting_page.dart';
|
||||
@@ -73,14 +77,14 @@ GetBuilder<MapPassengerController> leftMainMenuIcons() {
|
||||
tooltip: 'VIP Waiting Page', // More descriptive tooltip
|
||||
),
|
||||
// const SizedBox(width: 8),
|
||||
// _buildIconButtonWithAnimation(
|
||||
// controller: controller,
|
||||
// icon: Octicons.screen_full,
|
||||
// onPressed: () async {
|
||||
// Get.to(() => TestPage());
|
||||
// },
|
||||
// tooltip: 'Recent Locations', // More descriptive tooltip
|
||||
// ),
|
||||
_buildIconButtonWithAnimation(
|
||||
controller: controller,
|
||||
icon: Octicons.screen_full,
|
||||
onPressed: () async {
|
||||
Get.to(() => TestPage());
|
||||
},
|
||||
tooltip: 'Recent Locations', // More descriptive tooltip
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -99,7 +103,9 @@ class TestPage extends StatelessWidget {
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
await DeviceHelper.getDeviceFingerprint();
|
||||
// await DeviceHelper.getDeviceFingerprint();
|
||||
// await SecurityHelper.performSecurityChecks();
|
||||
LoginController().getJwtWallet();
|
||||
},
|
||||
child: Text(
|
||||
"Text Button",
|
||||
|
||||
Reference in New Issue
Block a user