Add password entry dialog and attempt LUKS unlock once (#795617)

Initial addition of a password entry dialog.  Looks like:

    +------------------------------------------------+
    |           LUKS Passphrase /dev/sdb1            |
    +------------------------------------------------+
    | Enter LUKS passphrase to open /dev/sdb1        |
    | Passphrase:    [                             ] |
    |                                                |
    |                          [ Cancel ] [ Unlock ] |
    +------------------------------------------------+

A standard Gtk Dialog is used to accept the password once, with any
errors displayed in a separate error dialog afterwards.  This is poor UI
design.  A password dialog should remain open for all authentication
attempts and only close when successful or the dialog is cancelled or
closed.  This UI design issue will be improved in following commits.

Bug 795617 - Implement opening and closing of LUKS mappings
This commit is contained in:
Mike Fleetwood 2017-10-22 19:52:12 +01:00 committed by Curtis Gedak
parent c47b1cdca1
commit f4d47fe5a5
6 changed files with 138 additions and 5 deletions

View File

@ -0,0 +1,42 @@
/* Copyright (C) 2017 Mike Fleetwood
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef GPARTED_DIALOGPASSWORDENTRY_H
#define GPARTED_DIALOGPASSWORDENTRY_H
#include "Partition.h"
#include <gtkmm/dialog.h>
#include <glibmm/ustring.h>
#include <gtkmm/entry.h>
namespace GParted
{
class DialogPasswordEntry : public Gtk::Dialog
{
public:
DialogPasswordEntry( const Partition & partition );
~DialogPasswordEntry();
Glib::ustring get_password();
private:
Gtk::Entry *entry;
};
} //GParted
#endif /* GPARTEDPASSWORDENTRY_H */

View File

@ -7,6 +7,7 @@ EXTRA_DIST = \
Device.h \
DialogFeatures.h \
DialogManageFlags.h \
DialogPasswordEntry.h \
Dialog_Base_Partition.h \
Dialog_Disklabel.h \
Dialog_FileSystem_Label.h \

View File

@ -6,6 +6,7 @@ org.gnome.gparted.policy.in.in
include/Utils.h
src/BlockSpecial.cc
src/CopyBlocks.cc
src/DialogPasswordEntry.cc
src/Dialog_Base_Partition.cc
src/Dialog_Disklabel.cc
src/Dialog_FileSystem_Label.cc

View File

@ -0,0 +1,76 @@
/* Copyright (C) 2017 Mike Fleetwood
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "DialogPasswordEntry.h"
#include "Partition.h"
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <gtkmm/stock.h>
namespace GParted
{
DialogPasswordEntry::DialogPasswordEntry( const Partition & partition )
{
this->set_resizable( false );
this->set_has_separator( false );
this->set_size_request( 400, -1 );
/* TO TRANSLATORS: dialog title, looks like LUKS Passphrase /dev/sda1 */
this->set_title( String::ucompose( _("LUKS Passphrase %1"), partition.get_path() ) );
// Separate VBox to hold lines in the dialog.
Gtk::VBox *vbox( manage( new Gtk::VBox() ) );
vbox->set_border_width( 5 );
vbox->set_spacing( 5 );
get_vbox()->pack_start( *vbox, Gtk::PACK_SHRINK );
// Line 1: "Enter LUKS passphrase to open /dev/sda1"
vbox->pack_start( *Utils::mk_label(
String::ucompose( _("Enter LUKS passphrase to open %1"), partition.get_path() ) ),
Gtk::PACK_SHRINK );
// Line 2: "Passphrase: [ ]"
// (HBox holding prompt and entry box)
Gtk::HBox *entry_hbox( manage( new Gtk::HBox() ) );
entry_hbox->pack_start( *Utils::mk_label( "<b>"+ Glib::ustring( _("Passphrase:") ) + "</b>" ) );
entry = manage( new Gtk::Entry() );
entry->set_width_chars( 30 );
entry->set_visibility( false );
entry->set_activates_default( true );
entry_hbox->pack_start( *entry );
vbox->pack_start( *entry_hbox );
// Line 3: blank
vbox->pack_start( *Utils::mk_label( "" ) );
this->add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL );
this->add_button( _("Unlock"), Gtk::RESPONSE_OK );
this->set_default_response( Gtk::RESPONSE_OK );
this->show_all_children();
}
DialogPasswordEntry::~DialogPasswordEntry()
{
}
Glib::ustring DialogPasswordEntry::get_password()
{
return Glib::ustring( entry->get_text() );
}
} //GParted

View File

@ -17,6 +17,7 @@ gpartedbin_SOURCES = \
Device.cc \
DialogFeatures.cc \
DialogManageFlags.cc \
DialogPasswordEntry.cc \
Dialog_Base_Partition.cc \
Dialog_Disklabel.cc \
Dialog_FileSystem_Label.cc \

View File

@ -18,6 +18,7 @@
#include "Win_GParted.h"
#include "Dialog_Progress.h"
#include "DialogFeatures.h"
#include "DialogPasswordEntry.h"
#include "Dialog_Disklabel.h"
#include "Dialog_Rescue_Data.h"
#include "Dialog_Partition_Resize_Move.h"
@ -40,10 +41,12 @@
#include "OperationNamePartition.h"
#include "Partition.h"
#include "PartitionVector.h"
#include "PasswordRAMStore.h"
#include "LVM2_PV_Info.h"
#include "Utils.h"
#include "../config.h"
#include <string.h>
#include <gtkmm/aboutdialog.h>
#include <gtkmm/messagedialog.h>
#include <gtkmm/radiobuttongroup.h>
@ -2458,7 +2461,6 @@ void Win_GParted::toggle_crypt_busy_state()
// state of the partition.
return;
show_pulsebar( pulse_msg );
bool success = false;
Glib::ustring cmd;
Glib::ustring output;
@ -2469,11 +2471,20 @@ void Win_GParted::toggle_crypt_busy_state()
case LUKSCLOSE:
cmd = "cryptsetup luksClose " +
Glib::shell_quote( selected_partition_ptr->get_mountpoint() );
show_pulsebar( pulse_msg );
success = ! Utils::execute_command( cmd, output, error );
hide_pulsebar();
error_msg = "<i># " + cmd + "\n" + error + "</i>";
break;
case LUKSOPEN:
{
DialogPasswordEntry dialog( *selected_partition_ptr );
dialog.set_transient_for( *this );
if ( dialog.run() != Gtk::RESPONSE_OK )
// Password dialog cancelled or closed
return;
// Create LUKS mapping name from partition name:
// "/dev/sdb1" -> "sdb1_crypt"
Glib::ustring mapping_name = selected_partition_ptr->get_path();
@ -2485,16 +2496,17 @@ void Win_GParted::toggle_crypt_busy_state()
cmd = "cryptsetup luksOpen " +
Glib::shell_quote( selected_partition_ptr->get_path() ) + " " +
Glib::shell_quote( mapping_name );
error_msg = "Opening LUKS encryption mapping is not yet implemented\n"
"<i># " + cmd + "</i>";
success = false;
show_pulsebar( pulse_msg );
success = ! Utils::execute_command( cmd, dialog.get_password().c_str(),
output, error );
hide_pulsebar();
error_msg = "<i># " + cmd + "\n" + error + "</i>";
break;
}
default:
// Impossible
break;
}
hide_pulsebar();
if ( ! success )
show_toggle_failure_dialog( failure_msg, error_msg );