public async Task Headers_should_parse_fields() { using (var input = TestFiles.Read("IO.Demo7Pass.kdbx")) { var result = await FileFormat.Headers(input); var headers = result.Headers; Assert.NotNull(headers); Assert.True(headers.UseGZip); Assert.Equal(6000U, headers.TransformRounds); Assert.Equal(CrsAlgorithm.Salsa20, headers.RandomAlgorithm); Assert.Equal( "2b4656399a5bdf9fdfe9e8705a34b6f484f9b1b940c3d7cfb7ffece3b634e0ae", CryptographicBuffer.EncodeToHexString(headers.MasterSeed)); Assert.Equal( "9525f6992beb739cbaa73ae6e050627fcaff378d3cd6f6c232d20aa92f6d0927", CryptographicBuffer.EncodeToHexString(headers.TransformSeed)); Assert.Equal( "f360c29e1a603a6548cfbb28da6fff50", CryptographicBuffer.EncodeToHexString(headers.EncryptionIV)); Assert.Equal( "54347fe32f3edbccae1fc60f72c11dafd0a72487b315f9b174ed1073ed67a6e0", CryptographicBuffer.EncodeToHexString(headers.StartBytes)); Assert.Equal( "W6YuG11d+8spXvO9K2J+dLFB19s+GVn85Tk0K6N2ISE=", CryptographicBuffer.EncodeToBase64String(headers.Hash)); Assert.Equal( "FDNbUwE9jt6Y9+syU+btBIOGRxYt2tiUqnb6FXWIF1E=", CryptographicBuffer.EncodeToBase64String(headers.ProtectedStreamKey)); } }
public async Task Headers_should_detect_supported_format() { using (var input = TestFiles.Read("IO.Demo7Pass.kdbx")) { var result = await FileFormat.Headers(input); Assert.NotNull(result.Headers); Assert.Equal(FileFormats.Supported, result.Format); } }
public async Task Headers_should_detect_not_supported_files() { using (var file = new InMemoryRandomAccessStream()) { await file.WriteAsync( CryptographicBuffer.GenerateRandom(1024)); file.Seek(0); var result = await FileFormat.Headers(file); Assert.Null(result.Headers); Assert.Equal(FileFormats.NotSupported, result.Format); } }
public async Task Headers_should_detect_1x_file_format() { using (var file = new InMemoryRandomAccessStream()) { await file.WriteAsync(CryptographicBuffer .DecodeFromHexString("03D9A29A65FB4BB5")); file.Seek(0); var result = await FileFormat.Headers(file); Assert.Null(result.Headers); Assert.Equal(FileFormats.KeePass1x, result.Format); } }
public async Task Headers_should_detect_old_format() { using (var file = new InMemoryRandomAccessStream()) { // Schema; 2.01 await file.WriteAsync(CryptographicBuffer .DecodeFromHexString("03D9A29A67FB4BB501000200")); file.Seek(0); var result = await FileFormat.Headers(file); Assert.Null(result.Headers); Assert.Equal(FileFormats.OldVersion, result.Format); } }
public async Task OpenDatabase() { var database = await OpenFileAsync(); using (var fs = await database.OpenReadAsync()) { // TODO: handle errors & display transformation progress var result = await FileFormat.Headers(fs); var headers = result.Headers; var masterKey = await _password .GetMasterKey(headers); using (var decrypted = await FileFormat .Decrypt(fs, masterKey, headers)) { // TODO: verify start bytes await FileFormat.VerifyStartBytes( decrypted, headers); // Parse content var doc = await FileFormat.ParseContent( decrypted, headers.UseGZip, headers); // TODO: verify headers integrity _cache.Cache(new CachedDatabase { Id = Id, Document = doc, Name = DisplayName, Headers = headers, }); _navigation .UriFor <GroupViewModel>() .Navigate(); _navigation.BackStack.Remove( _navigation.BackStack.Last()); } } }
public async Task Database_decryption() { using (var kdbx = TestFiles.Read("IO.Demo7Pass.kdbx")) { // Headers var result = await FileFormat.Headers(kdbx); Assert.Equal(FileFormats.Supported, result.Format); var headers = result.Headers; Assert.NotNull(headers); // Master Key var password = new PasswordData { Password = "******", }; var masterKey = await password .GetMasterKey(headers); // Decrypt using (var decrypted = await FileFormat .Decrypt(kdbx, masterKey, headers)) { // Start bytes Assert.True(await FileFormat .VerifyStartBytes(decrypted, headers)); // Parse content var doc = await FileFormat.ParseContent( decrypted, headers.UseGZip, headers); Assert.True(FileFormat.VerifyHeaders(headers, doc)); } } }
public async Task Headers_should_detect_partial_support_format() { using (var database = TestFiles.Read("IO.Demo7Pass.kdbx")) using (var file = new InMemoryRandomAccessStream()) { var buffer = WindowsRuntimeBuffer.Create(512); buffer = await database.ReadAsync( buffer, 512, InputStreamOptions.None); await file.WriteAsync(buffer); file.Seek(8); // Schema; 3.Max await file.WriteAsync(CryptographicBuffer .DecodeFromHexString("FFFF0300")); file.Seek(0); var result = await FileFormat.Headers(file); Assert.NotNull(result.Headers); Assert.Equal(FileFormats.PartialSupported, result.Format); } }
/// <summary> /// Registers the specified storage file. /// </summary> /// <param name="file">The database file.</param> /// <returns>The database registration information.</returns> public async Task <DatabaseRegistration> RegisterAsync(IStorageFile file) { using (var input = await file.OpenReadAsync()) { var headers = await FileFormat.Headers(input); switch (headers.Format) { case FileFormats.KeePass1x: case FileFormats.NewVersion: case FileFormats.NotSupported: case FileFormats.OldVersion: await _events.PublishOnUIThreadAsync( new DatabaseSupportMessage { FileName = file.Name, Format = headers.Format, }); return(null); case FileFormats.PartialSupported: await _events.PublishOnUIThreadAsync( new DatabaseSupportMessage { FileName = file.Name, Format = headers.Format, }); break; } } var meta = new DatabaseMetaData { Name = GetName(file.Name), }; // Check already registered database file var exists = _accessList.CheckAccess(file); if (exists) { await _events.PublishOnUIThreadAsync( new DuplicateDatabaseMessage()); return(null); } // Register for future access var token = _accessList.Add(file, JsonConvert.SerializeObject(meta)); await file.CopyAsync(await _cacheFolder, token + ".kdbx"); var info = new DatabaseRegistration { Id = token, Name = meta.Name, }; // Send notification message await _events.PublishOnUIThreadAsync( new DatabaseRegistrationMessage { Id = info.Id, Registration = info, Action = DatabaseRegistrationActions.Added, }); return(info); }