Commit 4da3a8ca authored by Jan Möbius's avatar Jan Möbius

Updated gui for License Manager



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6685 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3a01234c
......@@ -262,7 +262,6 @@ bool LicenseManager::authenticate() {
// Check signature of license file
QString license = saltPre + elements[0] + elements[1] + elements[2] + elements[3] + elements[4] + saltPost;
license = saltPre + license + saltPost;
QString licenseHash = QCryptographicHash::hash ( license.toAscii() , QCryptographicHash::Sha1 ).toHex();
QDate currentDate = QDate::currentDate();
......
......@@ -4,126 +4,18 @@
#include <QMessageBox>
#include <iostream>
#include <OpenFlipper/LicenseManager/keyGen/keygenWidget.hh>
#include "salt.hh"
int main(int argc, char **argv)
{
QApplication a( argc, argv );
// Get license information
QString name;
QString coreHash;
QString pluginHash;
QString macHash;
QString requestSig;
QString expiryDate;
KeyGenWidget* keyGenWidget = new KeyGenWidget(0);
if (argc == 3) {
QFile file(argv[1]);
// Show the widget
keyGenWidget->show();
a.exec();
if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
std::cerr << "Unable to open file " << std::endl;
std::cerr << " Call ./keygen <InfoFile> <Expiry date>" << std::endl;
std::cerr << "Date is of the form: YYYY-MM-DD" << std::endl;
return 1;
}
// Get license information
name = file.readLine().simplified();
coreHash = file.readLine().simplified();
pluginHash = file.readLine().simplified();
macHash = file.readLine().simplified();
requestSig = file.readLine().simplified();
expiryDate = argv[2];
file.close();
} else {
KeyGenWidget* keyGenWidget = new KeyGenWidget(0);
// Automatically set expire date to current date + 1 Year
QDate today = QDate::currentDate();
keyGenWidget->expires->setDate(today.addYears(1));
// Show the widget
keyGenWidget->show();
a.exec();
QString inputData = keyGenWidget->requestData->toPlainText();
QStringList data = inputData.split('\n',QString::SkipEmptyParts);
if ( data.size() != 5 ) {
std::cerr << "Request data has to containe 5 lines!" << std::endl;
exit(1);
}
// Clean strings
name = data[0].simplified();
coreHash = data[1].simplified();
pluginHash = data[2].simplified();
macHash = data[3].simplified();
requestSig = data[4].simplified();
expiryDate = keyGenWidget->expires->date().toString(Qt::ISODate);
}
std::cerr << "Generating key for Plugin : " << name.toStdString() << std::endl;
std::cerr << "Core Hash : " << coreHash.toStdString() << std::endl;
std::cerr << "Plugin Hash : " << pluginHash.toStdString() << std::endl;
std::cerr << "macHash is : " << macHash.toStdString() << std::endl;
std::cerr << "requestSignature is : " << requestSig.toStdString() << std::endl;
std::cerr << "expiryDate is : " << expiryDate.toStdString() << std::endl;
// Get the salts
QString saltPre;
ADD_SALT_PRE(saltPre);
QString saltPost;
ADD_SALT_POST(saltPost);
QString keyRequest = saltPre + name + coreHash + pluginHash + macHash + saltPost;
QString requestSigCheck = QCryptographicHash::hash ( keyRequest.toAscii() , QCryptographicHash::Sha1 ).toHex();
if ( requestSig != requestSigCheck ) {
QMessageBox::critical(0,"Signature of request invalid","The signature of the request is not valid");
return 1;
}
std::cerr << "Writing License file to output : " << name.toStdString() << std::endl;
QFile outFile(name + ".lic");
if (!outFile.open(QIODevice::WriteOnly|QIODevice::Text)) {
std::cerr << "Unable to open file " << std::endl;
return 1;
}
QTextStream output(&outFile);
// Add basic hashes
output << name << "\n";
output << coreHash << "\n";
output << pluginHash << "\n";
output << macHash << "\n";
// Add expiryDate
QDate date = QDate::fromString(expiryDate,Qt::ISODate);
output << date.toString(Qt::ISODate) << "\n";
// Sign the license file
QString license = saltPre + name + coreHash + pluginHash + macHash + date.toString(Qt::ISODate) + saltPost;
license = saltPre + license + saltPost;
QString licenseHash = QCryptographicHash::hash ( license.toAscii() , QCryptographicHash::Sha1 ).toHex();
output << licenseHash;
outFile.close();
return 0;
......
......@@ -10,6 +10,11 @@ KeyGenWidget::KeyGenWidget(QMainWindow *parent)
{
setupUi(this);
connect(generateButton,SIGNAL(clicked()),this,SLOT(slotGenerateButton()));
// Automatically set expire date to current date + 1 Year
QDate today = QDate::currentDate();
expires->setDate(today.addYears(1));
}
KeyGenWidget::~KeyGenWidget() {
......@@ -18,15 +23,71 @@ KeyGenWidget::~KeyGenWidget() {
void KeyGenWidget::slotGenerateButton() {
QString inputData = requestData->toPlainText();
QStringList data = inputData.split('\n',QString::SkipEmptyParts);
QString inputData = requestData->toPlainText();
QStringList data = inputData.split('\n',QString::SkipEmptyParts);
if ( data.size() != 5) {
QMessageBox::critical(this,"Wrong request data","The request has to contain 5 lines of data");
} else {
// Clean strings
QString name = data[0].simplified();
QString coreHash = data[1].simplified();
QString pluginHash = data[2].simplified();
QString macHash = data[3].simplified();
QString requestSig = data[4].simplified();
QString expiryDate = expires->date().toString(Qt::ISODate);
std::cerr << "Generating key for Plugin : " << name.toStdString() << std::endl;
std::cerr << "Core Hash : " << coreHash.toStdString() << std::endl;
std::cerr << "Plugin Hash : " << pluginHash.toStdString() << std::endl;
std::cerr << "macHash is : " << macHash.toStdString() << std::endl;
std::cerr << "requestSignature is : " << requestSig.toStdString() << std::endl;
std::cerr << "expiryDate is : " << expiryDate.toStdString() << std::endl;
// Get the salts
QString saltPre;
ADD_SALT_PRE(saltPre);
QString saltPost;
ADD_SALT_POST(saltPost);
if ( data.size() != 5) {
QMessageBox::critical(this,"Wrong request data","The request has to contain 5 lines of data");
} else {
close();
QString keyRequest = saltPre + name + coreHash + pluginHash + macHash + saltPost;
QString requestSigCheck = QCryptographicHash::hash ( keyRequest.toAscii() , QCryptographicHash::Sha1 ).toHex();
if ( requestSig != requestSigCheck ) {
QMessageBox::critical(this,"Signature of request invalid","The signature of the request is not valid");
return;
}
std::cerr << "Writing License file to output : " << name.toStdString() << std::endl;
QFile outFile(name + ".lic");
if (!outFile.open(QIODevice::WriteOnly|QIODevice::Text)) {
QMessageBox::critical(this,"Unable to open file","Unable to Open output File");
return;
}
QTextStream output(&outFile);
// Add basic hashes
output << name << "\n";
output << coreHash << "\n";
output << pluginHash << "\n";
output << macHash << "\n";
output << expiryDate << "\n";
// Sign the license file
QString license = saltPre + name + coreHash + pluginHash + macHash + expiryDate + saltPost;
QString licenseHash = QCryptographicHash::hash ( license.toAscii() , QCryptographicHash::Sha1 ).toHex();
output << licenseHash;
outFile.close();
}
close();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment