Fix #13: Remove hardcoded PII from Flutter apps, enable root detection in siro_admin
This commit is contained in:
@@ -49,159 +49,107 @@ class DeviceHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// class SecurityHelper {
|
||||
// /// Performs security checks and handles potential risks
|
||||
// static Future<void> performSecurityChecks() async {
|
||||
// bool isNotTrust = false;
|
||||
// bool isJailBroken = false;
|
||||
// bool isRealDevice = true;
|
||||
// bool isOnExternalStorage = false;
|
||||
// bool checkForIssues = false;
|
||||
// bool isDevMode = false;
|
||||
// bool isTampered = false;
|
||||
// String bundleId = "";
|
||||
class SecurityHelper {
|
||||
/// Performs security checks and handles potential risks
|
||||
static Future<void> performSecurityChecks() async {
|
||||
bool isNotTrust = false;
|
||||
bool isJailBroken = false;
|
||||
bool isRealDevice = true;
|
||||
bool isOnExternalStorage = false;
|
||||
bool checkForIssues = false;
|
||||
bool isDevMode = false;
|
||||
bool isTampered = false;
|
||||
String bundleId = "";
|
||||
|
||||
// try {
|
||||
// isNotTrust = await JailbreakRootDetection.instance.isNotTrust;
|
||||
// isJailBroken = await JailbreakRootDetection.instance.isJailBroken;
|
||||
// isRealDevice = await JailbreakRootDetection.instance.isRealDevice;
|
||||
// isOnExternalStorage =
|
||||
// await JailbreakRootDetection.instance.isOnExternalStorage;
|
||||
try {
|
||||
isNotTrust = await JailbreakRootDetection.instance.isNotTrust;
|
||||
isJailBroken = await JailbreakRootDetection.instance.isJailBroken;
|
||||
isRealDevice = await JailbreakRootDetection.instance.isRealDevice;
|
||||
isOnExternalStorage =
|
||||
await JailbreakRootDetection.instance.isOnExternalStorage;
|
||||
|
||||
// List<JailbreakIssue> issues =
|
||||
// await JailbreakRootDetection.instance.checkForIssues;
|
||||
// checkForIssues = issues.isNotEmpty;
|
||||
List<JailbreakIssue> issues =
|
||||
await JailbreakRootDetection.instance.checkForIssues;
|
||||
checkForIssues = issues.isNotEmpty;
|
||||
|
||||
// isDevMode = await JailbreakRootDetection.instance.isDevMode;
|
||||
isDevMode = await JailbreakRootDetection.instance.isDevMode;
|
||||
|
||||
// // Get Bundle ID
|
||||
// PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
// bundleId = packageInfo.packageName;
|
||||
// if (bundleId.isNotEmpty) {
|
||||
// // Pass the CORRECT bundle ID to isTampered
|
||||
// isTampered = await JailbreakRootDetection.instance.isTampered(bundleId);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// debugPrint("Error during security checks: $e");
|
||||
// // Consider handling specific exceptions, not just general errors.
|
||||
// }
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
bundleId = packageInfo.packageName;
|
||||
if (bundleId.isNotEmpty) {
|
||||
isTampered = await JailbreakRootDetection.instance.isTampered(bundleId);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("Error during security checks: $e");
|
||||
}
|
||||
|
||||
// // Save values to storage (using GetStorage)
|
||||
// await box.write('isNotTrust', isNotTrust); // Use await for write operations
|
||||
// await box.write('isTampered', isTampered); // Use await
|
||||
// await box.write('isJailBroken', isJailBroken); // Use await
|
||||
await box.write('isNotTrust', isNotTrust);
|
||||
await box.write('isTampered', isTampered);
|
||||
await box.write('isJailBroken', isJailBroken);
|
||||
|
||||
// // debugPrint("Security Check Results:");
|
||||
// // debugPrint("isNotTrust: $isNotTrust");
|
||||
// // debugPrint("isJailBroken: $isJailBroken");
|
||||
// // debugPrint("isRealDevice: $isRealDevice");
|
||||
// // debugPrint("isOnExternalStorage: $isOnExternalStorage");
|
||||
// // debugPrint("checkForIssues: $checkForIssues");
|
||||
// // debugPrint("isDevMode: $isDevMode");
|
||||
// // debugPrint("isTampered: $isTampered");
|
||||
// // debugPrint("Bundle ID: $bundleId"); // Print the bundle ID
|
||||
if (isJailBroken || isRealDevice == false || isTampered) {
|
||||
_showSecurityWarning();
|
||||
}
|
||||
}
|
||||
|
||||
// // Check for security risks and potentially show a warning
|
||||
// if (isJailBroken || isRealDevice == false || isTampered) {
|
||||
// // print("security_warning".tr); //using easy_localization
|
||||
// // Use a more robust approach to show a warning, like a dialog:
|
||||
// _showSecurityWarning();
|
||||
// }
|
||||
// }
|
||||
static Future<void> clearAllData() async {
|
||||
await box.erase();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// /// 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() {
|
||||
RxInt secondsRemaining = 10.obs;
|
||||
|
||||
// // static void _showSecurityWarning() {
|
||||
// // // Show a dialog, navigate to an error screen, etc.
|
||||
// // // Example using Get.dialog (if you use GetX):
|
||||
// //
|
||||
// // 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
|
||||
// // ),
|
||||
// // ],
|
||||
// // ),
|
||||
// // barrierDismissible: false, // Prevent closing by tapping outside
|
||||
// // );
|
||||
// // }
|
||||
// static void _showSecurityWarning() {
|
||||
// // Use an RxInt to track the remaining seconds. This is the KEY!
|
||||
// RxInt secondsRemaining = 10.obs;
|
||||
Get.dialog(
|
||||
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({
|
||||
'seconds': secondsRemaining.value.toString(),
|
||||
}),
|
||||
)),
|
||||
SizedBox(height: 24),
|
||||
Obx(() => SizedBox(
|
||||
width: double.infinity,
|
||||
child: CupertinoActivityIndicator(
|
||||
radius: 15,
|
||||
animating: true,
|
||||
))),
|
||||
SizedBox(height: 8),
|
||||
Obx(() => ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: LinearProgressIndicator(
|
||||
value: secondsRemaining.value / 10,
|
||||
backgroundColor: Colors.grey.shade300,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
CupertinoColors.systemRed),
|
||||
minHeight: 8,
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
|
||||
// Get.dialog(
|
||||
// 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,
|
||||
// );
|
||||
Timer.periodic(Duration(seconds: 1), (timer) {
|
||||
secondsRemaining.value--;
|
||||
if (secondsRemaining.value <= 0) {
|
||||
timer.cancel();
|
||||
_clearDataAndExit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 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');
|
||||
// }
|
||||
// }
|
||||
static Future<void> _clearDataAndExit() async {
|
||||
await box.erase();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// class DeviceInfoPlus {
|
||||
// static List<Map<String, dynamic>> deviceDataList = [];
|
||||
|
||||
Reference in New Issue
Block a user