mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
WIP saving
This commit is contained in:
@@ -54,7 +54,7 @@
|
||||
<HyperlinkButton Grid.Row="0" Grid.ColumnSpan="2" Content="Select password database" Click="Button_Click" />
|
||||
<TextBlock Grid.Column="0" Grid.Row="1" x:Name="PasswordTextBlock" HorizontalAlignment="Left" Visibility="{Binding Visibility}" TextWrapping="Wrap" Text="Password" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
||||
<PasswordBox Grid.Column="1" Grid.Row="1" x:Name="PasswordBox" VerticalAlignment="Top" HorizontalAlignment=" Right" Visibility="{Binding Visibility}" Width="130" Password="{Binding Password, Mode=TwoWay}" IsPasswordRevealButtonEnabled="True" Margin="0,0,10,0"/>
|
||||
<TextBlock Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Text="{Binding ErrorMessage}" Foreground="#FF9E1B1B" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding ErrorMessage}" Foreground="#FF9E1B1B" />
|
||||
<Button Grid.Column="1" Grid.Row="3" x:Name="OpenButton" Content="OK" HorizontalAlignment="Right" VerticalAlignment="Top" Visibility="{Binding Visibility}" Click="openBbutton_Click" Margin="0,0,7,0" Width="auto"/>
|
||||
</Grid>
|
||||
<HyperlinkButton Grid.Column="2" Name="SaveButton" Content="Save file" Click="saveBbutton_Click" VerticalAlignment="Top" Margin="0,30,0,0" Visibility="Collapsed" />
|
||||
|
@@ -159,8 +159,8 @@
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ModernKeePassLib, Version=2.19.0.24806, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ModernKeePassLib.2.19.0.24806\lib\netstandard1.2\ModernKeePassLib.dll</HintPath>
|
||||
<Reference Include="ModernKeePassLib, Version=2.19.0.33692, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ModernKeePassLib.2.19.0.33692\lib\netstandard1.2\ModernKeePassLib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<packages>
|
||||
<package id="Microsoft.NETCore.Platforms" version="2.0.0" targetFramework="win81" />
|
||||
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" targetFramework="win81" />
|
||||
<package id="ModernKeePassLib" version="2.19.0.24806" targetFramework="win81" />
|
||||
<package id="ModernKeePassLib" version="2.19.0.33692" targetFramework="win81" />
|
||||
<package id="NETStandard.Library" version="2.0.0" targetFramework="win81" />
|
||||
<package id="System.Net.Requests" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="win81" />
|
||||
|
@@ -18,17 +18,16 @@ namespace ModernKeePassLib.Serialization
|
||||
private IEnumerator<byte> m_enumerator = null;
|
||||
|
||||
public CryptoStream(Stream s, String strAlgName, bool bEncrypt, byte[] pbKey, byte[] pbIV)
|
||||
: base()
|
||||
{
|
||||
IBuffer iv = CryptographicBuffer.CreateFromByteArray(pbIV);
|
||||
SymmetricKeyAlgorithmProvider objAlg = SymmetricKeyAlgorithmProvider.OpenAlgorithm(strAlgName);
|
||||
CryptographicKey key = objAlg.CreateSymmetricKey( CryptographicBuffer.CreateFromByteArray(pbKey) );
|
||||
if (bEncrypt)
|
||||
/*if (bEncrypt)
|
||||
{
|
||||
Debug.Assert(false, "Not implemented yet");
|
||||
}
|
||||
else
|
||||
{
|
||||
{*/
|
||||
// For the time being, WinRT CryptographicEngine doesn't support stream decoding. Bummer.
|
||||
// Copy the file to a memory buffer, then decode all at once.
|
||||
|
||||
@@ -50,7 +49,7 @@ namespace ModernKeePassLib.Serialization
|
||||
}
|
||||
CryptographicBuffer.CopyToByteArray(decoded, out m_decoded);
|
||||
m_enumerator = m_decoded.AsEnumerable().GetEnumerator();
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -281,13 +281,13 @@ namespace ModernKeePassLib.Serialization
|
||||
return CreateWebClient(ioc).OpenWrite(uri);
|
||||
}
|
||||
#else
|
||||
public async static Task<Stream> OpenWrite(IOConnectionInfo ioc)
|
||||
public static async Task<Stream> OpenWrite(IOConnectionInfo ioc)
|
||||
{
|
||||
return await OpenWriteLocal(ioc);
|
||||
}
|
||||
#endif
|
||||
|
||||
private async static Task<Stream> OpenWriteLocal(IOConnectionInfo ioc)
|
||||
private static async Task<Stream> OpenWriteLocal(IOConnectionInfo ioc)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -303,18 +303,15 @@ namespace ModernKeePassLib.Serialization
|
||||
|
||||
public static bool FileExists(IOConnectionInfo ioc)
|
||||
{
|
||||
return FileExists(ioc, false);
|
||||
//return FileExists(ioc, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool FileExists(IOConnectionInfo ioc, bool bThrowErrors)
|
||||
/*public static bool FileExists(IOConnectionInfo ioc, bool bThrowErrors)
|
||||
{
|
||||
Debug.Assert(false, "Not implemented yet");
|
||||
return false;
|
||||
#if TODO
|
||||
|
||||
if(ioc == null) { Debug.Assert(false); return false; }
|
||||
|
||||
if(ioc.IsLocalFile()) return File.Exists(ioc.Path);
|
||||
if(ioc.IsLocalFile()) return ioc.StorageFile.IsAvailable;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -334,15 +331,12 @@ namespace ModernKeePassLib.Serialization
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void DeleteFile(IOConnectionInfo ioc)
|
||||
public static async void DeleteFile(IOConnectionInfo ioc)
|
||||
{
|
||||
Debug.Assert(false, "Not implemented yet");
|
||||
return ;
|
||||
#if TODO
|
||||
if(ioc.IsLocalFile()) { File.Delete(ioc.Path); return; }
|
||||
if(ioc.IsLocalFile()) { await ioc.StorageFile.DeleteAsync(StorageDeleteOption.Default);
|
||||
}
|
||||
|
||||
#if !KeePassLibSD && TODO
|
||||
WebRequest req = CreateWebRequest(ioc);
|
||||
@@ -359,7 +353,6 @@ namespace ModernKeePassLib.Serialization
|
||||
|
||||
DisposeResponse(req.GetResponse(), true);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -372,11 +365,9 @@ namespace ModernKeePassLib.Serialization
|
||||
/// </summary>
|
||||
/// <param name="iocFrom">Source file path.</param>
|
||||
/// <param name="iocTo">Target file path.</param>
|
||||
public static void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
|
||||
public static async void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
|
||||
{
|
||||
return;
|
||||
#if TODO
|
||||
if(iocFrom.IsLocalFile()) { File.Move(iocFrom.Path, iocTo.Path); return; }
|
||||
if(iocFrom.IsLocalFile()) { await iocTo.StorageFile.RenameAsync(iocTo.Path, NameCollisionOption.GenerateUniqueName); }
|
||||
|
||||
#if !KeePassLibSD && TODO
|
||||
WebRequest req = CreateWebRequest(iocFrom);
|
||||
@@ -419,7 +410,6 @@ namespace ModernKeePassLib.Serialization
|
||||
// sIn.Close();
|
||||
// }
|
||||
// DeleteFile(iocFrom);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void DisposeResponse(WebResponse wr, bool bGetStream)
|
||||
|
@@ -100,29 +100,33 @@ namespace ModernKeePassLib.Serialization
|
||||
|
||||
Stream writerStream;
|
||||
BinaryWriter bw = null;
|
||||
if(m_format == Kdb4Format.Default)
|
||||
if (m_format == Kdb4Format.Default)
|
||||
{
|
||||
bw = new BinaryWriter(hashedStream, encNoBom);
|
||||
WriteHeader(bw); // Also flushes bw
|
||||
|
||||
Stream sEncrypted = AttachStreamEncryptor(hashedStream);
|
||||
if((sEncrypted == null) || (sEncrypted == hashedStream))
|
||||
if ((sEncrypted == null) || (sEncrypted == hashedStream))
|
||||
throw new SecurityException(KLRes.CryptoStreamFailed);
|
||||
|
||||
sEncrypted.Write(m_pbStreamStartBytes, 0, m_pbStreamStartBytes.Length);
|
||||
|
||||
Stream sHashed = new HashedBlockStream(sEncrypted, true);
|
||||
|
||||
if(m_pwDatabase.Compression == PwCompressionAlgorithm.GZip)
|
||||
if (m_pwDatabase.Compression == PwCompressionAlgorithm.GZip)
|
||||
writerStream = new GZipStream(sHashed, CompressionMode.Compress);
|
||||
else
|
||||
writerStream = sHashed;
|
||||
}
|
||||
else if(m_format == Kdb4Format.PlainXml)
|
||||
else if (m_format == Kdb4Format.PlainXml)
|
||||
writerStream = hashedStream;
|
||||
else { Debug.Assert(false); throw new FormatException("KdbFormat"); }
|
||||
else
|
||||
{
|
||||
Debug.Assert(false);
|
||||
throw new FormatException("KdbFormat");
|
||||
}
|
||||
|
||||
using (m_xmlWriter = XmlWriter.Create(writerStream, new XmlWriterSettings { Encoding = encNoBom }))
|
||||
using (m_xmlWriter = XmlWriter.Create(writerStream, new XmlWriterSettings {Encoding = encNoBom}))
|
||||
{
|
||||
WriteDocument(pgDataSource);
|
||||
|
||||
@@ -130,6 +134,10 @@ namespace ModernKeePassLib.Serialization
|
||||
writerStream.Dispose();
|
||||
}
|
||||
GC.KeepAlive(bw);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
finally { CommonCleanUpWrite(sSaveTo, hashedStream); }
|
||||
}
|
||||
|
Reference in New Issue
Block a user