Commit 1cfeb1b8 authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'LicenseManager' into 'master'

License manager

Licensemanager checking systemtime

See merge request !29
parents 7a1fcb6e 06021ed4
......@@ -84,6 +84,8 @@ License File format:
#include <QCryptographicHash>
#include <QNetworkInterface>
#include <limits>
/** \brief decode string
*
......@@ -128,6 +130,83 @@ void LicenseManager::blockSignals( bool _state) {
}
bool LicenseManager::timestampOk() {
bool notExpired = false;
bool gotTimestampEntry = false;
quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
quint64 lastTimestamp = timestamp;
quint64 timestampEntry = 0;
quint64 lastTimestampEntryNum = 0;
// ===============================================================================================
// Read last Timestemp
// ===============================================================================================
const QString title = "Timestamp/"+pluginFileName();
QString lastTimestampEntry = OpenFlipperSettings().value(title,"empty").toString();
if( lastTimestampEntry==QString("empty") ){
notExpired = true;
} else {
lastTimestampEntryNum = lastTimestampEntry.toULongLong(&gotTimestampEntry,16);
}
// ===============================================================================================
// Decrypt last Timestamp
// ===============================================================================================
const unsigned int factor = 30000;
const std::string name = pluginFileName().toStdString();
const unsigned int moduloFactor = 72; //<100
const int nameSize = pluginFileName().size();
const int nameEncr = ( name[0] ) + ( name[nameSize-1] ) + (name[(nameSize-1) / 2] );
bool moduloOK = (lastTimestampEntryNum -( 100 * (lastTimestampEntryNum / 100) ) == (lastTimestampEntryNum/100) % moduloFactor );
lastTimestampEntryNum = lastTimestampEntryNum / 100;
lastTimestampEntryNum = lastTimestampEntryNum - nameEncr;
lastTimestampEntryNum = lastTimestampEntryNum * factor;
lastTimestamp = lastTimestampEntryNum;
// ===============================================================================================
// Check last Timestemp
// ===============================================================================================
if (notExpired||(timestamp>(lastTimestamp-360000) && moduloOK)) {
notExpired = true;
} else {
timestamp = std::numeric_limits<quint64>::max();
}
// ===============================================================================================
// Encrypt new Timestamp
// ===============================================================================================
timestampEntry = timestamp;
timestampEntry = timestampEntry / factor;
timestampEntry = timestampEntry + nameEncr;
timestampEntry = (timestampEntry * 100) + (timestampEntry % moduloFactor);
// ===============================================================================================
// Write new Timestemp
// ===============================================================================================
OpenFlipperSettings().setValue ( title, QString::number(timestampEntry,16) );
return notExpired;
}
// Plugin authentication function.
bool LicenseManager::authenticate() {
......@@ -422,7 +501,9 @@ bool LicenseManager::authenticate() {
// ===============================================================================================
// Check License or generate request
// ===============================================================================================
// ===============================================================================================
bool alreadyExpired = true;
if (!elements.empty()) //valid file was found
{
// Check expiry date
......@@ -441,10 +522,17 @@ bool LicenseManager::authenticate() {
macFound = true;
}
if (timestampOk()) {
alreadyExpired = false;
}
if ( !signatureOk ) {
authstring_ += tr("License Error: The license file signature for Plugin \"") + name() + tr("\" is invalid!\n\n");
} else if ( expired ) {
authstring_ += tr("License Error: The license for plugin \"") + name() + tr("\" has expired on ") + elements[1] + "!\n\n";
} else if ( alreadyExpired ) {
authstring_ += tr("License Error: System time has been reset. The license for plugin \"") + name() + tr("\" has been expired!\n\n");
} else if ( elements[2] != pluginFileName() ) {
authstring_ += tr("License Error: The license file contains plugin name\"") + elements[2] + tr("\" but this is plugin \"") + name() + "\"!\n\n";
} else if ( elements[3] != coreHash ) {
......
......@@ -107,6 +107,10 @@ Q_INTERFACES(SecurityInterface)
QString licenseError();
private:
bool timestampOk();
/** This is used to get the plugins Name from derived classes
The plugin name is the usual name of the plugin
*/
......
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