LicenseManagerActive.cc 22.1 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
49

Jan Möbius's avatar
Jan Möbius committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66


/*
License File format:

0:    Signature     over all other entries
1:    Expiry date
2:    Plugin filename
3:    coreHash
4:    pluginHash
5:    cpuHash
6:    windowsProductId (Windows only otherwise filled with "-" before hashing)
7..?: mac Address hashes

*/


Jan Möbius's avatar
Jan Möbius committed
67 68 69 70 71 72
// Windows required to get network address infos
#ifdef WIN32
  #include <winsock2.h>
  #include <iphlpapi.h>
  #pragma comment(lib, "IPHLPAPI.lib")
#endif
Jan Möbius's avatar
Jan Möbius committed
73

Jan Möbius's avatar
Jan Möbius committed
74 75 76 77
#ifdef ARCH_DARWIN
  #include <sys/types.h>
  #include <sys/sysctl.h>
#endif
Jan Möbius's avatar
Jan Möbius committed
78 79


80
#include <OpenFlipper/LicenseManager/LicenseManagerActive.hh>
81 82
#include <OpenFlipper/common/GlobalOptions.hh>
#include <QFile>
83
#include <QString>
84 85 86
#include <QCryptographicHash>
#include <QNetworkInterface>

87 88
#include <limits>

Jan Möbius's avatar
Jan Möbius committed
89

90 91 92 93 94 95 96 97 98
/** \brief decode string
 *
 *  Decodes a QString either via utf8 or latin1
 *
 * @param _string Input string
 * @param _utf8 true->toUtf8 or false ->toLatin1
 * @return Decoded String
 */
QByteArray decodeString(const QString& _string ,bool _utf8){
99

100 101 102 103 104 105
  if (_utf8)
    return _string.toUtf8();
  else
    return _string.toLatin1();

}
106

107
LicenseManager::~LicenseManager()
108 109 110 111 112 113
{ 
  exit(0); 
}

LicenseManager::LicenseManager()
{
Jan Möbius's avatar
Jan Möbius committed
114

115
  authenticated_ = false;
Jan Möbius's avatar
Jan Möbius committed
116 117
  
  // On startup, block all signals by default until the plugin is authenticated!
118 119 120
  QObject::blockSignals( true );
}

Jan Möbius's avatar
Jan Möbius committed
121 122
// Override default block signals. Transparent if authenticated, otherwise
// the function will always block the signals automatically
123
void LicenseManager::blockSignals( bool _state) {
Jan Möbius's avatar
Jan Möbius committed
124

125 126 127 128 129 130 131 132
  if ( !authenticated() ) {
    QObject::blockSignals( true );
  } else {
    QObject::blockSignals(_state);
  }

}

133 134 135 136

bool LicenseManager::timestampOk() {

    bool notExpired = false;
137
    bool gotTimestampEntry = false;
138 139 140 141 142

    quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
    quint64 lastTimestamp = timestamp;
    quint64 timestampEntry = 0;
    quint64 lastTimestampEntryNum = 0;
143

144 145 146 147 148

    // ===============================================================================================
    // Read last Timestemp
    // ===============================================================================================

Jan Möbius's avatar
Jan Möbius committed
149
    const QString title = "Timestamp/"+pluginFileName();
150 151 152

    QString lastTimestampEntry = OpenFlipperSettings().value(title,"empty").toString();

Jan Möbius's avatar
Jan Möbius committed
153
    if( lastTimestampEntry==QString("empty") ){
154
        notExpired = true;
Jan Möbius's avatar
Jan Möbius committed
155
    } else {
156
        lastTimestampEntryNum = lastTimestampEntry.toULongLong(&gotTimestampEntry,16);
157 158 159 160 161 162
    }

    // ===============================================================================================
    // Decrypt last Timestamp
    // ===============================================================================================

Jan Möbius's avatar
Jan Möbius committed
163 164 165 166 167
    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] );
168

Jan Möbius's avatar
Jan Möbius committed
169
    bool moduloOK = (lastTimestampEntryNum -( 100 * (lastTimestampEntryNum / 100) ) == (lastTimestampEntryNum/100) % moduloFactor );
170 171 172 173 174 175 176 177 178 179 180

    lastTimestampEntryNum = lastTimestampEntryNum / 100;
    lastTimestampEntryNum = lastTimestampEntryNum - nameEncr;
    lastTimestampEntryNum = lastTimestampEntryNum * factor;

    lastTimestamp = lastTimestampEntryNum;

    // ===============================================================================================
    // Check last Timestemp
    // ===============================================================================================

