diff --git a/LicenseManager/LicenseManager.cc b/LicenseManager/LicenseManager.cc index cf1c7eaaf87c082bfcadc1e0a341406f2cda1edc..447de8ac2ccc4adebcaa52d43ce49db6ffd77391 100644 --- a/LicenseManager/LicenseManager.cc +++ b/LicenseManager/LicenseManager.cc @@ -257,8 +257,51 @@ bool LicenseManager::authenticate() { QString keyHash = QCryptographicHash::hash ( keyClear.toAscii() , QCryptographicHash::Sha1 ).toHex(); std::cerr << "key is: " << keyHash.toStdString() << std::endl; + + QString licenseFileName = OpenFlipper::Options::licenseDirStr() + QDir::separator() + pluginFileName() + ".lic"; + QFile file( licenseFileName ); + + if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { + std::cerr << "Unable to find license File " << licenseFileName.toStdString() << std::endl; + } else { + QString licenseContents = file.readAll(); + QStringList elements = licenseContents.split(' '); + for ( int i = 0 ; i < elements.size(); ++i ) + elements[i] = elements[i].simplified(); + + + if ( elements.size() != 3 ) { + std::cerr << "Invalid License File! " << std::endl; + } else { + QString license = saltPre + elements[0] + " " + elements[1] + saltPost; + QString licenseHash = QCryptographicHash::hash ( license.toAscii() , QCryptographicHash::Sha1 ).toHex(); + + if ( licenseHash == elements[2] ) { + std::cerr << "License Hash is correct" << std::endl; + + if ( keyHash == elements[0] ) { + std::cerr << "Key verified" << std::endl; + QDate currentDate = QDate::currentDate(); + QDate expiryDate = QDate::fromString(elements[1],Qt::ISODate); + + if ( currentDate < expiryDate ) { + std::cerr << "License is valid" << std::endl; + authenticated_ = true; + } else { + std::cerr << "License expired on " << elements[1].toStdString() << std::endl; + } + } + } else { + std::cerr << "License Hash is invalid!! " << std::endl; + + } + + } + + } + if ( authenticated_ ) - std::cerr << "Authentication succcessfull" << std::endl; + std::cerr << "Authentication succcessfull for Plugin " << name().toStdString() << std::endl; else { QString text = "License check for plugin has failed.\n"; text += "Please get a valid License!\n"; diff --git a/LicenseManager/keyGen/keygen.cc b/LicenseManager/keyGen/keygen.cc index 45c239178f3e8ac3234338a0e9e0e7d342c4f1ea..2c0573e80e082c0cc065c985d0e944efdc6084d0 100644 --- a/LicenseManager/keyGen/keygen.cc +++ b/LicenseManager/keyGen/keygen.cc @@ -9,38 +9,71 @@ int main(int argc, char **argv) QApplication a( argc, argv ); if (argc == 2) { - std::cerr << " Call ./keygen " << std::endl; + std::cerr << " Call ./keygen " << std::endl; + std::cerr << "Date is of the form: YYYY-MM-DD" << std::endl; exit(1); } QFile file(argv[1]); - if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) + if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { std::cerr << "Unable to open file " << std::endl; + return 1; + } + // Get license information QString name = file.readLine().simplified(); QString coreHash = file.readLine().simplified(); QString pluginHash = file.readLine().simplified(); QString macHash = file.readLine().simplified(); + file.close(); + 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; + + // Get the salts QString saltPre; ADD_SALT_PRE(saltPre); - QString saltPost; ADD_SALT_POST(saltPost); - std::cerr << "Core Hash : " << coreHash.toStdString() << std::endl; - std::cerr << "Plugin Hash : " << pluginHash.toStdString() << std::endl; - - std::cerr << "macHash is: " << macHash.toStdString() << std::endl; - + // Generate basic key QString keyClear = coreHash + saltPre + pluginHash + saltPost + macHash; std::cerr << "keyClear is: " << keyClear.toStdString() << std::endl; QString keyHash = QCryptographicHash::hash ( keyClear.toAscii() , QCryptographicHash::Sha1 ).toHex(); std::cerr << "key is: " << keyHash.toStdString() << std::endl; + // generate license + QDate date = QDate::fromString(argv[2],Qt::ISODate); + QString license = keyHash + " " + date.toString(Qt::ISODate); + + 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); + + output << license << " "; + + std::cerr << "License : " << license.toStdString() << std::endl; + + license = saltPre + license + saltPost; + QString licenseHash = QCryptographicHash::hash ( license.toAscii() , QCryptographicHash::Sha1 ).toHex(); + + output << licenseHash; + + outFile.close(); + + + return 0; }