diff options
Diffstat (limited to 'src/coap/qcoapprotocol.cpp')
-rw-r--r-- | src/coap/qcoapprotocol.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/coap/qcoapprotocol.cpp b/src/coap/qcoapprotocol.cpp index 46f420c..3a6f3ca 100644 --- a/src/coap/qcoapprotocol.cpp +++ b/src/coap/qcoapprotocol.cpp @@ -690,9 +690,7 @@ QCoapToken QCoapProtocolPrivate::generateUniqueToken() const // TODO: Store used token for the period specified by CoAP spec QCoapToken token; while (isTokenRegistered(token)) { - // TODO: Allow setting minimum token size as a security setting - quint8 length = static_cast<quint8>(QtCoap::randomGenerator().bounded(1, 8)); - + quint8 length = static_cast<quint8>(QtCoap::randomGenerator().bounded(minimumTokenSize, 9)); token.resize(length); quint8 *tokenData = reinterpret_cast<quint8 *>(token.data()); for (int i = 0; i < token.size(); ++i) @@ -1151,4 +1149,24 @@ void QCoapProtocol::setMaximumServerResponseDelay(uint responseDelay) d->maximumServerResponseDelay = responseDelay; } +/*! + \internal + + Sets the minimum token size to \a tokenSize in bytes. For security reasons it is + recommended to use tokens with a length of at least 4 bytes. The default value for + this parameter is 4 bytes. +*/ +void QCoapProtocol::setMinimumTokenSize(int tokenSize) +{ + Q_D(QCoapProtocol); + + if (tokenSize > 0 && tokenSize <= 8) { + d->minimumTokenSize = tokenSize; + } else { + qCWarning(lcCoapProtocol, + "Failed to set the minimum token size," + "it should not be more than 8 bytes and cannot be 0."); + } +} + QT_END_NAMESPACE |