Jan Möbius's avatar
Jan Möbius committed
181
    if (notExpired||(timestamp>(lastTimestamp-360000) && moduloOK)) {
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        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
    // ===============================================================================================

203
    OpenFlipperSettings().setValue ( title, QString::number(timestampEntry,16) );
204 205 206 207 208 209

    return notExpired;

}


Jan Möbius's avatar
Jan Möbius committed
210
// Plugin authentication function.
211
bool LicenseManager::authenticate() {
212

Jan Möbius's avatar
Jan Möbius committed
213
  // Construct license string (will be cleaned up if license valid)
214 215
  authstring_ = "==\n";
  authstring_ += "PluginName: " + pluginFileName() + "\n";
216
  
217 218 219 220 221 222 223 224 225 226 227 228 229
  // ===============================================================================================
  // Read License file, if exists
  // ===============================================================================================
  QString saltPre;
  ADD_SALT_PRE(saltPre);

  QString saltPost;
  ADD_SALT_POST(saltPost);

  QString licenseFileName = OpenFlipper::Options::licenseDirStr() + QDir::separator() + pluginFileName() + ".lic";
  QFile file( licenseFileName );
  QStringList elements; //has no elements, if file is invalid or was not found
  bool signatureOk = false;
230 231

  bool utf8Encoded = true;
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

  if (file.open(QIODevice::ReadOnly|QIODevice::Text))
  {
    QString licenseContents = file.readAll();
    elements = licenseContents.split('\n',QString::SkipEmptyParts);
    bool fileOk = !elements.empty() && elements[0] != "ERROR";

    if (fileOk)
    {
      // simplify license file entries
      for ( int i = 0 ; i < elements.size(); ++i )
        elements[i] = elements[i].simplified();

      // Check the signature of the file (excluding first element as this is the signature itself)
      QString license = saltPre;
      for ( int i = 1 ; i < elements.size(); ++i )
        license += elements[i];
      license += saltPost;
      QString licenseHash = QCryptographicHash::hash ( license.toUtf8()  , QCryptographicHash::Sha1 ).toHex();
      signatureOk = licenseHash == elements[0];

      if (signatureOk)
254
        utf8Encoded = true;
255 256 257 258 259
      else
      {
        licenseHash = QCryptographicHash::hash ( license.toLatin1()  , QCryptographicHash::Sha1 ).toHex();
        signatureOk = licenseHash == elements[0];
        if (signatureOk)
260
          utf8Encoded = false;
261 262 263 264 265 266 267
      }

    }
    else
      elements = QStringList();
  }

268
  // ===============================================================================================
Jan Möbius's avatar
Jan Möbius committed
269
  // Compute hash value of Core application binary
270 271 272
  // ===============================================================================================

  #ifdef WIN32
Jan Möbius's avatar
Jan Möbius committed
273
    QFile coreApp(OpenFlipper::Options::applicationDirStr() + QDir::separator() + "OpenFlipper.exe");
Jan Möbius's avatar
Jan Möbius committed
274 275 276 277 278
  #elif defined ARCH_DARWIN
    QFile coreApp(OpenFlipper::Options::applicationDirStr() + QDir::separator() + ".." + 
                                                              QDir::separator() + "MacOS"+
							      QDir::separator() + "OpenFlipper");
  #else 
279
    QFile coreApp(OpenFlipper::Options::applicationDirStr() + QDir::separator() + "bin" + QDir::separator() + TOSTRING(PRODUCT_STRING));
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
  #endif

  if ( ! coreApp.exists() ) {
    std::cerr << "Error finding core application for security check! : " << coreApp.fileName().toStdString() << std::endl;
    return false;
  }

  coreApp.open(QIODevice::ReadOnly);
  QCryptographicHash sha1sumCore( QCryptographicHash::Sha1 );
  sha1sumCore.addData(coreApp.readAll() );
  coreApp.close();

  QString coreHash = QString(sha1sumCore.result().toHex());
  

  // ===============================================================================================
Jan Möbius's avatar
Jan Möbius committed
296
  // Compute hash of Plugin binary
297 298 299 300
  // ===============================================================================================

  #ifdef WIN32
    QFile pluginFile(OpenFlipper::Options::pluginDirStr() + QDir::separator() + pluginFileName() + ".dll");
Jan Möbius's avatar
Jan Möbius committed
301 302
  #elif defined ARCH_DARWIN
    QFile pluginFile(OpenFlipper::Options::pluginDirStr() + QDir::separator() + "lib" + pluginFileName() + ".so");
303
  #else
Jan Möbius's avatar
Jan Möbius committed
304
    QFile pluginFile(OpenFlipper::Options::pluginDirStr() + QDir::separator() + "lib" + pluginFileName() + ".so");
305 306 307 308
  #endif

  if ( ! pluginFile.exists() ) {
    std::cerr << "Error finding plugin file for security check!" << std::endl;
Jan Möbius's avatar
Jan Möbius committed
309
    std::cerr << "Path: " << pluginFile.fileName().toStdString() << std::endl;
310 311 312 313 314 315 316 317 318 319
    return false;
  }

  pluginFile.open(QIODevice::ReadOnly);
  QCryptographicHash sha1sumPlugin( QCryptographicHash::Sha1 );
  sha1sumPlugin.addData(pluginFile.readAll());
  pluginFile.close();

  QString pluginHash = QString(sha1sumPlugin.result().toHex());

Jan Möbius's avatar
Jan Möbius committed
320 321 322
  // ===============================================================================================
  // Compute hash of network interfaces
  // ===============================================================================================  
323

Jan Möbius's avatar
Jan Möbius committed
324
  QStringList macHashes;
325

326 327
#ifdef WIN32

Jan Möbius's avatar
Jan Möbius committed
328 329
  #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
  #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
330 331

  // Pointer for iterating over adapters
Jan Möbius's avatar
Jan Möbius committed
332 333 334 335
  PIP_ADAPTER_ADDRESSES pAddresses = NULL;

  // Length of the buffer to get information
  ULONG outBufLen = 0;
336 337

  // Allocate enough for one info struct
Jan Möbius's avatar
Jan Möbius committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  outBufLen = sizeof (IP_ADAPTER_ADDRESSES);
  pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen);

  // default to unspecified address family ( get all interfaces .. 4 and 6)
  ULONG family = AF_UNSPEC;

  // Set the flags to pass to GetAdaptersAddresses
  ULONG flags = GAA_FLAG_INCLUDE_PREFIX;

  // Make an initial call to GetAdaptersAddresses to get the 
  // size needed into the outBufLen variable
  if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW) {
      FREE(pAddresses);
      pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen);
  }

  // If we allocated the required memory
  if (pAddresses != NULL) {
    
    // Get the required info
    DWORD dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);

    if (dwRetVal == NO_ERROR) {
        
      // pointer to iterate over all available structs .. initialize to first one
      PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses;

      while (pCurrAddresses) {

        // Check if this device contains a mac
        if (pCurrAddresses->PhysicalAddressLength != 0) {
          QString currentMac = "";
          
          for (uint i = 0; i < pCurrAddresses->PhysicalAddressLength; i++) {
            
            currentMac += QString("%1").arg( (int) pCurrAddresses->PhysicalAddress[i] , 2 ,16,QChar('0'));
            
            if (i != (pCurrAddresses->PhysicalAddressLength - 1))
              currentMac +=":";
          }

Jan Möbius's avatar
Jan Möbius committed
379 380 381 382
          // Ignore non ethernet macs with more than 5 blocks
          // Only check ethernet and wireless interfaces
          if ( (currentMac.count(":") == 5) && 
               ( pCurrAddresses->IfType == IF_TYPE_IEEE80211 || pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD )  ) {
Jan Möbius's avatar
Jan Möbius committed
383
                // Cleanup and remember mac adress
384 385

                currentMac = (decodeString(currentMac,utf8Encoded)).toUpper();
Jan Möbius's avatar
Jan Möbius committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
                currentMac = currentMac.remove(":");
                macHashes.push_back(currentMac);
          }

        }

        // Next interface
        pCurrAddresses = pCurrAddresses->Next;
      }
      
    }

  }

  FREE(pAddresses);
