mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 18:55:38 +08:00
Ref T730, CPP check issues fixed
This commit is contained in:
committed by
Mat Sutcliffe
parent
1d9cd50463
commit
30baa12a86
@@ -187,10 +187,11 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (m_receiver->getFrequencyHz() < 30000000)
|
if (m_receiver->getFrequencyHz() < 30000000)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652);
|
double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652);
|
||||||
|
|
||||||
if (crackleFactor < 0.0f) { crackleFactor = 0.00f; }
|
if (crackleFactor < 0.0f) { crackleFactor = 0.00f; }
|
||||||
if (crackleFactor > 0.20f) { crackleFactor = 0.20f; }
|
if (crackleFactor > 0.20f) { crackleFactor = 0.20f; }
|
||||||
|
**/
|
||||||
|
|
||||||
m_hfWhiteNoise->setGain(m_hfWhiteNoiseGainMin);
|
m_hfWhiteNoise->setGain(m_hfWhiteNoiseGainMin);
|
||||||
m_acBusNoise->setGain(m_acBusGainMin + 0.001f);
|
m_acBusNoise->setGain(m_acBusGainMin + 0.001f);
|
||||||
|
|||||||
@@ -156,14 +156,11 @@ namespace BlackCore
|
|||||||
samples = convertFromStereoToMono(samples);
|
samples = convertFromStereoToMono(samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
int value = 0;
|
|
||||||
for (qint16 &sample : samples)
|
for (qint16 &sample : samples)
|
||||||
{
|
{
|
||||||
value = qRound(sample * m_volume);
|
int value = qRound(sample * m_volume);
|
||||||
if (value > std::numeric_limits<qint16>::max())
|
if (value > std::numeric_limits<qint16>::max()) value = std::numeric_limits<qint16>::max();
|
||||||
value = std::numeric_limits<qint16>::max();
|
if (value < std::numeric_limits<qint16>::min()) value = std::numeric_limits<qint16>::min();
|
||||||
if (value < std::numeric_limits<qint16>::min())
|
|
||||||
value = std::numeric_limits<qint16>::min();
|
|
||||||
sample = static_cast<qint16>(value);
|
sample = static_cast<qint16>(value);
|
||||||
|
|
||||||
qint16 sampleInput = qAbs(sample);
|
qint16 sampleInput = qAbs(sample);
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cryptodtochannel.h"
|
#include "cryptodtochannel.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -14,26 +17,18 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
namespace Crypto
|
namespace Crypto
|
||||||
{
|
{
|
||||||
CCryptoDtoChannel::CCryptoDtoChannel(QString channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize)
|
CCryptoDtoChannel::CCryptoDtoChannel(const QString &channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize):
|
||||||
{
|
m_aeadTransmitKey(aeadTransmitKey), m_aeadReceiveKey(aeadReceiveKey), m_receiveSequenceSizeMaxSize(receiveSequenceHistorySize), m_channelTag(channelTag)
|
||||||
m_channelTag = channelTag;
|
|
||||||
m_aeadReceiveKey = aeadReceiveKey;
|
|
||||||
m_aeadTransmitKey = aeadTransmitKey;
|
|
||||||
|
|
||||||
m_receiveSequenceSizeMaxSize = receiveSequenceHistorySize;
|
{
|
||||||
if (m_receiveSequenceSizeMaxSize < 1) { m_receiveSequenceSizeMaxSize = 1; }
|
if (m_receiveSequenceSizeMaxSize < 1) { m_receiveSequenceSizeMaxSize = 1; }
|
||||||
m_receiveSequenceHistory.fill(0, m_receiveSequenceSizeMaxSize);
|
m_receiveSequenceHistory.fill(0, m_receiveSequenceSizeMaxSize);
|
||||||
m_receiveSequenceHistoryDepth = 0;
|
m_receiveSequenceHistoryDepth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCryptoDtoChannel::CCryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize)
|
CCryptoDtoChannel::CCryptoDtoChannel(const CryptoDtoChannelConfigDto &channelConfig, int receiveSequenceHistorySize) :
|
||||||
|
m_aeadTransmitKey(channelConfig.aeadTransmitKey), m_aeadReceiveKey(channelConfig.aeadReceiveKey), m_receiveSequenceSizeMaxSize(receiveSequenceHistorySize), m_hmacKey(channelConfig.hmacKey), m_channelTag(channelConfig.channelTag)
|
||||||
{
|
{
|
||||||
m_channelTag = channelConfig.channelTag;
|
|
||||||
m_aeadReceiveKey = channelConfig.aeadReceiveKey;
|
|
||||||
m_aeadTransmitKey = channelConfig.aeadTransmitKey;
|
|
||||||
m_hmacKey = channelConfig.hmacKey;
|
|
||||||
|
|
||||||
m_receiveSequenceSizeMaxSize = receiveSequenceHistorySize;
|
|
||||||
if (m_receiveSequenceSizeMaxSize < 1) { m_receiveSequenceSizeMaxSize = 1; }
|
if (m_receiveSequenceSizeMaxSize < 1) { m_receiveSequenceSizeMaxSize = 1; }
|
||||||
m_receiveSequenceHistory.fill(0, m_receiveSequenceSizeMaxSize);
|
m_receiveSequenceHistory.fill(0, m_receiveSequenceSizeMaxSize);
|
||||||
m_receiveSequenceHistoryDepth = 0;
|
m_receiveSequenceHistoryDepth = 0;
|
||||||
@@ -46,7 +41,8 @@ namespace BlackCore
|
|||||||
case CryptoDtoMode::AEAD_ChaCha20Poly1305: return m_aeadTransmitKey;
|
case CryptoDtoMode::AEAD_ChaCha20Poly1305: return m_aeadTransmitKey;
|
||||||
case CryptoDtoMode::Undefined:
|
case CryptoDtoMode::Undefined:
|
||||||
case CryptoDtoMode::None:
|
case CryptoDtoMode::None:
|
||||||
qFatal("GetTransmitKey called with wrong argument.");
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "GetTransmitKey called with wrong argument.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@@ -63,7 +59,8 @@ namespace BlackCore
|
|||||||
case CryptoDtoMode::AEAD_ChaCha20Poly1305: return m_aeadTransmitKey;
|
case CryptoDtoMode::AEAD_ChaCha20Poly1305: return m_aeadTransmitKey;
|
||||||
case CryptoDtoMode::Undefined:
|
case CryptoDtoMode::Undefined:
|
||||||
case CryptoDtoMode::None:
|
case CryptoDtoMode::None:
|
||||||
qFatal("GetTransmitKey called with wrong argument.");
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "GetTransmitKey called with wrong argument.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@@ -81,7 +78,8 @@ namespace BlackCore
|
|||||||
case CryptoDtoMode::AEAD_ChaCha20Poly1305: return m_aeadReceiveKey;
|
case CryptoDtoMode::AEAD_ChaCha20Poly1305: return m_aeadReceiveKey;
|
||||||
case CryptoDtoMode::Undefined:
|
case CryptoDtoMode::Undefined:
|
||||||
case CryptoDtoMode::None:
|
case CryptoDtoMode::None:
|
||||||
qFatal("getReceiveKey called with wrong argument.");
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "GetReceiveKey called with wrong argument.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Ctor
|
//! Ctor
|
||||||
CCryptoDtoChannel(QString channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize = 10);
|
CCryptoDtoChannel(const QString &channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize = 10);
|
||||||
|
|
||||||
//! Ctor
|
//! Ctor
|
||||||
CCryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize = 10);
|
CCryptoDtoChannel(const CryptoDtoChannelConfigDto &channelConfig, int receiveSequenceHistorySize = 10);
|
||||||
|
|
||||||
//! Transmit key @{
|
//! Transmit key @{
|
||||||
QByteArray getTransmitKey(CryptoDtoMode mode);
|
QByteArray getTransmitKey(CryptoDtoMode mode);
|
||||||
|
|||||||
@@ -879,7 +879,6 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (!m_fsdClient) { return {}; }
|
if (!m_fsdClient) { return {}; }
|
||||||
return m_fsdClient->getPresetValues();
|
return m_fsdClient->getPresetValues();
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CAtcStation CContextNetwork::getOnlineStationForCallsign(const CCallsign &callsign) const
|
CAtcStation CContextNetwork::getOnlineStationForCallsign(const CCallsign &callsign) const
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace BlackCore
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
ClientIdentification::ClientIdentification(const QString &sender, quint16 clientId, const QString &clientName, int clientVersionMajor,
|
ClientIdentification::ClientIdentification(const QString &sender, quint16 clientId, const QString &clientName, int clientVersionMajor,
|
||||||
int clientVersionMinor, const QString &userCid, const QString &sysUid, const QString &initialChallenge)
|
int clientVersionMinor, const QString &userCid, const QString &sysUid, const QString &initialChallenge)
|
||||||
: MessageBase(sender, "SERVER"),
|
: MessageBase(sender, "SERVER"),
|
||||||
m_clientId(clientId), m_clientName(clientName),
|
m_clientId(clientId), m_clientName(clientName),
|
||||||
m_clientVersionMajor(clientVersionMajor), m_clientVersionMinor(clientVersionMinor),
|
m_clientVersionMajor(clientVersionMajor), m_clientVersionMinor(clientVersionMinor),
|
||||||
@@ -47,9 +47,10 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
BlackMisc::CLogMessage(static_cast<ClientIdentification *>(nullptr)).warning(u"Wrong number of arguments.");
|
BlackMisc::CLogMessage(static_cast<ClientIdentification *>(nullptr)).warning(u"Wrong number of arguments.");
|
||||||
return {};
|
return {};
|
||||||
};
|
}
|
||||||
|
|
||||||
ClientIdentification packet(tokens[0], tokens[2].toUShort(nullptr, 16), tokens[3], tokens[4].toInt(), tokens[5].toInt(),
|
ClientIdentification packet(tokens[0], tokens[2].toUShort(nullptr, 16), tokens[3], tokens[4].toInt(), tokens[5].toInt(),
|
||||||
tokens[6], tokens[7], tokens.size() > 8 ? tokens[8] : QString());
|
tokens[6], tokens[7], tokens.size() > 8 ? tokens[8] : QString());
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#define BLACKCORE_FSD_CLIENTIDENTIFICATION_H
|
#define BLACKCORE_FSD_CLIENTIDENTIFICATION_H
|
||||||
|
|
||||||
#include "messagebase.h"
|
#include "messagebase.h"
|
||||||
|
#include "blackconfig/buildconfig.h"
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -34,8 +35,8 @@ namespace BlackCore
|
|||||||
|
|
||||||
std::uint16_t m_clientId;
|
std::uint16_t m_clientId;
|
||||||
QString m_clientName;
|
QString m_clientName;
|
||||||
int m_clientVersionMajor;
|
int m_clientVersionMajor = BlackConfig::CBuildConfig::getVersion().majorVersion();
|
||||||
int m_clientVersionMinor;
|
int m_clientVersionMinor = BlackConfig::CBuildConfig::getVersion().minorVersion();
|
||||||
QString m_userCid;
|
QString m_userCid;
|
||||||
QString m_sysUid;
|
QString m_sysUid;
|
||||||
QString m_initialChallenge;
|
QString m_initialChallenge;
|
||||||
|
|||||||
365
src/blackmisc/network/external/qjsonwebtoken.cpp
vendored
365
src/blackmisc/network/external/qjsonwebtoken.cpp
vendored
@@ -10,154 +10,156 @@
|
|||||||
|
|
||||||
QJsonWebToken::QJsonWebToken()
|
QJsonWebToken::QJsonWebToken()
|
||||||
{
|
{
|
||||||
// create the header with default algorithm
|
// create the header with default algorithm
|
||||||
setAlgorithmStr("HS256");
|
setAlgorithmStr("HS256");
|
||||||
m_jdocPayload = QJsonDocument::fromJson("{}");
|
m_jdocPayload = QJsonDocument::fromJson("{}");
|
||||||
|
|
||||||
// default for random generation
|
// default for random generation
|
||||||
m_intRandLength = 10;
|
m_intRandLength = 10;
|
||||||
m_strRandAlphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
m_strRandAlphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonWebToken::QJsonWebToken(const QJsonWebToken &other)
|
QJsonWebToken::QJsonWebToken(const QJsonWebToken &other) :
|
||||||
|
m_jdocHeader(other.m_jdocHeader),
|
||||||
|
m_jdocPayload(other.m_jdocPayload),
|
||||||
|
m_byteSignature(other.m_byteSignature),
|
||||||
|
m_strSecret(other.m_strSecret),
|
||||||
|
m_strAlgorithm(other.m_strAlgorithm)
|
||||||
{
|
{
|
||||||
this->m_jdocHeader = other.m_jdocHeader;
|
// void
|
||||||
this->m_jdocPayload = other.m_jdocPayload;
|
|
||||||
this->m_byteSignature = other.m_byteSignature;
|
|
||||||
this->m_strSecret = other.m_strSecret;
|
|
||||||
this->m_strAlgorithm = other.m_strAlgorithm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument QJsonWebToken::getHeaderJDoc() const
|
QJsonDocument QJsonWebToken::getHeaderJDoc() const
|
||||||
{
|
{
|
||||||
return m_jdocHeader;
|
return m_jdocHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QJsonWebToken::getHeaderQStr(const QJsonDocument::JsonFormat &format/* = QJsonDocument::JsonFormat::Indented*/) const
|
QString QJsonWebToken::getHeaderQStr(const QJsonDocument::JsonFormat &format/* = QJsonDocument::JsonFormat::Indented*/) const
|
||||||
{
|
{
|
||||||
return m_jdocHeader.toJson(format);
|
return m_jdocHeader.toJson(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QJsonWebToken::setHeaderJDoc(const QJsonDocument &jdocHeader)
|
bool QJsonWebToken::setHeaderJDoc(const QJsonDocument &jdocHeader)
|
||||||
{
|
{
|
||||||
if (jdocHeader.isEmpty() || jdocHeader.isNull() || !jdocHeader.isObject())
|
if (jdocHeader.isEmpty() || jdocHeader.isNull() || !jdocHeader.isObject())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if supported algorithm
|
// check if supported algorithm
|
||||||
QString strAlgorithm = jdocHeader.object().value("alg").toString("");
|
const QString strAlgorithm = jdocHeader.object().value("alg").toString("");
|
||||||
if (!isAlgorithmSupported(strAlgorithm))
|
if (!isAlgorithmSupported(strAlgorithm))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_jdocHeader = jdocHeader;
|
m_jdocHeader = jdocHeader;
|
||||||
|
|
||||||
// set also new algorithm
|
// set also new algorithm
|
||||||
m_strAlgorithm = strAlgorithm;
|
m_strAlgorithm = strAlgorithm;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QJsonWebToken::setHeaderQStr(const QString &strHeader)
|
bool QJsonWebToken::setHeaderQStr(const QString &strHeader)
|
||||||
{
|
{
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument tmpHeader = QJsonDocument::fromJson(strHeader.toUtf8(), &error);
|
QJsonDocument tmpHeader = QJsonDocument::fromJson(strHeader.toUtf8(), &error);
|
||||||
|
|
||||||
// validate and set header
|
// validate and set header
|
||||||
if (error.error != QJsonParseError::NoError || !setHeaderJDoc(tmpHeader))
|
if (error.error != QJsonParseError::NoError || !setHeaderJDoc(tmpHeader))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument QJsonWebToken::getPayloadJDoc() const
|
QJsonDocument QJsonWebToken::getPayloadJDoc() const
|
||||||
{
|
{
|
||||||
return m_jdocPayload;
|
return m_jdocPayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QJsonWebToken::getPayloadQStr(const QJsonDocument::JsonFormat &format/* = QJsonDocument::JsonFormat::Indented*/) const
|
QString QJsonWebToken::getPayloadQStr(const QJsonDocument::JsonFormat &format/* = QJsonDocument::JsonFormat::Indented*/) const
|
||||||
{
|
{
|
||||||
return m_jdocPayload.toJson(format);
|
return m_jdocPayload.toJson(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QJsonWebToken::setPayloadJDoc(const QJsonDocument &jdocPayload)
|
bool QJsonWebToken::setPayloadJDoc(const QJsonDocument &jdocPayload)
|
||||||
{
|
{
|
||||||
if (jdocPayload.isEmpty() || jdocPayload.isNull() || !jdocPayload.isObject())
|
if (jdocPayload.isEmpty() || jdocPayload.isNull() || !jdocPayload.isObject())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_jdocPayload = jdocPayload;
|
m_jdocPayload = jdocPayload;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QJsonWebToken::setPayloadQStr(const QString &strPayload)
|
bool QJsonWebToken::setPayloadQStr(const QString &strPayload)
|
||||||
{
|
{
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument tmpPayload = QJsonDocument::fromJson(strPayload.toUtf8(), &error);
|
QJsonDocument tmpPayload = QJsonDocument::fromJson(strPayload.toUtf8(), &error);
|
||||||
|
|
||||||
// validate and set payload
|
// validate and set payload
|
||||||
if (error.error != QJsonParseError::NoError || !setPayloadJDoc(tmpPayload))
|
if (error.error != QJsonParseError::NoError || !setPayloadJDoc(tmpPayload))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray QJsonWebToken::getSignature()
|
QByteArray QJsonWebToken::getSignature()
|
||||||
{
|
{
|
||||||
// recalculate
|
// recalculate
|
||||||
// get header in compact mode and base64 encoded
|
// get header in compact mode and base64 encoded
|
||||||
QByteArray byteHeaderBase64 = getHeaderQStr(QJsonDocument::JsonFormat::Compact).toUtf8().toBase64();
|
QByteArray byteHeaderBase64 = getHeaderQStr(QJsonDocument::JsonFormat::Compact).toUtf8().toBase64();
|
||||||
// get payload in compact mode and base64 encoded
|
// get payload in compact mode and base64 encoded
|
||||||
QByteArray bytePayloadBase64 = getPayloadQStr(QJsonDocument::JsonFormat::Compact).toUtf8().toBase64();
|
QByteArray bytePayloadBase64 = getPayloadQStr(QJsonDocument::JsonFormat::Compact).toUtf8().toBase64();
|
||||||
// calculate signature based on chosen algorithm and secret
|
// calculate signature based on chosen algorithm and secret
|
||||||
m_byteAllData = byteHeaderBase64 + "." + bytePayloadBase64;
|
m_byteAllData = byteHeaderBase64 + "." + bytePayloadBase64;
|
||||||
if (m_strAlgorithm.compare("HS256", Qt::CaseSensitive) == 0) // HMAC using SHA-256 hash algorithm
|
if (m_strAlgorithm.compare("HS256", Qt::CaseSensitive) == 0) // HMAC using SHA-256 hash algorithm
|
||||||
{
|
{
|
||||||
m_byteSignature = QMessageAuthenticationCode::hash(m_byteAllData, m_strSecret.toUtf8(), QCryptographicHash::Sha256);
|
m_byteSignature = QMessageAuthenticationCode::hash(m_byteAllData, m_strSecret.toUtf8(), QCryptographicHash::Sha256);
|
||||||
}
|
}
|
||||||
else if (m_strAlgorithm.compare("HS384", Qt::CaseSensitive) == 0) // HMAC using SHA-384 hash algorithm
|
else if (m_strAlgorithm.compare("HS384", Qt::CaseSensitive) == 0) // HMAC using SHA-384 hash algorithm
|
||||||
{
|
{
|
||||||
m_byteSignature = QMessageAuthenticationCode::hash(m_byteAllData, m_strSecret.toUtf8(), QCryptographicHash::Sha384);
|
m_byteSignature = QMessageAuthenticationCode::hash(m_byteAllData, m_strSecret.toUtf8(), QCryptographicHash::Sha384);
|
||||||
}
|
}
|
||||||
else if (m_strAlgorithm.compare("HS512", Qt::CaseSensitive) == 0) // HMAC using SHA-512 hash algorithm
|
else if (m_strAlgorithm.compare("HS512", Qt::CaseSensitive) == 0) // HMAC using SHA-512 hash algorithm
|
||||||
{
|
{
|
||||||
m_byteSignature = QMessageAuthenticationCode::hash(m_byteAllData, m_strSecret.toUtf8(), QCryptographicHash::Sha512);
|
m_byteSignature = QMessageAuthenticationCode::hash(m_byteAllData, m_strSecret.toUtf8(), QCryptographicHash::Sha512);
|
||||||
}
|
}
|
||||||
// TODO : support other algorithms
|
// TODO : support other algorithms
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_byteSignature = QByteArray();
|
m_byteSignature = QByteArray();
|
||||||
}
|
}
|
||||||
// return recalculated
|
// return recalculated
|
||||||
return m_byteSignature;
|
return m_byteSignature;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray QJsonWebToken::getSignatureBase64()
|
QByteArray QJsonWebToken::getSignatureBase64()
|
||||||
{
|
{
|
||||||
// note we return through getSignature() to force recalculation
|
// note we return through getSignature() to force recalculation
|
||||||
return getSignature().toBase64();
|
return getSignature().toBase64();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QJsonWebToken::getSecret() const
|
QString QJsonWebToken::getSecret() const
|
||||||
{
|
{
|
||||||
return m_strSecret;
|
return m_strSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QJsonWebToken::setSecret(const QString &strSecret)
|
bool QJsonWebToken::setSecret(const QString &strSecret)
|
||||||
{
|
{
|
||||||
if (strSecret.isEmpty() || strSecret.isNull())
|
if (strSecret.isEmpty() || strSecret.isNull())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_strSecret = strSecret;
|
m_strSecret = strSecret;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -173,75 +175,76 @@ void QJsonWebToken::setRandomSecret()
|
|||||||
|
|
||||||
QString QJsonWebToken::getAlgorithmStr() const
|
QString QJsonWebToken::getAlgorithmStr() const
|
||||||
{
|
{
|
||||||
return m_strAlgorithm;
|
return m_strAlgorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QJsonWebToken::setAlgorithmStr(const QString &strAlgorithm)
|
bool QJsonWebToken::setAlgorithmStr(const QString &strAlgorithm)
|
||||||
{
|
{
|
||||||
// check if supported algorithm
|
// check if supported algorithm
|
||||||
if (!isAlgorithmSupported(strAlgorithm))
|
if (!isAlgorithmSupported(strAlgorithm))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// set algorithm
|
// set algorithm
|
||||||
m_strAlgorithm = strAlgorithm;
|
m_strAlgorithm = strAlgorithm;
|
||||||
// modify header
|
// modify header
|
||||||
m_jdocHeader = QJsonDocument::fromJson(QObject::trUtf8("{\"typ\": \"JWT\", \"alg\" : \"").toUtf8()
|
m_jdocHeader = QJsonDocument::fromJson(QObject::trUtf8("{\"typ\": \"JWT\", \"alg\" : \"").toUtf8()
|
||||||
+ m_strAlgorithm.toUtf8()
|
+ m_strAlgorithm.toUtf8()
|
||||||
+ QObject::trUtf8("\"}").toUtf8());
|
+ QObject::trUtf8("\"}").toUtf8());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QJsonWebToken::getToken()
|
QString QJsonWebToken::getToken()
|
||||||
{
|
{
|
||||||
// important to execute first to update m_byteAllData which contains header + "." + payload in base64
|
// important to execute first to update m_byteAllData which contains header + "." + payload in base64
|
||||||
QByteArray byteSignatureBase64 = this->getSignatureBase64();
|
QByteArray byteSignatureBase64 = this->getSignatureBase64();
|
||||||
// compose token and return it
|
// compose token and return it
|
||||||
return m_byteAllData + "." + byteSignatureBase64;
|
return m_byteAllData + "." + byteSignatureBase64;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QJsonWebToken::setToken(const QString &strToken)
|
bool QJsonWebToken::setToken(const QString &strToken)
|
||||||
{
|
{
|
||||||
// assume base64 encoded at first, if not try decoding
|
// assume base64 encoded at first, if not try decoding
|
||||||
bool isBase64Encoded = true;
|
bool isBase64Encoded = true;
|
||||||
QStringList listJwtParts = strToken.split(".");
|
QStringList listJwtParts = strToken.split(".");
|
||||||
// check correct size
|
// check correct size
|
||||||
if (listJwtParts.count() != 3)
|
if (listJwtParts.count() != 3)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check all parts are valid using another instance,
|
// check all parts are valid using another instance,
|
||||||
// so we dont overwrite this instance in case of error
|
// so we dont overwrite this instance in case of error
|
||||||
QJsonWebToken tempTokenObj;
|
QJsonWebToken tempTokenObj;
|
||||||
if ( !tempTokenObj.setHeaderQStr(QByteArray::fromBase64(listJwtParts.at(0).toUtf8())) ||
|
if (!tempTokenObj.setHeaderQStr(QByteArray::fromBase64(listJwtParts.at(0).toUtf8())) ||
|
||||||
!tempTokenObj.setPayloadQStr(QByteArray::fromBase64(listJwtParts.at(1).toUtf8())) )
|
!tempTokenObj.setPayloadQStr(QByteArray::fromBase64(listJwtParts.at(1).toUtf8())))
|
||||||
{
|
{
|
||||||
// try unencoded
|
// try unencoded
|
||||||
if (!tempTokenObj.setHeaderQStr(listJwtParts.at(0)) ||
|
if (!tempTokenObj.setHeaderQStr(listJwtParts.at(0)) ||
|
||||||
!tempTokenObj.setPayloadQStr(listJwtParts.at(1)))
|
!tempTokenObj.setPayloadQStr(listJwtParts.at(1)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isBase64Encoded = false;
|
isBase64Encoded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set parts on this instance
|
// set parts on this instance
|
||||||
setHeaderQStr(tempTokenObj.getHeaderQStr());
|
setHeaderQStr(tempTokenObj.getHeaderQStr());
|
||||||
setPayloadQStr(tempTokenObj.getPayloadQStr());
|
setPayloadQStr(tempTokenObj.getPayloadQStr());
|
||||||
if (isBase64Encoded)
|
if (isBase64Encoded)
|
||||||
{ // unencode
|
{
|
||||||
m_byteSignature = QByteArray::fromBase64(listJwtParts.at(2).toUtf8());
|
// unencode
|
||||||
}
|
m_byteSignature = QByteArray::fromBase64(listJwtParts.at(2).toUtf8());
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
m_byteSignature = listJwtParts.at(2).toUtf8();
|
{
|
||||||
}
|
m_byteSignature = listJwtParts.at(2).toUtf8();
|
||||||
// allData not valid anymore
|
}
|
||||||
m_byteAllData.clear();
|
// allData not valid anymore
|
||||||
// success
|
m_byteAllData.clear();
|
||||||
|
// success
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +255,7 @@ QString QJsonWebToken::getRandAlphanum() const
|
|||||||
|
|
||||||
void QJsonWebToken::setRandAlphanum(const QString &strRandAlphanum)
|
void QJsonWebToken::setRandAlphanum(const QString &strRandAlphanum)
|
||||||
{
|
{
|
||||||
if(strRandAlphanum.isNull())
|
if (strRandAlphanum.isNull())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -264,9 +267,9 @@ int QJsonWebToken::getRandLength() const
|
|||||||
return m_intRandLength;
|
return m_intRandLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QJsonWebToken::setRandLength(const int &intRandLength)
|
void QJsonWebToken::setRandLength(int intRandLength)
|
||||||
{
|
{
|
||||||
if(intRandLength < 0 || intRandLength > 1e6)
|
if (intRandLength < 0 || intRandLength > 1e6)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -275,63 +278,63 @@ void QJsonWebToken::setRandLength(const int &intRandLength)
|
|||||||
|
|
||||||
bool QJsonWebToken::isValid() const
|
bool QJsonWebToken::isValid() const
|
||||||
{
|
{
|
||||||
// calculate token on other instance,
|
// calculate token on other instance,
|
||||||
// so we dont overwrite this instance's signature
|
// so we dont overwrite this instance's signature
|
||||||
QJsonWebToken tempTokenObj = *this;
|
QJsonWebToken tempTokenObj = *this;
|
||||||
if (m_byteSignature != tempTokenObj.getSignature())
|
if (m_byteSignature != tempTokenObj.getSignature())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonWebToken QJsonWebToken::fromTokenAndSecret(const QString &strToken, const QString &srtSecret)
|
QJsonWebToken QJsonWebToken::fromTokenAndSecret(const QString &strToken, const QString &srtSecret)
|
||||||
{
|
{
|
||||||
QJsonWebToken tempTokenObj;
|
QJsonWebToken tempTokenObj;
|
||||||
// set Token
|
// set Token
|
||||||
tempTokenObj.setToken(strToken);
|
tempTokenObj.setToken(strToken);
|
||||||
// set Secret
|
// set Secret
|
||||||
tempTokenObj.setSecret(srtSecret);
|
tempTokenObj.setSecret(srtSecret);
|
||||||
// return
|
// return
|
||||||
return tempTokenObj;
|
return tempTokenObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QJsonWebToken::appendClaim(const QString &strClaimType, const QString &strValue)
|
void QJsonWebToken::appendClaim(const QString &strClaimType, const QString &strValue)
|
||||||
{
|
{
|
||||||
// have to make a copy of the json object, modify the copy and then put it back, sigh
|
// have to make a copy of the json object, modify the copy and then put it back, sigh
|
||||||
QJsonObject jObj = m_jdocPayload.object();
|
QJsonObject jObj = m_jdocPayload.object();
|
||||||
jObj.insert(strClaimType, strValue);
|
jObj.insert(strClaimType, strValue);
|
||||||
m_jdocPayload = QJsonDocument(jObj);
|
m_jdocPayload = QJsonDocument(jObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QJsonWebToken::removeClaim(const QString &strClaimType)
|
void QJsonWebToken::removeClaim(const QString &strClaimType)
|
||||||
{
|
{
|
||||||
// have to make a copy of the json object, modify the copy and then put it back, sigh
|
// have to make a copy of the json object, modify the copy and then put it back, sigh
|
||||||
QJsonObject jObj = m_jdocPayload.object();
|
QJsonObject jObj = m_jdocPayload.object();
|
||||||
jObj.remove(strClaimType);
|
jObj.remove(strClaimType);
|
||||||
m_jdocPayload = QJsonDocument(jObj);
|
m_jdocPayload = QJsonDocument(jObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QJsonWebToken::isAlgorithmSupported(const QString &strAlgorithm)
|
bool QJsonWebToken::isAlgorithmSupported(const QString &strAlgorithm)
|
||||||
{
|
{
|
||||||
// TODO : support other algorithms
|
// TODO : support other algorithms
|
||||||
if (strAlgorithm.compare("HS256", Qt::CaseSensitive) != 0 && // HMAC using SHA-256 hash algorithm
|
if (strAlgorithm.compare("HS256", Qt::CaseSensitive) != 0 && // HMAC using SHA-256 hash algorithm
|
||||||
strAlgorithm.compare("HS384", Qt::CaseSensitive) != 0 && // HMAC using SHA-384 hash algorithm
|
strAlgorithm.compare("HS384", Qt::CaseSensitive) != 0 && // HMAC using SHA-384 hash algorithm
|
||||||
strAlgorithm.compare("HS512", Qt::CaseSensitive) != 0 /*&& // HMAC using SHA-512 hash algorithm
|
strAlgorithm.compare("HS512", Qt::CaseSensitive) != 0 /*&& // HMAC using SHA-512 hash algorithm
|
||||||
strAlgorithm.compare("RS256", Qt::CaseSensitive) != 0 && // RSA using SHA-256 hash algorithm
|
strAlgorithm.compare("RS256", Qt::CaseSensitive) != 0 && // RSA using SHA-256 hash algorithm
|
||||||
strAlgorithm.compare("RS384", Qt::CaseSensitive) != 0 && // RSA using SHA-384 hash algorithm
|
strAlgorithm.compare("RS384", Qt::CaseSensitive) != 0 && // RSA using SHA-384 hash algorithm
|
||||||
strAlgorithm.compare("RS512", Qt::CaseSensitive) != 0 && // RSA using SHA-512 hash algorithm
|
strAlgorithm.compare("RS512", Qt::CaseSensitive) != 0 && // RSA using SHA-512 hash algorithm
|
||||||
strAlgorithm.compare("ES256", Qt::CaseSensitive) != 0 && // ECDSA using P-256 curve and SHA-256 hash algorithm
|
strAlgorithm.compare("ES256", Qt::CaseSensitive) != 0 && // ECDSA using P-256 curve and SHA-256 hash algorithm
|
||||||
strAlgorithm.compare("ES384", Qt::CaseSensitive) != 0 && // ECDSA using P-384 curve and SHA-384 hash algorithm
|
strAlgorithm.compare("ES384", Qt::CaseSensitive) != 0 && // ECDSA using P-384 curve and SHA-384 hash algorithm
|
||||||
strAlgorithm.compare("ES512", Qt::CaseSensitive) != 0*/) // ECDSA using P-521 curve and SHA-512 hash algorithm
|
strAlgorithm.compare("ES512", Qt::CaseSensitive) != 0*/) // ECDSA using P-521 curve and SHA-512 hash algorithm
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QJsonWebToken::supportedAlgorithms()
|
QStringList QJsonWebToken::supportedAlgorithms()
|
||||||
{
|
{
|
||||||
// TODO : support other algorithms
|
// TODO : support other algorithms
|
||||||
return QStringList() << "HS256" << "HS384" << "HS512";
|
return QStringList() << "HS256" << "HS384" << "HS512";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ public:
|
|||||||
\sa QJsonWebToken::getRandLength()
|
\sa QJsonWebToken::getRandLength()
|
||||||
|
|
||||||
*/
|
*/
|
||||||
void setRandLength(const int &intRandLength);
|
void setRandLength(int intRandLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
@@ -397,8 +397,8 @@ private:
|
|||||||
QString m_strSecret;
|
QString m_strSecret;
|
||||||
QString m_strAlgorithm;
|
QString m_strAlgorithm;
|
||||||
|
|
||||||
int m_intRandLength ;
|
int m_intRandLength = 10;
|
||||||
QString m_strRandAlphanum;
|
QString m_strRandAlphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
QByteArray m_byteAllData;
|
QByteArray m_byteAllData;
|
||||||
|
|||||||
@@ -21,20 +21,19 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
namespace SampleProvider
|
namespace SampleProvider
|
||||||
{
|
{
|
||||||
CResourceSound::CResourceSound()
|
CResourceSound::CResourceSound() : m_data(new CResourceSoundData)
|
||||||
{
|
{
|
||||||
m_data = new CResourceSoundData;
|
// void
|
||||||
}
|
}
|
||||||
|
|
||||||
CResourceSound::CResourceSound(const QString &audioFileName)
|
CResourceSound::CResourceSound(const QString &audioFileName) : m_data(new CResourceSoundData)
|
||||||
{
|
{
|
||||||
m_data = new CResourceSoundData;
|
|
||||||
m_data->fileName = audioFileName;
|
m_data->fileName = audioFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CResourceSound::load()
|
bool CResourceSound::load()
|
||||||
{
|
{
|
||||||
if (m_data->fileName.isEmpty()) { return false; }
|
if (!m_data || m_data->fileName.isEmpty()) { return false; }
|
||||||
|
|
||||||
CWavFile wavFile;
|
CWavFile wavFile;
|
||||||
m_data->samples.clear();
|
m_data->samples.clear();
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ namespace BlackSound
|
|||||||
//! CResourceSound shared data
|
//! CResourceSound shared data
|
||||||
struct CResourceSoundData : public QSharedData
|
struct CResourceSoundData : public QSharedData
|
||||||
{
|
{
|
||||||
QString fileName; //!< file name
|
QString fileName; //!< file name
|
||||||
bool isLoaded = false; //!< is audio loaded
|
bool isLoaded = false; //!< is audio loaded
|
||||||
QVector<float> samples; //!< audio samples
|
QVector<float> samples; //!< audio samples
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user