Commit d6ecab29 authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

add encryption to verification responses as well

parent e6a042e4
...@@ -69,15 +69,26 @@ class VerificationBloc extends Bloc<VerificationEvent, VerificationState> { ...@@ -69,15 +69,26 @@ class VerificationBloc extends Bloc<VerificationEvent, VerificationState> {
} }
if ((response?.verified ?? false) && !(response?.hasError ?? false)) { if ((response?.verified ?? false) && !(response?.hasError ?? false)) {
_verification = response; _verification = response;
await _verificationStore!.writeAsString(json.encode(_verification!.toMap)); final iv = IV.fromLength(16);
await _verificationStore!.writeAsString(
iv.base64 + _encrypter!.encrypt(json.encode(_verification!.toMap), iv: iv).base64);
yield VerificationState.verified; yield VerificationState.verified;
} else if (((((await Connectivity().checkConnectivity()) == ConnectivityResult.none) || } else if (((((await Connectivity().checkConnectivity()) == ConnectivityResult.none) ||
((response?.hasError ?? false) && ((response?.hasError ?? false) &&
response!.error == VerificationErrorType.server)) && response!.error == VerificationErrorType.server)) &&
(_verificationStore?.existsSync() ?? false))) { (_verificationStore?.existsSync() ?? false))) {
// get verification from local storage // get verification from local storage
final loaded = String rawVerification;
VerificationResponse.fromMap(json.decode(await _verificationStore!.readAsString())); final storeData = await _verificationStore!.readAsString();
final iv = IV.fromBase64(storeData.substring(0, 24));
final encrypted = Encrypted.fromBase64(storeData.substring(24));
try {
rawVerification = _encrypter!.decrypt(encrypted, iv: iv);
} catch (e) {
yield VerificationState.unverified;
return;
}
final loaded = VerificationResponse.fromMap(json.decode(rawVerification));
if (loaded.timestamp.isAfter(DateTime.now().subtract(const Duration(minutes: 30)))) { if (loaded.timestamp.isAfter(DateTime.now().subtract(const Duration(minutes: 30)))) {
_verification = loaded; _verification = loaded;
yield VerificationState.verified; yield VerificationState.verified;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment