Support for decrypting LUKS volumes.

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1362680
This commit is contained in:
Andrius Štikonas 2013-08-09 19:25:48 +00:00
parent aec4f3554c
commit 2b75f43bb0
7 changed files with 275 additions and 0 deletions

View File

@ -20,6 +20,8 @@
#include "fs/luks.h"
#include "gui/decryptluksdialog.h"
#include "util/capacity.h"
#include "util/externalcommand.h"
@ -84,11 +86,37 @@ namespace FS
return 3 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
}
QString luks::mountTitle() const
{
return i18nc("@title:menu", "Decrypt");
}
QString luks::unmountTitle() const
{
return i18nc("@title:menu", "Deactivate");
}
bool luks::mount(const QString& deviceNode)
{
QPointer<DecryptLuksDialog> dlg = new DecryptLuksDialog(deviceNode);
if (dlg->exec() == KDialog::Accepted)
{
std::vector<QString> commands;
commands.push_back("echo");
commands.push_back("cryptsetup");
std::vector<QStringList> args;
args.push_back(QStringList() << dlg->luksPassphrase().text());
args.push_back(QStringList() << "luksOpen" << deviceNode << dlg->luksName().text());
ExternalCommand cmd(commands, args);
delete dlg;
return cmd.run(-1) && cmd.exitCode() == 0;
}
delete dlg;
return false;
}
bool luks::unmount(const QString& deviceNode)
{
ExternalCommand cmd("cryptsetup", QStringList() << "luksClose" << mapperName(deviceNode));

View File

@ -63,9 +63,12 @@ namespace FS
virtual QString readUUID(const QString& deviceNode) const;
virtual bool updateUUID(Report& report, const QString& deviceNode) const;
virtual bool canMount(const QString&) const { return true; };
virtual bool canUnmount(const QString&) const { return true; };
virtual bool mount(const QString& deviceNode);
virtual bool unmount(const QString& deviceNode);
virtual QString mountTitle() const;
virtual QString unmountTitle() const;
static QString mapperName (const QString& deviceNode);

View File

@ -0,0 +1,39 @@
/***************************************************************************
* Copyright (C) 2013 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "gui/decryptluksdialog.h"
#include "gui/decryptluksdialogwidget.h"
#include "core/device.h"
#include "core/partitiontable.h"
#include <KLocale>
#include <KMessageBox>
#include <config.h>
DecryptLuksDialog::DecryptLuksDialog(/*QWidget* parent, */const QString& deviceNode) :
// KDialog(parent),
m_DialogWidget(new DecryptLuksDialogWidget(this)),
m_DeviceNode(deviceNode)
{
setMainWidget(&widget());
setCaption(i18nc("@title:window", "Decrypt LUKS partition on <filename>%1</filename>", this->deviceNode()));
setButtonText(KDialog::Ok, i18nc("@action:button", "&Decrypt"));
}

View File

@ -0,0 +1,55 @@
/***************************************************************************
* Copyright (C) 2013 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#if !defined(DECRYPTLUKSDIALOG__H)
#define DECRYPTLUKSDIALOG__H
#include "gui/decryptluksdialogwidget.h"
#include <KDialog>
class Device;
class DecryptLuksDialog : public KDialog
{
Q_OBJECT
public:
DecryptLuksDialog(/*QWidget* parent, */const QString& deviceNode);
protected:
DecryptLuksDialogWidget& widget() { return *m_DialogWidget; }
const DecryptLuksDialogWidget& widget() const { return *m_DialogWidget; }
const QString& deviceNode() const { return m_DeviceNode; }
private:
DecryptLuksDialogWidget* m_DialogWidget;
const QString& m_DeviceNode;
public:
KLineEdit& luksName() { return widget().luksName(); }
const KLineEdit& luksName() const { return widget().luksName(); }
KLineEdit& luksPassphrase() { return widget().luksPassphrase(); }
const KLineEdit& luksPassphrase() const { return widget().luksPassphrase(); }
};
#endif

View File

@ -0,0 +1,26 @@
/***************************************************************************
* Copyright (C) 2013 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "gui/decryptluksdialogwidget.h"
DecryptLuksDialogWidget::DecryptLuksDialogWidget(QWidget* parent) :
QWidget(parent)
{
setupUi(this);
}

View File

@ -0,0 +1,46 @@
/***************************************************************************
* Copyright (C) 2013 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#if !defined(DECRYPTLUKSDIALOGWIDGET__H)
#define DECRYPTLUKSDIALOGWIDGET__H
#include "ui_decryptluksdialogwidgetbase.h"
#include <QWidget>
#include <QLabel>
#include <KLineEdit>
class DecryptLuksDialogWidget : public QWidget, public Ui::DecryptLuksDialogWidgetBase
{
Q_OBJECT
public:
DecryptLuksDialogWidget(QWidget* parent);
public:
KLineEdit& luksName() { return *m_LineEditName; }
const KLineEdit& luksName() const { return *m_LineEditName; }
KLineEdit& luksPassphrase() { return *m_LineEditPassphrase; }
const KLineEdit& luksPassphrase() const { return *m_LineEditPassphrase; }
};
#endif

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DecryptLuksDialogWidgetBase</class>
<widget class="QWidget" name="DecryptLuksDialogWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>377</width>
<height>122</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>10</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QLabel" name="label_Name">
<property name="text">
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>m_LineEditName</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KLineEdit" name="m_LineEditName"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_Pass">
<property name="text">
<string>&amp;Passphrase:</string>
</property>
<property name="buddy">
<cstring>m_LineEditPassphrase</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KLineEdit" name="m_LineEditPassphrase">
<property name="passwordMode">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>