401 402 403

#else

404 405
  // Get all Network Interfaces
  QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
Jan Möbius's avatar
Jan Möbius committed
406
  foreach ( QNetworkInterface netInterface, interfaces ) {
Jan Möbius's avatar
Jan Möbius committed
407
    
Jan Möbius's avatar
Jan Möbius committed
408 409
    // Ignore loopback interfaces
    if ( ( netInterface.flags() & QNetworkInterface::IsLoopBack ) ) {
410
      continue;
Jan Möbius's avatar
Jan Möbius committed
411
    }
412
    
Jan Möbius's avatar
Jan Möbius committed
413 414 415 416 417 418
    // Ignore non ethernet macs
    if ( netInterface.hardwareAddress().count(":") != 5 ) {
      continue;
    }

    // Cleanup mac adress
419
    QString currentMac = (decodeString(netInterface.hardwareAddress(),utf8Encoded)).toUpper();
Jan Möbius's avatar
Jan Möbius committed
420
    currentMac = currentMac.remove(":");
Jan Möbius's avatar
Jan Möbius committed
421
    
Jan Möbius's avatar
Jan Möbius committed
422
    macHashes.push_back(currentMac);
423
  }
424

425
#endif
Jan Möbius's avatar
Jan Möbius committed
426 427


Jan Möbius's avatar
Jan Möbius committed
428
  // cleanup the list from duplicates (virtual interfaces on windows connected to an existing device ... )
