keygen.cc 2.21 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
#include <qapplication.h>
#include <QtGui>
#include <QFile>
Jan Möbius's avatar
Jan Möbius committed
4 5
#include <iostream>
#include "salt.hh"
Jan Möbius's avatar
Jan Möbius committed
6 7 8

int main(int argc, char **argv)
{	
Jan Möbius's avatar
Jan Möbius committed
9 10 11
  QApplication a( argc, argv );

  if (argc == 2) {
Jan Möbius's avatar
Jan Möbius committed
12 13
    std::cerr  << " Call ./keygen <InfoFile> <Expiry date>" << std::endl;
    std::cerr << "Date is of the form: YYYY-MM-DD" << std::endl;
Jan Möbius's avatar
Jan Möbius committed
14 15 16 17 18
    exit(1);
  }

  QFile file(argv[1]);

Jan Möbius's avatar
Jan Möbius committed
19
  if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
Jan Möbius's avatar
Jan Möbius committed
20
    std::cerr << "Unable to open file " << std::endl;
Jan Möbius's avatar
Jan Möbius committed
21 22
    return 1;
  }
Jan Möbius's avatar
Jan Möbius committed
23

Jan Möbius's avatar
Jan Möbius committed
24
  // Get license information
Jan Möbius's avatar
Jan Möbius committed
25 26 27 28
  QString name       = file.readLine().simplified();
  QString coreHash   = file.readLine().simplified();
  QString pluginHash = file.readLine().simplified();
  QString macHash    = file.readLine().simplified();
Jan Möbius's avatar
Jan Möbius committed
29

Jan Möbius's avatar
Jan Möbius committed
30 31
  file.close();

Jan Möbius's avatar
Jan Möbius committed
32
  std::cerr << "Generating key for Plugin : " << name.toStdString() << std::endl;
Jan Möbius's avatar
Jan Möbius committed
33 34 35 36 37
  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
Jan Möbius's avatar
Jan Möbius committed
38 39 40 41 42
  QString saltPre;
  ADD_SALT_PRE(saltPre);
  QString saltPost;
  ADD_SALT_POST(saltPost);

Jan Möbius's avatar
Jan Möbius committed
43
  // Generate basic key
Jan Möbius's avatar
Jan Möbius committed
44
  QString keyClear = coreHash + saltPre + pluginHash + saltPost + macHash;
Jan Möbius's avatar
Jan Möbius committed
45
  std::cerr << "keyClear is: " << keyClear.toStdString() << std::endl;
Jan Möbius's avatar
Jan Möbius committed
46 47 48 49

  QString keyHash = QCryptographicHash::hash ( keyClear.toAscii()  , QCryptographicHash::Sha1 ).toHex();
  std::cerr << "key is: " << keyHash.toStdString() << std::endl;

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 67 68 69 70 71 72 73 74 75 76
  // 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();

  

Jan Möbius's avatar
Jan Möbius committed
77
  return 0;
Jan Möbius's avatar
Jan Möbius committed
78 79 80

}