Skip to content

Commit

Permalink
add ability to store keyfile path in a wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogomchungu committed Jul 19, 2024
1 parent 73bb27f commit f6cdfe8
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 34 deletions.
27 changes: 27 additions & 0 deletions src/favorites2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@

const QString COMMENT = "-SiriKali_Comment_ID" ;

QString favorites2::encodeKeyKeyFile( const QString& key,const QString& keyFile )
{
if( keyFile.isEmpty() ){

return key ;
}else{
return key + "-SiriKali_KeyFile-" + keyFile ;
}
}

QStringList favorites2::decodeKeyKeyFile( const QString& e )
{
return utility::split( e,"-SiriKali_KeyFile-" ) ;
}

Task::future< void >& favorites2::deleteKey( secrets::wallet& wallet,const QString& id )
{
return Task::run( [ &wallet,id ](){
Expand Down Expand Up @@ -162,6 +177,16 @@ favorites2::favorites2( QWidget * parent,
connect( m_ui->cbShowMountDialogWhenAutoMounting,&QCheckBox::toggled,[ this ]( bool e ){

m_settings.showMountDialogWhenAutoMounting( e ) ;
} ) ;

connect( m_ui->pbKeyFileVolumePathFromFavorites,&QPushButton::clicked,[ this ](){

auto e = this->getExistingFile( tr( "Path To KeyFile" ) ) ;

if( !e.isEmpty() ){

m_ui->lineEditVolumeKeyFilePath->setText( e ) ;
}
} ) ;

connect( m_ui->pbConfigFilePath,&QPushButton::clicked,[ this ](){
Expand Down Expand Up @@ -705,6 +730,8 @@ void favorites2::addkeyToWallet()
m_ui->tableWidgetWallet->setEnabled( false ) ;
m_ui->pbAddKeyToWallet->setEnabled( false ) ;

b = favorites2::encodeKeyKeyFile( b,m_ui->lineEditVolumeKeyFilePath->text() ) ;

favorites2::addKey( m_wallet.get(),a,b ).then( [ this,a ]( bool s ){

m_ui->tableWidgetWallet->setEnabled( true ) ;
Expand Down
4 changes: 4 additions & 0 deletions src/favorites2.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class favorites2 : public QDialog
{
Q_OBJECT
public:
static QString encodeKeyKeyFile( const QString&,const QString& ) ;
static QStringList decodeKeyKeyFile( const QString& ) ;

static Task::future< void >& deleteKey( secrets::wallet&,const QString& id ) ;

static Task::future< bool >& addKey( secrets::wallet&,
Expand Down Expand Up @@ -114,6 +117,7 @@ private :
std::function< void() > m_function ;
const engines::engine& m_engine ;
QString m_cipherPath ;
QString m_keyFilePath ;

class wallet{

Expand Down
92 changes: 64 additions & 28 deletions src/favorites2.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</rect>
</property>
<property name="currentIndex">
<number>3</number>
<number>2</number>
</property>
<widget class="QWidget" name="FavoritesList">
<attribute name="title">
Expand All @@ -48,9 +48,6 @@
<property name="text">
<string>Volume ID</string>
</property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
</widget>
<widget class="QFrame" name="frame">
Expand Down Expand Up @@ -1201,7 +1198,7 @@
<x>220</x>
<y>10</y>
<width>511</width>
<height>301</height>
<height>231</height>
</rect>
</property>
<property name="editTriggers">
Expand All @@ -1214,17 +1211,56 @@
<property name="text">
<string>Volume Path</string>
</property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
</widget>
<widget class="QLabel" name="label_29">
<property name="geometry">
<rect>
<x>260</x>
<y>360</y>
<width>401</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Enter KeyFile Path Below(Optional)</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLineEdit" name="lineEditVolumeKeyFilePath">
<property name="geometry">
<rect>
<x>260</x>
<y>390</y>
<width>401</width>
<height>31</height>
</rect>
</property>
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
</widget>
<widget class="QPushButton" name="pbKeyFileVolumePathFromFavorites">
<property name="geometry">
<rect>
<x>670</x>
<y>390</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="label_21">
<property name="geometry">
<rect>
<x>260</x>
<y>310</y>
<width>421</width>
<y>240</y>
<width>401</width>
<height>31</height>
</rect>
</property>
Expand All @@ -1239,7 +1275,7 @@
<property name="geometry">
<rect>
<x>260</x>
<y>340</y>
<y>270</y>
<width>401</width>
<height>31</height>
</rect>
Expand All @@ -1252,8 +1288,8 @@
<property name="geometry">
<rect>
<x>260</x>
<y>370</y>
<width>421</width>
<y>300</y>
<width>401</width>
<height>31</height>
</rect>
</property>
Expand All @@ -1268,7 +1304,7 @@
<property name="geometry">
<rect>
<x>260</x>
<y>400</y>
<y>330</y>
<width>401</width>
<height>31</height>
</rect>
Expand All @@ -1294,7 +1330,7 @@
<property name="geometry">
<rect>
<x>670</x>
<y>340</y>
<y>270</y>
<width>31</width>
<height>31</height>
</rect>
Expand All @@ -1307,7 +1343,7 @@
<property name="geometry">
<rect>
<x>700</x>
<y>340</y>
<y>270</y>
<width>31</width>
<height>31</height>
</rect>
Expand Down Expand Up @@ -1352,7 +1388,7 @@
<property name="geometry">
<rect>
<x>670</x>
<y>400</y>
<y>330</y>
<width>31</width>
<height>31</height>
</rect>
Expand All @@ -1367,7 +1403,7 @@
<x>-10</x>
<y>0</y>
<width>761</width>
<height>481</height>
<height>471</height>
</rect>
</property>
<property name="autoFillBackground">
Expand Down Expand Up @@ -1405,12 +1441,12 @@
<attribute name="title">
<string>Settings</string>
</attribute>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget4">
<property name="geometry">
<rect>
<x>191</x>
<y>130</y>
<width>383</width>
<width>399</width>
<height>26</height>
</rect>
</property>
Expand All @@ -1434,12 +1470,12 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget3">
<property name="geometry">
<rect>
<x>191</x>
<y>170</y>
<width>297</width>
<width>311</width>
<height>26</height>
</rect>
</property>
Expand All @@ -1463,12 +1499,12 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>191</x>
<y>210</y>
<width>331</width>
<width>344</width>
<height>26</height>
</rect>
</property>
Expand Down Expand Up @@ -1498,12 +1534,12 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget1">
<property name="geometry">
<rect>
<x>191</x>
<y>250</y>
<width>297</width>
<width>307</width>
<height>26</height>
</rect>
</property>
Expand All @@ -1527,12 +1563,12 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget2">
<property name="geometry">
<rect>
<x>191</x>
<y>290</y>
<width>366</width>
<width>378</width>
<height>26</height>
</rect>
</property>
Expand Down
28 changes: 22 additions & 6 deletions src/keydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ void keyDialog::unlockVolume()
* Called when creating volumes
*
*/
keyDialog::keyDialog( QWidget * parent,secrets& s,
keyDialog::keyDialog( QWidget * parent,
secrets& s,
std::function< void() > p,
std::function< void() > l,
bool o,
Expand Down Expand Up @@ -473,7 +474,22 @@ void keyDialog::setUpVolumeProperties( const keyDialog::entry& ee )
}
}

m_ui->lineEditKey->setText( ee.volEntry.password() ) ;
auto mm = favorites2::decodeKeyKeyFile( ee.volEntry.password() ) ;

if( mm.size() == 1 ){

m_ui->lineEditKey->setText( mm.at( 0 ) ) ;

}else if( mm.size() > 1 ){

m_ui->lineEditKey->setText( Task::await( [ & ](){

const auto& key = mm.at( 0 ) ;
const auto& keyFile = mm.at( 1 ) ;

return crypto::hmac_key( keyFile,key ) ;
} ) ) ;
}

this->setUIVisible( true ) ;

Expand Down Expand Up @@ -1536,10 +1552,10 @@ void keyDialog::keyTypeChanged()
auto _showVisibleKeyOption = [ this ]( bool e ){

bool s = m_settings.enableRevealingPasswords() ;
m_ui->tbVisibleKey->setEnabled( e && s ) ;
m_ui->tbVisibleKey->setIcon(QIcon(":/icons/password_show.png")) ;
m_ui->lineEditKey->setEchoMode( QLineEdit::Password );
m_ui->tbVisibleKey->setVisible( e ) ;
m_ui->tbVisibleKey->setEnabled( e && s ) ;
m_ui->tbVisibleKey->setIcon(QIcon(":/icons/password_show.png")) ;
m_ui->lineEditKey->setEchoMode( QLineEdit::Password );
m_ui->tbVisibleKey->setVisible( e ) ;
m_ui->pbkeyOption->setVisible( !e ) ;
} ;

Expand Down

0 comments on commit f6cdfe8

Please sign in to comment.