"Fossies" - the Fresh Open Source Software Archive

Member "zuluCrypt-5.7.1/zuluCrypt-gui/password_dialog.cpp" (31 Jan 2020, 28938 Bytes) of package /linux/misc/zuluCrypt-5.7.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "password_dialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.7.0_vs_5.7.1.

    1 /*
    2  *
    3  *  Copyright ( c ) 2011-2015
    4  *  name : Francis Banyikwa
    5  *  email: mhogomchungu@gmail.com
    6  *  This program is free software: you can redistribute it and/or modify
    7  *  it under the terms of the GNU General Public License as published by
    8  *  the Free Software Foundation, either version 2 of the License, or
    9  *  ( at your option ) any later version.
   10  *
   11  *  This program is distributed in the hope that it will be useful,
   12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  *  GNU General Public License for more details.
   15  *
   16  *  You should have received a copy of the GNU General Public License
   17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   18  */
   19 
   20 #include "password_dialog.h"
   21 #include "zulucrypt.h"
   22 #include "lxqt_wallet.h"
   23 #include "../plugin_path.h"
   24 
   25 #include <QMenu>
   26 #include <Qt>
   27 #include <QObject>
   28 #include <QFileDialog>
   29 #include <QDir>
   30 #include <iostream>
   31 #include <QRadioButton>
   32 #include <QPushButton>
   33 #include <QMessageBox>
   34 
   35 #include <QDebug>
   36 #include <QString>
   37 #include <QByteArray>
   38 #include <QFileDialog>
   39 #include <QStringList>
   40 #include <QCloseEvent>
   41 #include <QTableWidget>
   42 #include <stdlib.h>
   43 
   44 #include "ui_password.h"
   45 #include "openvolume.h"
   46 #include "tcrypt.h"
   47 #include "task.hpp"
   48 #include "utility.h"
   49 #include "dialogmsg.h"
   50 #include "plugin_path.h"
   51 #include "tablewidget.h"
   52 #include "../zuluCrypt-cli/constants.h"
   53 
   54 #include "utility.h"
   55 
   56 #define KWALLET         "KDE Wallet"
   57 #define INTERNAL_WALLET "Internal Wallet"
   58 #define GNOME_WALLET    "GNOME keyring"
   59 
   60 /*
   61  * this header is created at config time
   62  */
   63 #include "truecrypt_support.h"
   64 
   65 passwordDialog::passwordDialog( QTableWidget * table,
   66                 QWidget * parent,
   67                 secrets& s,
   68                 std::function< void( const QString& ) > f ) :
   69     QDialog( parent ),
   70     m_ui( new Ui::PasswordDialog() ),
   71     m_secrets( s ),
   72     m_openFolder( std::move( f ) )
   73 {
   74     m_ui->setupUi( this ) ;
   75 
   76     m_label.setOptions( m_ui->veraCryptWarning,m_ui->pbOK ) ;
   77 
   78     m_ui->PassPhraseField->setMaxLength( 32767 ) ;
   79 
   80     m_parent = parent ;
   81 
   82     this->setFixedSize( this->size() ) ;
   83     this->setWindowFlags( Qt::Window | Qt::Dialog ) ;
   84     this->setFont( parent->font() ) ;
   85     this->setDefaultOpenMode() ;
   86 
   87     m_ui->cbShareMountPoint->setChecked( utility::mountWithSharedMountPoint() ) ;
   88 
   89     m_ui->PushButtonMountPointPath->setIcon( QIcon( ":/folder.png" ) ) ;
   90 
   91     m_ui->pushButtonLuksExternalHeaderPath->setIcon( QIcon( ":/file.png" ) ) ;
   92 
   93     m_open_with_path = false ;
   94 
   95     m_table = table ;
   96 
   97     m_pluginMenu = new QMenu( this ) ;
   98     m_pluginMenu->setFont( this->font() ) ;
   99 
  100     connect( m_ui->PushButtonCancel,SIGNAL( clicked() ),this,SLOT( HideUI() ) ) ;
  101     connect( m_ui->PushButtonOpen,SIGNAL( clicked() ),this,SLOT( buttonOpenClicked() ) ) ;
  102     connect( m_ui->PushButtonMountPointPath,SIGNAL( clicked() ),this,SLOT( mount_point() ) ) ;
  103     connect( m_ui->PushButtonVolumePath,SIGNAL( clicked() ),this,SLOT( file_path() ) ) ;
  104     connect( m_ui->pushButtonPassPhraseFromFile,SIGNAL( clicked() ),this,SLOT( clickedPassPhraseFromFileButton() ) ) ;
  105     connect( m_ui->OpenVolumePath,SIGNAL( textChanged( QString ) ),this,SLOT( mountPointPath( QString ) ) ) ;
  106     connect( m_ui->checkBoxReadOnly,SIGNAL( stateChanged( int ) ),this,SLOT( cbStateChanged( int ) ) ) ;
  107     connect( m_ui->pbKeyOption,SIGNAL( clicked() ),this,SLOT( pbKeyOption() ) ) ;
  108     connect( m_ui->cbKeyType,SIGNAL( currentIndexChanged( int ) ),this,SLOT( cbActicated( int ) ) ) ;
  109     connect( m_ui->cbVolumeType,SIGNAL( currentIndexChanged( int ) ),this,SLOT( cbVolumeType( int ) ) ) ;
  110     connect( m_ui->checkBoxVisibleKey,SIGNAL( stateChanged( int ) ),this,SLOT( cbVisibleKeyStateChanged( int ) ) ) ;
  111 
  112     connect( m_ui->cbShareMountPoint,&QCheckBox::stateChanged,[]( int s ){
  113 
  114         utility::mountWithSharedMountPoint( s == Qt::Checked ) ;
  115     } ) ;
  116 
  117     m_ui->cbVolumeType->setCurrentIndex( utility::defaultUnlockingVolumeType() ) ;
  118     this->cbVolumeType( utility::defaultUnlockingVolumeType() ) ;
  119 
  120     m_ui->PushButtonMountPointPath->setVisible( false ) ;
  121     m_ui->pushButtonPassPhraseFromFile->setVisible( false ) ;
  122 
  123     m_veraCryptWarning.setWarningLabel( m_ui->veraCryptWarning ) ;
  124 
  125     m_ui->cbShareMountPoint->setToolTip( utility::shareMountPointToolTip() ) ;
  126 
  127     m_ui->cbKeyType->addItem( tr( "TrueCrypt/VeraCrypt Keys" ) ) ;
  128 
  129     m_ui->cbKeyType->addItem( tr( "YubiKey Challenge/Response" ) ) ;
  130 
  131     m_ui->pushButtonPlainDmCryptOptions->setMenu( [ this ](){
  132 
  133         auto m = new QMenu( this ) ;
  134 
  135         connect( m,SIGNAL( triggered( QAction * ) ),
  136              this,SLOT( plainDmCryptOption( QAction * ) ) ) ;
  137 
  138         auto s = utility::plainDmCryptOptions() ;
  139 
  140         if( s.isEmpty() ){
  141 
  142             m_plainDmCryptProperty = "aes.cbc-essiv:sha256.256.ripemd160" ;
  143             m->addAction( "aes.cbc-essiv:sha256.256.ripemd160" ) ;
  144         }else{
  145             m_plainDmCryptProperty = s.first() ;
  146 
  147             for( const auto& it : s ){
  148 
  149                 m->addAction( it ) ;
  150             }
  151         }
  152 
  153         return m ;
  154     }() ) ;
  155 
  156     connect( m_ui->pushButtonLuksExternalHeaderPath,&QPushButton::clicked,[ this ](){
  157 
  158         auto a = tr( "Select External LUKS Header File" ) ;
  159 
  160         auto Z = QFileDialog::getOpenFileName( this,a,utility::homePath() ) ;
  161 
  162         if( !Z.isEmpty() ){
  163 
  164             m_ui->lineEditVolumeProperty->setText( Z ) ;
  165         }
  166     } ) ;
  167 
  168     m_ui->checkBoxVisibleKey->setToolTip( tr( "Check This Box To Make Password Visible" ) ) ;
  169 
  170     this->setWindowTitle( tr( "Unlock Encrypted Volume" ) ) ;
  171 
  172     this->installEventFilter( this ) ;
  173 }
  174 
  175 void passwordDialog::plainDmCryptOption( QAction * ac )
  176 {
  177     m_plainDmCryptProperty = ac->text().remove( "&" ) ;
  178 }
  179 
  180 void passwordDialog::cbVolumeType( int e )
  181 {
  182     m_ui->lineEditVolumeProperty->clear() ;
  183 
  184     m_ui->lineEditVolumeProperty->setToolTip( QString() ) ;
  185 
  186     if( e == 0 ){
  187 
  188         /*
  189          * LUKS,TrueCrypt,BitLocker
  190          */
  191         m_ui->labelVolumeProperty->setText( tr( "LUKS External Header Path" ) ) ;
  192         m_ui->lineEditVolumeProperty->setEnabled( true ) ;
  193         m_ui->pushButtonPlainDmCryptOptions->setEnabled( false ) ;
  194         m_veraCryptVolume = false ;
  195         m_ui->pushButtonLuksExternalHeaderPath->setEnabled( true ) ;
  196         m_ui->lineEditVolumeProperty->setEchoMode( QLineEdit::Normal ) ;
  197 
  198     }else if( e == 1 || e == 2 ){
  199 
  200         /*
  201          * VeraCrypt volume
  202          */
  203         m_ui->labelVolumeProperty->setText( tr( "PIM Value" ) ) ;
  204         m_ui->lineEditVolumeProperty->setEnabled( true ) ;
  205         m_ui->pushButtonPlainDmCryptOptions->setEnabled( false ) ;
  206         m_veraCryptVolume = true ;
  207         m_ui->pushButtonLuksExternalHeaderPath->setEnabled( false ) ;
  208         m_ui->lineEditVolumeProperty->setEchoMode( QLineEdit::Password ) ;
  209 
  210     }else if( e == 3 ){
  211 
  212         /*
  213          * PLAIN dm-crypt
  214          */
  215         m_ui->pushButtonPlainDmCryptOptions->setEnabled( true ) ;
  216         m_ui->labelVolumeProperty->setText( tr( "Offset" ) ) ;
  217         m_ui->lineEditVolumeProperty->setEnabled( true ) ;
  218         m_ui->lineEditVolumeProperty->setToolTip( tr( "Offset Will Be In Sectors If The Entry Is Made Up Of Only Digits\nAnd In Bytes If The Entry Ends With \"b\"\nAnd In Kilobytes If The Entry Ends With \"k\"\nAnd In Megabytes If The Entry Ends With \"m\"\nAnd In Terabytes If The Entry Ends With \"t\"" ) ) ;
  219         m_veraCryptVolume = false ;
  220         m_ui->pushButtonLuksExternalHeaderPath->setEnabled( false ) ;
  221         m_ui->lineEditVolumeProperty->setEchoMode( QLineEdit::Password ) ;
  222     }
  223 
  224     utility::defaultUnlockingVolumeType( e ) ;
  225 }
  226 
  227 bool passwordDialog::eventFilter( QObject * watched,QEvent * event )
  228 {
  229     return utility::eventFilter( this,watched,event,[ this ](){ this->HideUI() ; } ) ;
  230 }
  231 
  232 void passwordDialog::pbPlugin()
  233 {
  234     //utility::createPlugInMenu( m_pluginMenu,tr( INTERNAL_WALLET ),
  235     //             tr( GNOME_WALLET ),tr( KWALLET ),!utility::useZuluPolkit() ) ;
  236 
  237     utility::createPlugInMenu( m_pluginMenu,tr( INTERNAL_WALLET ),
  238                    tr( GNOME_WALLET ),tr( KWALLET ),true ) ;
  239 
  240     m_pluginMenu->addSeparator() ;
  241 
  242     m_pluginMenu->addAction( tr( "Cancel" ) ) ;
  243 
  244     connect( m_pluginMenu,SIGNAL( triggered( QAction * ) ),this,SLOT( pbPluginEntryClicked( QAction * ) ) ) ;
  245 
  246     m_pluginMenu->exec( QCursor::pos() ) ;
  247 }
  248 
  249 void passwordDialog::pbPluginEntryClicked( QAction * e )
  250 {
  251     auto text = e->text() ;
  252 
  253     text.remove( "&" ) ;
  254 
  255     if( text != tr( "Cancel" ) ){
  256 
  257         m_ui->PassPhraseField->setText( text ) ;
  258     }
  259 }
  260 
  261 void passwordDialog::tcryptGui()
  262 {
  263     this->disableAll() ;
  264 
  265     m_ui->PassPhraseField->setText( QString() ) ;
  266 
  267     tcrypt::instance( this,false,[ this ]( const QString& key,const QStringList& keyFiles ) {
  268 
  269         m_key = key.toLatin1() ;
  270         m_keyFiles = keyFiles ;
  271 
  272         this->openVolume() ;
  273 
  274         m_ui->cbKeyType->setCurrentIndex( passwordDialog::key ) ;
  275         m_ui->PassPhraseField->setText( QString() ) ;
  276 
  277     },[ this ](){
  278 
  279         m_key.clear() ;
  280         m_keyFiles.clear() ;
  281         m_ui->cbKeyType->setCurrentIndex( passwordDialog::key ) ;
  282         m_ui->PassPhraseField->setText( QString() ) ;
  283 
  284         this->enableAll() ;
  285     } ) ;
  286 }
  287 
  288 void passwordDialog::cbStateChanged( int state )
  289 {
  290     m_ui->checkBoxReadOnly->setEnabled( false ) ;
  291     m_ui->checkBoxReadOnly->setChecked( utility::setOpenVolumeReadOnly( this,state == Qt::Checked,"zuluCrypt-gui" ) ) ;
  292     m_ui->checkBoxReadOnly->setEnabled( true ) ;
  293 }
  294 
  295 void passwordDialog::setDefaultOpenMode()
  296 {
  297     m_ui->checkBoxReadOnly->setChecked( utility::getOpenVolumeReadOnlyOption( "zuluCrypt-gui" ) ) ;
  298 }
  299 
  300 void passwordDialog::closeEvent( QCloseEvent * e )
  301 {
  302     e->ignore() ;
  303     this->HideUI() ;
  304 }
  305 
  306 void passwordDialog::ShowUI( const QString& volumePath,const QString& mount_point )
  307 {
  308     auto volume = volumePath.split( "/" ).last() ;
  309 
  310     this->setWindowTitle( tr( "Mount \"%1\"" ).arg( volume ) ) ;
  311 
  312     if( mount_point.isEmpty() ){
  313 
  314         m_point = utility::mountPathPostFix( volume ) ;
  315     }else{
  316         m_point = utility::mountPathPostFix( mount_point.split( "/" ).last() ) ;
  317     }
  318 
  319     m_open_with_path = true ;
  320 
  321     this->passphraseOption() ;
  322 
  323     m_ui->OpenVolumePath->setText( volumePath ) ;
  324     m_ui->OpenVolumePath->setEnabled( false ) ;
  325     m_ui->PushButtonVolumePath->setEnabled( false ) ;
  326     m_ui->MountPointPath->setText( m_point ) ;
  327     m_ui->PassPhraseField->setFocus() ;
  328 
  329     if( volumePath.startsWith( "/dev/" ) || volumePath.startsWith( "UUID=" ) ){
  330 
  331         m_ui->PushButtonVolumePath->setIcon( QIcon( ":/partition.png" ) ) ;
  332     }else{
  333         m_ui->PushButtonVolumePath->setIcon( QIcon( ":/file.png" ) ) ;
  334     }
  335 
  336     this->show() ;
  337 }
  338 
  339 void passwordDialog::ShowUI( QString dev )
  340 {
  341     auto m_point = utility::homePath() + "/" + dev.split( "/" ).last() ;
  342 
  343     this->ShowUI( dev,m_point ) ;
  344 }
  345 
  346 void passwordDialog::cbVisibleKeyStateChanged( int s )
  347 {
  348     if( m_ui->cbKeyType->currentIndex() == passwordDialog::key ){
  349 
  350         if( s == Qt::Checked ){
  351 
  352             m_ui->PassPhraseField->setEchoMode( QLineEdit::Normal ) ;
  353         }else{
  354             m_ui->PassPhraseField->setEchoMode( QLineEdit::Password ) ;
  355         }
  356 
  357         m_ui->PassPhraseField->setFocus() ;
  358     }
  359 }
  360 
  361 void passwordDialog::ShowUI()
  362 {
  363     this->passphraseOption() ;
  364 
  365     m_ui->OpenVolumePath->setFocus() ;
  366     m_ui->PushButtonVolumePath->setIcon( QIcon( ":/file.png" ) ) ;
  367 
  368     this->show() ;
  369 }
  370 
  371 void passwordDialog::mountPointPath( QString path )
  372 {
  373     m_ui->MountPointPath->setText( utility::mountPathPostFix( path.split( "/" ).last() ) ) ;
  374 }
  375 
  376 void passwordDialog::cbActicated( int e )
  377 {
  378     if( e == passwordDialog::key || e == passwordDialog::yubikey ){
  379 
  380         m_ui->checkBoxVisibleKey->setEnabled( true ) ;
  381     }else{
  382         m_ui->checkBoxVisibleKey->setEnabled( false ) ;
  383         m_ui->checkBoxVisibleKey->setChecked( false ) ;
  384     }
  385 
  386     switch( e ){
  387 
  388         case passwordDialog::key         : return this->passphraseOption() ;
  389         case passwordDialog::yubikey     : return this->passphraseOption() ;
  390         case passwordDialog::keyfile     : return this->passphraseFromFileOption() ;
  391         case passwordDialog::keyKeyFile  : return this->keyAndKeyFile() ;
  392         case passwordDialog::plugin      : return this->pluginOption() ;
  393         case passwordDialog::tcryptKeys  : return this->tcryptGui() ;
  394     }
  395 }
  396 
  397 void passwordDialog::keyAndKeyFile()
  398 {
  399     QByteArray key ;
  400 
  401     if( utility::pluginKey( this,&key,"hmac" ) ){
  402 
  403         m_ui->cbKeyType->setCurrentIndex( 0 ) ;
  404     }else{
  405         this->passphraseOption() ;
  406 
  407         m_ui->PassPhraseField->setEnabled( false ) ;
  408         m_ui->PassPhraseField->setText( key ) ;
  409     }
  410 }
  411 
  412 void passwordDialog::pbKeyOption()
  413 {
  414     if( m_ui->cbKeyType->currentIndex() == passwordDialog::plugin ){
  415 
  416         this->pbPlugin() ;
  417     }else{
  418         this->clickedPassPhraseFromFileButton() ;
  419     }
  420 }
  421 
  422 void passwordDialog::pluginOption()
  423 {
  424     m_ui->pushButtonPassPhraseFromFile->setToolTip( tr( "Choose A Module From The File System" ) ) ;
  425     m_ui->PassPhraseField->setToolTip( tr( "Enter A Module Name To Use To Get Passphrase" ) ) ;
  426     m_ui->PassPhraseField->setEchoMode( QLineEdit::Normal ) ;
  427     m_ui->pushButtonPassPhraseFromFile->setEnabled( false ) ;
  428     m_ui->labelPassphrase->setText( tr( "Plugin Name" ) ) ;
  429     m_ui->pushButtonPassPhraseFromFile->setIcon( QIcon( ":/keyfile.png" ) ) ;
  430     m_ui->pbKeyOption->setIcon( QIcon( ":/module.png" ) ) ;
  431     m_ui->pbKeyOption->setEnabled( true ) ;
  432     m_ui->PassPhraseField->setEnabled( false ) ;
  433     m_ui->PassPhraseField->setText( INTERNAL_WALLET ) ;
  434 }
  435 
  436 void passwordDialog::passphraseOption()
  437 {
  438     m_ui->PassPhraseField->setToolTip( tr( "Enter A Key" ) ) ;
  439     m_ui->PassPhraseField->setEchoMode( QLineEdit::Password ) ;
  440     m_ui->PassPhraseField->clear() ;
  441     m_ui->pushButtonPassPhraseFromFile->setEnabled( false ) ;
  442     m_ui->labelPassphrase->setText( tr( "Password" ) ) ;
  443     m_ui->pushButtonPassPhraseFromFile->setIcon( QIcon( ":/passphrase.png" ) ) ;
  444     m_ui->pbKeyOption->setIcon( QIcon() ) ;
  445     m_ui->pbKeyOption->setEnabled( false ) ;
  446     m_ui->PassPhraseField->setFocus() ;
  447     m_ui->PassPhraseField->setEnabled( true ) ;
  448 }
  449 
  450 void passwordDialog::passphraseFromFileOption()
  451 {
  452     m_ui->pushButtonPassPhraseFromFile->setToolTip( tr( "Choose A KeyFile From The File System" ) ) ;
  453     m_ui->PassPhraseField->setToolTip( tr( "Enter A Path To A Keyfile Location" ) ) ;
  454     m_ui->PassPhraseField->setEchoMode( QLineEdit::Normal ) ;
  455     m_ui->PassPhraseField->clear() ;
  456     m_ui->pushButtonPassPhraseFromFile->setEnabled( true ) ;
  457     m_ui->pushButtonPassPhraseFromFile->setFocus() ;
  458     m_ui->labelPassphrase->setText( tr( "KeyFile Path" ) ) ;
  459     m_ui->pushButtonPassPhraseFromFile->setIcon( QIcon( ":/keyfile.png" ) ) ;
  460     m_ui->pbKeyOption->setIcon( QIcon( ":/keyfile.png" ) ) ;
  461     m_ui->pbKeyOption->setEnabled( true ) ;
  462     m_ui->PassPhraseField->setEnabled( true ) ;
  463 }
  464 
  465 void passwordDialog::clickedPassPhraseFromFileButton()
  466 {
  467     QString msg ;
  468 
  469     if( m_ui->cbKeyType->currentIndex() == passwordDialog::keyfile ){
  470 
  471         msg = tr( "Select A KeyFile" ) ;
  472     }else{
  473         msg = tr( "Select A Key Module" ) ;
  474     }
  475 
  476     auto Z = QFileDialog::getOpenFileName( this,msg,utility::homePath() ) ;
  477 
  478     if( !Z.isEmpty() ){
  479 
  480         m_ui->PassPhraseField->setText( Z ) ;
  481     }
  482 }
  483 
  484 void passwordDialog::mount_point( void )
  485 {
  486     auto p = tr( "Select Path To Mount Point Folder" ) ;
  487     auto Z = QFileDialog::getExistingDirectory( this,p,utility::homePath(),QFileDialog::ShowDirsOnly ) ;
  488 
  489     while( true ){
  490 
  491         if( Z.endsWith( '/' ) ){
  492 
  493             Z.truncate( Z.length() - 1 ) ;
  494         }else{
  495             break ;
  496         }
  497     }
  498 
  499     if( !Z.isEmpty() ){
  500 
  501         Z = Z + "/" + m_ui->OpenVolumePath->text().split( "/" ).last() ;
  502         m_ui->MountPointPath->setText( Z ) ;
  503     }
  504 
  505     if( m_ui->MountPointPath->text().isEmpty() ){
  506 
  507         m_ui->MountPointPath->setFocus() ;
  508 
  509     }else if( m_ui->PassPhraseField->text().isEmpty() ){
  510 
  511         m_ui->PassPhraseField->setFocus() ;
  512     }
  513 }
  514 
  515 void passwordDialog::file_path( void )
  516 {
  517     auto Z = QFileDialog::getOpenFileName( this,tr( "Select Encrypted volume" ),utility::homePath() ) ;
  518 
  519     m_ui->OpenVolumePath->setText( Z ) ;
  520 
  521     if( !Z.isEmpty() ){
  522 
  523         m_ui->MountPointPath->setText( utility::mountPathPostFix( Z.split( "/" ).last() ) ) ;
  524         m_ui->PassPhraseField->setFocus() ;
  525     }
  526 }
  527 
  528 void passwordDialog::HideUI()
  529 {
  530     if( !m_working ){
  531 
  532         this->hide() ;
  533         this->deleteLater() ;
  534     }
  535 }
  536 
  537 void passwordDialog::buttonOpenClicked( void )
  538 {
  539     this->disableAll() ;
  540 
  541     if( m_ui->cbKeyType->currentIndex() == passwordDialog::plugin ){
  542 
  543         auto wallet = m_ui->PassPhraseField->text() ;
  544         auto keyID = m_ui->OpenVolumePath->text() ;
  545 
  546         using wbe = LXQt::Wallet::BackEnd ;
  547 
  548         utility::wallet w ;
  549 
  550         if( wallet == tr( KWALLET ) ){
  551 
  552             auto s = m_secrets.walletBk( wbe::kwallet ) ;
  553 
  554             w = utility::getKey( s.bk(),keyID ) ;
  555 
  556         }else if( wallet == tr( INTERNAL_WALLET ) ){
  557 
  558             auto s = m_secrets.walletBk( wbe::internal ) ;
  559 
  560             w = utility::getKey( s.bk(),keyID,"zuluCrypt" ) ;
  561 
  562             if( w.notConfigured ){
  563 
  564                 DialogMsg msg( this ) ;
  565                 msg.ShowUIOK( tr( "ERROR!" ),tr( "Internal wallet is not configured" ) ) ;
  566                 return this->enableAll() ;
  567             }
  568 
  569         }else if( wallet == tr( GNOME_WALLET ) ){
  570 
  571             auto s = m_secrets.walletBk( wbe::libsecret ) ;
  572 
  573             w = utility::getKey( s.bk(),keyID ) ;
  574         }else{
  575             m_key = m_ui->PassPhraseField->text().toLatin1() ;
  576             return this->openVolume() ;
  577         }
  578 
  579         if( w.opened ){
  580 
  581             if( w.key.isEmpty() ){
  582 
  583                 DialogMsg msg( this ) ;
  584 
  585                 msg.ShowUIOK( tr( "ERROR!" ),tr( "The volume does not appear to have an entry in the wallet" ) ) ;
  586 
  587                 this->enableAll() ;
  588             }else{
  589                 m_key = w.key.toLatin1() ;
  590                 this->openVolume() ;
  591             }
  592         }else{
  593             this->enableAll() ;
  594         }
  595     }else{
  596         if( m_ui->cbKeyType->currentIndex() == passwordDialog::yubikey ){
  597 
  598             auto m = utility::yubiKey( m_ui->PassPhraseField->text() ) ;
  599 
  600             if( m.has_value() ){
  601 
  602                 m_key = m.value() ;
  603             }else{
  604                 DialogMsg( this ).ShowUIOK( tr( "ERROR" ),tr( "Failed To Locate Or Run Yubikey's \"ykchalresp\" Program." ) ) ;
  605                 return this->enableAll() ;
  606             }
  607         }else{
  608             m_key = m_ui->PassPhraseField->text().toLatin1() ;
  609         }
  610 
  611         this->openVolume() ;
  612     }
  613 }
  614 
  615 void passwordDialog::sendKey( const QString& sockpath )
  616 {
  617     utility::keySend( sockpath,m_key ) ;
  618 }
  619 
  620 void passwordDialog::disableAll()
  621 {
  622     m_ui->labelVolumeProperty->setEnabled( false ) ;
  623     m_ui->lineEditVolumeProperty->setEnabled( false ) ;
  624     m_ui->pushButtonPlainDmCryptOptions->setEnabled( false ) ;
  625     m_ui->cbVolumeType->setEnabled( false ) ;
  626     m_ui->labelVolumeType->setEnabled( false ) ;
  627     m_ui->cbShareMountPoint->setEnabled( false ) ;
  628     m_ui->checkBoxReadOnly->setEnabled( false ) ;
  629     m_ui->labelMoutPointPath->setEnabled( false ) ;
  630     m_ui->labelPassphrase->setEnabled( false ) ;
  631     m_ui->labelVolumePath->setEnabled( false ) ;
  632     m_ui->MountPointPath->setEnabled( false ) ;
  633     m_ui->OpenVolumePath->setEnabled( false ) ;
  634     m_ui->PassPhraseField->setEnabled( false ) ;
  635     m_ui->PushButtonCancel->setEnabled( false ) ;
  636     m_ui->PushButtonMountPointPath->setEnabled( false ) ;
  637     m_ui->PushButtonOpen->setEnabled( false ) ;
  638     m_ui->pushButtonPassPhraseFromFile->setEnabled( false ) ;
  639     m_ui->PushButtonVolumePath->setEnabled( false ) ;
  640     m_ui->pbKeyOption->setEnabled( false ) ;
  641     m_ui->cbKeyType->setEnabled( false ) ;
  642     m_ui->checkBoxVisibleKey->setEnabled( false ) ;
  643     m_ui->lineEditVolumeProperty->setEnabled( false ) ;
  644     m_ui->labelVolumeProperty->setEnabled( false ) ;
  645     m_ui->pushButtonLuksExternalHeaderPath->setEnabled( false ) ;
  646 }
  647 
  648 void passwordDialog::enableAll()
  649 {
  650     auto index = m_ui->cbVolumeType->currentIndex() ;
  651 
  652     if( index == 0 ){
  653 
  654         m_ui->pushButtonLuksExternalHeaderPath->setEnabled( true ) ;
  655 
  656     }
  657 
  658     m_ui->lineEditVolumeProperty->setEnabled( true ) ;
  659     m_ui->labelVolumeProperty->setEnabled( true ) ;
  660     m_ui->pushButtonPlainDmCryptOptions->setEnabled( index == 3 ) ;
  661     m_ui->cbVolumeType->setEnabled( true ) ;
  662     m_ui->labelVolumeType->setEnabled( true ) ;
  663     m_ui->cbShareMountPoint->setEnabled( true ) ;
  664     m_ui->checkBoxReadOnly->setEnabled( true ) ;
  665     m_ui->labelMoutPointPath->setEnabled( true ) ;
  666     m_ui->labelPassphrase->setEnabled( true ) ;
  667     m_ui->labelVolumePath->setEnabled( true ) ;
  668     m_ui->MountPointPath->setEnabled( true ) ;
  669     m_ui->OpenVolumePath->setEnabled( true ) ;
  670     m_ui->PassPhraseField->setEnabled( true ) ;
  671     m_ui->PushButtonCancel->setEnabled( true ) ;
  672     m_ui->PushButtonMountPointPath->setEnabled( true ) ;
  673     m_ui->PushButtonOpen->setEnabled( true ) ;
  674     m_ui->pushButtonPassPhraseFromFile->setEnabled( true ) ;
  675     m_ui->PushButtonVolumePath->setEnabled( true ) ;
  676     m_ui->cbKeyType->setEnabled( true ) ;
  677 
  678     auto m = m_ui->cbKeyType->currentIndex() ;
  679 
  680     if( m_open_with_path ){
  681 
  682         m_ui->OpenVolumePath->setEnabled( false ) ;
  683         m_ui->PushButtonVolumePath->setEnabled( false ) ;
  684     }
  685 
  686     if( m == passwordDialog::key || m == passwordDialog::yubikey ){
  687 
  688         m_ui->checkBoxVisibleKey->setEnabled( true ) ;
  689         m_ui->pushButtonPassPhraseFromFile->setEnabled( false ) ;
  690         m_ui->PassPhraseField->setEnabled( true ) ;
  691     }else{
  692         m_ui->checkBoxVisibleKey->setEnabled( false ) ;
  693         m_ui->pbKeyOption->setEnabled( true ) ;
  694         m_ui->PassPhraseField->setEnabled( false ) ;
  695     }
  696 }
  697 
  698 void passwordDialog::openVolume()
  699 {
  700     m_device = utility::resolvePath( m_ui->OpenVolumePath->text() ) ;
  701 
  702     m_point = m_ui->MountPointPath->text() ;
  703 
  704     if( m_point.isEmpty() || m_device.isEmpty() ){
  705 
  706         m_label.show( tr( "Atleast one required field is empty" ) ) ;
  707 
  708         return this->enableAll() ;
  709     }
  710 
  711     if( m_point.contains( "/" ) ){
  712 
  713         m_label.show( tr( "\"/\" character is not allowed in mount name field" ) ) ;
  714 
  715         m_ui->OpenVolumePath->setFocus() ;
  716 
  717         return this->enableAll() ;
  718     }
  719 
  720     QString mode ;
  721 
  722     if( m_ui->checkBoxReadOnly->isChecked() ){
  723 
  724         mode =" ro" ;
  725     }else{
  726         mode = "rw" ;
  727     }
  728 
  729     QString passtype ;
  730 
  731     QString keyPath ;
  732 
  733     int keySource = m_ui->cbKeyType->currentIndex() ;
  734 
  735     if( keySource == passwordDialog::keyfile ){
  736 
  737         if( m_key.isEmpty() ){
  738 
  739             m_label.show( tr( "Atleast one required field is empty" ) ) ;
  740 
  741             return this->enableAll() ;
  742         }else{
  743             passtype = "-f" ;
  744             keyPath = utility::resolvePath( m_key ).replace( "\"","\"\"\"" ) ;
  745         }
  746     }else if( keySource == passwordDialog::key ||
  747           keySource == passwordDialog::keyKeyFile ||
  748           keySource == passwordDialog::yubikey ){
  749 
  750         passtype = "-f" ;
  751         keyPath = utility::keyPath() ;
  752 
  753         this->sendKey( keyPath ) ;
  754 
  755     }else if( keySource == passwordDialog::plugin ){
  756 
  757         if( m_key.isEmpty() ){
  758 
  759             m_label.show( tr( "Atleast one required field is empty" ) ) ;
  760 
  761             return this->enableAll() ;
  762         }else{
  763             auto r = m_ui->PassPhraseField->text() ;
  764 
  765             if( utility::equalsAtleastOne( r,tr( KWALLET ),tr( INTERNAL_WALLET ),tr( GNOME_WALLET ) ) ){
  766 
  767                 passtype = "-f" ;
  768                 keyPath = utility::keyPath() ;
  769 
  770                 this->sendKey( keyPath ) ;
  771 
  772             }else if( utility::equalsAtleastOne( r,"hmac","gpg","keykeyfile" ) ){
  773 
  774                 if( utility::pluginKey( m_secrets.parent(),&m_key,r ) ){
  775 
  776                     return this->enableAll() ;
  777                 }else{
  778                     passtype = "-f" ;
  779                     keyPath = utility::keyPath() ;
  780                     this->sendKey( keyPath ) ;
  781                 }
  782 
  783             }else if( r == "network" ){
  784 
  785                 auto e = utility::Task::makePath( m_device ) ;
  786 
  787                 auto z = QString( "%1 -i -d %2" ).arg( ZULUCRYPTzuluCrypt,e ) ;
  788 
  789                 auto& s = utility::Task::run( z ) ;
  790 
  791                 auto q = utility::split( s.await().stdOut() ) ;
  792 
  793                 if( q.size() < 2 ){
  794 
  795                     m_label.show( tr( "Volume is not a LUKS volume" ) ) ;
  796 
  797                     m_ui->OpenVolumePath->setFocus() ;
  798 
  799                     return this->enableAll() ;
  800                 }else{
  801                     this->disableAll() ;
  802 
  803                     auto s =  utility::getKeyFromNetwork( q.at( 1 ) ) ;
  804 
  805                     if( s.first ){
  806 
  807                         m_key = s.second ;
  808 
  809                         passtype = "-f" ;
  810                         keyPath = utility::keyPath() ;
  811 
  812                         this->sendKey( keyPath ) ;
  813                     }else{
  814                         m_label.show( tr( "Failed to get a key from the network" ) ) ;
  815 
  816                         m_ui->OpenVolumePath->setFocus() ;
  817                         return this->enableAll() ;
  818                     }
  819                 }
  820             }else{
  821                 auto env = QProcessEnvironment::systemEnvironment() ;
  822 
  823                 env.insert( "zuluCryptPrintToStdOut","true" ) ;
  824 
  825                 m_key = Task::process::run( ZULUCRYPTpluginPath + r,{},-1,"",env ).await().std_out() ;
  826 
  827                 if( m_key.isEmpty() ){
  828 
  829                     m_label.show( tr( "Failed to get a key from a plugin" ) ) ;
  830 
  831                     m_ui->OpenVolumePath->setFocus() ;
  832                     return this->enableAll() ;
  833                 }else{
  834                     passtype = "-f" ;
  835                     keyPath = utility::keyPath() ;
  836                     this->sendKey( keyPath ) ;
  837                 }
  838             }
  839         }
  840     }else if( keySource == passwordDialog::tcryptKeys ){
  841 
  842         passtype = "-f" ;
  843         keyPath = utility::keyPath() ;
  844 
  845         this->sendKey( keyPath ) ;
  846     }else{
  847         utility::debug() << "Error: uncaught condition" ;
  848     }
  849 
  850     QString a = ZULUCRYPTzuluCrypt ;
  851     QString b = m_device ;
  852     b.replace( "\"","\"\"\"" ) ;
  853     QString c = m_point ;
  854     c.replace( "\"","\"\"\"" ) ;
  855     const QString& d = mode ;
  856     const QString& e = passtype ;
  857     const QString& f = keyPath ;
  858 
  859     if( !b.startsWith( "/dev/" ) ){
  860 
  861         auto s = utility::loopDevicePath( b ) ;
  862 
  863         if( !s.isEmpty() ){
  864 
  865             b = s ;
  866         }
  867     }
  868 
  869     auto exe = QString( "%1 -o -d \"%2\" -m \"%3\" -e %4 %5 \"%6\"" ).arg( a,b,c,d,e,f ) ;
  870 
  871     if( m_ui->cbVolumeType->currentIndex() == 0 ){
  872 
  873         auto s = m_ui->lineEditVolumeProperty->text() ;
  874 
  875         if( !s.isEmpty() ){
  876 
  877             exe += " -z " + utility::Task::makePath( s ) ;
  878         }
  879     }
  880 
  881     if( !m_keyFiles.isEmpty() ){
  882 
  883         for( const auto& it : m_keyFiles ){
  884 
  885             QString e = it ;
  886             e.replace( "\"","\"\"\"" ) ;
  887 
  888             exe += " -F \"" + e + "\"" ;
  889         }
  890     }
  891 
  892     if( m_ui->cbVolumeType->currentIndex() == 1 ){
  893 
  894         auto e = m_ui->lineEditVolumeProperty->text() ;
  895 
  896         if( e.isEmpty() ){
  897 
  898             exe += " -t vcrypt" ;
  899         }else {
  900             exe += " -t vcrypt." + e ;
  901         }
  902 
  903     }else if( m_ui->cbVolumeType->currentIndex() == 2 ){
  904 
  905         auto e = m_ui->lineEditVolumeProperty->text() ;
  906 
  907         if( e.isEmpty() ){
  908 
  909             exe += " -t vcrypt-sys" ;
  910         }else {
  911             exe += " -t vcrypt-sys." + e ;
  912         }
  913 
  914     }else if( m_ui->cbVolumeType->currentIndex() == 3 ){
  915 
  916         auto e = m_ui->lineEditVolumeProperty->text() ;
  917 
  918         if( e.isEmpty() ){
  919 
  920             exe += " -t " + m_plainDmCryptProperty + ".0" ;
  921         }else {
  922             exe += " -t " + m_plainDmCryptProperty + "." + e ;
  923         }
  924     }
  925 
  926     if( m_ui->cbShareMountPoint->isChecked() ){
  927 
  928         exe += " -M" ;
  929     }
  930 
  931     this->disableAll() ;
  932 
  933     m_veraCryptWarning.show( m_veraCryptVolume ) ;
  934 
  935     m_working = true ;
  936 
  937     auto r = utility::Task::run( utility::appendUserUID( exe ) ).await() ;
  938 
  939     m_working = false ;
  940 
  941     m_veraCryptWarning.stopTimer() ;
  942 
  943     if( r.success() ){
  944 
  945         m_openFolder( utility::mountPath( m_point ) ) ;
  946 
  947         this->HideUI() ;
  948     }else{
  949         this->failed( r ) ;
  950 
  951         m_veraCryptWarning.hide() ;
  952     }
  953 }
  954 
  955 void passwordDialog::failed( const utility::Task& e )
  956 {
  957     int r = e.exitCode() ;
  958 
  959     if( r == 12 && m_ui->cbKeyType->currentIndex() == passwordDialog::plugin ){
  960         /*
  961          * A user cancelled the plugin
  962          */
  963         return this->enableAll() ;
  964     }
  965 
  966 
  967     switch ( r ){
  968         case 0 : return ;
  969         case 1 : m_label.show( tr( "Failed to mount ntfs/exfat file system using ntfs-3g,is ntfs-3g/exfat package installed?" ) ) ; break ;
  970         case 2 : m_label.show( tr( "There seem to be an open volume accociated with given address" ) ) ;                break ;
  971         case 3 : m_label.show( tr( "No file or device exist on given path" ) ) ;                        break ;
  972         case 4 : m_label.show( tr( "Volume could not be opened with the presented key" ) ) ;                    break ;
  973         case 5 : m_label.show( tr( "Insufficient privilege to mount the device with given options" ) ) ;                break ;
  974         case 6 : m_label.show( tr( "Insufficient privilege to open device in read write mode or device does not exist" ) ) ;    break ;
  975         case 7 : m_label.show( tr( "Only root user can perform this operation" ) ) ;                        break ;
  976         case 8 : m_label.show( tr( "-O and -m options can not be used together" ) ) ;                       break ;
  977         case 9 : m_label.show( tr( "Could not create mount point, invalid path or path already taken" ) ) ;         break ;
  978         case 10: m_label.show( tr( "Shared mount point path already taken" ) ) ;                            break ;
  979         case 11: m_label.show( tr( "There seem to be an opened mapper associated with the device" ) ) ;             break ;
  980         case 12: m_label.show( tr( "Could not get a passphrase from the module" ) ) ;                       break ;
  981         case 13: m_label.show( tr( "Could not get passphrase in silent mode" ) ) ;                      break ;
  982         case 14: m_label.show( tr( "Insufficient memory to hold passphrase" ) ) ;                           break ;
  983         case 15: m_label.show( tr( "One or more required argument(s) for this operation is missing" ) ) ;               break ;
  984         case 16: m_label.show( tr( "Invalid path to key file" ) ) ;                             break ;
  985         case 17: m_label.show( tr( "Could not get enought memory to hold the key file" ) ) ;                    break ;
  986         case 18: m_label.show( tr( "Insufficient privilege to open key file for reading" ) ) ;                  break ;
  987         case 19: m_label.show( tr( "Could not get a passphrase through a local socket" ) ) ;                    break ;
  988         case 20: m_label.show( tr( "Failed to mount a filesystem:invalid/unsupported mount option or unsupported file system encountered" ) ) ; break ;
  989         case 21: m_label.show( tr( "Could not create a lock on /etc/mtab" ) ) ;                         break ;
  990         case 22: m_label.show( tr( "Insufficient privilege to open a system volume.\n\nConsult menu->help->permission for more informaion\n" ) ) ;                  break ;
  991         case 113:m_label.show( tr( "A non supported device encountered,device is missing or permission denied\n\
  992 Possible reasons for getting the error are:\n1.Device path is invalid.\n2.The device has LVM or MDRAID signature" ) ) ;                 break ;
  993         default: m_label.show( tr( "Error Code: %1\n--\nStdOut: %2\n--\nStdError: %3").arg( QString::number( e.exitCode() ),QString( e.stdError() ),QString( e.stdOut() ) ) ) ;
  994     }
  995 
  996     utility::debug() << e.stdOut() << "--" << e.stdError() ;
  997 
  998     this->enableAll() ;
  999 
 1000     auto index = m_ui->cbKeyType->currentIndex() ;
 1001 
 1002     if( utility:: clearPassword() && ( index == passwordDialog::key || index == passwordDialog::yubikey ) ){
 1003 
 1004         m_ui->PassPhraseField->clear() ;
 1005         m_ui->PassPhraseField->setFocus() ;
 1006     }
 1007 
 1008     if( r == 4 ){
 1009 
 1010         if( index == passwordDialog::key || index == passwordDialog::yubikey ){
 1011 
 1012             m_ui->PassPhraseField->setFocus() ;
 1013 
 1014         }else if( index == passwordDialog::keyKeyFile ){
 1015 
 1016             m_ui->cbKeyType->setCurrentIndex( 0 ) ;
 1017             this->passphraseOption() ;
 1018         }
 1019     }
 1020 }
 1021 
 1022 passwordDialog::~passwordDialog()
 1023 {
 1024     m_pluginMenu->deleteLater() ;
 1025     delete m_ui ;
 1026 }