keygen.cc 2.05 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 38 39
  std::cerr << "Core Hash   : " << coreHash.toStdString() << std::endl;
  std::cerr << "Plugin Hash : " << pluginHash.toStdString() << std::endl;
  std::cerr << "macHash is  : " << macHash.toStdString()  << std::endl;


  std::cerr << "Writing License file to output : " << name.toStdString() << std::endl;
  QFile outFile(name + ".lic");
Jan Möbius's avatar
Jan Möbius committed
40

Jan Möbius's avatar
Jan Möbius committed
41 42 43 44 45 46
  if (!outFile.open(QIODevice::WriteOnly|QIODevice::Text)) {
    std::cerr << "Unable to open file " << std::endl;
    return 1;
  }

  QTextStream output(&outFile);
Jan Möbius's avatar
Jan Möbius committed
47 48 49 50 51 52 53 54 55 56 57

  // Add basic hashes
  output << name         << "\n";
  output << coreHash     << "\n";
  output << pluginHash   << "\n";
  output << macHash      << "\n";

  // Add expiryDate
  QDate date = QDate::fromString(argv[2],Qt::ISODate);

  output << date.toString(Qt::ISODate) << "\n";
Jan Möbius's avatar
Jan Möbius committed
58
  
Jan Möbius's avatar
Jan Möbius committed
59 60 61 62 63
  // Get the salts
  QString saltPre;
  ADD_SALT_PRE(saltPre);
  QString saltPost;
  ADD_SALT_POST(saltPost);
Jan Möbius's avatar
Jan Möbius committed
64

Jan Möbius's avatar
Jan Möbius committed
65 66
  // Sign the license file
  QString license = saltPre + name + coreHash + pluginHash + macHash + date.toString(Qt::ISODate) + saltPost;
Jan Möbius's avatar
Jan Möbius committed
67 68 69

  license = saltPre + license + saltPost;
  QString licenseHash = QCryptographicHash::hash ( license.toAscii()  , QCryptographicHash::Sha1 ).toHex();
Jan Möbius's avatar
Jan Möbius committed
70
  
Jan Möbius's avatar
Jan Möbius committed
71 72 73 74
  output << licenseHash;

  outFile.close();

Jan Möbius's avatar
Jan Möbius committed
75
  return 0;
Jan Möbius's avatar
Jan Möbius committed
76 77 78

}