Commit 1426fe0c authored by Jan Möbius's avatar Jan Möbius
Browse files

Changed license manager (did not work on windows)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10523 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 10e6c7b9
...@@ -66,7 +66,11 @@ class SecurityInterface { ...@@ -66,7 +66,11 @@ class SecurityInterface {
SecurityInterface(){}; SecurityInterface(){};
public slots: public slots:
bool authenticate(); /// Function starting the authentication process
bool authenticate();
/// If authenticate returns fals, this string will containe the license info
QString licenseError();
private : private :
bool authenticated(); bool authenticated();
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $LastChangedBy$ * * $LastChangedBy$ *
* $Date$ * * $Date$ *
* * * *
\*===========================================================================*/ \*===========================================================================*/
...@@ -587,7 +587,11 @@ void Core::loadPlugin(QString filename, bool silent, QString& _licenseErrors, QO ...@@ -587,7 +587,11 @@ void Core::loadPlugin(QString filename, bool silent, QString& _licenseErrors, QO
emit log(LOGINFO,tr("Plugin uses security interface. Trying to authenticate against plugin ...")); emit log(LOGINFO,tr("Plugin uses security interface. Trying to authenticate against plugin ..."));
bool success = false; bool success = false;
QMetaObject::invokeMethod(plugin,"authenticate", Q_RETURN_ARG( bool , success ) , Q_ARG(QString&, _licenseErrors)) ; QMetaObject::invokeMethod(plugin,"authenticate", Q_RETURN_ARG( bool , success ) ) ;
QString message = "";
QMetaObject::invokeMethod(plugin,"licenseError", Q_RETURN_ARG( QString , message ) ) ;
_licenseErrors = message;
if ( success ) if ( success )
emit log(LOGINFO,tr("... ok. Loading plugin ")); emit log(LOGINFO,tr("... ok. Loading plugin "));
......
...@@ -182,11 +182,11 @@ void LicenseManager::blockSignals( bool _state) { ...@@ -182,11 +182,11 @@ void LicenseManager::blockSignals( bool _state) {
} }
// Plugin authentication function. // Plugin authentication function.
bool LicenseManager::authenticate(QString& _authstring) { bool LicenseManager::authenticate() {
// Construct license string (will be cleaned up if license valid) // Construct license string (will be cleaned up if license valid)
_authstring = "==\n"; authstring_ = "==\n";
_authstring += "PluginName: " + pluginFileName() + "\n"; authstring_ += "PluginName: " + pluginFileName() + "\n";
// =============================================================================================== // ===============================================================================================
// Compute hash value of Core application binary // Compute hash value of Core application binary
...@@ -282,24 +282,24 @@ bool LicenseManager::authenticate(QString& _authstring) { ...@@ -282,24 +282,24 @@ bool LicenseManager::authenticate(QString& _authstring) {
QDate expiryDate = QDate::fromString(elements[4],Qt::ISODate); QDate expiryDate = QDate::fromString(elements[4],Qt::ISODate);
if ( licenseHash != elements[5] ) { if ( licenseHash != elements[5] ) {
_authstring += tr("License Error: The license file signature for plugin \"") + name() + tr("\" is invalid!\n\n"); authstring_ += tr("License Error: The license file signature for plugin \"") + name() + tr("\" is invalid!\n\n");
} else if ( elements[0] != pluginFileName() ) { } else if ( elements[0] != pluginFileName() ) {
_authstring += tr("License Error: The license file contains plugin name\"") + elements[0] + tr("\" but this is plugin \"") + name() + "\"!\n\n"; authstring_ += tr("License Error: The license file contains plugin name\"") + elements[0] + tr("\" but this is plugin \"") + name() + "\"!\n\n";
} else if ( elements[1] != coreHash ) { } else if ( elements[1] != coreHash ) {
_authstring += tr("License Error: The license file for plugin \"") + name() + tr("\" is invalid for the currently running OpenFlipper Core!\n\n"); authstring_ += tr("License Error: The license file for plugin \"") + name() + tr("\" is invalid for the currently running OpenFlipper Core!\n\n");
} else if ( elements[2] != pluginHash ) { } else if ( elements[2] != pluginHash ) {
_authstring += tr("License Error: The plugin \"") + name() + tr("\" is a different version than specified in license file!\n\n"); authstring_ += tr("License Error: The plugin \"") + name() + tr("\" is a different version than specified in license file!\n\n");
} else if ( elements[3] != macHash ) { } else if ( elements[3] != macHash ) {
_authstring += "License Error: The plugin \"" + name() + "\" is not allowed to run on the current system (Changed Hardware?)!\n\n"; authstring_ += "License Error: The plugin \"" + name() + "\" is not allowed to run on the current system (Changed Hardware?)!\n\n";
} else if ( currentDate > expiryDate ) { } else if ( currentDate > expiryDate ) {
_authstring += tr("License Error: The license for plugin \"") + name() + tr("\" has expired on ") + elements[1] + "!\n\n"; authstring_ += tr("License Error: The license for plugin \"") + name() + tr("\" has expired on ") + elements[1] + "!\n\n";
} else { } else {
authenticated_ = true; authenticated_ = true;
} }
// Clean it on success // Clean it on success
if ( authenticated_ ) if ( authenticated_ )
_authstring = ""; authstring_ = "";
} }
} }
...@@ -307,18 +307,18 @@ bool LicenseManager::authenticate(QString& _authstring) { ...@@ -307,18 +307,18 @@ bool LicenseManager::authenticate(QString& _authstring) {
if ( authenticated_ ) { if ( authenticated_ ) {
blockSignals(false); blockSignals(false);
} else { } else {
_authstring += tr("Message: License check for plugin failed.\n"); authstring_ += tr("Message: License check for plugin failed.\n");
_authstring += tr("Message: Please get a valid License!\n"); authstring_ += tr("Message: Please get a valid License!\n");
_authstring += tr("Message: Send the following Information to \n"); authstring_ += tr("Message: Send the following Information to \n");
_authstring += tr("Contact mail: ") + CONTACTMAIL + "\n\n"; authstring_ += tr("Contact mail: ") + CONTACTMAIL + "\n\n";
_authstring += pluginFileName() +"\n"; authstring_ += pluginFileName() +"\n";
_authstring += coreHash +"\n"; authstring_ += coreHash +"\n";
_authstring += pluginHash +"\n"; authstring_ += pluginHash +"\n";
_authstring += macHash +"\n"; authstring_ += macHash +"\n";
QString keyRequest = saltPre + pluginFileName() + coreHash+pluginHash+macHash +saltPost; QString keyRequest = saltPre + pluginFileName() + coreHash+pluginHash+macHash +saltPost;
QString requestSig = QCryptographicHash::hash ( keyRequest.toAscii() , QCryptographicHash::Sha1 ).toHex(); QString requestSig = QCryptographicHash::hash ( keyRequest.toAscii() , QCryptographicHash::Sha1 ).toHex();
_authstring += requestSig + "\n"; authstring_ += requestSig + "\n";
authenticated_ = false; authenticated_ = false;
} }
...@@ -326,6 +326,10 @@ bool LicenseManager::authenticate(QString& _authstring) { ...@@ -326,6 +326,10 @@ bool LicenseManager::authenticate(QString& _authstring) {
return authenticated_; return authenticated_;
} }
QString LicenseManager::licenseError() {
return authstring_;
}
bool LicenseManager::authenticated() { bool LicenseManager::authenticated() {
// Function to check if the plugin is authenticated // Function to check if the plugin is authenticated
return authenticated_; return authenticated_;
......
...@@ -56,13 +56,14 @@ ...@@ -56,13 +56,14 @@
#define LICENSEMANAGER_HH #define LICENSEMANAGER_HH
#include <OpenFlipper/BasePlugin/SecurityInterface.hh> #include <OpenFlipper/BasePlugin/SecurityInterface.hh>
#include <OpenFlipper/common/GlobalDefines.hh>
/** The salt file has to be provided for each plugin. It can be the same /** The salt file has to be provided for each plugin. It can be the same
for all plugins. See example for details on how this file has to be setup for all plugins. See example for details on how this file has to be setup
*/ */
#include "salt.hh" #include "salt.hh"
class LicenseManager : public QObject, SecurityInterface { class DLLEXPORT LicenseManager : public QObject, SecurityInterface {
Q_OBJECT Q_OBJECT
Q_INTERFACES(SecurityInterface) Q_INTERFACES(SecurityInterface)
...@@ -91,7 +92,11 @@ Q_INTERFACES(SecurityInterface) ...@@ -91,7 +92,11 @@ Q_INTERFACES(SecurityInterface)
@param _authstring String returned, containing hashed license request, if something went wrong or no valid license available. @param _authstring String returned, containing hashed license request, if something went wrong or no valid license available.
*/ */
bool authenticate(QString& _authstring); bool authenticate();
/** if authenticate returns false, this string will containe the license information
*/
QString licenseError();
private: private:
/** This is used to get the plugins Name from derived classes /** This is used to get the plugins Name from derived classes
...@@ -106,6 +111,9 @@ Q_INTERFACES(SecurityInterface) ...@@ -106,6 +111,9 @@ Q_INTERFACES(SecurityInterface)
/// This flag is true if authentication was successfull /// This flag is true if authentication was successfull
bool authenticated_; bool authenticated_;
/// License information string
QString authstring_;
protected : protected :
......
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