Files
duplicati/Duplicati/Library/Backend/File/FileUI.cs
T
kenneth.skovhede@gmail.com effdba0558 Update issue #134
Status: Fixed

I have now implemented a password protection control.
You can now only view passwords when you enter them.
After this, you may reset the passwords, by entering a
new one, but you cannot read the existing passwords.

To protect against people reading the database,
which contains the passwords in clear text, the
database is now encrypted by using the standard 
SQLite encryption method. This is different
than what I proposed, but is a much stronger
protection than merely scrambling the passwords,
and also protects all information (servername, etc).

It works by setting an environment variable
called DUPLICATI_DB_KEY. When no password
is set, Duplicati will use the key "Duplicati_Key_42",
ensuring that all databases are encrypted by default.

Using a pre-defined publicly known key is obviously
not a strong protection, but it protects from casual
users attempting to browse the database, and it also
protects from string scanners that scan a harddisk
for possible passwords.

On the first startup, Duplicati will encrypt the database,
using the mentioned key. You may want to delete any backup
databases that are placed in the same folder as the database.

Should you wish to decrypt the database, you can start 
Duplicati.exe with the commandline option "--unencrypted-database".
This will use the current key to decrypt the database, and save it
without encryption.

Should you wish to change the database password, simply decrypt the
database, then change the password via the environment variable,
and start Duplicati.exe as normal.

The SQLite documentation for the feature is here:
http://www.hwaci.com/sw/sqlite/see.html

Unfortunately, it does not seem as if any
of the free SQLite tools supports this.

The SQLite library found on Ubuntu
does not support encryption, so I have disabled 
this feature by default on Linux.

If a user has a special compiled version
of SQLite, they may use the environment
variables as mentioned above.

I will write this information into a wiki
page as soon asap.

git-svn-id: https://duplicati.googlecode.com/svn/trunk@498 59da171f-624f-0410-aa54-27559c288bec
2010-09-07 21:39:22 +00:00

241 lines
9.4 KiB
C#

