| | | 1 | | using LOCKnet.Core.DataAbstractions; |
| | | 2 | | |
| | | 3 | | namespace LOCKnet.Data.Repositories; |
| | | 4 | | |
| | | 5 | | internal static class StoredCredentialGuard |
| | | 6 | | { |
| | | 7 | | public static void ValidateForPersistence(CredentialRecord credential) |
| | 83 | 8 | | { |
| | 83 | 9 | | ArgumentNullException.ThrowIfNull(credential); |
| | | 10 | | |
| | 83 | 11 | | if (credential.MetadataFormatVersion != CredentialMetadataFormatVersion.Current) |
| | 1 | 12 | | throw new InvalidOperationException("Direkte Persistenz akzeptiert nur aktuelle verschluesselte Metadatenformate." |
| | | 13 | | |
| | 82 | 14 | | if (credential.SecretFormatVersion == CredentialSecretFormatVersion.Current && credential.EncryptedPassword.Length = |
| | 0 | 15 | | throw new InvalidOperationException("Aktuelle Secret-Records muessen verschluesselte Secret-Daten enthalten."); |
| | | 16 | | |
| | 82 | 17 | | if (!Guid.TryParseExact(credential.CredentialUuid, "N", out _)) |
| | 0 | 18 | | throw new InvalidOperationException("Aktuelle Metadata-Records muessen eine stabile CredentialUuid im N-Format ent |
| | | 19 | | |
| | 82 | 20 | | if (credential.EncryptedMetadata.Length == 0) |
| | 1 | 21 | | throw new InvalidOperationException("Aktuelle Metadata-Records muessen verschluesselte Metadaten enthalten."); |
| | | 22 | | |
| | 81 | 23 | | if (HasPlaintextMetadataResidue(credential)) |
| | 3 | 24 | | throw new InvalidOperationException("Aktuelle Metadata-Records duerfen keine Klartext-Metadaten persistieren."); |
| | 78 | 25 | | } |
| | | 26 | | |
| | | 27 | | private static bool HasPlaintextMetadataResidue(CredentialRecord credential) |
| | 81 | 28 | | => !string.IsNullOrEmpty(credential.Title) || |
| | 81 | 29 | | !string.IsNullOrEmpty(credential.Username) || |
| | 81 | 30 | | !string.IsNullOrEmpty(credential.Url) || |
| | 81 | 31 | | !string.IsNullOrEmpty(credential.Notes) || |
| | 81 | 32 | | !string.IsNullOrEmpty(credential.IconKey) || |
| | 81 | 33 | | credential.CredentialType != CredentialType.Password; |
| | | 34 | | } |