keygenWidget.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <QtGui>
00045 #include "keygenWidget.hh"
00046 #include <iostream>
00047
00048 #include "salt.hh"
00049
00050 KeyGenWidget::KeyGenWidget(QMainWindow *parent)
00051 : QMainWindow(parent)
00052 {
00053 setupUi(this);
00054 connect(generateButton,SIGNAL(clicked()),this,SLOT(slotGenerateButton()));
00055
00056
00057 QDate today = QDate::currentDate();
00058 expires->setDate(today.addYears(1));
00059
00060 }
00061
00062 KeyGenWidget::~KeyGenWidget() {
00063
00064 }
00065
00066 void KeyGenWidget::slotGenerateButton() {
00067
00068 QString inputData = requestData->toPlainText();
00069 QStringList data = inputData.split('\n',QString::SkipEmptyParts);
00070
00071 if ( data.size() != 5) {
00072 QMessageBox::critical(this,tr("Wrong request data"),tr("The request has to contain 5 lines of data"));
00073 } else {
00074
00075
00076 QString name = data[0].simplified();
00077 QString coreHash = data[1].simplified();
00078 QString pluginHash = data[2].simplified();
00079 QString macHash = data[3].simplified();
00080 QString requestSig = data[4].simplified();
00081
00082 QString expiryDate = expires->date().toString(Qt::ISODate);
00083
00084 std::cerr << "Generating key for Plugin : " << name.toStdString() << std::endl;
00085 std::cerr << "Core Hash : " << coreHash.toStdString() << std::endl;
00086 std::cerr << "Plugin Hash : " << pluginHash.toStdString() << std::endl;
00087 std::cerr << "macHash is : " << macHash.toStdString() << std::endl;
00088 std::cerr << "requestSignature is : " << requestSig.toStdString() << std::endl;
00089 std::cerr << "expiryDate is : " << expiryDate.toStdString() << std::endl;
00090
00091
00092 QString saltPre;
00093 ADD_SALT_PRE(saltPre);
00094 QString saltPost;
00095 ADD_SALT_POST(saltPost);
00096
00097 QString keyRequest = saltPre + name + coreHash + pluginHash + macHash + saltPost;
00098 QString requestSigCheck = QCryptographicHash::hash ( keyRequest.toAscii() , QCryptographicHash::Sha1 ).toHex();
00099
00100 if ( requestSig != requestSigCheck ) {
00101 QMessageBox::critical(this,tr("Signature of request invalid"),tr("The signature of the request is not valid"));
00102 return;
00103 }
00104
00105 std::cerr << "Writing License file to output : " << name.toStdString() << std::endl;
00106 QFile outFile(name + ".lic");
00107
00108 if (!outFile.open(QIODevice::WriteOnly|QIODevice::Text)) {
00109 QMessageBox::critical(this,tr("Unable to open file"),tr("Unable to Open output File"));
00110 return;
00111 }
00112
00113 QTextStream output(&outFile);
00114
00115
00116 output << name << "\n";
00117 output << coreHash << "\n";
00118 output << pluginHash << "\n";
00119 output << macHash << "\n";
00120 output << expiryDate << "\n";
00121
00122
00123 QString license = saltPre + name + coreHash + pluginHash + macHash + expiryDate + saltPost;
00124 QString licenseHash = QCryptographicHash::hash ( license.toAscii() , QCryptographicHash::Sha1 ).toHex();
00125
00126 output << licenseHash;
00127
00128 outFile.close();
00129 }
00130
00131 close();
00132
00133
00134
00135 }