Jan Möbius's avatar
Jan Möbius committed
429
  macHashes.removeDuplicates();
430

Jan Möbius's avatar
Jan Möbius committed
431 432
  // generate hashes
  for (int i = 0 ; i < macHashes.size(); ++i ) 
433 434
    // Cleanup mac adress
    macHashes[i] = QCryptographicHash::hash ( decodeString(macHashes[i],utf8Encoded) , QCryptographicHash::Sha1 ).toHex();
435

436 437 438 439
  // ===============================================================================================
  // Compute hash of processor information
  // ===============================================================================================  

Jan Möbius's avatar
Jan Möbius committed
440
  QString processor("Unknown");
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467

  #ifdef WIN32
    QSettings registryCPU("HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor", QSettings::NativeFormat);

    QStringList cpus = registryCPU.childGroups(); 
    if ( cpus.size() != 0 ) { 
      processor = registryCPU.value( cpus[0]+"/ProcessorNameString", "Unknown" ).toString();
    } 

  #elif defined ARCH_DARWIN 

    size_t lenCPU;
    char *pCPU;
    
    // First call to get required size
    sysctlbyname("machdep.cpu.brand_string", NULL, &lenCPU, NULL, 0);
    
    // allocate
    pCPU = (char * )malloc(lenCPU);
    
    // Second call to get data
    sysctlbyname("machdep.cpu.brand_string", pCPU, &lenCPU, NULL, 0);
    
    // Output
    processor = QString(pCPU);
    
    // free memory
Jan Möbius's avatar
Jan Möbius committed
468
    free(pCPU);
469 470 471 472 473 474 475 476

  #else
    QFile cpuinfo("/proc/cpuinfo");
    if ( cpuinfo.exists() ) {   
      cpuinfo.open(QFile::ReadOnly);
      QTextStream stream(&cpuinfo);
      QStringList splitted = stream.readAll().split("\n",QString::SkipEmptyParts);
      
Jan Möbius's avatar
Jan Möbius committed
477
      int position = splitted.indexOf ( QRegExp("^model name.*") );
478 479
      if ( position != -1 ){
        QString cpuModel = splitted[position].section(':', -1).simplified();
Jan Möbius's avatar
Jan Möbius committed
480
        processor = cpuModel;
481 482 483 484
      } 
    }
  #endif

485
  QString cpuHash = QCryptographicHash::hash ( decodeString(processor,utf8Encoded)  , QCryptographicHash::Sha1 ).toHex();
486

Jan Möbius's avatar
Jan Möbius committed
487 488 489 490 491
  // ===============================================================================================
  // Get windows product id
  // =============================================================================================== 
  
  
Jan Möbius's avatar
Jan Möbius committed
492

Jan Möbius's avatar
Jan Möbius committed
493
  #ifdef WIN32
494
    QSettings registryProduct("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", QSettings::NativeFormat);
Jan Möbius's avatar
Jan Möbius committed
495 496 497
    QString productId = registryProduct.value( "ProductId", "Unknown" ).toString();
  #else
    QString productId = "-";
Jan Möbius's avatar
Jan Möbius committed
498 499
  #endif
  
500
  QString productHash = QCryptographicHash::hash ( decodeString(productId,utf8Encoded)  , QCryptographicHash::Sha1 ).toHex();
501 502 503

  // ===============================================================================================
  // Check License or generate request
504 505
  // ===============================================================================================

