2021-01-06 17:35:57 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
2021-02-03 20:26:38 +00:00
|
|
|
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/server_details.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/user.dart';
|
|
|
|
|
|
|
|
class HiveConfig {
|
|
|
|
static Future<void> init() async {
|
|
|
|
await Hive.initFlutter();
|
|
|
|
Hive.registerAdapter(UserAdapter());
|
|
|
|
Hive.registerAdapter(HetznerServerDetailsAdapter());
|
|
|
|
Hive.registerAdapter(CloudFlareDomainAdapter());
|
2021-02-03 20:26:38 +00:00
|
|
|
Hive.registerAdapter(BackblazeCredentialAdapter());
|
2021-01-06 17:35:57 +00:00
|
|
|
|
|
|
|
await Hive.openBox(BNames.appSettings);
|
|
|
|
var cipher = HiveAesCipher(await getEncriptedKey());
|
|
|
|
|
|
|
|
await Hive.openBox(BNames.appConfig, encryptionCipher: cipher);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<Uint8List> getEncriptedKey() async {
|
|
|
|
final FlutterSecureStorage secureStorage = FlutterSecureStorage();
|
|
|
|
var containsEncryptionKey =
|
|
|
|
await secureStorage.containsKey(key: BNames.key);
|
|
|
|
if (!containsEncryptionKey) {
|
|
|
|
var key = Hive.generateSecureKey();
|
|
|
|
await secureStorage.write(key: BNames.key, value: base64UrlEncode(key));
|
|
|
|
}
|
|
|
|
|
2021-03-15 15:39:44 +00:00
|
|
|
String? string = await secureStorage.read(key: BNames.key);
|
|
|
|
return base64Url.decode(string!);
|
2021-01-06 17:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BNames {
|
|
|
|
static String appConfig = 'appConfig';
|
|
|
|
static String isDarkModeOn = 'isDarkModeOn';
|
|
|
|
static String isOnbordingShowing = 'isOnbordingShowing';
|
|
|
|
|
|
|
|
static String appSettings = 'appSettings';
|
|
|
|
|
|
|
|
static String key = 'key';
|
|
|
|
|
2021-01-21 07:35:38 +00:00
|
|
|
static String cloudFlareDomain = 'cloudFlareDomain';
|
2021-01-06 17:35:57 +00:00
|
|
|
static String hetznerKey = 'hetznerKey';
|
|
|
|
static String cloudFlareKey = 'cloudFlareKey';
|
|
|
|
static String rootUser = 'rootUser';
|
2021-01-21 21:01:42 +00:00
|
|
|
static String hetznerServer = 'hetznerServer';
|
2021-02-16 18:48:15 +00:00
|
|
|
static String hasFinalChecked = 'hasFinalChecked';
|
2021-01-21 21:01:42 +00:00
|
|
|
static String isServerStarted = 'isServerStarted';
|
2021-02-03 19:51:07 +00:00
|
|
|
static String backblazeKey = 'backblazeKey';
|
2021-02-16 18:48:15 +00:00
|
|
|
static String isLoading = 'isLoading';
|
|
|
|
static String isServerReseted = 'isServerReseted';
|
2021-01-06 17:35:57 +00:00
|
|
|
}
|