...
 
Commits (11)
*.pro.user *.pro.user
*.pro.user* *.pro.user*
/builds/
/Qt-Secret/src/build/
/Qt-Secret/src/mini-gmp/src/build/
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
This diff is collapsed.
//#
//# Copyright (C) 2018-2019 QuasarApp.
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#ifndef QRSAENCRYPTION_H
#define QRSAENCRYPTION_H
#include <QByteArray>
#include <QList>
#include <QFile>
#include <cmath>
#include <QDebug>
#include <QCryptographicHash> // to use sha256
#include "./../qtsecret_global.h"
#include <bigint.h>
class Qt_SECRETSHARED_EXPORT QRSAEncryption
{
public:
typedef BigInt INT;
typedef QCryptographicHash::Algorithm HashAlgorithm;
enum Rsa {
Invalid = 0,
RSA_64 = 64,
RSA_128 = 128,
RSA_256 = 256,
RSA_512 = 512,
RSA_1024 = 1024,
RSA_2048 = 2048,
RSA_4096 = 4096,
RSA_8192 = 8192,
};
enum BlockSize {
Auto = 0, // fast but not stable. (using by default)
OneByte = 1 // stable but slow. (using for sig and check sig messages)
};
QRSAEncryption(Rsa rsa = Rsa::RSA_256);
// static methods
// OLDMETHODS DELETE IN next Version
static bool generatePairKeyS(QByteArray &pubKey, QByteArray &privKey,
QRSAEncryption::Rsa rsa = RSA_256);
static QByteArray encodeS(const QByteArray &rawData, const QByteArray &pubKey,
Rsa rsa = RSA_256, BlockSize blockSizeMode = BlockSize::Auto);
static QByteArray decodeS(const QByteArray &rawData, const QByteArray &privKey,
Rsa rsa = RSA_256, BlockSize blockSizeMode = BlockSize::Auto);
static QByteArray signMessageS(QByteArray rawData, const QByteArray &privKey,
Rsa rsa = RSA_256);
static bool checkSignMessageS(const QByteArray &rawData, const QByteArray &pubKey,
Rsa rsa);
// OLDMETHODS END
static bool generatePairKey(QByteArray &pubKey, QByteArray &privKey,
QRSAEncryption::Rsa rsa);
static QByteArray encode(const QByteArray &rawData, const QByteArray &pubKey,
Rsa rsa, BlockSize blockSizeMode = BlockSize::Auto);
static QByteArray decode(const QByteArray &rawData, const QByteArray &privKey,
Rsa rsa, BlockSize blockSizeMode = BlockSize::Auto);
static QByteArray signMessage(QByteArray rawData, const QByteArray &privKey,
Rsa rsa);
static bool checkSignMessage(const QByteArray &rawData, const QByteArray &pubKey,
Rsa rsa);
static bool isValidRsaKey(const QByteArray& key);
static unsigned int getKeyBytesSize(QRSAEncryption::Rsa rsa);
// non-static methods
bool generatePairKey(QByteArray &pubKey, QByteArray &privKey);
QByteArray encode(const QByteArray &rawData, const QByteArray &pubKey,
BlockSize blockSizeMode = BlockSize::Auto);
QByteArray decode(const QByteArray &rawData, const QByteArray &privKey,
BlockSize blockSizeMode = BlockSize::Auto);
QByteArray signMessage(QByteArray rawData, const QByteArray &privKey);
bool checkSignMessage(const QByteArray &rawData, const QByteArray &pubKey);
Rsa getRsa() const;
private:
Rsa _rsa;
bool testKeyPair(const QByteArray &pubKey, const QByteArray &privKey);
bool isMutuallyPrime(const INT &a, const INT &b);
Rsa getBitsSize(const INT& i) const;
Rsa getBitsSize(const QByteArray& array) const;
INT fromArray(const QByteArray& array) const;
QByteArray toArray(const INT &i, short sizeBlok = -1);
INT randomNumber(bool fullFilled = true) const;
INT toPrime(INT) const;
INT randomPrimeNumber(INT no = 0) const;
INT extEuclid(INT a, INT b) const;
short getBlockSize(INT i) const;
QByteArray encodeBlok(const INT& block, const INT& e, const INT& m, short blockSize);
QByteArray decodeBlok(const INT& block, const INT& d, const INT& m, short blockSize);
};
#endif // QRSAENCRYPTION_H
#
# Copyright (C) 2018-2019 QuasarApp.
# Distributed under the lgplv3 software license, see the accompanying
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
!isEmpty(Qt_SECRET_LIB):error("Qt-Secret.pri already included")
Qt_SECRET_LIB = 1
#DEPENDS
CONFIG(release, debug|release): {
Qt_SECRET_LIB_OUTPUT_DIR="$$PWD/build/release"
} else {
Qt_SECRET_LIB_OUTPUT_DIR="$$PWD/build/debug"
}
unix:LIBS += -L$$Qt_SECRET_LIB_OUTPUT_DIR -lQt-Secret
win32:LIBS += -L$$Qt_SECRET_LIB_OUTPUT_DIR -lQt-Secret1
include($$PWD/mini-gmp/src/GMPIncudePah.pri)
INCLUDEPATH += "$$PWD/Qt-RSA"
INCLUDEPATH += "$$PWD/Qt-AES"
#
# Copyright (C) 2018-2019 QuasarApp.
# Distributed under the lgplv3 software license, see the accompanying
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
QT -= gui
CONFIG += c++11
TARGET = Qt-Secret
TEMPLATE = lib
DEFINES += Qt_SECRET_LIBRARY
DEFINES += QT_DEPRECATED_WARNINGS
#DEPENDS
CONFIG(release, debug|release): {
DESTDIR="$$PWD/build/release"
} else {
DESTDIR="$$PWD/build/debug"
}
include($$PWD/mini-gmp/GMP.pri)
VERSION = 1.2.0
HEADERS += \
qtsecret_global.h \
Qt-RSA/qrsaencryption.h
SOURCES += \
Qt-RSA/qrsaencryption.cpp
#
# Copyright (C) 2018-2019 QuasarApp.
# Distributed under the lgplv3 software license, see the accompanying
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
include($$PWD/src/GMP.pri)
#
# Copyright (C) 2018-2019 QuasarApp.
# Distributed under the lgplv3 software license, see the accompanying
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \
src
src.file = src/GMP.pro
MIT License
Copyright (c) 2019 QuasarApp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#
# Copyright (C) 2018-2019 QuasarApp.
# Distributed under the lgplv3 software license, see the accompanying
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
!isEmpty(Qt_GMP_LIB):error("GMP.pri already included")
Qt_GMP_LIB = 1
#DEPENDS
CONFIG(release, debug|release): {
MINIGMP_LIBRARY_OUTPUT_DIR="$$PWD/build/release"
} else {
MINIGMP_LIBRARY_OUTPUT_DIR="$$PWD/build/debug"
}
unix:LIBS += -L$$MINIGMP_LIBRARY_OUTPUT_DIR -lQtBigInt
win32:LIBS += -L$$MINIGMP_LIBRARY_OUTPUT_DIR -lQtBigInt
include(GMPIncudePah.pri)
include(ccache.pri);
#
# Copyright (C) 2018-2019 QuasarApp.
# Distributed under the lgplv3 software license, see the accompanying
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
QT -= core gui
TARGET = MiniGMP
TEMPLATE = lib
DEFINES += MINIGMP_LIBRARY
DEFINES += QT_DEPRECATED_WARNINGS
TARGET = QtBigInt
CONFIG += static
VERSION = 6.1.2
CONFIG(release, debug|release): {
DESTDIR="$$PWD/build/release"
} else {
DESTDIR="$$PWD/build/debug"
}
DISTFILES += \
README \
HEADERS += \
bigint.h \
mini-gmp.h \
minigmp_global.h
SOURCES += \
bigint.cpp \
mini-gmp.c
include(ccache.pri);
#
# Copyright (C) 2018-2019 QuasarApp.
# Distributed under the lgplv3 software license, see the accompanying
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
INCLUDEPATH += "$$PWD"
obj-m += minigmp.o
minigmp-objs := mini-gmp.o export.o
EXTRA_CFLAGS+=-DKERNEL=1
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
This diff is collapsed.
//#
//# Copyright (C) 2018-2019 QuasarApp.
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#ifndef BIGINT_H
#define BIGINT_H
#include "mini-gmp.h"
#include <string>
#include <vector>
#include "minigmp_global.h"
/**
* @brief The BigInt class - c++ minigmp wrapper
*/
class MINIGMPSHARED_EXPORT BigInt
{
mpz_t data;
public:
BigInt();
BigInt(const BigInt& val, int bitCount = -1);
BigInt(const std::string &imput, int base = 10);
BigInt(intMpz val);
BigInt(char item, unsigned int size, int base);
std::string getString(int base = 10) const;
~BigInt();
BigInt& powm(const BigInt &pow, const BigInt &mod);
static BigInt powm(BigInt val, const BigInt & pow, const BigInt &mod);
BigInt& pow(uIntMpz pow);
BigInt& log(int base);
/**
* @brief sizeBits
* @return size of bits in memory
*/
int sizeBits() const;
int sizeBytes() const;
/**
* @brief longBits
* @return current length in Bits of number
*/
int longBits() const;
int longBytes() const;
int sizeType() const;
bool isPrime(bool absalut = false) const;
BigInt& gcd(const BigInt &a, const BigInt &b);
void fromHex(const std::string& hex);
/**
* @brief bigPow10
* @param pow
* @return number 10 ^ pow
*/
static BigInt bigPow10(unsigned short pow);
BigInt& toNegative();
BigInt& operator = (const BigInt& val);
BigInt& operator = (const std::string &imput);
BigInt& operator = (intMpz val);
friend BigInt operator + ( BigInt left, const BigInt& right);
friend BigInt operator + ( BigInt left, const std::string &right);
friend BigInt operator + ( BigInt left, intMpz right);
friend BigInt operator + ( intMpz left, BigInt right);
friend BigInt operator + ( const std::string &left, const BigInt &right);
friend BigInt& operator += ( BigInt &left, intMpz right);
friend BigInt& operator += ( BigInt &left, const BigInt& right);
friend BigInt& operator += ( BigInt &left, const std::string &right);
friend BigInt operator - ( BigInt left, const BigInt& right);
friend BigInt operator - ( BigInt left, intMpz right);
friend BigInt operator - ( BigInt left, const std::string &right);
friend BigInt operator - ( intMpz right, BigInt left);
friend BigInt operator - ( const std::string &right, const BigInt &left);
friend BigInt operator-(BigInt val);
friend BigInt& operator -= ( BigInt &left, intMpz right);
friend BigInt& operator -= ( BigInt &left, const BigInt& right);
friend BigInt& operator -= ( BigInt &left, const std::string &right);
friend BigInt operator / ( BigInt left, const BigInt& right);
friend BigInt operator / ( BigInt left, const std::string &right);
friend BigInt operator / ( BigInt left, intMpz right);
friend BigInt operator / ( intMpz left, BigInt right);
friend BigInt operator / ( const std::string &left, const BigInt &right);
friend BigInt& operator /= ( BigInt &left, intMpz right);
friend BigInt& operator /= ( BigInt &left, const std::string &right);
friend BigInt& operator /= ( BigInt &left, const BigInt& right);
friend BigInt operator * ( BigInt left, const BigInt& right);
friend BigInt operator * ( BigInt left, const std::string &right);
friend BigInt operator * ( BigInt left, intMpz right);
friend BigInt operator * ( intMpz left, BigInt right);
friend BigInt& operator *= ( BigInt &left, const BigInt& right);
friend BigInt& operator *= ( BigInt &left, intMpz right);
friend BigInt& operator *= ( BigInt &left, const std::string &right);
friend BigInt operator % ( BigInt left, const BigInt& right);
friend BigInt operator % ( BigInt left, const std::string &right);
friend BigInt operator % ( BigInt left, intMpz right);
friend BigInt operator % ( intMpz left, BigInt right);
friend BigInt operator % ( const std::string & left, const BigInt &right);
friend BigInt& operator %= ( BigInt &left, intMpz right);
friend BigInt& operator %= ( BigInt &left, const std::string &right);
friend BigInt& operator %= ( BigInt &left, const BigInt& right);
friend BigInt operator << ( BigInt left, int right);
friend BigInt operator >> ( BigInt left, int right);
friend BigInt& operator <<= ( BigInt &left, int right);
friend BigInt& operator >>= ( BigInt &left, int right);
friend bool operator == ( const BigInt& left, const BigInt& right);
friend bool operator == ( const BigInt& left, intMpz right);
friend bool operator == ( const BigInt& left, const std::string& right);
friend bool operator == ( const std::string& left, const BigInt& right);
friend bool operator == ( const BigInt& left, const std::string& right);
friend bool operator == ( intMpz left, const std::string& right);
friend bool operator != ( const BigInt& left, const BigInt& right);
friend bool operator != ( const BigInt& left, intMpz right);
friend bool operator != ( const BigInt& left, const std::string& str);
friend bool operator != ( const std::string& left, const BigInt& right);
friend bool operator != ( const BigInt& left, const std::string& right);
friend bool operator != ( intMpz left, const std::string& right);
friend bool operator < ( const BigInt& left, const BigInt& right);
friend bool operator < ( const BigInt& left, intMpz right);
friend bool operator < ( const BigInt& left, const std::string& str);
friend bool operator < ( const std::string& left, const BigInt& right);
friend bool operator < ( const BigInt& left, const std::string& right);
friend bool operator < ( intMpz left, const std::string& right);
friend bool operator > ( const BigInt& left, const BigInt& right);
friend bool operator > ( const BigInt& left, intMpz right);
friend bool operator > ( const BigInt& left, const std::string& str);
friend bool operator > ( const std::string& left, const BigInt& right);
friend bool operator > ( const BigInt& left, const std::string& right);
friend bool operator > ( intMpz left, const std::string& right);
friend bool operator <= ( const BigInt& left, const BigInt& right);
friend bool operator <= ( const BigInt& left, intMpz right);
friend bool operator <= ( const BigInt& left, const std::string& str);
friend bool operator <= ( const std::string& left, const BigInt& right);
friend bool operator <= ( const BigInt& left, const std::string& right);
friend bool operator <= ( intMpz left, const std::string& right);
friend bool operator >= ( const BigInt& left, const BigInt& right);
friend bool operator >= ( const BigInt& left, intMpz right);
friend bool operator >= ( const BigInt& left, const std::string& str);
friend bool operator >= ( const std::string& left, const BigInt& right);
friend bool operator >= ( const BigInt& left, const std::string& right);
friend bool operator >= ( intMpz left, const std::string& right);
friend bool operator!(const BigInt& val);
BigInt& operator-- ();
BigInt& operator++ ();
BigInt operator-- (int);
BigInt operator++ (int);
friend BigInt operator~ (BigInt val);
friend BigInt operator| (BigInt left, const BigInt& right);
friend BigInt operator| (const BigInt &left, intMpz right);
friend BigInt& operator|= (BigInt &left, const BigInt& right);
friend BigInt& operator|= (BigInt &left, intMpz right);
friend BigInt operator& (BigInt left, const BigInt& right);
friend BigInt operator& (const BigInt &left, intMpz right);
friend BigInt& operator&= (BigInt &left, const BigInt& right);
friend BigInt& operator&= (BigInt &left, intMpz right);
friend BigInt operator^ (BigInt left, const BigInt& right);
friend BigInt operator^ (const BigInt &left, intMpz right);
friend BigInt& operator^= (BigInt &left, const BigInt& right);
friend BigInt& operator^= (BigInt &left, intMpz right);
};
#endif // BIGINT_H
#
# Copyright (C) 2018-2019 QuasarApp.
# Distributed under the lgplv3 software license, see the accompanying
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
!isEmpty(CCACHE_INCLUDE):error("ccache.pri already included")
CCACHE_INCLUDE = 1
contains(QMAKE_HOST.os, Linux):{
BIN = $$system(which ccache)
!isEmpty(BIN) {
message(ccache detected in $$BIN)
QMAKE_CXX='$$BIN $$QMAKE_CXX'
}
}
This diff is collapsed.
This diff is collapsed.
//#
//# Copyright (C) 2018-2019 QuasarApp.
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#ifndef MINIGMP_GLOBAL_H
#define MINIGMP_GLOBAL_H
#ifdef _WIN32
# define MINIGMPSHARED_EXPORT __declspec(dllexport)
#endif
#ifdef linux
# define MINIGMPSHARED_EXPORT __attribute__((visibility("default")))
#endif
#endif //MINIGMP_GLOBAL_H
#ifndef QTSECRET_GLOBAL_H
#define QTSECRET_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(Qt_SECRET_LIBRARY)
# define Qt_SECRETSHARED_EXPORT Q_DECL_EXPORT
#else
# define Qt_SECRETSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // QTSECRET_GLOBAL_H
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include <QMediaPlayer> #include <QMediaPlayer>
#include <QSound> #include <QSound>
#include <QSoundEffect> #include <QSoundEffect>
#include <QCryptographicHash>
#include <qrsaencryption.h>
#include "extensionconn.h" #include "extensionconn.h"
#include "speedtimer.h" #include "speedtimer.h"
......
...@@ -31,6 +31,10 @@ public: ...@@ -31,6 +31,10 @@ public:
QStringList updateSubscriptions; QStringList updateSubscriptions;
QTcpSocket * socket; QTcpSocket * socket;
bool usingTerminationKeys;
QString readBuffer;
}; };
QList<socketClient> clients; QList<socketClient> clients;
...@@ -49,6 +53,7 @@ public slots: ...@@ -49,6 +53,7 @@ public slots:
qint64 sendToClient(QTcpSocket *socket, const QString &str); qint64 sendToClient(QTcpSocket *socket, const QString &str);
// --- helper functions --- // --- helper functions ---
void processSocketMessage(socketClient * socket, QString message);
QList<socketClient> getClients(); QList<socketClient> getClients();
private: private:
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
"init": { "init": {
"type": "bool", "type": "bool",
"desc": "should all signals be sent once for initialisation purposes?" "desc": "should all signals be sent once for initialisation purposes?"
},
"usingTerminationKeys":{
"type": "bool",
"desc": "do future messages from this client use the <message></message> format?"
} }
} }
}, },
...@@ -294,7 +298,17 @@ ...@@ -294,7 +298,17 @@
} }
] ]
} }
},
"5000": {
"desc": "update firmware",
"requestData": {
"type": "string",
"desc": "long string containing the version, new binary as base64 and an official signature of Itsblue Development",
"def": "<VER>major.minor.patch</VER><BIN>###updated binary as base64###</BIN>-SIGN-###signature###-SIGN-"
}
} }
}, },
"response codes": { "response codes": {
......
...@@ -232,7 +232,7 @@ QVariantList AthleteProfiles::getResults( QString userName ) { ...@@ -232,7 +232,7 @@ QVariantList AthleteProfiles::getResults( QString userName ) {
results.append(athlete); results.append(athlete);
} }
qDebug() << "found results: " << results; //qDebug() << "found results: " << results;
return results; return results;
} }
......
...@@ -76,7 +76,7 @@ bool AudioPlayer::play(QString path){ ...@@ -76,7 +76,7 @@ bool AudioPlayer::play(QString path){
// play sound // play sound
connect(this->soundProcess, SIGNAL(finished(int, QProcess::ExitStatus)), waitLoop, SLOT(quit())); connect(this->soundProcess, SIGNAL(finished(int, QProcess::ExitStatus)), waitLoop, SLOT(quit()));
soundProcess->start("omxplayer " + pGlobalAppSettings->qrcToNormalFile(path) + " --vol " + QString::number(-1500*(1-pGlobalAppSettings->loadSetting("soundVolume").toDouble()))); soundProcess->start("omxplayer -o local " + pGlobalAppSettings->qrcToNormalFile(path) + " --vol " + QString::number(-1500*(1-pGlobalAppSettings->loadSetting("soundVolume").toDouble())));
waitLoop->exec(); waitLoop->exec();
disconnect(this->soundProcess, SIGNAL(finished(int, QProcess::ExitStatus)), waitLoop, SLOT(quit())); disconnect(this->soundProcess, SIGNAL(finished(int, QProcess::ExitStatus)), waitLoop, SLOT(quit()));
......
...@@ -203,7 +203,7 @@ void ExtensionConn::gotError(QAbstractSocket::SocketError err) ...@@ -203,7 +203,7 @@ void ExtensionConn::gotError(QAbstractSocket::SocketError err)
this->lastError = strError; this->lastError = strError;
emit lastErrorChanged(); emit lastErrorChanged();
this->log("got error: " + strError + "(" + QString::number(err) + ")", 0); this->log("got error: " + strError + "(" + QString::number(err) + ")", 2);
} }
void ExtensionConn::connectionTimeout() { void ExtensionConn::connectionTimeout() {
......
#include <QCoreApplication> #include <QCoreApplication>
#include <QProcess>
#include "headers/mainactivity.h" #include "headers/mainactivity.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
...@@ -22,5 +23,15 @@ int main(int argc, char *argv[]) ...@@ -22,5 +23,15 @@ int main(int argc, char *argv[])
qDebug() << "end: " << currentExitCode << "\n---------------------------------------------\n"; qDebug() << "end: " << currentExitCode << "\n---------------------------------------------\n";
} }
if(currentExitCode == 1020) {
// a reboot of the host was requested
QProcess rebootProcess;
rebootProcess.start("sudo reboot now");
QEventLoop rebootWaitLoop;
QObject::connect(&rebootProcess, SIGNAL(finished), &rebootWaitLoop, SLOT(quit));
rebootWaitLoop.exec();
}
return currentExitCode; return currentExitCode;
} }
...@@ -436,6 +436,8 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient, ...@@ -436,6 +436,8 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient,
// init session // init session
socketClient->sessionActive = true; socketClient->sessionActive = true;
socketClient->updateSubscriptions = requestData["updateSubs"].toVariant().toStringList(); socketClient->updateSubscriptions = requestData["updateSubs"].toVariant().toStringList();
socketClient->usingTerminationKeys = requestData["usingTerminationKeys"].toBool();
qDebug() << "set update subs to: " << socketClient->updateSubscriptions; qDebug() << "set update subs to: " << socketClient->updateSubscriptions;
replyHeader = 200; replyHeader = 200;
...@@ -700,15 +702,13 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient, ...@@ -700,15 +702,13 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient,
replyObj.insert("activeAthlete", this->athleteProfiles->getCurrentAthlete()); replyObj.insert("activeAthlete", this->athleteProfiles->getCurrentAthlete());
replyData = replyObj; replyData = replyObj;
qDebug() << athltesVar;
//replyData = athletes; //replyData = athletes;
replyHeader = 200; replyHeader = 200;
break; break;
} }
case 4004: { case 4004: {
// get all athletes // get results of an athlete
QVariant resultsVar = this->athleteProfiles->getResults(requestData.toString()); QVariant resultsVar = this->athleteProfiles->getResults(requestData.toString());
replyData = resultsVar.toJsonValue(); replyData = resultsVar.toJsonValue();
...@@ -718,6 +718,78 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient, ...@@ -718,6 +718,78 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient,
break; break;
} }
case 5000: {
if(this->state != IDLE){
replyHeader = 900;
break;
}
qDebug() << "[INFO][MAIN] recieved a software update ... checking signature ...";
// this is the public key of the offical Itsblue Development software team.
QByteArray pub = QByteArray::fromBase64("GetAJE+g0xJ0tUuEcdK5ELV1Wqr4f/7tq0xMGUDy1Udbgd68Ro1eabzBRhuoqzy6+MDDhhB5aYl9fIE8/DHcyGSRX/CcjIpH6CFJyBk9u2WStllyYJM6++kDTgDGG7V4Dq9gKBPr4GOG3Lq4xAtiIEYr/ZVTaR+tHl2SZYBMxgkr7Q62gc6x7MITIKINUjlKh084+7/CSlo+s0VSyUrCB+pTFHWn33DGeoX8TySxalIjyELBfEiGWKaW4LQD/s//a792Ff8AaSNDTUUq0gVMCY1oFgY++4DpQGoUy69Pn7cw5EbYAyF/mISVVvqSLTh99Uy3bhPEm55ed7TJ1xNZYQ==");
QRSAEncryption e(QRSAEncryption::Rsa::RSA_1024);
// check the signature of the update
QString signedMessage = requestData.toString();
if (!e.checkSignMessage(signedMessage.toUtf8(), pub)) {
qDebug() << "[INFO][MAIN] update signature invalid ...";
replyHeader = 401;
break;
}
// message signed success
qDebug() << "[INFO][MAIN] update signature valid ...";
QString newFirmwareVersion = signedMessage.split("<VER>")[1].split("</VER>")[0];
int newFirmwareVersionMajor = newFirmwareVersion.split(".")[0].toInt();
int newFirmwareVersionMinor = newFirmwareVersion.split(".")[1].toInt();
int newFirmwareVersionPatch = newFirmwareVersion.split(".")[2].toInt();
QString currentFirmwareVersion = APP_VERSION;
int currentFirmwareVersionMajor = currentFirmwareVersion.split(".")[0].toInt();
int currentFirmwareVersionMinor = currentFirmwareVersion.split(".")[1].toInt();
int currentFirmwareVersionPatch = currentFirmwareVersion.split(".")[2].toInt();
if (newFirmwareVersionMajor < currentFirmwareVersionMajor || newFirmwareVersionMinor < currentFirmwareVersionMinor || newFirmwareVersionPatch <= currentFirmwareVersionPatch ) {
// the firmware is already up-to-date
qDebug() << "[INFO][MAIN] ... already up-to-date!";
replyHeader = 304;
break;
}
qDebug() << "[INFO][MAIN] UPDATE ACCEPTED new Version is: " << newFirmwareVersion;
// send a reply to the client
// insert the data into the reply object
replyObj.insert("id", requestId);
replyObj.insert("header", 200);
replyObj.insert("data", replyData);
QJsonDocument jsonReply(replyObj);
// send the reply back to the client
this->socketServer->sendToClient(socket, jsonReply.toJson());
// perform the actual update
QString newFirmwareString = signedMessage.split("<BIN>")[1].split("</BIN>")[0];
//qDebug() << newFirmwareString;
QFile newFile(qApp->applicationFilePath() + "-update.zip");
newFile.open(QFile::WriteOnly);
newFile.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ReadUser | QFileDevice::WriteUser);
newFile.write( QByteArray::fromBase64( newFirmwareString.toUtf8() ));
// trigger a reboot
qDebug() << "[INFO][MAIN] UPDATE extracted, rebooting now ";
qApp->exit(1020);
return;
}
default: default:
replyHeader = 404; replyHeader = 404;
break; break;
......
...@@ -40,6 +40,8 @@ void SocketServer::newConnection() ...@@ -40,6 +40,8 @@ void SocketServer::newConnection()
socketClient client; socketClient client;
client.socket = clientSocket; client.socket = clientSocket;
client.sessionActive = false; client.sessionActive = false;
client.usingTerminationKeys = false;
client.readBuffer = "";
clients.append(client); clients.append(client);
...@@ -53,7 +55,12 @@ void SocketServer::readClient() ...@@ -53,7 +55,12 @@ void SocketServer::readClient()
// find sender in clients list // find sender in clients list
for(int i = 0; i < this->clients.length(); i++) { for(int i = 0; i < this->clients.length(); i++) {
if(this->clients[i].socket == sender()) { if(this->clients[i].socket == sender()) {
emit gotCommand(&this->clients[i], this->clients[i].socket->readAll()); if(!this->clients[i].usingTerminationKeys) {
emit gotCommand(&this->clients[i], this->clients[i].socket->readAll());
}
else {
this->processSocketMessage(&this->clients[i], this->clients[i].socket->readAll());
}
return; return;
} }
} }
...@@ -85,6 +92,58 @@ void SocketServer::gotDisconnection() ...@@ -85,6 +92,58 @@ void SocketServer::gotDisconnection()
// --- helper functions --- // --- helper functions ---
// ------------------------ // ------------------------
void SocketServer::processSocketMessage(socketClient * socket, QString message) {
QString startKey = "<message>";
QString endKey = "</message>";
//qWarning() << "... processing message now ... : " << message;
if(message == ""){
return;
}
if((message.startsWith(startKey) && message.endsWith(endKey)) && (message.count(startKey) == 1 && message.count(endKey) == 1)){
// non-split message ( e.g.: <message>123456789</message>
}
else if(!message.contains(endKey) && (!socket->readBuffer.isEmpty() || message.startsWith(startKey))){
// begin of a split message ( e.g.: <message>123 )
// or middle of a split message ( e.g.: 456 )
//qWarning() << "this is a begin or middle of split a message";
socket->readBuffer += message;
return;
}
else if(!message.contains(startKey) && message.endsWith(endKey)) {
// end of a split message ( e.g.: 789</message> )
if(!socket->readBuffer.isEmpty()){
message = socket->readBuffer + message;
socket->readBuffer.clear();
}
}
else if((message.count(startKey) > 1 || message.count(endKey) > 1) || (message.contains(endKey) && !message.endsWith(endKey) && message.contains(startKey) && !message.startsWith(startKey))) {
// multiple messages in one packet ( e.g.: <message>123456789</message><message>987654321</message> )
// or multiple message fragments in one message ( e.g.: 56789</message><message>987654321</message> or 56789</message><message>98765 )
//qDebug() << "detected multiple messages";
int startOfSecondMessage = message.lastIndexOf(startKey);
// process first part of message
QString firstMessage = message.left(startOfSecondMessage);
this->processSocketMessage(socket, firstMessage);
// process second part of message
QString secondMessage = message.right(message.length() - startOfSecondMessage);
this->processSocketMessage(socket, secondMessage);
return;
}
else {
// invalid message
return;
}
//qWarning() << "... done processing, message: " << message;
emit gotCommand(socket, message.replace(startKey, "").replace(endKey, ""));
}
QList<SocketServer::socketClient> SocketServer::getClients() QList<SocketServer::socketClient> SocketServer::getClients()
{ {
return clients; return clients;
......
...@@ -57,3 +57,5 @@ HEADERS += \ ...@@ -57,3 +57,5 @@ HEADERS += \
RESOURCES += \ RESOURCES += \
resources/shared.qrc resources/shared.qrc
include($$PWD/Qt-Secret/src/Qt-Secret.pri)