#include "acltabs.h"
#include <QBoxLayout>
+#include <QCryptographicHash>
+#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QInputDialog>
return;
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);
+ if(!fdlg.exec())return;
+ fn=fdlg.selectedFiles();
+ if(fn.size()!=1)return;
+ 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.toAscii(),QCryptographicHash::Md5).toHex();
+ QString out="MagicSmokeHostKey\n"+name+"\n"+key+"\n"+chk;
+ fd.write(out.toAscii());
+ fd.close();
+ //convert key to hash
+ key=key2hash(key);
//set it
MTSetHost sh=MTSetHost::query(name,key);
if(sh.hasError()){
void MHostTab::importHost()
{
QStringList fn;
- QFileDialog fdlg(this,tr("Import Key from File"),QString(),"Magic Smoke Host Key (*.mshk)");
+ QFileDialog fdlg(this,tr("Import Key from File"),QString(),"Magic Smoke Host Key (*.mshk);;Magic Smoke Host Hash (*.mshh);;All Files (*)");
fdlg.setDefaultSuffix("mshk");
fdlg.setAcceptMode(QFileDialog::AcceptOpen);
fdlg.setFileMode(QFileDialog::ExistingFile);
QMessageBox::warning(this,tr("Warning"),tr("This is not a host key file."));
return;
}
- if(fc[0].trimmed()!="MagicSmokeHostKey"){
- QMessageBox::warning(this,tr("Warning"),tr("This is not a host key file."));
+ bool ishash = fc[0].trimmed()=="MagicSmokeHostHash";
+ if(!ishash && fc[0].trimmed()!="MagicSmokeHostKey"){
+ QMessageBox::warning(this,tr("Warning"),tr("This is not a host key/hash file."));
return;
}
QString hname=fc[1].trimmed();
return;
}
QString key=fc[2].trimmed();
- if(!QRegExp("[0-9a-fA-F]+").exactMatch(key) || key.size()<40){
- QMessageBox::warning(this,tr("Warning"),tr("This host key file does not contain a valid key."));
- return;
- }
QString chk=QCryptographicHash::hash(key.toAscii(),QCryptographicHash::Md5).toHex();
if(chk!=fc[3].trimmed()){
QMessageBox::warning(this,tr("Warning"),tr("The key check sum did not match. Please get a clean copy of the host key file."));
return;
}
+ //convert to hash
+ if(ishash){
+ if(!QRegExp("[0-9a-fA-F]+ [0-9a-fA-F]{32,40}").exactMatch(key)){
+ QMessageBox::warning(this,tr("Warning"),tr("This host hash file does not contain a valid key hash."));
+ return;
+ }
+ }else{
+ if(!QRegExp("[0-9a-fA-F]+").exactMatch(key) || key.size()<40){
+ QMessageBox::warning(this,tr("Warning"),tr("This host key file does not contain a valid key."));
+ return;
+ }
+ key=key2hash(key);
+ }
//save
MTSetHost sh=MTSetHost::query(hname,key);
if(sh.hasError()){
updateHosts();
}
+QString MHostTab::key2hash(QString key)
+{
+ QString salt;
+ MKeyGen mkg;
+ salt=mkg.getKey(8);
+ if(salt=="")
+ if(mkg.exec()!=QDialog::Accepted)
+ return key;
+ salt=mkg.getKey(8);
+ return salt+" "+ QCryptographicHash::hash((salt+key).toAscii(),QCryptographicHash::Sha1).toHex();
+}
+
+
void MHostTab::exportHost()
{
//get selection
}
//save
QStringList fn;
- QFileDialog fdlg(this,tr("Export Key to File"),QString(),"Magic Smoke Host Key (*.mshk)");
- fdlg.setDefaultSuffix("mshk");
+ QFileDialog fdlg(this,tr("Export Key to File"),QString(),"Magic Smoke Host Hash (*.mshh)");
+ fdlg.setDefaultSuffix("mshh");
fdlg.setAcceptMode(QFileDialog::AcceptSave);
fdlg.setFileMode(QFileDialog::AnyFile);
if(!fdlg.exec())return;
return;
}
QString chk=QCryptographicHash::hash(key.toAscii(),QCryptographicHash::Md5).toHex();
- QString out="MagicSmokeHostKey\n"+name+"\n"+key+"\n"+chk;
+ QString out="MagicSmokeHostHash\n"+name+"\n"+key+"\n"+chk;
fd.write(out.toAscii());
fd.close();
}