From: Konrad Rosenbaum Date: Sun, 19 Jan 2014 18:44:03 +0000 (+0100) Subject: fix host key generator: save key and transmit proper hash X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=ff92336c6ef5d6f071075aaddca3d9228437bb2b;p=konrad%2Fsmoke.git fix host key generator: save key and transmit proper hash --- diff --git a/src/mwin/acltabs.cpp b/src/mwin/acltabs.cpp index 6b46f8b..3eb45a2 100644 --- a/src/mwin/acltabs.cpp +++ b/src/mwin/acltabs.cpp @@ -402,8 +402,10 @@ void MHostTab::newHost() return; key=mkg.getKey(); } + //save it + exportKey(hname,key); //set it - MTSetHost sh=MTSetHost::query(hname,key); + MTSetHost sh=MTSetHost::query(hname,key2hash(key)); if(sh.hasError()){ QMessageBox::warning(this,tr("Warning"),tr("Error while creating new host: %1").arg(sh.errorString())); return; @@ -450,25 +452,7 @@ void MHostTab::changeHostKey() key=mkg.getKey(); } //save as mshk file - QStringList fn; - QFileDialog fdlg(this,tr("Export Key to File"),QString(),"Magic Smoke Host Key (*.mshk)"); - fdlg.setDefaultSuffix("mshk"); - fdlg.setAcceptMode(QFileDialog::AcceptSave); - fdlg.setFileMode(QFileDialog::AnyFile); - fdlg.setDirectory(currentDir()); - if(!fdlg.exec())return; - fn=fdlg.selectedFiles(); - if(fn.size()!=1)return; - setCurrentDir(fn[0]); - QFile fd(fn[0]); - if(!fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for writing: %2").arg(fn[0]).arg(fd.errorString())); - return; - } - QString chk=QCryptographicHash::hash(key.toLatin1(),QCryptographicHash::Md5).toHex(); - QString out="MagicSmokeHostKey\n"+name+"\n"+key+"\n"+chk; - fd.write(out.toLatin1()); - fd.close(); + exportKey(name,key); //convert key to hash key=key2hash(key); //set it @@ -481,6 +465,30 @@ void MHostTab::changeHostKey() updateHosts(); } +void MHostTab::exportKey(QString name, QString key) +{ + QStringList fn; + QFileDialog fdlg(this,tr("Export Key to File"),QString(),"Magic Smoke Host Key (*.mshk)"); + fdlg.setDefaultSuffix("mshk"); + fdlg.setAcceptMode(QFileDialog::AcceptSave); + fdlg.setFileMode(QFileDialog::AnyFile); + fdlg.setDirectory(currentDir()); + fdlg.selectFile(name+".mshk"); + if(!fdlg.exec())return; + fn=fdlg.selectedFiles(); + if(fn.size()!=1)return; + setCurrentDir(fn[0]); + QFile fd(fn[0]); + if(!fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for writing: %2").arg(fn[0]).arg(fd.errorString())); + return; + } + const QString chk=QCryptographicHash::hash(key.toLatin1(),QCryptographicHash::Md5).toHex(); + const QString out="MagicSmokeHostKey\n"+name+"\n"+key+"\n"+chk; + fd.write(out.toLatin1()); + fd.close(); +} + void MHostTab::importHost() { QStringList fn; @@ -565,13 +573,13 @@ void MHostTab::exportHost() //get hname QString name=hostmodel->data(hostmodel->index(sel.row(),0)).toString(); QString key=hostmodel->data(hostmodel->index(sel.row(),1)).toString(); - if(name[0]=='_' || key==""){ + if(name.isEmpty() || name[0]=='_' || key==""){ QMessageBox::warning(this,tr("Warning"),tr("This host cannot be exported.")); return; } //save QStringList fn; - QFileDialog fdlg(this,tr("Export Key to File"),QString(),"Magic Smoke Host Hash (*.mshh)"); + QFileDialog fdlg(this,tr("Export Hash to File"),QString(),"Magic Smoke Host Hash (*.mshh)"); fdlg.setDefaultSuffix("mshh"); fdlg.setAcceptMode(QFileDialog::AcceptSave); fdlg.setFileMode(QFileDialog::AnyFile); diff --git a/src/mwin/acltabs.h b/src/mwin/acltabs.h index 5af0657..ce91ec1 100644 --- a/src/mwin/acltabs.h +++ b/src/mwin/acltabs.h @@ -83,8 +83,10 @@ class MHostTab:public QWidget void changeHostKey(); /**import host from file*/ void importHost(); - /**export host to file*/ + /**export host to hash file*/ void exportHost(); + /**export fresh host as key file*/ + void exportKey(QString name,QString key); private: //the profile associated with this session