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

License Manager

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6667 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c6e55ef6
......@@ -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";
......
......@@ -9,38 +9,71 @@ int main(int argc, char **argv)
QApplication a( argc, argv );
if (argc == 2) {
std::cerr << " Call ./keygen <InfoFile> <Output Key File>" << std::endl;
std::cerr << " Call ./keygen <InfoFile> <Expiry date>" << 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;
}
......
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