diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 559c77354..4811fa2d6 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -9,9 +9,6 @@ libretroshare_shared { } else { CONFIG += staticlib } -CONFIG += qt - -QT += network TARGET = retroshare TARGET_PRL = libretroshare @@ -732,7 +729,6 @@ HEADERS += tor/AddOnionCommand.h \ tor/HiddenService.h \ tor/PendingOperation.h \ tor/ProtocolInfoCommand.h \ - tor/SecureRNG.h \ tor/TorTypes.h \ tor/SetConfCommand.h \ tor/StrUtil.h \ @@ -757,7 +753,6 @@ SOURCES += tor/AddOnionCommand.cpp \ tor/TorProcess.cpp \ tor/CryptoKey.cpp \ tor/PendingOperation.cpp \ - tor/SecureRNG.cpp \ tor/StrUtil.cpp # gxs tunnels diff --git a/libretroshare/src/pqi/rstcpsocket.h b/libretroshare/src/pqi/rstcpsocket.h index b268d685c..0099189ba 100644 --- a/libretroshare/src/pqi/rstcpsocket.h +++ b/libretroshare/src/pqi/rstcpsocket.h @@ -7,7 +7,7 @@ class RsTcpSocket: public RsFdBinInterface public: RsTcpSocket(const std::string& tcp_address,uint16_t tcp_port); RsTcpSocket(); - virtual ~RsTcpSocket(); + virtual ~RsTcpSocket()=default; enum State: uint8_t { UNKNOWN = 0x00, diff --git a/libretroshare/src/tor/CryptoKey.cpp b/libretroshare/src/tor/CryptoKey.cpp index 2dd151bad..a914b03aa 100644 --- a/libretroshare/src/tor/CryptoKey.cpp +++ b/libretroshare/src/tor/CryptoKey.cpp @@ -33,7 +33,6 @@ #include #include "CryptoKey.h" -#include "SecureRNG.h" #include "Useful.h" #include @@ -134,7 +133,7 @@ ByteArray torControlHashedPassword(const ByteArray &password) ByteArray salt(8); RsRandom::random_bytes(&salt[0],8); - uint32_t count = ((quint32)16 + (96 & 15)) << ((96 >> 4) + 6); + uint32_t count = ((uint32_t)16 + (96 & 15)) << ((96 >> 4) + 6); Sha1CheckSum md = RsDirUtil::sha1sum((salt+password).data(),count); diff --git a/libretroshare/src/tor/HiddenService.h b/libretroshare/src/tor/HiddenService.h index ae77d51ed..0f4f50dbf 100644 --- a/libretroshare/src/tor/HiddenService.h +++ b/libretroshare/src/tor/HiddenService.h @@ -30,8 +30,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HIDDENSERVICE_H -#define HIDDENSERVICE_H +#pragma once #include "CryptoKey.h" #include "bytearray.h" @@ -109,5 +108,3 @@ private: }; } - -#endif // HIDDENSERVICE_H diff --git a/libretroshare/src/tor/SecureRNG.cpp b/libretroshare/src/tor/SecureRNG.cpp deleted file mode 100644 index 60cf3c048..000000000 --- a/libretroshare/src/tor/SecureRNG.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* Ricochet - https://ricochet.im/ - * Copyright (C) 2014, John Brooks - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * Neither the names of the copyright owners nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "SecureRNG.h" -#include -#include -#include -#include - -#ifdef Q_OS_WIN -#include -#include -#endif - -#if QT_VERSION >= 0x040700 -#include -#endif - -bool SecureRNG::seed() -{ -#if QT_VERSION >= 0x040700 - QElapsedTimer timer; - timer.start(); -#endif - -#ifdef Q_OS_WIN - /* RAND_poll is very unreliable on windows; with older versions of OpenSSL, - * it can take up to several minutes to run and has been known to crash. - * Even newer versions seem to take around 400ms, which is far too long for - * interactive startup. Random data from the windows CSP is used as a seed - * instead, as it should be very high quality random and fast. */ - HCRYPTPROV provider = 0; - if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) - { - qWarning() << "Failed to acquire CSP context for RNG seed:" << hex << GetLastError(); - return false; - } - - /* Same amount of entropy OpenSSL uses, apparently. */ - char buf[32]; - - if (!CryptGenRandom(provider, sizeof(buf), reinterpret_cast(buf))) - { - qWarning() << "Failed to get entropy from CSP for RNG seed: " << hex << GetLastError(); - CryptReleaseContext(provider, 0); - return false; - } - - CryptReleaseContext(provider, 0); - - RAND_seed(buf, sizeof(buf)); - memset(buf, 0, sizeof(buf)); -#else - if (!RAND_poll()) - { - qWarning() << "OpenSSL RNG seed failed:" << ERR_get_error(); - return false; - } -#endif - -#if QT_VERSION >= 0x040700 - qDebug() << "RNG seed took" << timer.elapsed() << "ms"; -#endif - - return true; -} - -void SecureRNG::random(char *buf, int size) -{ - int r = RAND_bytes(reinterpret_cast(buf), size); - if (r <= 0) - qFatal("RNG failed: %lu", ERR_get_error()); -} - -QByteArray SecureRNG::random(int size) -{ - QByteArray re(size, 0); - random(re.data(), size); - return re; -} - -QByteArray SecureRNG::randomPrintable(int length) -{ - QByteArray re(length, 0); - for (int i = 0; i < re.size(); i++) - re[i] = randomInt(95) + 32; - return re; -} - -unsigned SecureRNG::randomInt(unsigned max) -{ - unsigned cutoff = UINT_MAX - (UINT_MAX % max); - unsigned value = 0; - - for (;;) - { - random(reinterpret_cast(&value), sizeof(value)); - if (value < cutoff) - return value % max; - } -} - -#ifndef UINT64_MAX -#define UINT64_MAX ((quint64)-1) -#endif - -quint64 SecureRNG::randomInt64(quint64 max) -{ - quint64 cutoff = UINT64_MAX - (UINT64_MAX % max); - quint64 value = 0; - - for (;;) - { - random(reinterpret_cast(value), sizeof(value)); - if (value < cutoff) - return value % max; - } -} diff --git a/libretroshare/src/tor/SecureRNG.h b/libretroshare/src/tor/SecureRNG.h deleted file mode 100644 index f3b2a4b64..000000000 --- a/libretroshare/src/tor/SecureRNG.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Ricochet - https://ricochet.im/ - * Copyright (C) 2014, John Brooks - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * Neither the names of the copyright owners nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SECURERNG_H -#define SECURERNG_H - -#include - -class SecureRNG -{ -public: - static bool seed(); - - static void random(char *buf, int size); - static QByteArray random(int size); - - static QByteArray randomPrintable(int length); - static unsigned randomInt(unsigned max); - static quint64 randomInt64(quint64 max); -}; - -#endif // SECURERNG_H diff --git a/libretroshare/src/tor/TorControl.cpp b/libretroshare/src/tor/TorControl.cpp index 1051a0abe..f858c92b8 100644 --- a/libretroshare/src/tor/TorControl.cpp +++ b/libretroshare/src/tor/TorControl.cpp @@ -874,5 +874,4 @@ bool TorControl::torVersionAsNewAs(const std::string& match) const return true; } -#include "TorControl.moc" diff --git a/libretroshare/src/tor/TorControl.h b/libretroshare/src/tor/TorControl.h index 5ffc1174f..2f4df85b9 100644 --- a/libretroshare/src/tor/TorControl.h +++ b/libretroshare/src/tor/TorControl.h @@ -30,8 +30,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TORCONTROL_H -#define TORCONTROL_H +#pragma once #include @@ -171,5 +170,3 @@ private: } extern Tor::TorControl *torControl; - -#endif // TORCONTROLMANAGER_H diff --git a/libretroshare/src/tor/TorControlSocket.cpp b/libretroshare/src/tor/TorControlSocket.cpp index 849ca4926..f2142e1d1 100644 --- a/libretroshare/src/tor/TorControlSocket.cpp +++ b/libretroshare/src/tor/TorControlSocket.cpp @@ -49,6 +49,10 @@ TorControlSocket::~TorControlSocket() clear(); } +void TorControlSocket::connectToHost(const std::string& tcp_address,uint16_t tcp_port) +{ + RsTcpSocket::connect(tcp_address,tcp_port); +} std::string TorControlSocket::peerAddress() const { if(connectionState() == State::CONNECTED) diff --git a/libretroshare/src/tor/TorControlSocket.h b/libretroshare/src/tor/TorControlSocket.h index 979d85fa5..779fd6da5 100644 --- a/libretroshare/src/tor/TorControlSocket.h +++ b/libretroshare/src/tor/TorControlSocket.h @@ -52,8 +52,6 @@ public: explicit TorControlSocket(TorControlSocketClient *client); virtual ~TorControlSocket(); - void connect(const std::string& tcp_address,uint16_t tcp_port); - std::string errorMessage() const { return m_errorMessage; } void connectToHost(const std::string& tcp_address,uint16_t tcp_port); diff --git a/libretroshare/src/tor/TorManager.cpp b/libretroshare/src/tor/TorManager.cpp index 289e8ec0c..e06dec02b 100644 --- a/libretroshare/src/tor/TorManager.cpp +++ b/libretroshare/src/tor/TorManager.cpp @@ -580,8 +580,6 @@ void TorManagerPrivate::setError(const std::string &message) //emit q->errorChanged(); } -#include "TorManager.moc" - bool RsTor::isTorAvailable() { return !instance()->d->torExecutablePath().empty(); diff --git a/libretroshare/src/tor/TorManager.h b/libretroshare/src/tor/TorManager.h index 100d55779..e146a6819 100644 --- a/libretroshare/src/tor/TorManager.h +++ b/libretroshare/src/tor/TorManager.h @@ -32,8 +32,7 @@ // This code has been further modified to fit Retroshare context. -#ifndef TORMANAGER_H -#define TORMANAGER_H +#pragma once #include "retroshare/rstor.h" #include "HiddenService.h" @@ -107,6 +106,3 @@ private: }; } - -#endif -# diff --git a/libretroshare/src/tor/TorProcess.cpp b/libretroshare/src/tor/TorProcess.cpp index 77f561063..e744f1268 100644 --- a/libretroshare/src/tor/TorProcess.cpp +++ b/libretroshare/src/tor/TorProcess.cpp @@ -40,7 +40,6 @@ #include "TorProcess.h" #include "CryptoKey.h" -#include "SecureRNG.h" using namespace Tor; diff --git a/libretroshare/src/tor/Useful.h b/libretroshare/src/tor/Useful.h index 6bb6e44c1..cdead13e7 100644 --- a/libretroshare/src/tor/Useful.h +++ b/libretroshare/src/tor/Useful.h @@ -30,11 +30,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef UTILS_USEFUL_H -#define UTILS_USEFUL_H +#pragma once -#include -#include +#include "util/rsdebug.h" /* Print a warning for bug conditions, and assert on a debug build. * @@ -50,7 +48,7 @@ * triggered unless the code or logic is wrong. */ #if !defined(QT_NO_DEBUG) || defined(QT_FORCE_ASSERTS) -# define BUG() Explode(__FILE__,__LINE__), qWarning() << "BUG:" +# define BUG() Explode(__FILE__,__LINE__), RsWarn() << "BUG:" namespace { class Explode { @@ -59,13 +57,10 @@ public: int line; Explode(const char *file, int line) : file(file), line(line) { } ~Explode() { - qt_assert("something broke!", file, line); + RsErr() << "something broke! in file " << file << line; } }; } #else # define BUG() qWarning() << "BUG:" #endif - -#endif -