public async Task IsValid_should_require_at_least_password_or_keyfile() { // Not specified var data = new PasswordData(); Assert.False(data.IsValid); // Password only data.Password = "******"; Assert.True(data.IsValid); using (var keyfile = TestFiles.Read("IO.Demo7Pass.bin")) { // Password & keyfile await data.AddKeyFile(keyfile); Assert.True(data.IsValid); } // Keyfile only data.Password = null; Assert.True(data.IsValid); // Not specified data.ClearKeyfile(); Assert.False(data.IsValid); }
public async Task ParseContent_should_decrypt_passwords() { using (var decrypted = TestFiles.Read("IO.Demo7Pass.Decrypted.bin")) { var headers = new FileHeaders { RandomAlgorithm = CrsAlgorithm.Salsa20, ProtectedStreamKey = CryptographicBuffer.DecodeFromBase64String( "FDNbUwE9jt6Y9+syU+btBIOGRxYt2tiUqnb6FXWIF1E="), }; var doc = await FileFormat.ParseContent( decrypted, true, headers); Assert.NotNull(doc); var entry = doc.Descendants("Entry") .Where(x => (string)x.Element("UUID") == "H/DqrrE1mEKScz8VpPrafg==") .SelectMany(x => x.Elements("String")) .Where(x => (string)x.Element("Key") == "Password") .Select(x => (string)x.Element("Value")) .Single(); Assert.Equal("Password", entry); } }
public async Task Decrypt_should_decrypt_content() { using (var input = TestFiles.Read("IO.Demo7Pass.kdbx")) { input.Seek(222); var masterSeed = CryptographicBuffer.DecodeFromHexString( "2b4656399a5bdf9fdfe9e8705a34b6f484f9b1b940c3d7cfb7ffece3b634e0ae"); var masterKey = CryptographicBuffer.DecodeFromHexString( "87730050341ff55c46421f2f2a5f4e1e018d0443d19cacc8682f128f1874d0a4"); var encryptionIV = CryptographicBuffer.DecodeFromHexString( "f360c29e1a603a6548cfbb28da6fff50"); using (var decrypted = await FileFormat.Decrypt(input, masterKey, masterSeed, encryptionIV)) { var buffer = WindowsRuntimeBuffer.Create(32); buffer = await decrypted.ReadAsync(buffer, 32); Assert.Equal( "54347fe32f3edbccae1fc60f72c11dafd0a72487b315f9b174ed1073ed67a6e0", CryptographicBuffer.EncodeToHexString(buffer)); } } }
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 Should_read_correctly_formatted_stream() { using (var input = new InMemoryRandomAccessStream()) using (var expectedData = TestFiles.Read("IO.HashedBlockStream.Content.bin")) { await CopyData(input, "IO.HashedBlockStream.bin"); input.Seek(0); expectedData.Seek(0); using (var actualData = await HashedBlockFileFormat.Read(input)) { Assert.Equal(expectedData.Size, (ulong)actualData.Length); var actual = new byte[1024]; var expected = WindowsRuntimeBuffer.Create(actual.Length); while (true) { expected = await expectedData.ReadAsync(expected); var read = await actualData.ReadAsync(actual, 0, actual.Length); Assert.Equal(expected.Length, (uint)read); if (read == 0) { break; } Assert.Equal(expected.ToArray(), actual.Take(read)); } } } }
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 Should_support_hex_keyfile() { using (var input = TestFiles.Read("IO.Demo7Pass.hex")) { var data = new PasswordData(); await data.AddKeyFile(input); var master = data.GetMasterKey(); Assert.Equal( "964b383286fba51581e844762576671ba02f62dc9834a0d4954a6d0023d879e8", CryptographicBuffer.EncodeToHexString(master)); } }
public async Task Should_support_xml_keyfile() { using (var input = TestFiles.Read("IO.Demo7Pass.key")) { var data = new PasswordData(); await data.AddKeyFile(input); var master = data.GetMasterKey(); Assert.Equal( "2e6f6954faadf36c27b72d93da06a8f541cc54c4d4e84db886c0e06e99ab8e48", CryptographicBuffer.EncodeToHexString(master)); } }
public async Task Should_support_random_keyfile() { using (var input = TestFiles.Read("IO.Demo7Pass.txt")) { var data = new PasswordData(); await data.AddKeyFile(input); var master = data.GetMasterKey(); Assert.Equal( "f625b4ef8ccbb16ffcd96bf0742a5bf55e339f826ec103cfa13b1d97d3860c2e", CryptographicBuffer.EncodeToHexString(master)); } }
public async Task ClearKeyfile_should_clear_registered_keyfile() { using (var keyfile = TestFiles.Read("IO.Demo7Pass.bin")) { var data = new PasswordData(); await data.AddKeyFile(keyfile); Assert.True(data.HasKeyFile); data.ClearKeyfile(); Assert.False(data.HasKeyFile); } }
private static async Task CopyData(IOutputStream output, string name) { using (var input = TestFiles.Read(name)) { var buffer = WindowsRuntimeBuffer.Create(1024); do { buffer = await input.ReadAsync( buffer, buffer.Capacity); await output.WriteAsync(buffer); } while (buffer.Length > 0); } }
public async Task Should_support_password_and_keyfile() { using (var input = TestFiles.Read("IO.Demo7Pass.key")) { var data = new PasswordData { Password = "******", }; await data.AddKeyFile(input); var master = data.GetMasterKey(); Assert.Equal( "f78be10350f04cc87d3f7030eede60e33799c6665316975bb442f8b803bd6baa", CryptographicBuffer.EncodeToHexString(master)); } }
public async Task ParseContent_should_decompress_content() { using (var decrypted = TestFiles.Read("IO.Demo7Pass.Decrypted.bin")) { var headers = new FileHeaders { RandomAlgorithm = CrsAlgorithm.Salsa20, ProtectedStreamKey = CryptographicBuffer.DecodeFromBase64String( "FDNbUwE9jt6Y9+syU+btBIOGRxYt2tiUqnb6FXWIF1E="), }; var doc = await FileFormat.ParseContent( decrypted, true, headers); Assert.NotNull(doc); var root = doc.Root; Assert.NotNull(root); Assert.Equal("KeePassFile", root.Name.LocalName); } }
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); } }