Commit d466e45f authored by Jan Möbius's avatar Jan Möbius

Reworkedlicense system

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10805 383ad7c9-94d9-4d36-a494-682f7c89f535
parent be5b4b8f
This diff is collapsed.
......@@ -6,16 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>312</height>
<width>812</width>
<height>727</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
......@@ -33,42 +33,118 @@
</item>
</layout>
</item>
<item row="1" column="0" rowspan="2" colspan="2">
<widget class="QPushButton" name="splitButton">
<property name="text">
<string>Split</string>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QPushButton" name="splitButton">
<property name="text">
<string>Split</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="Line" name="line_2">
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QPushButton" name="validButton">
<property name="text">
<string>Valid</string>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
</widget>
<item row="0" column="1">
<widget class="QLineEdit" name="fileNameBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Core Hash</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="coreHashBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Plugin Hash</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="pluginHashBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Cpu Hash</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="cpuHashBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Filename</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="productIDBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>ProductID</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Signature</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="signatureBox"/>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Mac Hashes</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="macHashBox"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
......@@ -139,7 +215,7 @@
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_2">
......@@ -167,14 +243,14 @@
</item>
</layout>
</item>
<item row="5" column="0" colspan="2">
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item>
<widget class="QPushButton" name="generateButton">
<property name="text">
<string>Generate</string>
......
......@@ -48,14 +48,21 @@
#include "salt.hh"
KeyGenWidget::KeyGenWidget(QMainWindow *parent)
: QMainWindow(parent)
: QMainWindow(parent),
valid_(false)
{
setupUi(this);
connect(generateButton,SIGNAL(clicked()),this,SLOT(slotGenerateButton()));
connect(splitButton,SIGNAL(clicked()),this,SLOT(slotSplit()));
connect(validButton,SIGNAL(clicked()),this,SLOT(slotValid()));
connect(requestData,SIGNAL(textChanged()),this,SLOT(slotAnalyze()));
// connect spinboxes forexpiry date
connect(days ,SIGNAL(valueChanged(int)),this,SLOT(slotDate()));
connect(months,SIGNAL(valueChanged(int)),this,SLOT(slotDate()));
connect(years ,SIGNAL(valueChanged(int)),this,SLOT(slotDate()));
// Automatically set expire date to current date
// For security reasons no default span is set here!
......@@ -63,7 +70,7 @@ KeyGenWidget::KeyGenWidget(QMainWindow *parent)
}
void KeyGenWidget::slotValid() {
void KeyGenWidget::slotDate() {
QDate today = QDate::currentDate();
today = today.addDays(days->value());
today = today.addMonths(months->value());
......@@ -72,6 +79,107 @@ void KeyGenWidget::slotValid() {
expires->setDate(today);
}
void KeyGenWidget::slotAnalyze() {
// Convert to text and split to elements
QString inputData = requestData->toPlainText();
QStringList data = inputData.split('\n',QString::SkipEmptyParts);
// This is never avalid request!
if ( data.size() < 6 ) {
QPalette p = requestData->palette();
p.setColor( QPalette::Base, QColor(255,0,0) );
requestData->setPalette(p);
valid_ = false;
return;
} else {
QPalette p = requestData->palette();
p.setColor( QPalette::Base, QColor(255,255,255) );
requestData->setPalette(p);
}
// Get strings
QString name = data[0].simplified();
QString coreHash = data[1].simplified();
QString pluginHash = data[2].simplified();
QString cpuHash = data[3].simplified();
QString productHash = data[4].simplified();
QStringList macHashes;
for ( int i = 5 ; i < data.size() - 1; ++i)
macHashes.push_back(data[i].simplified());
QString requestSig = data[data.size() - 1].simplified();
fileNameBox->setText(name);
coreHashBox->setText(coreHash);
pluginHashBox->setText(pluginHash);
cpuHashBox->setText(cpuHash);
productIDBox->setText(productHash);
macHashBox->setText(macHashes.join("\n"));
signatureBox->setText(requestSig);
// Get the salts
QString saltPre;
ADD_SALT_PRE(saltPre);
QString saltPost;
ADD_SALT_POST(saltPost);
QString keyRequest = saltPre + name + coreHash + pluginHash + cpuHash + productHash + macHashes.join("") + saltPost;
QString requestSigCheck = QCryptographicHash::hash ( keyRequest.toAscii() , QCryptographicHash::Sha1 ).toHex();
if ( requestSig != requestSigCheck ) {
QPalette p = signatureBox->palette();
p.setColor( QPalette::Base, QColor(255,0,0) );
signatureBox->setPalette(p);
valid_ = false;
return;
} else {
QPalette p = signatureBox->palette();
p.setColor( QPalette::Base, QColor(0,255,0) );
signatureBox->setPalette(p);
}
QString expiryDate = expires->date().toString(Qt::ISODate);
license_ = "";
// Add basic hashes
license_ += expiryDate + "\n";
license_ += name + "\n";
license_ += coreHash + "\n";
license_ += pluginHash + "\n";
license_ += cpuHash + "\n";
license_ += productHash + "\n";
license_ += macHashes.join("\n") + "\n";
QString licenseTmp = saltPre + expiryDate + name + coreHash + pluginHash + cpuHash + productHash + macHashes.join("") + saltPost;
QString licenseHash = QCryptographicHash::hash ( licenseTmp.toAscii() , QCryptographicHash::Sha1 ).toHex();
std::cerr << "license : " << licenseTmp.toStdString() << std::endl;
std::cerr << "hash : " << licenseHash.toStdString() << std::endl;
// Prepend signature
license_ = licenseHash + "\n" + license_;
std::cerr << "Full license : " << license_.toStdString() << std::endl;
valid_ = true;
licenseFileName_ = name;
}
void KeyGenWidget::slotSplit() {
// Get request data
......@@ -86,81 +194,29 @@ void KeyGenWidget::slotSplit() {
}
KeyGenWidget::~KeyGenWidget() {
}
void KeyGenWidget::slotGenerateButton() {
QString inputData = requestData->toPlainText();
QStringList data = inputData.split('\n',QString::SkipEmptyParts);
if ( ! valid_ ) {
std::cerr << "Invalid! " << std::endl;
return;
}
std::cerr << "Writing License file to output : " << licenseFileName_.toStdString() << std::endl;
QFile outFile(licenseFileName_ + ".lic");
if ( data.size() != 6) {
QMessageBox::critical(this,tr("Wrong request data"),tr("The request has to contain 6 lines of data"));
if (!outFile.open(QIODevice::WriteOnly|QIODevice::Text)) {
QMessageBox::critical(this,tr("Unable to open file"),tr("Unable to Open output File"));
return;
} else {
}
// Clean strings
QString name = data[0].simplified();
QString coreHash = data[1].simplified();
QString pluginHash = data[2].simplified();
QString macHash = data[3].simplified();
QString cpuHash = data[4].simplified();
QString requestSig = data[5].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 << "cpuHash is : " << cpuHash.toStdString() << std::endl;
std::cerr << "expiryDate is : " << expiryDate.toStdString() << std::endl;
std::cerr << "requestSignature is : " << requestSig.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 + cpuHash + saltPost;
QString requestSigCheck = QCryptographicHash::hash ( keyRequest.toAscii() , QCryptographicHash::Sha1 ).toHex();
if ( requestSig != requestSigCheck ) {
QMessageBox::critical(this,tr("Signature of request invalid"),tr("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,tr("Unable to open file"),tr("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 << cpuHash << "\n";
output << expiryDate << "\n";
// Sign the license file
QString license = saltPre + name + coreHash + pluginHash + macHash + cpuHash + expiryDate + saltPost;
QString licenseHash = QCryptographicHash::hash ( license.toAscii() , QCryptographicHash::Sha1 ).toHex();
output << licenseHash;
QTextStream output(&outFile);
output << license_;
outFile.close();
}
outFile.close();
close();
}
......@@ -58,11 +58,21 @@ public:
public slots:
void slotGenerateButton();
// Button slot taking license duration and convert to expiration date
void slotValid();
// slot taking license duration and convert to expiration date
void slotDate();
// Analyzes the current request
void slotAnalyze();
// Split Code based on ;; for broken windows requests
void slotSplit();
private:
bool valid_;
QString license_;
QString licenseFileName_;
};
......
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