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> {
}
if ((response?.verified ?? false) && !(response?.hasError ?? false)) {
_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;
} else if (((((await Connectivity().checkConnectivity()) == ConnectivityResult.none) ||
((response?.hasError ?? false) &&
response!.error == VerificationErrorType.server)) &&
(_verificationStore?.existsSync() ?? false))) {
// get verification from local storage
final loaded =
VerificationResponse.fromMap(json.decode(await _verificationStore!.readAsString()));
String rawVerification;
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)))) {
_verification = loaded;
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