Commit f8904216 authored by Jan Möbius's avatar Jan Möbius

Remove function pointers which produce errors in C++11



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20198 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e6b310fc
...@@ -73,11 +73,27 @@ License File format: ...@@ -73,11 +73,27 @@ License File format:
#include <OpenFlipper/LicenseManager/LicenseManagerActive.hh> #include <OpenFlipper/LicenseManager/LicenseManagerActive.hh>
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include <QFile> #include <QFile>
#include <QString>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QNetworkInterface> #include <QNetworkInterface>
/** \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){
if (_utf8)
return _string.toUtf8();
else
return _string.toLatin1();
}
LicenseManager::~LicenseManager() LicenseManager::~LicenseManager()
{ {
...@@ -125,7 +141,8 @@ bool LicenseManager::authenticate() { ...@@ -125,7 +141,8 @@ bool LicenseManager::authenticate() {
QFile file( licenseFileName ); QFile file( licenseFileName );
QStringList elements; //has no elements, if file is invalid or was not found QStringList elements; //has no elements, if file is invalid or was not found
bool signatureOk = false; bool signatureOk = false;
QByteArray (QString::*codingfun)()const = &QString::toUtf8;
bool utf8Encoded = true;
if (file.open(QIODevice::ReadOnly|QIODevice::Text)) if (file.open(QIODevice::ReadOnly|QIODevice::Text))
{ {
...@@ -148,13 +165,13 @@ bool LicenseManager::authenticate() { ...@@ -148,13 +165,13 @@ bool LicenseManager::authenticate() {
signatureOk = licenseHash == elements[0]; signatureOk = licenseHash == elements[0];
if (signatureOk) if (signatureOk)
codingfun = &QString::toUtf8; utf8Encoded = true;
else else
{ {
licenseHash = QCryptographicHash::hash ( license.toLatin1() , QCryptographicHash::Sha1 ).toHex(); licenseHash = QCryptographicHash::hash ( license.toLatin1() , QCryptographicHash::Sha1 ).toHex();
signatureOk = licenseHash == elements[0]; signatureOk = licenseHash == elements[0];
if (signatureOk) if (signatureOk)
codingfun = &QString::toLatin1; utf8Encoded = false;
} }
} }
...@@ -278,7 +295,8 @@ bool LicenseManager::authenticate() { ...@@ -278,7 +295,8 @@ bool LicenseManager::authenticate() {
if ( (currentMac.count(":") == 5) && if ( (currentMac.count(":") == 5) &&
( pCurrAddresses->IfType == IF_TYPE_IEEE80211 || pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD ) ) { ( pCurrAddresses->IfType == IF_TYPE_IEEE80211 || pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD ) ) {
// Cleanup and remember mac adress // Cleanup and remember mac adress
currentMac = (currentMac.*codingfun)().toUpper();
currentMac = (decodeString(currentMac,utf8Encoded)).toUpper();
currentMac = currentMac.remove(":"); currentMac = currentMac.remove(":");
macHashes.push_back(currentMac); macHashes.push_back(currentMac);
} }
...@@ -312,7 +330,7 @@ bool LicenseManager::authenticate() { ...@@ -312,7 +330,7 @@ bool LicenseManager::authenticate() {
} }
// Cleanup mac adress // Cleanup mac adress
QString currentMac = (netInterface.hardwareAddress().*codingfun)().toUpper(); QString currentMac = (decodeString(netInterface.hardwareAddress(),utf8Encoded)).toUpper();
currentMac = currentMac.remove(":"); currentMac = currentMac.remove(":");
macHashes.push_back(currentMac); macHashes.push_back(currentMac);
...@@ -326,7 +344,8 @@ bool LicenseManager::authenticate() { ...@@ -326,7 +344,8 @@ bool LicenseManager::authenticate() {
// generate hashes // generate hashes
for (int i = 0 ; i < macHashes.size(); ++i ) for (int i = 0 ; i < macHashes.size(); ++i )
macHashes[i] = QCryptographicHash::hash ( (macHashes[i].*codingfun)() , QCryptographicHash::Sha1 ).toHex(); // Cleanup mac adress
macHashes[i] = QCryptographicHash::hash ( decodeString(macHashes[i],utf8Encoded) , QCryptographicHash::Sha1 ).toHex();
// =============================================================================================== // ===============================================================================================
// Compute hash of processor information // Compute hash of processor information
...@@ -377,7 +396,7 @@ bool LicenseManager::authenticate() { ...@@ -377,7 +396,7 @@ bool LicenseManager::authenticate() {
} }
#endif #endif
QString cpuHash = QCryptographicHash::hash ( (processor.*codingfun)() , QCryptographicHash::Sha1 ).toHex(); QString cpuHash = QCryptographicHash::hash ( decodeString(processor,utf8Encoded) , QCryptographicHash::Sha1 ).toHex();
// =============================================================================================== // ===============================================================================================
// Get windows product id // Get windows product id
...@@ -392,7 +411,7 @@ bool LicenseManager::authenticate() { ...@@ -392,7 +411,7 @@ bool LicenseManager::authenticate() {
QString productId = "-"; QString productId = "-";
#endif #endif
QString productHash = QCryptographicHash::hash ( (productId.*codingfun)() , QCryptographicHash::Sha1 ).toHex(); QString productHash = QCryptographicHash::hash ( decodeString(productId,utf8Encoded) , QCryptographicHash::Sha1 ).toHex();
// =============================================================================================== // ===============================================================================================
// Check License or generate request // Check License or generate request
......
...@@ -66,7 +66,7 @@ KeyGen::KeyGen(QString n, QString cHash, QString pHash, QString cpHash, QString ...@@ -66,7 +66,7 @@ KeyGen::KeyGen(QString n, QString cHash, QString pHash, QString cpHash, QString
requestSig = request; requestSig = request;
} }
QString KeyGen::computeSignature(QByteArray (QString::*_codingfun)()const ) const { QString KeyGen::computeSignature(const bool _utf8 ) const {
// Get the salts // Get the salts
QString saltPre; QString saltPre;
ADD_SALT_PRE(saltPre); ADD_SALT_PRE(saltPre);
...@@ -75,8 +75,16 @@ QString KeyGen::computeSignature(QByteArray (QString::*_codingfun)()const ) cons ...@@ -75,8 +75,16 @@ QString KeyGen::computeSignature(QByteArray (QString::*_codingfun)()const ) cons
QString keyRequest = saltPre + name + coreHash + pluginHash + cpuHash QString keyRequest = saltPre + name + coreHash + pluginHash + cpuHash
+ productHash + macHashes.join("") + saltPost; + productHash + macHashes.join("") + saltPost;
QString requestSigCheck =
QCryptographicHash::hash((keyRequest.*_codingfun)(), QString requestSigCheck;
if ( _utf8 )
requestSigCheck =
QCryptographicHash::hash(keyRequest.toUtf8(),
QCryptographicHash::Sha1).toHex();
else
requestSigCheck =
QCryptographicHash::hash(keyRequest.toLatin1(),
QCryptographicHash::Sha1).toHex(); QCryptographicHash::Sha1).toHex();
return requestSigCheck; return requestSigCheck;
...@@ -84,11 +92,11 @@ QString KeyGen::computeSignature(QByteArray (QString::*_codingfun)()const ) cons ...@@ -84,11 +92,11 @@ QString KeyGen::computeSignature(QByteArray (QString::*_codingfun)()const ) cons
KeyGen::ValidationResult KeyGen::isValid() const KeyGen::ValidationResult KeyGen::isValid() const
{ {
if (requestSig == computeSignature(&QString::toUtf8)) if (requestSig == computeSignature(true))
{ {
return UTF8; return UTF8;
} }
else if(requestSig == computeSignature(&QString::toLatin1)) else if(requestSig == computeSignature(false))
{ {
return LATIN1; return LATIN1;
} }
......
...@@ -61,7 +61,7 @@ class KeyGen ...@@ -61,7 +61,7 @@ class KeyGen
//returns string containing the key //returns string containing the key
QString Generate(QString expiryDate) const; QString Generate(QString expiryDate) const;
//finds all occurrences of info in messy string //finds all occurrences of info in messy string
QString computeSignature(QByteArray (QString::*_codingfun)()const = &QString::toUtf8) const; QString computeSignature(bool _utf8 = true) const;
enum ValidationResult enum ValidationResult
{ {
INVALID = 0, INVALID = 0,
......
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