| | | 1 | | using LOCKnet.Core.Crypto; |
| | | 2 | | using LOCKnet.Core.DataAbstractions; |
| | | 3 | | using LOCKnet.Core.Security; |
| | | 4 | | using LOCKnet.Core.Services; |
| | | 5 | | using LOCKnet.Data; |
| | | 6 | | using LOCKnet.Data.Repositories; |
| | | 7 | | |
| | | 8 | | namespace LOCKnet.App; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Zentraler Service-Container. Wird einmalig beim App-Start erzeugt |
| | | 12 | | /// und von ViewModels über AppServices.Current zugegriffen. |
| | | 13 | | /// </summary> |
| | | 14 | | public sealed class AppServices |
| | | 15 | | { |
| | | 16 | | private static AppServices? _current; |
| | | 17 | | |
| | | 18 | | /// <summary>Die aktuelle, einmalig erzeugte Instanz.</summary> |
| | 172 | 19 | | public static AppServices Current => _current |
| | 172 | 20 | | ?? throw new InvalidOperationException("AppServices wurde noch nicht initialisiert."); |
| | | 21 | | |
| | | 22 | | // ── Exposed services ────────────────────────────────────────────────────── |
| | | 23 | | |
| | 65 | 24 | | public IMasterKeyManager MasterKeyManager { get; } |
| | 43 | 25 | | public ISessionManager SessionManager { get; } |
| | 41 | 26 | | public IActivityMonitor ActivityMonitor { get; } |
| | 21 | 27 | | public ICredentialService CredentialService { get; } |
| | 2 | 28 | | public VaultStorageDescriptor StorageDescriptor { get; } |
| | | 29 | | |
| | | 30 | | // ── Constructor ─────────────────────────────────────────────────────────── |
| | | 31 | | |
| | 19 | 32 | | private AppServices(string dbPath) |
| | 19 | 33 | | { |
| | 19 | 34 | | var storage = new VaultStorageBootstrap(dbPath); |
| | 19 | 35 | | StorageDescriptor = storage.Storage; |
| | | 36 | | |
| | | 37 | | // Data layer |
| | 19 | 38 | | storage.InitializeAccessibleStorage(); |
| | | 39 | | |
| | 19 | 40 | | ICredentialRepository credRepo = storage.CreateCredentialRepository(); |
| | 19 | 41 | | IMasterKeyRepository masterKeyRepo = storage.CreateMasterKeyRepository(); |
| | 19 | 42 | | IVaultMigrationRepository vaultMigrationRepo = storage.CreateVaultMigrationRepository(); |
| | | 43 | | |
| | | 44 | | // Crypto layer |
| | 19 | 45 | | IKeyDerivationService kdf = new Pbkdf2KeyDerivationService(); |
| | 19 | 46 | | IEncryptionService encryption = new AesGcmEncryptionService(); |
| | 19 | 47 | | ICredentialEnvelopeService credentialEnvelope = new CredentialEnvelopeService(encryption); |
| | 19 | 48 | | ISecureStringService secureStr = new SecureStringService(); |
| | | 49 | | |
| | | 50 | | // Security layer |
| | 19 | 51 | | var sessionManager = new SessionManager(); |
| | 19 | 52 | | SessionManager = sessionManager; |
| | 19 | 53 | | MasterKeyManager = new MasterKeyManager(kdf, masterKeyRepo, vaultMigrationRepo, encryption, credentialEnvelope, sess |
| | 19 | 54 | | ActivityMonitor = new ActivityMonitor(sessionManager) |
| | 19 | 55 | | { |
| | 19 | 56 | | Timeout = TimeSpan.FromSeconds(60) |
| | 19 | 57 | | }; |
| | | 58 | | |
| | | 59 | | // Service layer |
| | 19 | 60 | | CredentialService = new CredentialService(credRepo, masterKeyRepo, encryption, credentialEnvelope, sessionManager, s |
| | 19 | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Initialisiert die AppServices einmalig. |
| | | 65 | | /// </summary> |
| | | 66 | | /// <param name="dbPath">Pfad zur SQLite-Datenbank.</param> |
| | | 67 | | public static void Initialize(string dbPath) |
| | 19 | 68 | | { |
| | 19 | 69 | | _current = new AppServices(dbPath); |
| | 19 | 70 | | } |
| | | 71 | | } |