25-2/24/1

This commit is contained in:
Hamza-Ayed
2025-02-24 23:38:01 +03:00
parent 5f53461b34
commit d41314cfed
64 changed files with 1180 additions and 494 deletions

View File

@@ -1,12 +1,18 @@
import 'dart:convert';
import 'package:secure_string_operations/secure_string_operations.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
import 'package:sefer_driver/controller/functions/add_error.dart';
import 'package:sefer_driver/main.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:sefer_driver/env/env.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import '../../constant/api_key.dart';
import '../../constant/char_map.dart';
import '../../constant/info.dart';
import '../../print.dart';
import 'gemeni.dart';
import 'upload_image.dart';
@@ -25,28 +31,43 @@ class CRUD {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
},
);
Log.print('request: ${response.request}');
Log.print('response: ${response.body}');
Log.print('payload: ${payload}');
// if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return response.body;
}
if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return response.body;
}
return jsonData['status'];
return jsonData['status'];
} else if (response.statusCode == 401) {
// Specifically handle 401 Unauthorized
var jsonData = jsonDecode(response.body);
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
await Get.put(LoginDriverController()).getJWT();
mySnackbarSuccess('please order now'.tr);
return 'token_expired'; // Return a specific value for token expiration
} else {
// Other 401 errors
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
addError('Non-200 response code: ${response.statusCode}',
'crud().post - Other');
return 'failure';
}
}
// }
Future<dynamic> post({
Future<dynamic> getWallet({
required String link,
Map<String, dynamic>? payload,
}) async {
// String? basicAuthCredentials =
// await storage.read(key: BoxName.basicAuthCredentials);
var s = await LoginDriverController().getJwtWallet();
var url = Uri.parse(
link,
);
@@ -55,25 +76,94 @@ class CRUD {
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
'Authorization': 'Bearer $s'
},
);
Log.print('request: ${response.request}');
Log.print('response: ${response.body}');
Log.print('payload: ${payload}');
var jsonData = jsonDecode(response.body);
if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return response.body;
}
return jsonData['status'];
} else if (response.statusCode == 401) {
// Specifically handle 401 Unauthorized
var jsonData = jsonDecode(response.body);
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
await Get.put(LoginDriverController()).getJwtWallet();
return 'token_expired'; // Return a specific value for token expiration
} else {
// String errorMessage = jsonData['message'];
// Get.snackbar('Error'.tr, errorMessage.tr,
// backgroundColor: AppColor.redColor);
return (jsonData['status']);
// Other 401 errors
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
return response.statusCode;
addError('Non-200 response code: ${response.statusCode}',
'crud().post - Other');
return 'failure';
}
}
Future<dynamic> post(
{required String link, Map<String, dynamic>? payload}) async {
var url = Uri.parse(link);
try {
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
// 'Authorization': 'Bearer ${box.read(BoxName.jwt)}'
},
);
if (response.statusCode == 200) {
try {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return jsonData;
} else {
return jsonData['status'];
}
} catch (e) {
addError(e.toString(), 'crud().post - JSON decoding');
return 'failure';
}
} else if (response.statusCode == 401) {
// Specifically handle 401 Unauthorized
var jsonData = jsonDecode(response.body);
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
await Get.put(LoginDriverController()).getJWT();
// MyDialog().getDialog(
// 'Session expired. Please log in again.'.tr,
// '',
// () {
// Get.put(LoginController()).loginUsingCredentials(
// box.read(BoxName.passengerID), box.read(BoxName.email));
// Get.back();
// },
// );
return 'token_expired'; // Return a specific value for token expiration
} else {
// Other 401 errors
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
addError('Non-200 response code: ${response.statusCode}',
'crud().post - Other');
return 'failure';
}
} catch (e) {
addError('HTTP request error: $e', 'crud().post - HTTP');
return 'failure';
}
}

View File

