Store the key in secure storage
This commit is contained in:
parent
09035dff60
commit
414d23d92a
4 changed files with 17 additions and 4 deletions
|
@ -44,7 +44,7 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "io.ente.photos"
|
||||
minSdkVersion 16
|
||||
minSdkVersion 18
|
||||
targetSdkVersion 28
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'dart:io' as io;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:photos/utils/crypto_util.dart';
|
||||
|
@ -22,17 +23,21 @@ class Configuration {
|
|||
static final String iv = base64.encode(List.filled(16, 0));
|
||||
|
||||
SharedPreferences _preferences;
|
||||
FlutterSecureStorage _secureStorage;
|
||||
String _key;
|
||||
String _documentsDirectory;
|
||||
String _tempDirectory;
|
||||
String _thumbnailsDirectory;
|
||||
|
||||
Future<void> init() async {
|
||||
_preferences = await SharedPreferences.getInstance();
|
||||
_secureStorage = FlutterSecureStorage();
|
||||
_documentsDirectory = (await getApplicationDocumentsDirectory()).path;
|
||||
_tempDirectory = _documentsDirectory + "/temp/";
|
||||
_thumbnailsDirectory = _documentsDirectory + "/thumbnails/";
|
||||
new io.Directory(_tempDirectory).createSync(recursive: true);
|
||||
new io.Directory(_thumbnailsDirectory).createSync(recursive: true);
|
||||
_key = await _secureStorage.read(key: keyKey);
|
||||
}
|
||||
|
||||
Future<void> generateAndSaveKey(String passphrase) async {
|
||||
|
@ -109,7 +114,8 @@ class Configuration {
|
|||
}
|
||||
|
||||
Future<void> setKey(String key) async {
|
||||
await _preferences.setString(keyKey, key);
|
||||
await _secureStorage.write(key: keyKey, value: key);
|
||||
_key = key;
|
||||
}
|
||||
|
||||
Future<void> decryptEncryptedKey(String passphrase) async {
|
||||
|
@ -120,9 +126,8 @@ class Configuration {
|
|||
await setKey(key);
|
||||
}
|
||||
|
||||
// TODO: Store in secure storage
|
||||
String getKey() {
|
||||
return _preferences.getString(keyKey);
|
||||
return _key;
|
||||
}
|
||||
|
||||
String getDocumentsDirectory() {
|
||||
|
|
|
@ -265,6 +265,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.5"
|
||||
flutter_secure_storage:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_secure_storage
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.3.3"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
|
|
@ -59,6 +59,7 @@ dependencies:
|
|||
animate_do: ^1.7.2
|
||||
flutter_cache_manager: ^1.4.1
|
||||
computer: ^1.0.2
|
||||
flutter_secure_storage: ^3.3.3
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Add table
Reference in a new issue