new: secure store

This commit is contained in:
lollipopkit
2023-11-03 00:23:57 -06:00
parent e80d115e4f
commit a9f9a1650e
13 changed files with 209 additions and 105 deletions

View File

@@ -1,10 +1,39 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:toolbox/data/res/path.dart';
class SecureStore {
SecureStore._();
static const _secureStorage = FlutterSecureStorage();
static HiveAesCipher? _cipher;
static const _hiveKey = 'hive_key';
static Future<void> init() async {
final encryptionKeyString = await _secureStorage.read(key: _hiveKey);
if (encryptionKeyString == null) {
final key = Hive.generateSecureKey();
await _secureStorage.write(
key: _hiveKey,
value: base64UrlEncode(key),
);
}
final key = await _secureStorage.read(key: _hiveKey);
if (key == null) {
throw Exception('Failed to init SecureStore');
}
final encryptionKeyUint8List = base64Url.decode(key);
_cipher = HiveAesCipher(encryptionKeyUint8List);
}
}
class PersistentStore<E> {
late final Box<E> box;
@@ -12,7 +41,10 @@ class PersistentStore<E> {
PersistentStore(this.boxName);
Future<void> init() async => box = await Hive.openBox(boxName);
Future<void> init() async => box = await Hive.openBox(
boxName,
encryptionCipher: SecureStore._cipher,
);
/// Get all db filenames.
///

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 627;
static const int build = 630;
static const String engine = "3.13.8";
static const String buildAt = "2023-11-01 20:01:37";
static const int modifications = 14;
static const String buildAt = "2023-11-02 13:45:05";
static const int modifications = 1;
static const int script = 25;
}

View File

@@ -74,7 +74,7 @@ Future<void> initApp() async {
await _initMacOSWindow();
// Base of all data.
await _initHive();
await _initDb();
await setupLocator();
_setupLogger();
_setupProviders();
@@ -98,7 +98,8 @@ void _setupProviders() {
Pros.key.load();
}
Future<void> _initHive() async {
Future<void> _initDb() async {
// await SecureStore.init();
await Hive.initFlutter();
// Ordered by typeId
Hive.registerAdapter(PrivateKeyInfoAdapter()); // 1

View File

@@ -328,19 +328,16 @@ class _DockerManagePageState extends State<DockerManagePage> {
}
Widget _buildPs() {
final items = <Widget>[
ListTile(
title: Text(l10n.containerStatus),
subtitle: Text(
_buildPsCardSubtitle(Pros.docker.items!),
style: UIs.textGrey,
),
final items = Pros.docker.items;
if (items == null) return UIs.placeholder;
return ExpandTile(
title: Text(l10n.containerStatus),
subtitle: Text(
_buildPsCardSubtitle(items),
style: UIs.textGrey,
),
];
items.addAll(Pros.docker.items!.map(_buildPsItem));
return Column(
mainAxisSize: MainAxisSize.min,
children: items,
initiallyExpanded: items.length <= 7,
children: items.map(_buildPsItem).toList(),
);
}