@@ -1,34 +1,50 @@
import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:flutter/foundation.dart';
import '../../env/env.dart';
var secretKey = Env.keyOfApp
.toString()
.split('XrXlBl')[0]; // Must be 16 characters for AES-128
String initializationVector = Env.initializationVector; // Must be 16 characters
final encryptionHelper = EncryptionHelper(
secretKey: secretKey,
initializationVector: initializationVector,
);
import '../../constant/box_name.dart';
import '../../main.dart';
class EncryptionHelper {
final encrypt.Key key;
final encrypt.IV iv;
static EncryptionHelper? _instance;
EncryptionHelper(
{required String secretKey, required String initializationVector})
: key = encrypt.Key.fromUtf8(secretKey),
iv = encrypt.IV.fromUtf8(initializationVector);
late final encrypt.Key key;
late final encrypt.IV iv;
// Initialize the helper
EncryptionHelper._(this.key, this.iv);
static EncryptionHelper get instance {
if (_instance == null) {
throw Exception(
"EncryptionHelper is not initialized. Call `await EncryptionHelper.initialize()` in main.");
}
return _instance!;
}
/// Encrypts the given plain text
/// Initializes and stores the instance globally
static Future<void> initialize() async {
if (_instance != null) {
debugPrint("EncryptionHelper is already initialized.");
return; // Prevent re-initialization
}
debugPrint("Initializing EncryptionHelper...");
// Read stored keys
String? keyOfApp = await storage.read(key: BoxName.keyOfApp);
// Log.print('keyOfApp: ${keyOfApp}');
String? initializationVector =
await storage.read(key: BoxName.initializationVector);
// Log.print('initializationVector: ${initializationVector}');
// Set the global instance
_instance = EncryptionHelper._(
encrypt.Key.fromUtf8(keyOfApp!),
encrypt.IV.fromUtf8(initializationVector!),
);
debugPrint("EncryptionHelper initialized successfully.");
}
/// Encrypts a string
String encryptData(String plainText) {
try {
final encrypter = encrypt.Encrypter(encrypt.AES(key,
mode: encrypt.AESMode.cbc)); // Explicitly use CBC mode
final encrypter =
encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
final encrypted = encrypter.encrypt(plainText, iv: iv);
return encrypted.base64;
} catch (e) {
@@ -37,14 +53,13 @@ class EncryptionHelper {
}
}
/// Decrypts the given encrypted text
/// Decrypts a string
String decryptData(String encryptedText) {
try {
final encrypter = encrypt.Encrypter(encrypt.AES(key,
mode: encrypt.AESMode.cbc)); // Explicitly use CBC mode
final encrypter =
encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
final encrypted = encrypt.Encrypted.fromBase64(encryptedText);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
return decrypted;
return encrypter.decrypt(encrypted, iv: iv);
} catch (e) {
debugPrint('Decryption Error: $e');
return '';

View File

@@ -24,9 +24,9 @@ Future<String> faceDetector() async {
request.body = json.encode({
"url1":
"${AppLink.seferCairoServer}/card_image/id_front-${encryptionHelper.decryptData(box.read(BoxName.driverID))}.jpg",
"${AppLink.seferCairoServer}/card_image/id_front-${EncryptionHelper.instance.decryptData(box.read(BoxName.driverID))}.jpg",
"url2":
"https://api.sefer.live/sefer/card_image/face_detect-${encryptionHelper.decryptData(box.read(BoxName.driverID))}.jpg"
"https://api.sefer.live/sefer/card_image/face_detect-${EncryptionHelper.instance.decryptData(box.read(BoxName.driverID))}.jpg"
});
print('request.body: ${request.body}');
request.headers.addAll(headers);

View File

@@ -394,10 +394,10 @@ class AI extends GetxController {
update();
var payload = {
'first_name': encryptionHelper.encryptData(
'first_name': EncryptionHelper.instance.encryptData(
responseNonIdCardFront['full_name'].toString().split(' ')[0]) ??
'Not specified',
'last_name': encryptionHelper.encryptData(
'last_name': EncryptionHelper.instance.encryptData(
responseNonIdCardFront['full_name'].toString().split(' ').last) ??
'Not specified',
'email': box.read(BoxName.emailDriver)?.toString() ?? 'Not specified',
@@ -410,14 +410,14 @@ class AI extends GetxController {
.passwordController
.text
.toString(),
'gender': encryptionHelper
'gender': EncryptionHelper.instance
.encryptData(responseNonIdCardFront['gender'].toString()) ??
'Not specified',
'license_type': 'Foreign',
'national_number': encryptionHelper
'national_number': EncryptionHelper.instance
.encryptData(responseNonIdCardFront['passport_no'].toString()) ??
'Not specified',
'name_arabic': encryptionHelper
'name_arabic': EncryptionHelper.instance
.encryptData(responseNonIdCardFront['full_name'].toString()) ??
'Not specified',
'name_english': 'Not specified',
@@ -431,30 +431,30 @@ class AI extends GetxController {
? responseIdEgyptDriverLicense['license_categories'].join(', ')
: responseIdEgyptDriverLicense['license_categories']?.toString() ??
'Not specified',
'address': encryptionHelper
'address': EncryptionHelper.instance
.encryptData(responseNonIdCardFront['address'].toString()) ??
'Not specified',
'card_id': encryptionHelper
'card_id': EncryptionHelper.instance
.encryptData(responseNonIdCardFront['card_id'].toString()) ??
'Not specified',
'occupation': encryptionHelper
'occupation': EncryptionHelper.instance
.encryptData(responseNonIdCardBack['workStatus'].toString()) ??
'Not specified',
'education': 'Not specified',
'licenseIssueDate':
responseNonIdCardBack['issueDate']?.toString() ?? 'Not specified',
'religion': encryptionHelper
'religion': EncryptionHelper.instance
.encryptData(responseNonIdCardFront['country'].toString()) ??
'Not specified',
'status': 'yet',
'birthdate': encryptionHelper
'birthdate': EncryptionHelper.instance
.encryptData(responseNonIdCardFront['birthdate'].toString()) ??
'Not specified',
'maritalStatus': 'Not specified',
'site': encryptionHelper
'site': EncryptionHelper.instance
.encryptData(responseNonIdCardFront['address'].toString()) ??
'Not specified',
'employmentType': encryptionHelper
'employmentType': EncryptionHelper.instance
.encryptData(responseNonIdCardBack['residencyType'].toString()) ??
'Not specified',
};
@@ -499,10 +499,10 @@ class AI extends GetxController {
update();
var payload = {
'first_name': encryptionHelper.encryptData(
'first_name': EncryptionHelper.instance.encryptData(
responseIdEgyptDriverLicense['firstName'].toString()) ??
'Not specified',
'last_name': encryptionHelper.encryptData(
'last_name': EncryptionHelper.instance.encryptData(
responseIdEgyptDriverLicense['lastName'].toString()) ??
'Not specified',
'email': box.read(BoxName.emailDriver)?.toString() ?? 'Not specified',
@@ -515,18 +515,18 @@ class AI extends GetxController {
.passwordController
.text
.toString(),
'gender': encryptionHelper
'gender': EncryptionHelper.instance
.encryptData(responseIdEgyptBack['gender'].toString()) ??
'Not specified',
'license_type': encryptionHelper.encryptData(
'license_type': EncryptionHelper.instance.encryptData(
responseIdEgyptDriverLicense['license_type'].toString()) ??
'Not specified',
'national_number': encryptionHelper
'national_number': EncryptionHelper.instance
.encryptData(responseIdEgyptBack['nationalID'].toString()) ??
'Not specified',
'name_arabic': encryptionHelper
'name_arabic': EncryptionHelper.instance
.encryptData(responseIdEgyptDriverLicense['name_arabic'].toString()),
'name_english': encryptionHelper
'name_english': EncryptionHelper.instance
.encryptData(responseIdEgyptDriverLicense['name_english'].toString()),
'issue_date': responseIdEgyptDriverLicense['issue_date']?.toString() ??
'Not specified',
@@ -537,34 +537,34 @@ class AI extends GetxController {
? responseIdEgyptDriverLicense['license_categories'].join(', ')
: responseIdEgyptDriverLicense['license_categories']?.toString() ??
'Not specified',
'address': encryptionHelper
'address': EncryptionHelper.instance
.encryptData(responseIdEgyptFront['address'].toString()) ??
'Not specified',
'card_id': encryptionHelper
'card_id': EncryptionHelper.instance
.encryptData(responseIdEgyptFront['card_id'].toString()) ??
'Not specified',
'occupation': encryptionHelper
'occupation': EncryptionHelper.instance
.encryptData(responseIdEgyptBack['occupation'].toString()) ??
'Not specified',
'education': encryptionHelper
'education': EncryptionHelper.instance
.encryptData(responseIdEgyptBack['occupation'].toString()) ??
'Not specified',
'licenseIssueDate':
responseIdEgyptDriverLicense['issue_date'].toString() ??
'Not specified',
'religion': encryptionHelper
'religion': EncryptionHelper.instance
.encryptData(responseIdEgyptBack['religion'].toString()) ??
'Not specified',
'status': 'yet',
'birthdate': encryptionHelper.encryptData(extractDOB(
'birthdate': EncryptionHelper.instance.encryptData(extractDOB(
responseIdEgyptDriverLicense['national_number'].toString())),
'maritalStatus': encryptionHelper
'maritalStatus': EncryptionHelper.instance
.encryptData(responseIdEgyptBack['maritalStatus'].toString()) ??
'Not specified',
'site': encryptionHelper.encryptData(
'site': EncryptionHelper.instance.encryptData(
responseIdEgyptDriverLicense['address'].toString()) ??
'Not specified',
'employmentType': encryptionHelper.encryptData(
'employmentType': EncryptionHelper.instance.encryptData(
responseIdEgyptDriverLicense['employmentType'].toString()) ??
'Not specified',
};
@@ -609,7 +609,7 @@ class AI extends GetxController {
var res = await CRUD().post(link: AppLink.addCriminalDocuments, payload: {
"driverId": box.read(BoxName.driverID),
"IssueDate": responseCriminalRecordEgypt['IssueDate'],
"InspectionResult": encryptionHelper
"InspectionResult": EncryptionHelper.instance
.encryptData(responseCriminalRecordEgypt['InspectionResult']),
});
if (res != 'failure') {
@@ -624,7 +624,7 @@ class AI extends GetxController {
var res = await CRUD().post(link: AppLink.addRegisrationCar, payload: {
'driverID': box.read(BoxName.driverID),
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
'car_plate': encryptionHelper.encryptData(
'car_plate': EncryptionHelper.instance.encryptData(
responseIdCardDriverEgyptFront['car_plate'].toString()),
'make': (responseIdCardDriverEgyptBack['make'].toString()),
'model': (responseIdCardDriverEgyptBack['model']),
@@ -632,10 +632,10 @@ class AI extends GetxController {
'expiration_date':
responseIdCardDriverEgyptFront['LicenseExpirationDate'].toString(),
'color': responseIdCardDriverEgyptBack['color'],
'owner': encryptionHelper
'owner': EncryptionHelper.instance
.encryptData(responseIdCardDriverEgyptFront['owner']),
'color_hex': responseIdCardDriverEgyptBack['color_hex'].toString(),
'address': encryptionHelper
'address': EncryptionHelper.instance
.encryptData(responseIdCardDriverEgyptFront['address'].toString()),
'displacement': responseIdCardDriverEgyptBack['engine'].toString(),
'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
@@ -654,7 +654,7 @@ class AI extends GetxController {
payload: {
'driverID': box.read(BoxName.driverID),
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
'car_plate': encryptionHelper.encryptData(
'car_plate': EncryptionHelper.instance.encryptData(
responseIdCardDriverEgyptFront['car_plate'].toString()),
'make': (responseIdCardDriverEgyptBack['make'].toString()),
'model': (responseIdCardDriverEgyptBack['model']),
@@ -663,11 +663,11 @@ class AI extends GetxController {
responseIdCardDriverEgyptFront['LicenseExpirationDate']
.toString(),
'color': responseIdCardDriverEgyptBack['color'],
'owner': encryptionHelper
'owner': EncryptionHelper.instance
.encryptData(responseIdCardDriverEgyptFront['owner']),
'color_hex':
responseIdCardDriverEgyptBack['color_hex'].toString(),
'address': encryptionHelper.encryptData(
'address': EncryptionHelper.instance.encryptData(
responseIdCardDriverEgyptFront['address'].toString()),
'displacement':
responseIdCardDriverEgyptBack['engine'].toString(),
@@ -680,7 +680,7 @@ class AI extends GetxController {
payload: {
'driverID': box.read(BoxName.driverID),
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
'car_plate': encryptionHelper.encryptData(
'car_plate': EncryptionHelper.instance.encryptData(
responseIdCardDriverEgyptFront['car_plate'].toString()),
'make': (responseIdCardDriverEgyptBack['make'].toString()),
'model': (responseIdCardDriverEgyptBack['model']),
@@ -689,11 +689,11 @@ class AI extends GetxController {
responseIdCardDriverEgyptFront['LicenseExpirationDate']
.toString(),
'color': responseIdCardDriverEgyptBack['color'],
'owner': encryptionHelper
'owner': EncryptionHelper.instance
.encryptData(responseIdCardDriverEgyptFront['owner']),
'color_hex':
responseIdCardDriverEgyptBack['color_hex'].toString(),
'address': encryptionHelper.encryptData(
'address': EncryptionHelper.instance.encryptData(
responseIdCardDriverEgyptFront['address'].toString()),
'displacement':
responseIdCardDriverEgyptBack['engine'].toString(),

View File

@@ -91,7 +91,7 @@ class LocationController extends GetxController {
longitude >= minLongitude &&
longitude <= maxLongitude) {
box.write(BoxName.serverChosen,
encryptionHelper.decryptData(locationData['server_link']));
EncryptionHelper.instance.decryptData(locationData['server_link']));
// Log.print(
// 'locationData----server_link: ${locationData['server_link']}');
return locationData['name'];

View File

@@ -76,7 +76,8 @@ class LogOutController extends GetxController {
title: 'Delete'.tr,
onPressed: () async {
if (checkTxtController.text ==
encryptionHelper.decryptData(box.read(BoxName.nameDriver))) {
EncryptionHelper.instance
.decryptData(box.read(BoxName.nameDriver))) {
// deletecaptainAccount();
var id = await checkBeforeDelete();
@@ -101,23 +102,10 @@ class LogOutController extends GetxController {
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(AppColor.redColor),
),
onPressed: () {
onPressed: () async {
// box.remove(BoxName.agreeTerms);
box.remove(BoxName.driverID);
box.remove(BoxName.email);
box.remove(BoxName.lang);
box.remove(BoxName.name);
box.remove(BoxName.passengerID);
box.remove(BoxName.phone);
box.remove(BoxName.tokenFCM);
box.remove(BoxName.tokens);
box.remove(BoxName.addHome);
box.remove(BoxName.addWork);
box.remove(BoxName.agreeTerms);
box.remove(BoxName.apiKeyRun);
box.remove(BoxName.countryCode);
box.remove(BoxName.accountIdStripeConnect);
box.remove(BoxName.passengerWalletTotal);
await box.erase();
await storage.deleteAll();
Get.offAll(OnBoardingPage());
},
child: Text(
@@ -144,27 +132,10 @@ class LogOutController extends GetxController {
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(AppColor.redColor),
),
onPressed: () {
onPressed: () async {
// box.remove(BoxName.agreeTerms);
box.remove(BoxName.driverID);
box.remove(BoxName.sexDriver);
box.remove(BoxName.dobDriver);
box.remove(BoxName.nameDriver);
box.remove(BoxName.emailDriver);
box.remove(BoxName.phoneDriver);
box.remove(BoxName.statusDriverLocation);
box.remove(BoxName.cvvCodeDriver);
box.remove(BoxName.lastNameDriver);
box.remove(BoxName.passwordDriver);
box.remove(BoxName.cardNumberDriver);
box.remove(BoxName.expiryDateDriver);
box.remove(BoxName.cardHolderNameDriver);
box.remove(BoxName.vin);
box.remove(BoxName.make);
box.remove(BoxName.year);
box.remove(BoxName.owner);
box.remove(BoxName.onBoarding);
box.remove(BoxName.agreeTerms);
await box.erase();
await storage.deleteAll();
Get.offAll(OnBoardingPage());
},
child: Text(

View File

@@ -1,6 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'dart:ui';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:jailbreak_root_detection/jailbreak_root_detection.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/colors.dart';
import 'package:sefer_driver/constant/links.dart';
@@ -12,6 +14,7 @@ import 'package:package_info_plus/package_info_plus.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../constant/info.dart';
import '../../main.dart';
import 'encrypt_decrypt.dart';
Future<void> checkForUpdate(BuildContext context) async {
final packageInfo = await PackageInfo.fromPlatform();
@@ -159,3 +162,122 @@ void showUpdateDialog(BuildContext context) {
},
);
}
getDeviceFingerprint() async {
final deviceInfo = await DeviceInfoPlugin().deviceInfo;
var deviceData;
if (Platform.isAndroid) {
deviceData = deviceInfo.data;
} else if (Platform.isIOS) {
deviceData = deviceInfo.data;
}
final String deviceId =
deviceData['androidId'] ?? deviceData['identifierForVendor'];
final String deviceModel = deviceData['model'];
final String osVersion = deviceData['systemVersion'];
return EncryptionHelper.instance
.encryptData('${deviceId}_${deviceModel}_$osVersion');
}
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;
List<JailbreakIssue> issues =
await JailbreakRootDetection.instance.checkForIssues;
checkForIssues = issues.isNotEmpty;
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.
}
// 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
// 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
// Check for security risks and potentially show a warning
if (isNotTrust ||
isJailBroken ||
isTampered ||
isDevMode ||
isOnExternalStorage ||
!isRealDevice) {
// print("security_warning".tr); //using easy_localization
// Use a more robust approach to show a warning, like a dialog:
_showSecurityWarning();
}
}
/// 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):
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
);
}
}

View File

@@ -1,9 +1,14 @@
import 'dart:convert';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:jwt_decoder/jwt_decoder.dart';
import 'package:secure_string_operations/secure_string_operations.dart';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
import 'package:sefer_driver/controller/functions/encrypt_decrypt.dart';
import '../../constant/box_name.dart';
import '../../constant/char_map.dart';
import '../../constant/info.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
@@ -34,24 +39,41 @@ class AppInitializer {
List<Map<String, dynamic>> links = [];
Future<void> initializeApp() async {
await getKey();
await getAIKey('FCM_PRIVATE_KEY');
Log.print('box.read("jwt"): ${box.read(BoxName.jwt)}');
if (box.read(BoxName.jwt) == null) {
await LoginDriverController().getJWT();
} else {
print('firstTimeLoadKey ${box.read(BoxName.firstTimeLoadKey)}');
bool isTokenExpired = JwtDecoder.isExpired(X
.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
.toString()
.split(AppInformation.addd)[0]);
Log.print('isTokenExpired: $isTokenExpired');
if (isTokenExpired) {
await LoginDriverController().getJWT();
}
}
// await getKey();
}
getAIKey(String key) async {
var res =
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key});
if (res != 'failure') {
var d = jsonDecode(res)['message'];
storage.write(key: 'FCM_PRIVATE_KEY', value: d[key].toString());
// return d[key].toString();
} else {}
getAIKey(String key1) async {
if (box.read(BoxName.firstTimeLoadKey) == null) {
var res =
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key1});
if (res != 'failure') {
var d = jsonDecode(res)['message'];
await storage.write(key: key1, value: d[key1].toString());
await Future.delayed(Duration.zero);
} else {}
}
}
Future<void> getKey() async {
try {
var res =
await CRUD().get(link: AppLink.getLocationAreaLinks, payload: {});
// Log.print('res: ${res}');
if (res != 'failure') {
links = List<Map<String, dynamic>>.from(jsonDecode(res)['message']);
await box.remove(BoxName.locationName);
@@ -61,14 +83,18 @@ class AppInitializer {
await box.remove(links[2]['name']);
await box.write(BoxName.locationName, links);
await box.write(BoxName.basicLink,
encryptionHelper.decryptData(links[0]['server_link']));
EncryptionHelper.instance.decryptData(links[0]['server_link']));
await box.write(links[2]['name'],
encryptionHelper.decryptData(links[2]['server_link']));
EncryptionHelper.instance.decryptData(links[2]['server_link']));
await box.write(links[1]['name'],
encryptionHelper.decryptData(links[1]['server_link']));
EncryptionHelper.instance.decryptData(links[3]['server_link']));
await box.write(links[3]['name'],
EncryptionHelper.instance.decryptData(links[1]['server_link']));
await box.write(BoxName.paymentLink,
encryptionHelper.decryptData(links[4]['server_link']));
EncryptionHelper.instance.decryptData(links[4]['server_link']));
}
} catch (e) {}
} catch (e) {
print('Error fetching or decoding location data: $e');
}
}
}

View File

@@ -46,12 +46,12 @@ class SmsEgyptController extends GetxController {
if (jsonDecode(res.body)['message'].toString() != "Success") {
await CRUD().post(link: AppLink.updatePhoneInvalidSMS, payload: {
"phone_number": encryptionHelper.encryptData(
"phone_number": EncryptionHelper.instance.encryptData(
'+2${Get.find<RegisterCaptainController>().phoneController.text}')
});
box.write(
BoxName.phoneDriver,
encryptionHelper.encryptData(
EncryptionHelper.instance.encryptData(
'+2${Get.find<RegisterCaptainController>().phoneController.text}'));
box.write(BoxName.phoneVerified, '1');

View File

@@ -419,9 +419,10 @@ class ImageController extends GetxController {
await uploadImage(
compressedImage,
{
'driverID':
encryptionHelper.decryptData(box.read(BoxName.driverID)) ??
encryptionHelper.decryptData(box.read(BoxName.passengerID)),
'driverID': EncryptionHelper.instance
.decryptData(box.read(BoxName.driverID)) ??
EncryptionHelper.instance
.decryptData(box.read(BoxName.passengerID)),
'imageType': imageType
},
link,
@@ -461,7 +462,7 @@ class ImageController extends GetxController {
stream,
length,
filename:
'${encryptionHelper.decryptData(box.read(BoxName.driverID))}.jpg',
'${EncryptionHelper.instance.decryptData(box.read(BoxName.driverID))}.jpg',
),
);
data.forEach((key, value) {