#region Disclaimer / License
// Copyright (C) 2010, Kenneth Skovhede
// http://www.hexad.dk, opensource@hexad.dk
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Duplicati.Library.Backend
{
public partial class FileUI : UserControl
{
IDictionary<string, string> m_options;
private const string DESTINATION_FOLDER = "Destination";
private const string USERNAME = "Username";
private const string PASSWORD = "Password";
private const string CHECKED_EMPTY = "UI: Checked empty";
private bool m_hasCheckedEmpty = false;
public FileUI(IDictionary<string, string> options)
: this()
{
m_options = options;
}
private FileUI()
{
InitializeComponent();
}
internal bool Save(bool validate)
{
string targetpath;
if (UsePath.Checked)
targetpath = TargetFolder.Text;
else
targetpath = TargetDrive.Text + "\\" + Folder.Text;
if (m_hasCheckedEmpty && m_options.ContainsKey(DESTINATION_FOLDER) && targetpath != m_options[DESTINATION_FOLDER])
m_hasCheckedEmpty = false;
m_options.Clear();
m_options[CHECKED_EMPTY] = m_hasCheckedEmpty.ToString();
m_options[DESTINATION_FOLDER] = targetpath;
if (UseCredentials.Checked)
{
m_options[USERNAME] = Username.Text;
m_options[PASSWORD] = Password.Text;
}
else
{
m_options[USERNAME] = "";
m_options[PASSWORD] = "";
}
if (!validate)
return false;
if (UseCredentials.Checked)
if (!Duplicati.Library.Backend.File.PreAuthenticate(targetpath, Username.Text, Password.Text))
{
MessageBox.Show(this, Strings.FileUI.AuthenticationError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
try
{
if (targetpath.Trim().Length == 0)
{
MessageBox.Show(this, Strings.FileUI.EmptyFoldernameError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (!System.IO.Path.IsPathRooted(targetpath))
{
MessageBox.Show(this, Strings.FileUI.NonRootedPathError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (!System.IO.Directory.Exists(targetpath))
{
switch (MessageBox.Show(this, Strings.FileUI.CreateFolderQuestion, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
{
case DialogResult.Yes:
System.IO.Directory.CreateDirectory(targetpath);
break;
case DialogResult.Cancel:
return false;
}
}
}
catch (Exception ex)
{
MessageBox.Show(this, string.Format(Strings.FileUI.FolderValidationError, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
try
{
//The UI cannot determine if we are restoring or creating a backup,
//so the check below is not active
/*if (m_options.ContainsKey("PrimaryAction") && m_options["PrimaryAction"] == "Restore")
{
if (System.IO.Directory.GetFileSystemEntries(targetpath).Length == 0)
if (MessageBox.Show(this, Strings.FileUI.FolderEmptyError, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) != DialogResult.Yes)
return false;
}
else
{
if (!m_hasCheckedEmpty && System.IO.Directory.GetFileSystemEntries(targetpath).Length > 0)
if (MessageBox.Show(this, Strings.FileUI.FolderNotEmptyWarning, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) != DialogResult.Yes)
return false;
}
m_hasCheckedEmpty = true;
m_options[CHECKED_EMPTY] = "true";*/
}
catch (Exception ex)
{
MessageBox.Show(this, string.Format(Strings.FileUI.FolderValidationError, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
private void RescanDrives()
{
TargetDrive.Items.Clear();
if (!Library.Core.Utility.IsClientLinux)
for (char i = 'A'; i < 'Z'; i++)
{
try
{
System.IO.DriveInfo di = new System.IO.DriveInfo(i.ToString());
if (di.DriveType == System.IO.DriveType.Removable)
TargetDrive.Items.Add(i.ToString() + ":");
}
catch { }
}
}
void FileUI_Load(object sender, EventArgs args)
{
RescanDrives();
UsePath.Checked = true;
if (m_options.ContainsKey(DESTINATION_FOLDER))
TargetFolder.Text = m_options[DESTINATION_FOLDER];
UseCredentials.Checked = m_options.ContainsKey(USERNAME) && !string.IsNullOrEmpty(m_options[USERNAME]);
if (m_options.ContainsKey(USERNAME))
Username.Text = m_options[USERNAME];
if (m_options.ContainsKey(PASSWORD))
Password.Text = m_options[PASSWORD];
Password.AskToEnterNewPassword = !string.IsNullOrEmpty(Password.Text);
if (!m_options.ContainsKey(CHECKED_EMPTY) || !bool.TryParse(m_options[CHECKED_EMPTY], out m_hasCheckedEmpty))
m_hasCheckedEmpty = false;
}
private void UseCredentials_CheckedChanged(object sender, EventArgs e)
{
Credentials.Enabled = UseCredentials.Checked;
}
private void UsePath_CheckedChanged(object sender, EventArgs e)
{
TargetFolder.Enabled = BrowseTargetFolder.Enabled = UsePath.Checked;
}
private void BrowseTargetFolder_Click(object sender, EventArgs e)
{
if (folderBrowserDialog.ShowDialog(this) == DialogResult.OK)
TargetFolder.Text = folderBrowserDialog.SelectedPath;
}
private void UseDisk_CheckedChanged(object sender, EventArgs e)
{
TargetDrive.Enabled = Folder.Enabled = FolderLabel.Enabled = UseDisk.Checked;
RescanDrives();
if (TargetDrive.Enabled && TargetDrive.Items.Count == 0)
{
MessageBox.Show(this, Strings.FileUI.NoRemovableDrivesError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
UsePath.Checked = true;
}
}
public static string GetConfiguration(IDictionary<string, string> guiOptions, IDictionary<string, string> commandlineOptions)
{
if (guiOptions.ContainsKey(USERNAME) && !string.IsNullOrEmpty(guiOptions[USERNAME]))
commandlineOptions["ftp-username"] = guiOptions[USERNAME];
if (guiOptions.ContainsKey(PASSWORD) && !string.IsNullOrEmpty(guiOptions[PASSWORD]))
commandlineOptions["ftp-password"] = guiOptions[PASSWORD];
if (!guiOptions.ContainsKey(DESTINATION_FOLDER))
throw new Exception(string.Format(Interface.CommonStrings.ConfigurationIsMissingItemError, DESTINATION_FOLDER));
return "file://" + guiOptions[DESTINATION_FOLDER];
}
public static string PageTitle
{
get { return Strings.FileUI.PageTitle; }
}
public static string PageDescription
{
get { return Strings.FileUI.PageDescription; }
}
}
}