keygenWidget.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 83 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-02-27 17:31:45 +0100 (Fr, 27. Feb 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 #include <QtGui>
00045 #include "keygenWidget.hh"
00046 #include <iostream>
00047 
00048 #include "salt.hh"
00049 
00050 KeyGenWidget::KeyGenWidget(QMainWindow *parent)
00051     : QMainWindow(parent)
00052 {
00053   setupUi(this);
00054   connect(generateButton,SIGNAL(clicked()),this,SLOT(slotGenerateButton()));
00055   
00056   // Automatically set expire date to current date + 1 Year
00057   QDate today = QDate::currentDate();
00058   expires->setDate(today.addYears(1));
00059   
00060 }
00061 
00062 KeyGenWidget::~KeyGenWidget() {
00063 
00064 }
00065 
00066 void KeyGenWidget::slotGenerateButton() {
00067 
00068   QString inputData = requestData->toPlainText();
00069   QStringList data = inputData.split('\n',QString::SkipEmptyParts);
00070 
00071   if ( data.size() != 5) {
00072     QMessageBox::critical(this,tr("Wrong request data"),tr("The request has to contain 5 lines of data"));
00073   } else {
00074 
00075     // Clean strings
00076     QString name       = data[0].simplified();
00077     QString coreHash   = data[1].simplified();
00078     QString pluginHash = data[2].simplified();
00079     QString macHash    = data[3].simplified();
00080     QString requestSig = data[4].simplified();
00081 
00082     QString expiryDate = expires->date().toString(Qt::ISODate);
00083 
00084     std::cerr << "Generating key for Plugin : " << name.toStdString()       << std::endl;
00085     std::cerr << "Core Hash                 : " << coreHash.toStdString()   << std::endl;
00086     std::cerr << "Plugin Hash               : " << pluginHash.toStdString() << std::endl;
00087     std::cerr << "macHash is                : " << macHash.toStdString()    << std::endl;
00088     std::cerr << "requestSignature is       : " << requestSig.toStdString() << std::endl;
00089     std::cerr << "expiryDate is             : " << expiryDate.toStdString() << std::endl;
00090 
00091     // Get the salts
00092     QString saltPre;
00093     ADD_SALT_PRE(saltPre);
00094     QString saltPost;
00095     ADD_SALT_POST(saltPost);
00096 
00097     QString keyRequest = saltPre + name + coreHash + pluginHash + macHash + saltPost;
00098     QString requestSigCheck = QCryptographicHash::hash ( keyRequest.toAscii()  , QCryptographicHash::Sha1 ).toHex();
00099     
00100     if ( requestSig != requestSigCheck ) {
00101       QMessageBox::critical(this,tr("Signature of request invalid"),tr("The signature of the request is not valid"));
00102       return;
00103     }
00104 
00105     std::cerr << "Writing License file to output : " << name.toStdString() << std::endl;
00106     QFile outFile(name + ".lic");
00107 
00108     if (!outFile.open(QIODevice::WriteOnly|QIODevice::Text)) {
00109       QMessageBox::critical(this,tr("Unable to open file"),tr("Unable to Open output File"));
00110       return;
00111     }
00112 
00113     QTextStream output(&outFile);
00114 
00115     // Add basic hashes
00116     output << name         << "\n";
00117     output << coreHash     << "\n";
00118     output << pluginHash   << "\n";
00119     output << macHash      << "\n";
00120     output << expiryDate << "\n";
00121     
00122     // Sign the license file
00123     QString license = saltPre + name + coreHash + pluginHash + macHash + expiryDate + saltPost;
00124     QString licenseHash = QCryptographicHash::hash ( license.toAscii()  , QCryptographicHash::Sha1 ).toHex();
00125     
00126     output << licenseHash;
00127 
00128     outFile.close();
00129   }
00130   
00131   close();
00132 
00133   
00134  
00135 }

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .