mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Re-enabled write mode in KeePassLib
Set database as part of App (so, Singleton) Changed main page view model WIP and testing saving mechanism
This commit is contained in:
@@ -1,20 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
|
||||||
using Windows.ApplicationModel;
|
using Windows.ApplicationModel;
|
||||||
using Windows.ApplicationModel.Activation;
|
using Windows.ApplicationModel.Activation;
|
||||||
using Windows.Foundation;
|
|
||||||
using Windows.Foundation.Collections;
|
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Controls.Primitives;
|
|
||||||
using Windows.UI.Xaml.Data;
|
|
||||||
using Windows.UI.Xaml.Input;
|
|
||||||
using Windows.UI.Xaml.Media;
|
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
|
|
||||||
|
using ModernKeePass.Common;
|
||||||
|
|
||||||
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
|
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
|
||||||
|
|
||||||
namespace ModernKeePass
|
namespace ModernKeePass
|
||||||
@@ -24,6 +16,7 @@ namespace ModernKeePass
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed partial class App : Application
|
sealed partial class App : Application
|
||||||
{
|
{
|
||||||
|
public DatabaseHelper Database { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the singleton application object. This is the first line of authored code
|
/// Initializes the singleton application object. This is the first line of authored code
|
||||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||||
|
59
ModernKeePass/Common/DatabaseHelper.cs
Normal file
59
ModernKeePass/Common/DatabaseHelper.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using Windows.Storage;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using ModernKeePass.ViewModels;
|
||||||
|
using ModernKeePassLib;
|
||||||
|
using ModernKeePassLib.Interfaces;
|
||||||
|
using ModernKeePassLib.Keys;
|
||||||
|
using ModernKeePassLib.Serialization;
|
||||||
|
|
||||||
|
namespace ModernKeePass.Common
|
||||||
|
{
|
||||||
|
public class DatabaseHelper
|
||||||
|
{
|
||||||
|
private PwDatabase _pwDatabase = new PwDatabase();
|
||||||
|
private StorageFile databaseFile;
|
||||||
|
|
||||||
|
public GroupVm RootGroup { get; set; }
|
||||||
|
public bool IsOpen { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public DatabaseHelper(StorageFile databaseFile)
|
||||||
|
{
|
||||||
|
this.databaseFile = databaseFile;
|
||||||
|
}
|
||||||
|
public async Task<string> Open(string password)
|
||||||
|
{
|
||||||
|
var key = new CompositeKey();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
key.AddUserKey(new KcpPassword(password));
|
||||||
|
await _pwDatabase.Open(IOConnectionInfo.FromFile(databaseFile), key, new NullStatusLogger());
|
||||||
|
IsOpen = _pwDatabase.IsOpen;
|
||||||
|
Name = databaseFile.DisplayName;
|
||||||
|
RootGroup = new GroupVm(_pwDatabase.RootGroup);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException)
|
||||||
|
{
|
||||||
|
return "Password cannot be empty";
|
||||||
|
}
|
||||||
|
catch (InvalidCompositeKeyException)
|
||||||
|
{
|
||||||
|
return "Wrong password";
|
||||||
|
}
|
||||||
|
/*finally
|
||||||
|
{
|
||||||
|
// TODO: move this when implementing write mode
|
||||||
|
_pwDatabase.Close();
|
||||||
|
}*/
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
_pwDatabase.Save(new NullStatusLogger());
|
||||||
|
_pwDatabase.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -9,7 +9,7 @@
|
|||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
|
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
|
||||||
<Page.DataContext>
|
<Page.DataContext>
|
||||||
<ViewModels:DatabaseVm/>
|
<ViewModels:HomeVm/>
|
||||||
</Page.DataContext>
|
</Page.DataContext>
|
||||||
|
|
||||||
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
|
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
@@ -31,11 +31,13 @@
|
|||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Grid.Column="0" Grid.Row="0" x:Name="passwordTextBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Password" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
<TextBlock Grid.Column="0" Grid.Row="0" x:Name="passwordTextBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Password" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
||||||
<PasswordBox Grid.Column="1" Grid.Row="0" x:Name="passwordBox" VerticalAlignment="Top" HorizontalAlignment="Right" Width="130" Password="{Binding Password, Mode=TwoWay}" IsPasswordRevealButtonEnabled="True" Margin="0,0,10,0"/>
|
<PasswordBox Grid.Column="1" Grid.Row="0" x:Name="passwordBox" VerticalAlignment="Top" HorizontalAlignment="Right" Width="130" Password="{Binding Password, Mode=TwoWay}" IsPasswordRevealButtonEnabled="True" Margin="0,0,10,0"/>
|
||||||
<Button Grid.Column="1" Grid.Row="1" x:Name="openBbutton" Content="Open" HorizontalAlignment="Right" VerticalAlignment="Top" Click="openBbutton_Click" Margin="0,0,7,0" Width="auto"/>
|
<Button Grid.Column="1" Grid.Row="1" x:Name="openBbutton" Content="Open" HorizontalAlignment="Right" VerticalAlignment="Top" Click="openBbutton_Click" Margin="0,0,7,0" Width="auto"/>
|
||||||
<TextBlock Grid.Column="1" Grid.Row="2" x:Name="errorTextBlock" TextWrapping="Wrap" Text="{Binding ErrorMessage}" HorizontalAlignment="Right" Height="auto" Width="auto" Foreground="#FF9E0909" Margin="0,0,10,0"/>
|
<TextBlock Grid.Column="1" Grid.Row="2" x:Name="errorTextBlock" TextWrapping="Wrap" Text="{Binding ErrorMessage}" HorizontalAlignment="Right" Height="auto" Width="auto" Foreground="#FF9E0909" Margin="0,0,10,0"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Button Grid.Column="1" Grid.Row="3" x:Name="saveBbutton" Content="Save" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,7,0" Width="auto" Click="saveBbutton_Click"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Input;
|
|
||||||
|
|
||||||
using ModernKeePass.Pages;
|
using ModernKeePass.Pages;
|
||||||
using ModernKeePass.ViewModels;
|
using ModernKeePass.ViewModels;
|
||||||
@@ -19,7 +19,7 @@ namespace ModernKeePass
|
|||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
|
private async void Button_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var picker = new Windows.Storage.Pickers.FileOpenPicker();
|
var picker = new Windows.Storage.Pickers.FileOpenPicker();
|
||||||
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
|
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
|
||||||
@@ -31,19 +31,31 @@ namespace ModernKeePass
|
|||||||
if (file != null)
|
if (file != null)
|
||||||
{
|
{
|
||||||
// Application now has read/write access to the picked file
|
// Application now has read/write access to the picked file
|
||||||
DataContext = new DatabaseVm(file);
|
//DataContext = new DatabaseVm(file);
|
||||||
}
|
((App)Application.Current).Database = new Common.DatabaseHelper(file);
|
||||||
else
|
var homeVm = DataContext as HomeVm;
|
||||||
{
|
homeVm.Visibility = Visibility.Visible;
|
||||||
|
homeVm.NotifyPropertyChanged("Visibility");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openBbutton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
|
private async void openBbutton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var database = DataContext as DatabaseVm;
|
/*var database = DataContext as DatabaseVm;
|
||||||
database.Open();
|
database.Open();
|
||||||
if (database.IsOpen)
|
if (database.IsOpen)
|
||||||
Frame.Navigate(typeof(GroupDetailPage), database.RootGroup);
|
Frame.Navigate(typeof(GroupDetailPage), database.RootGroup);*/
|
||||||
|
var homeVm = DataContext as HomeVm;
|
||||||
|
var app = ((App)Application.Current);
|
||||||
|
homeVm.ErrorMessage = await app.Database.Open(homeVm.Password);
|
||||||
|
if (!app.Database.IsOpen) homeVm.NotifyPropertyChanged("ErrorMessage");
|
||||||
|
else Frame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveBbutton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var database = DataContext as HomeVm;
|
||||||
|
((App)Application.Current).Database.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -110,6 +110,7 @@
|
|||||||
<Compile Include="App.xaml.cs">
|
<Compile Include="App.xaml.cs">
|
||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Common\DatabaseHelper.cs" />
|
||||||
<Compile Include="Common\NavigationHelper.cs" />
|
<Compile Include="Common\NavigationHelper.cs" />
|
||||||
<Compile Include="Common\ObservableDictionary.cs" />
|
<Compile Include="Common\ObservableDictionary.cs" />
|
||||||
<Compile Include="Common\RelayCommand.cs" />
|
<Compile Include="Common\RelayCommand.cs" />
|
||||||
@@ -124,7 +125,7 @@
|
|||||||
<DependentUpon>GroupDetailPage.xaml</DependentUpon>
|
<DependentUpon>GroupDetailPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ViewModels\DatabaseVm.cs" />
|
<Compile Include="ViewModels\HomeVm.cs" />
|
||||||
<Compile Include="ViewModels\EntryVm.cs" />
|
<Compile Include="ViewModels\EntryVm.cs" />
|
||||||
<Compile Include="ViewModels\GroupVm.cs" />
|
<Compile Include="ViewModels\GroupVm.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@@ -77,6 +77,8 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
|
<Button x:Name="addGroupButton" VerticalAlignment="Bottom" HorizontalAlignment="Right" Click="addGroupButton_Click" Content="Add Group" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</GridView.Header>
|
</GridView.Header>
|
||||||
<GridView.ItemContainerStyle>
|
<GridView.ItemContainerStyle>
|
||||||
|
@@ -89,5 +89,11 @@ namespace ModernKeePass.Pages
|
|||||||
var listView = sender as ListView;
|
var listView = sender as ListView;
|
||||||
Frame.Navigate(typeof(EntryDetailPage), listView.SelectedItem as EntryVm);
|
Frame.Navigate(typeof(EntryDetailPage), listView.SelectedItem as EntryVm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addGroupButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var group = DataContext as GroupVm;
|
||||||
|
group.AddGroup("New group");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,69 +0,0 @@
|
|||||||
using System.ComponentModel;
|
|
||||||
using Windows.Storage;
|
|
||||||
|
|
||||||
using ModernKeePassLib;
|
|
||||||
using ModernKeePassLib.Keys;
|
|
||||||
using ModernKeePassLib.Serialization;
|
|
||||||
using ModernKeePassLib.Interfaces;
|
|
||||||
using Windows.UI.Xaml;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
|
||||||
{
|
|
||||||
public class DatabaseVm : INotifyPropertyChanged
|
|
||||||
{
|
|
||||||
private PwDatabase database = new PwDatabase();
|
|
||||||
private StorageFile databaseFile;
|
|
||||||
|
|
||||||
public string Password { get; set; }
|
|
||||||
public bool IsOpen { get; set; }
|
|
||||||
public Visibility Visibility { get; private set; }
|
|
||||||
public string ErrorMessage { get; set; }
|
|
||||||
public string Name { get; set; }
|
|
||||||
public GroupVm RootGroup { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
public DatabaseVm()
|
|
||||||
{
|
|
||||||
Visibility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
public DatabaseVm(StorageFile databaseFile)
|
|
||||||
{
|
|
||||||
this.databaseFile = databaseFile;
|
|
||||||
Visibility = Visibility.Visible;
|
|
||||||
}
|
|
||||||
public async void Open()
|
|
||||||
{
|
|
||||||
var key = new CompositeKey();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
key.AddUserKey(new KcpPassword(Password));
|
|
||||||
await database.Open(IOConnectionInfo.FromFile(databaseFile), key, new NullStatusLogger());
|
|
||||||
IsOpen = database.IsOpen;
|
|
||||||
Name = databaseFile.DisplayName;
|
|
||||||
RootGroup = new GroupVm (database.RootGroup);
|
|
||||||
}
|
|
||||||
catch (ArgumentNullException)
|
|
||||||
{
|
|
||||||
ErrorMessage = "Password cannot be empty";
|
|
||||||
NotifyPropertyChanged("ErrorMessage");
|
|
||||||
}
|
|
||||||
catch (InvalidCompositeKeyException)
|
|
||||||
{
|
|
||||||
ErrorMessage = "Wrong password";
|
|
||||||
NotifyPropertyChanged("ErrorMessage");
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
// TODO: move this when implementing write mode
|
|
||||||
database.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
|
||||||
public void NotifyPropertyChanged(string propertyName)
|
|
||||||
{
|
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -7,6 +7,8 @@ namespace ModernKeePass.ViewModels
|
|||||||
{
|
{
|
||||||
public class GroupVm : INotifyPropertyChanged
|
public class GroupVm : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
private PwGroup _pwGroup;
|
||||||
|
|
||||||
public ObservableCollection<EntryVm> Entries { get; set; }
|
public ObservableCollection<EntryVm> Entries { get; set; }
|
||||||
public ObservableCollection<GroupVm> Groups { get; set; }
|
public ObservableCollection<GroupVm> Groups { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
@@ -35,11 +37,23 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
public GroupVm(PwGroup group)
|
public GroupVm(PwGroup group)
|
||||||
{
|
{
|
||||||
|
_pwGroup = group;
|
||||||
Name = group.Name;
|
Name = group.Name;
|
||||||
Entries = new ObservableCollection<EntryVm>(group.Entries.Select(e => new EntryVm(e)));
|
Entries = new ObservableCollection<EntryVm>(group.Entries.Select(e => new EntryVm(e)));
|
||||||
Groups = new ObservableCollection<GroupVm>(group.Groups.Select(g => new GroupVm(g)));
|
Groups = new ObservableCollection<GroupVm>(group.Groups.Select(g => new GroupVm(g)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddGroup(string title)
|
||||||
|
{
|
||||||
|
var pwGroup = new PwGroup
|
||||||
|
{
|
||||||
|
Name = title
|
||||||
|
};
|
||||||
|
Groups.Add(new GroupVm(pwGroup));
|
||||||
|
NotifyPropertyChanged("Groups");
|
||||||
|
this._pwGroup.Groups.Add(pwGroup);
|
||||||
|
}
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
public void NotifyPropertyChanged(string propertyName)
|
public void NotifyPropertyChanged(string propertyName)
|
||||||
|
30
ModernKeePass/ViewModels/HomeVm.cs
Normal file
30
ModernKeePass/ViewModels/HomeVm.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using Windows.Storage;
|
||||||
|
|
||||||
|
using ModernKeePassLib;
|
||||||
|
using ModernKeePassLib.Keys;
|
||||||
|
using ModernKeePassLib.Serialization;
|
||||||
|
using ModernKeePassLib.Interfaces;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ModernKeePass.ViewModels
|
||||||
|
{
|
||||||
|
public class HomeVm : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
public string Password { get; set; }
|
||||||
|
public Visibility Visibility { get; set; }
|
||||||
|
public string ErrorMessage { get; set; }
|
||||||
|
|
||||||
|
public HomeVm()
|
||||||
|
{
|
||||||
|
Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
public void NotifyPropertyChanged(string propertyName)
|
||||||
|
{
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -20,6 +20,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Windows.Security.Cryptography;
|
||||||
using Windows.Security.Cryptography.Core;
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
namespace ModernKeePassLib.Cryptography
|
namespace ModernKeePassLib.Cryptography
|
||||||
@@ -29,6 +30,7 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
private Stream m_sBaseStream;
|
private Stream m_sBaseStream;
|
||||||
private bool m_bWriting;
|
private bool m_bWriting;
|
||||||
private Queue<byte[]> m_DataToHash;
|
private Queue<byte[]> m_DataToHash;
|
||||||
|
//private HashAlgorithm m_hash;
|
||||||
|
|
||||||
public byte[] Hash
|
public byte[] Hash
|
||||||
{
|
{
|
||||||
@@ -125,8 +127,7 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
m_sBaseStream.Flush();
|
m_sBaseStream.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TODO
|
/*public override void Close()
|
||||||
public override void Close()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if(m_hash != null)
|
if(m_hash != null)
|
||||||
@@ -144,8 +145,7 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
|
|
||||||
m_sBaseStream.Close();
|
m_sBaseStream.Close();
|
||||||
|
|
||||||
}
|
}*/
|
||||||
#endif
|
|
||||||
|
|
||||||
public override long Seek(long lOffset, SeekOrigin soOrigin)
|
public override long Seek(long lOffset, SeekOrigin soOrigin)
|
||||||
{
|
{
|
||||||
@@ -182,18 +182,15 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
|
|
||||||
public override void Write(byte[] pbBuffer, int nOffset, int nCount)
|
public override void Write(byte[] pbBuffer, int nOffset, int nCount)
|
||||||
{
|
{
|
||||||
// BERT TODO: Not implemented.
|
|
||||||
Debug.Assert(false);
|
|
||||||
#if TODO
|
|
||||||
if(!m_bWriting) throw new InvalidOperationException();
|
if(!m_bWriting) throw new InvalidOperationException();
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
byte[] pbOrg = new byte[pbBuffer.Length];
|
byte[] pbOrg = new byte[pbBuffer.Length];
|
||||||
Array.Copy(pbBuffer, pbOrg, pbBuffer.Length);
|
Array.Copy(pbBuffer, pbOrg, pbBuffer.Length);
|
||||||
#endif
|
#endif
|
||||||
|
// TODO: implement this
|
||||||
if((m_hash != null) && (nCount > 0))
|
/*if((m_hash != null) && (nCount > 0))
|
||||||
m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);
|
m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);*/
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
||||||
@@ -201,7 +198,6 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
|
|
||||||
m_sBaseStream.Write(pbBuffer, nOffset, nCount);
|
m_sBaseStream.Write(pbBuffer, nOffset, nCount);
|
||||||
|
|
||||||
#endif // TODO
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,13 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Security;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
//using System.Drawing;
|
//using System.Drawing;
|
||||||
//using System.Drawing.Imaging;
|
//using System.Drawing.Imaging;
|
||||||
|
|
||||||
@@ -30,10 +36,13 @@ using ModernKeePassLibSD;
|
|||||||
|
|
||||||
using ModernKeePassLib.Collections;
|
using ModernKeePassLib.Collections;
|
||||||
using ModernKeePassLib.Cryptography;
|
using ModernKeePassLib.Cryptography;
|
||||||
|
using ModernKeePassLib.Cryptography.Cipher;
|
||||||
using ModernKeePassLib.Interfaces;
|
using ModernKeePassLib.Interfaces;
|
||||||
using ModernKeePassLib.Keys;
|
using ModernKeePassLib.Keys;
|
||||||
|
using ModernKeePassLib.Resources;
|
||||||
using ModernKeePassLib.Security;
|
using ModernKeePassLib.Security;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
|
using ModernKeePassLib.Delegates;
|
||||||
|
|
||||||
namespace ModernKeePassLib.Serialization
|
namespace ModernKeePassLib.Serialization
|
||||||
{
|
{
|
||||||
@@ -62,13 +71,9 @@ namespace ModernKeePassLib.Serialization
|
|||||||
/// be written.</param>
|
/// be written.</param>
|
||||||
/// <param name="format">Format of the file to create.</param>
|
/// <param name="format">Format of the file to create.</param>
|
||||||
/// <param name="slLogger">Logger that recieves status information.</param>
|
/// <param name="slLogger">Logger that recieves status information.</param>
|
||||||
public void Save(Stream sSaveTo, PwGroup pgDataSource, Kdb4Format format,
|
public async void Save(Stream sSaveTo, PwGroup pgDataSource, Kdb4Format format,
|
||||||
IStatusLogger slLogger)
|
IStatusLogger slLogger)
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "not yet implemented");
|
|
||||||
return;
|
|
||||||
#if TODO
|
|
||||||
|
|
||||||
Debug.Assert(sSaveTo != null);
|
Debug.Assert(sSaveTo != null);
|
||||||
if(sSaveTo == null) throw new ArgumentNullException("sSaveTo");
|
if(sSaveTo == null) throw new ArgumentNullException("sSaveTo");
|
||||||
|
|
||||||
@@ -100,7 +105,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
bw = new BinaryWriter(hashedStream, encNoBom);
|
bw = new BinaryWriter(hashedStream, encNoBom);
|
||||||
WriteHeader(bw); // Also flushes bw
|
WriteHeader(bw); // Also flushes bw
|
||||||
|
|
||||||
Stream sEncrypted = AttachStreamEncryptor(hashedStream);
|
Stream sEncrypted = await AttachStreamEncryptor(hashedStream);
|
||||||
if((sEncrypted == null) || (sEncrypted == hashedStream))
|
if((sEncrypted == null) || (sEncrypted == hashedStream))
|
||||||
throw new SecurityException(KLRes.CryptoStreamFailed);
|
throw new SecurityException(KLRes.CryptoStreamFailed);
|
||||||
|
|
||||||
@@ -117,31 +122,26 @@ namespace ModernKeePassLib.Serialization
|
|||||||
writerStream = hashedStream;
|
writerStream = hashedStream;
|
||||||
else { Debug.Assert(false); throw new FormatException("KdbFormat"); }
|
else { Debug.Assert(false); throw new FormatException("KdbFormat"); }
|
||||||
|
|
||||||
m_xmlWriter = new XmlTextWriter(writerStream, encNoBom);
|
using (m_xmlWriter = XmlWriter.Create(writerStream, new XmlWriterSettings { Encoding = encNoBom }))
|
||||||
|
{
|
||||||
WriteDocument(pgDataSource);
|
WriteDocument(pgDataSource);
|
||||||
|
|
||||||
m_xmlWriter.Flush();
|
m_xmlWriter.Flush();
|
||||||
m_xmlWriter.Close();
|
writerStream.Dispose();
|
||||||
writerStream.Close();
|
}
|
||||||
|
|
||||||
GC.KeepAlive(bw);
|
GC.KeepAlive(bw);
|
||||||
}
|
}
|
||||||
finally { CommonCleanUpWrite(sSaveTo, hashedStream); }
|
finally { CommonCleanUpWrite(sSaveTo, hashedStream); }
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CommonCleanUpWrite(Stream sSaveTo, HashingStreamEx hashedStream)
|
private void CommonCleanUpWrite(Stream sSaveTo, HashingStreamEx hashedStream)
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "not yet implemented");
|
//hashedStream.Close();
|
||||||
return;
|
|
||||||
#if TODO
|
|
||||||
hashedStream.Close();
|
|
||||||
m_pbHashOfFileOnDisk = hashedStream.Hash;
|
m_pbHashOfFileOnDisk = hashedStream.Hash;
|
||||||
|
|
||||||
sSaveTo.Close();
|
sSaveTo.Dispose();
|
||||||
|
|
||||||
m_xmlWriter = null;
|
m_xmlWriter = null;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteHeader(BinaryWriter bw)
|
private void WriteHeader(BinaryWriter bw)
|
||||||
@@ -193,12 +193,10 @@ namespace ModernKeePassLib.Serialization
|
|||||||
else bwOut.Write((ushort)0);
|
else bwOut.Write((ushort)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream AttachStreamEncryptor(Stream s)
|
private async Task<Stream> AttachStreamEncryptor(Stream s)
|
||||||
|
{
|
||||||
|
using (MemoryStream ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "not yet implemented");
|
|
||||||
return null;
|
|
||||||
#if TODO
|
|
||||||
MemoryStream ms = new MemoryStream();
|
|
||||||
|
|
||||||
Debug.Assert(m_pbMasterSeed != null);
|
Debug.Assert(m_pbMasterSeed != null);
|
||||||
Debug.Assert(m_pbMasterSeed.Length == 32);
|
Debug.Assert(m_pbMasterSeed.Length == 32);
|
||||||
@@ -206,7 +204,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
Debug.Assert(m_pwDatabase != null);
|
Debug.Assert(m_pwDatabase != null);
|
||||||
Debug.Assert(m_pwDatabase.MasterKey != null);
|
Debug.Assert(m_pwDatabase.MasterKey != null);
|
||||||
ProtectedBinary pbinKey = m_pwDatabase.MasterKey.GenerateKey32(
|
ProtectedBinary pbinKey = await m_pwDatabase.MasterKey.GenerateKey32(
|
||||||
m_pbTransformSeed, m_pwDatabase.KeyEncryptionRounds);
|
m_pbTransformSeed, m_pwDatabase.KeyEncryptionRounds);
|
||||||
Debug.Assert(pbinKey != null);
|
Debug.Assert(pbinKey != null);
|
||||||
if (pbinKey == null)
|
if (pbinKey == null)
|
||||||
@@ -216,24 +214,20 @@ namespace ModernKeePassLib.Serialization
|
|||||||
throw new SecurityException(KLRes.InvalidCompositeKey);
|
throw new SecurityException(KLRes.InvalidCompositeKey);
|
||||||
ms.Write(pKey32, 0, 32);
|
ms.Write(pKey32, 0, 32);
|
||||||
|
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = SHA256Managed.Instance;
|
||||||
byte[] aesKey = sha256.ComputeHash(ms.ToArray());
|
byte[] aesKey = sha256.ComputeHash(ms.ToArray());
|
||||||
|
|
||||||
ms.Close();
|
|
||||||
Array.Clear(pKey32, 0, 32);
|
Array.Clear(pKey32, 0, 32);
|
||||||
|
|
||||||
Debug.Assert(CipherPool.GlobalPool != null);
|
Debug.Assert(CipherPool.GlobalPool != null);
|
||||||
ICipherEngine iEngine = CipherPool.GlobalPool.GetCipher(m_pwDatabase.DataCipherUuid);
|
ICipherEngine iEngine = CipherPool.GlobalPool.GetCipher(m_pwDatabase.DataCipherUuid);
|
||||||
if(iEngine == null) throw new SecurityException(KLRes.FileUnknownCipher);
|
if(iEngine == null) throw new SecurityException(KLRes.FileUnknownCipher);
|
||||||
return iEngine.EncryptStream(s, aesKey, m_pbEncryptionIV);
|
return iEngine.EncryptStream(s, aesKey, m_pbEncryptionIV);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteDocument(PwGroup pgDataSource)
|
private void WriteDocument(PwGroup pgDataSource)
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "not yet implemented");
|
|
||||||
return;
|
|
||||||
#if TODO
|
|
||||||
Debug.Assert(m_xmlWriter != null);
|
Debug.Assert(m_xmlWriter != null);
|
||||||
if(m_xmlWriter == null) throw new InvalidOperationException();
|
if(m_xmlWriter == null) throw new InvalidOperationException();
|
||||||
|
|
||||||
@@ -244,9 +238,8 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
BinPoolBuild(pgRoot);
|
BinPoolBuild(pgRoot);
|
||||||
|
|
||||||
m_xmlWriter.Formatting = Formatting.Indented;
|
m_xmlWriter.Settings.Indent = true;
|
||||||
m_xmlWriter.IndentChar = '\t';
|
m_xmlWriter.Settings.IndentChars = "\t";
|
||||||
m_xmlWriter.Indentation = 1;
|
|
||||||
|
|
||||||
m_xmlWriter.WriteStartDocument(true);
|
m_xmlWriter.WriteStartDocument(true);
|
||||||
m_xmlWriter.WriteStartElement(ElemDocNode);
|
m_xmlWriter.WriteStartElement(ElemDocNode);
|
||||||
@@ -313,7 +306,6 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
m_xmlWriter.WriteEndElement(); // ElemDocNode
|
m_xmlWriter.WriteEndElement(); // ElemDocNode
|
||||||
m_xmlWriter.WriteEndDocument();
|
m_xmlWriter.WriteEndDocument();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteMeta()
|
private void WriteMeta()
|
||||||
@@ -380,9 +372,6 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
private void WriteEntry(PwEntry pe, bool bIsHistory)
|
private void WriteEntry(PwEntry pe, bool bIsHistory)
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "not yet implemented");
|
|
||||||
return;
|
|
||||||
#if TODO
|
|
||||||
Debug.Assert(pe != null); if(pe == null) throw new ArgumentNullException("pe");
|
Debug.Assert(pe != null); if(pe == null) throw new ArgumentNullException("pe");
|
||||||
|
|
||||||
m_xmlWriter.WriteStartElement(ElemEntry);
|
m_xmlWriter.WriteStartElement(ElemEntry);
|
||||||
@@ -408,7 +397,6 @@ namespace ModernKeePassLib.Serialization
|
|||||||
else { Debug.Assert(pe.History.UCount == 0); }
|
else { Debug.Assert(pe.History.UCount == 0); }
|
||||||
|
|
||||||
m_xmlWriter.WriteEndElement();
|
m_xmlWriter.WriteEndElement();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteList(ProtectedStringDictionary dictStrings, bool bEntryStrings)
|
private void WriteList(ProtectedStringDictionary dictStrings, bool bEntryStrings)
|
||||||
@@ -635,10 +623,6 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
private void WriteObject(string name, ProtectedString value, bool bIsEntryString)
|
private void WriteObject(string name, ProtectedString value, bool bIsEntryString)
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "not yet implemented");
|
|
||||||
return;
|
|
||||||
#if TODO
|
|
||||||
|
|
||||||
Debug.Assert(name != null);
|
Debug.Assert(name != null);
|
||||||
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value");
|
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value");
|
||||||
|
|
||||||
@@ -694,7 +678,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
// page area
|
// page area
|
||||||
if(char.IsSymbol(ch) || char.IsSurrogate(ch))
|
if(char.IsSymbol(ch) || char.IsSurrogate(ch))
|
||||||
{
|
{
|
||||||
System.Globalization.UnicodeCategory cat = char.GetUnicodeCategory(ch);
|
UnicodeCategory cat = CharUnicodeInfo.GetUnicodeCategory(ch);
|
||||||
// Map character to correct position in code page
|
// Map character to correct position in code page
|
||||||
chMapped = (char)((int)cat * 32 + ch);
|
chMapped = (char)((int)cat * 32 + ch);
|
||||||
}
|
}
|
||||||
@@ -706,7 +690,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
// in the low ANSI range (up to 255) when calling
|
// in the low ANSI range (up to 255) when calling
|
||||||
// ToLower on them with invariant culture (see
|
// ToLower on them with invariant culture (see
|
||||||
// http://lists.ximian.com/pipermail/mono-patches/2002-February/086106.html )
|
// http://lists.ximian.com/pipermail/mono-patches/2002-February/086106.html )
|
||||||
chMapped = char.ToLower(ch, CultureInfo.InvariantCulture);
|
chMapped = char.ToLowerInvariant(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -725,7 +709,6 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
m_xmlWriter.WriteEndElement(); // ElemValue
|
m_xmlWriter.WriteEndElement(); // ElemValue
|
||||||
m_xmlWriter.WriteEndElement(); // ElemString
|
m_xmlWriter.WriteEndElement(); // ElemString
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteObject(string name, ProtectedBinary value, bool bAllowRef)
|
private void WriteObject(string name, ProtectedBinary value, bool bAllowRef)
|
||||||
@@ -752,10 +735,6 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
private void SubWriteValue(ProtectedBinary value)
|
private void SubWriteValue(ProtectedBinary value)
|
||||||
{
|
{
|
||||||
|
|
||||||
Debug.Assert(false, "not yet implemented");
|
|
||||||
return ;
|
|
||||||
#if TODO
|
|
||||||
if(value.IsProtected && (m_format != Kdb4Format.PlainXml))
|
if(value.IsProtected && (m_format != Kdb4Format.PlainXml))
|
||||||
{
|
{
|
||||||
m_xmlWriter.WriteAttributeString(AttrProtected, ValTrue);
|
m_xmlWriter.WriteAttributeString(AttrProtected, ValTrue);
|
||||||
@@ -780,7 +759,6 @@ namespace ModernKeePassLib.Serialization
|
|||||||
m_xmlWriter.WriteBase64(pbRaw, 0, pbRaw.Length);
|
m_xmlWriter.WriteBase64(pbRaw, 0, pbRaw.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteObject(string name, PwDeletedObject value)
|
private void WriteObject(string name, PwDeletedObject value)
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
"NETStandard.Library": "2.0.0",
|
"NETStandard.Library": "2.0.0",
|
||||||
"System.Net.Requests": "4.3.0",
|
"System.Net.Requests": "4.3.0",
|
||||||
"System.Runtime.WindowsRuntime": "4.3.0",
|
"System.Runtime.WindowsRuntime": "4.3.0",
|
||||||
|
"System.Xml.ReaderWriter": "4.3.0",
|
||||||
"System.Xml.XmlSerializer": "4.3.0"
|
"System.Xml.XmlSerializer": "4.3.0"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
|
@@ -2988,6 +2988,7 @@
|
|||||||
"NETStandard.Library >= 2.0.0",
|
"NETStandard.Library >= 2.0.0",
|
||||||
"System.Net.Requests >= 4.3.0",
|
"System.Net.Requests >= 4.3.0",
|
||||||
"System.Runtime.WindowsRuntime >= 4.3.0",
|
"System.Runtime.WindowsRuntime >= 4.3.0",
|
||||||
|
"System.Xml.ReaderWriter >= 4.3.0",
|
||||||
"System.Xml.XmlSerializer >= 4.3.0"
|
"System.Xml.XmlSerializer >= 4.3.0"
|
||||||
],
|
],
|
||||||
".NETStandard,Version=v1.2": []
|
".NETStandard,Version=v1.2": []
|
||||||
|
Reference in New Issue
Block a user