From fbc45b1acb93e8d0c0a1fb4802617c1dd811d627 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Mon, 6 Mar 2023 21:39:21 -0500 Subject: [PATCH] Add an "account name" (app name) field to make finding keys in keychain browser easier --- lib/services/secrets_service.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/services/secrets_service.dart b/lib/services/secrets_service.dart index cf92ec0..9bdd06e 100644 --- a/lib/services/secrets_service.dart +++ b/lib/services/secrets_service.dart @@ -10,6 +10,8 @@ import '../models/auth/oauth_credentials.dart'; import '../models/auth/profile.dart'; import '../models/exec_error.dart'; +const _storageAccountName = 'social.myportal.relatica.secure_storage'; + class SecretsService { static const _basicProfilesKey = 'basic_profiles'; static const _oauthProfilesKey = 'oauth_profiles'; @@ -21,8 +23,12 @@ class SecretsService { final _secureStorage = const FlutterSecureStorage( iOptions: IOSOptions( + accountName: _storageAccountName, accessibility: KeychainAccessibility.first_unlock, ), + mOptions: MacOsOptions( + accountName: _storageAccountName, + ), ); FutureResult, ExecError> initialize() async { @@ -108,7 +114,7 @@ class SecretsService { _cachedProfiles.addAll(profiles); } - Future _saveJson( + FutureResult _saveJson( String key, ) async { final json = _cachedProfiles @@ -117,5 +123,15 @@ class SecretsService { .toList(); final jsonString = jsonEncode(json); await _secureStorage.write(key: key, value: jsonString); + final pulledResult = await _secureStorage.read(key: key); + if (pulledResult == jsonString) { + return Result.ok(true); + } + + return buildErrorResult( + type: ErrorType.localError, + message: + 'For key $key value read from secure storage did not match value to secure storage', + ); } }