506 507
  if (!elements.empty()) //valid file was found
  {
Jan Möbius's avatar
Jan Möbius committed
508

Jan Möbius's avatar
Jan Möbius committed
509 510 511 512 513 514 515 516 517
    // Check expiry date
    QDate currentDate = QDate::currentDate();
    QDate expiryDate  = QDate::fromString(elements[1],Qt::ISODate);
    bool expired = (currentDate > expiryDate);
    // Get number of available mac adresses
    QStringList licensedMacs;
    for ( int i = 7 ; i < elements.size(); ++i ) {
      licensedMacs.push_back(elements[i]);
    }
518

Jan Möbius's avatar
Jan Möbius committed
519 520
    bool macFound = false;
    for ( int i = 0; i < macHashes.size(); ++i ) {
521
      if ( licensedMacs.contains(macHashes[i]) )
Jan Möbius's avatar
Jan Möbius committed
522
        macFound = true;
Jan Möbius's avatar
Jan Möbius committed
523
    }
524

Jan Möbius's avatar
Jan Möbius committed
525 526 527 528
    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";       
Jan Möbius's avatar
Jan Möbius committed
529
    } else if ( !timestampOk() ) {
530
      authstring_ += tr("License Error: System time has been reset. The license for plugin \"") + name() + tr("\" has been expired!\n\n");
Jan Möbius's avatar
Jan Möbius committed
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
    } 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 ) {
      authstring_ += tr("License Error: The license file for plugin \"") + name() + tr("\" is invalid for the currently running OpenFlipper Core!\n\n");
    } else if ( elements[4] != pluginHash ) {
      authstring_ += tr("License Error: The plugin \"") + name() + tr("\" is a different version than specified in license file!\n\n");
    } else if ( elements[5] != cpuHash ) {
      authstring_ += "License Error: The plugin \"" + name() + "\" is not allowed to run on the current system (Changed CPU?)!\n\n";       
    } else if ( elements[6] != productHash ) {
      authstring_ += "License Error: The plugin \"" + name() + "\" is not allowed to run on the current system (Changed OS?)!\n\n";       
    } else if ( !macFound ) {
      authstring_ += "License Error: The plugin \"" + name() + "\" is not allowed to run on the current system (Changed Network?)!\n\n";
    } else {
      authenticated_ = true;
    }
    
    // Clean it on success
    if (  authenticated_ ) 
      authstring_ = "";
550

Jan Möbius's avatar
Jan Möbius committed
551 552
  }

Jan Möbius's avatar
Jan Möbius committed
553 554 555
  if ( authenticated_ ) {
    blockSignals(false);
  } else {
556 557 558 559 560 561 562
    authstring_ += tr("Message: License check for plugin failed.\n");
    authstring_ += tr("Message: Please get a valid License!\n");
    authstring_ += tr("Message: Send the following Information to \n");
    authstring_ += tr("Contact mail: ") + CONTACTMAIL + "\n\n";
    authstring_ += pluginFileName() +"\n";
    authstring_ += coreHash +"\n";
    authstring_ += pluginHash +"\n";
563
    authstring_ += cpuHash +"\n";
Jan Möbius's avatar
Jan Möbius committed
564 565 566 567
    authstring_ += productHash +"\n";
    
    for ( int i = 0 ; i < macHashes.size(); ++i )  
      authstring_ += macHashes[i] +"\n";
Jan Möbius's avatar
Jan Möbius committed
568

Jan Möbius's avatar
Jan Möbius committed
569
    QString keyRequest = saltPre + pluginFileName() + coreHash + pluginHash + cpuHash + productHash + macHashes.join("") +  saltPost;
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
570
    QString requestSig = QCryptographicHash::hash ( keyRequest.toUtf8()  , QCryptographicHash::Sha1 ).toHex();
571
    authstring_ += requestSig + "\n";
Jan Möbius's avatar
Jan Möbius committed
572

Jan Möbius's avatar
Jan Möbius committed
573
    authenticated_ = false;
574 575 576 577 578
  }

  return authenticated_;
}

579 580 581 582
QString LicenseManager::licenseError() {
  return authstring_;
}

583
bool LicenseManager::authenticated() {
Jan Möbius's avatar
Jan Möbius committed
584
  // Function to check if the plugin is authenticated
585 586 587 588
  return authenticated_;
}

void LicenseManager::connectNotify ( const char * /*signal*/ ) {
Jan Möbius's avatar
Jan Möbius committed
589 590 591

  // if the plugin is not authenticated and something wants to connect, we block all signals and force a direct disconnect
  // here, rendering all signal/slot connections useless.
592 593
  if ( !authenticated() ) {
    blockSignals(true);
Jan Möbius's avatar
Jan Möbius committed
594
    disconnect();
595
  }
Jan Möbius's avatar
Jan Möbius committed
596
  
597 598 599
}

QString LicenseManager::pluginFileName() {
Jan Möbius's avatar
Jan Möbius committed
600 601 602 603
  // FileName of the plugin. has to be set via the salt file
  QString pluginFileName;
  ADD_PLUGIN_FILENAME(pluginFileName);
  return pluginFileName;
604 605
}