mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
keeping Qt internally for a while and making RsTor Qt-free
This commit is contained in:
parent
d7fb3d8bf4
commit
f13b0cbe9f
@ -9,13 +9,18 @@ libretroshare_shared {
|
||||
} else {
|
||||
CONFIG += staticlib
|
||||
}
|
||||
CONFIG -= qt
|
||||
CONFIG += qt
|
||||
|
||||
QT += network
|
||||
|
||||
TARGET = retroshare
|
||||
TARGET_PRL = libretroshare
|
||||
DESTDIR = lib
|
||||
|
||||
!include("use_libretroshare.pri"):error("Including")
|
||||
|
||||
QMAKE_CXXFLAGS += -fPIC
|
||||
|
||||
# treat warnings as error for better removing
|
||||
#QMAKE_CFLAGS += -Werror
|
||||
#QMAKE_CXXFLAGS += -Werror
|
||||
@ -720,6 +725,8 @@ SOURCES += rsitems/rsnxsitems.cc \
|
||||
gxs/rsgxsrequesttypes.cc
|
||||
|
||||
# Tor
|
||||
HEADERS += retroshare/rstor.h
|
||||
|
||||
HEADERS += tor/AddOnionCommand.h \
|
||||
tor/AuthenticateCommand.h \
|
||||
tor/CryptoKey.h \
|
||||
|
@ -103,6 +103,9 @@ enum class RsEventType : uint32_t
|
||||
/// @see rspeers.h
|
||||
NETWORK = 16,
|
||||
|
||||
/// @see rspeers.h
|
||||
TOR_MANAGER = 17,
|
||||
|
||||
__MAX /// Used internally, keep last
|
||||
};
|
||||
|
||||
|
@ -34,7 +34,9 @@
|
||||
#define ADDONIONCOMMAND_H
|
||||
|
||||
#include "TorControlCommand.h"
|
||||
#include <list>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QVariant>
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
@ -43,28 +45,27 @@ class HiddenService;
|
||||
|
||||
class AddOnionCommand : public TorControlCommand
|
||||
{
|
||||
#ifdef NO_TOR_CONTROL_PROPERTIES
|
||||
Q_PROPERTY(std::string errorMessage READ errorMessage CONSTANT)
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(AddOnionCommand)
|
||||
|
||||
Q_PROPERTY(QString errorMessage READ errorMessage CONSTANT)
|
||||
Q_PROPERTY(bool successful READ isSuccessful CONSTANT)
|
||||
#endif
|
||||
|
||||
public:
|
||||
AddOnionCommand(HiddenService *service);
|
||||
|
||||
QByteArray build();
|
||||
|
||||
std::string errorMessage() const { return m_errorMessage; }
|
||||
QString errorMessage() const { return m_errorMessage; }
|
||||
bool isSuccessful() const;
|
||||
|
||||
#ifdef NO_TOR_CONTROL_SIGNALS
|
||||
signals:
|
||||
void succeeded();
|
||||
void failed(int code);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
HiddenService *m_service;
|
||||
std::string m_errorMessage;
|
||||
QString m_errorMessage;
|
||||
|
||||
virtual void onReply(int statusCode, const QByteArray &data);
|
||||
virtual void onFinished(int statusCode);
|
||||
|
@ -31,13 +31,13 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "CryptoKey.h"
|
||||
#include "SecureRNG.h"
|
||||
#include "Useful.h"
|
||||
#include "TorTypes.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QFile>
|
||||
#include <QByteArray>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/pem.h>
|
||||
@ -120,23 +120,17 @@ bool CryptoKey::loadFromData(const QByteArray &data, KeyType type, KeyFormat for
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CryptoKey::loadFromFile(const std::string &path)
|
||||
bool CryptoKey::loadFromFile(const QString& path)
|
||||
{
|
||||
FILE *f = fopen(path.c_str(),"r");
|
||||
|
||||
if(!f)
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
std::cerr << "Failed to open Tor key file " << path << std::endl;
|
||||
qWarning() << "Failed to open Tor key file " << path << ": " << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
Tor::TorByteArray data ;
|
||||
int c;
|
||||
|
||||
while( EOF != (c=fgetc(f)))
|
||||
data += (unsigned char)c;
|
||||
|
||||
fclose(f);
|
||||
QByteArray data = file.readAll();
|
||||
file.close();
|
||||
|
||||
if(data.contains("-----BEGIN RSA PRIVATE KEY-----"))
|
||||
{
|
||||
@ -152,14 +146,14 @@ bool CryptoKey::loadFromFile(const std::string &path)
|
||||
}
|
||||
|
||||
std::cerr << "Have read the following key: " << std::endl;
|
||||
std::cerr << data.toStdString() << std::endl;
|
||||
std::cerr << QString(data).toStdString() << std::endl;
|
||||
|
||||
key_data = data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CryptoKey::loadFromTorMessage(const Tor::TorByteArray& b)
|
||||
bool CryptoKey::loadFromTorMessage(const QByteArray& b)
|
||||
{
|
||||
// note: We should probably check the structure a bit more, for security.
|
||||
|
||||
@ -169,7 +163,7 @@ bool CryptoKey::loadFromTorMessage(const Tor::TorByteArray& b)
|
||||
std::cerr << " type: RSA-1024 (Tor v2)" << std::endl;
|
||||
else if(b.startsWith("ED25519-V3"))
|
||||
std::cerr << " type: ED25519-V3 (Tor v3)" << std::endl;
|
||||
else if(b.indexOf(':') >= 0)
|
||||
else if(b.indexOf(':'))
|
||||
{
|
||||
std::cerr << " unknown type, or bad syntax in key: \"" << b.left(b.indexOf(':')).toStdString() << "\". Not accepted." << std::endl;
|
||||
return false;
|
||||
@ -180,22 +174,22 @@ bool CryptoKey::loadFromTorMessage(const Tor::TorByteArray& b)
|
||||
}
|
||||
|
||||
/* Cryptographic hash of a password as expected by Tor's HashedControlPassword */
|
||||
Tor::TorByteArray torControlHashedPassword(const Tor::TorByteArray& password)
|
||||
QByteArray torControlHashedPassword(const QByteArray &password)
|
||||
{
|
||||
Tor::TorByteArray salt = SecureRNG::random(8);
|
||||
QByteArray salt = SecureRNG::random(8);
|
||||
if (salt.isNull())
|
||||
return Tor::TorByteArray();
|
||||
return QByteArray();
|
||||
|
||||
int count = ((quint32)16 + (96 & 15)) << ((96 >> 4) + 6);
|
||||
|
||||
SHA_CTX hash;
|
||||
SHA1_Init(&hash);
|
||||
|
||||
Tor::TorByteArray tmp = salt + password;
|
||||
QByteArray tmp = salt + password;
|
||||
while (count)
|
||||
{
|
||||
int c = std::min(count, tmp.size());
|
||||
SHA1_Update(&hash, reinterpret_cast<const void*>(tmp.data()), c);
|
||||
int c = qMin(count, tmp.size());
|
||||
SHA1_Update(&hash, reinterpret_cast<const void*>(tmp.constData()), c);
|
||||
count -= c;
|
||||
}
|
||||
|
||||
@ -203,8 +197,8 @@ Tor::TorByteArray torControlHashedPassword(const Tor::TorByteArray& password)
|
||||
SHA1_Final(md, &hash);
|
||||
|
||||
/* 60 is the hex-encoded value of 96, which is a constant used by Tor's algorithm. */
|
||||
return Tor::TorByteArray("16:") + salt.toHex().toUpper() + Tor::TorByteArray("60") +
|
||||
Tor::TorByteArray::fromRawData(reinterpret_cast<const char*>(md), 20).toHex().toUpper();
|
||||
return QByteArray("16:") + salt.toHex().toUpper() + QByteArray("60") +
|
||||
QByteArray::fromRawData(reinterpret_cast<const char*>(md), 20).toHex().toUpper();
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,7 +33,9 @@
|
||||
#ifndef CRYPTOKEY_H
|
||||
#define CRYPTOKEY_H
|
||||
|
||||
#include "tor/TorTypes.h"
|
||||
#include <QString>
|
||||
#include <QSharedData>
|
||||
#include <QExplicitlySharedDataPointer>
|
||||
|
||||
class CryptoKey
|
||||
{
|
||||
@ -55,13 +57,12 @@ public:
|
||||
bool loadFromData(const QByteArray &data, KeyType type, KeyFormat format = PEM);
|
||||
bool loadFromFile(const QString &path, KeyType type, KeyFormat format = PEM);
|
||||
#endif
|
||||
bool loadFromFile(const std::string& path);
|
||||
bool loadFromFile(const QString &path);
|
||||
void clear();
|
||||
|
||||
const Tor::TorByteArray& bytes() const { return key_data; }
|
||||
bool loadFromTorMessage(const Tor::TorByteArray& b);
|
||||
bool isLoaded() const { return !key_data.empty(); }
|
||||
|
||||
const QByteArray bytes() const { return key_data; }
|
||||
bool loadFromTorMessage(const QByteArray& b);
|
||||
bool isLoaded() const { return !key_data.isNull(); }
|
||||
#ifdef TO_REMOVE
|
||||
bool isPrivate() const;
|
||||
|
||||
@ -100,6 +101,6 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
Tor::TorByteArray torControlHashedPassword(const Tor::TorByteArray& password);
|
||||
QByteArray torControlHashedPassword(const QByteArray &password);
|
||||
|
||||
#endif // CRYPTOKEY_H
|
||||
|
@ -30,11 +30,9 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "TorTypes.h"
|
||||
#include "GetConfCommand.h"
|
||||
#include "StrUtil.h"
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Tor;
|
||||
|
||||
@ -45,28 +43,27 @@ GetConfCommand::GetConfCommand(Type t)
|
||||
|
||||
QByteArray GetConfCommand::build(const QByteArray &key)
|
||||
{
|
||||
return build(std::list<QByteArray>{key});
|
||||
return build(QList<QByteArray>() << key);
|
||||
}
|
||||
|
||||
QByteArray GetConfCommand::build(const std::list<QByteArray> &keys)
|
||||
QByteArray GetConfCommand::build(const QList<QByteArray> &keys)
|
||||
{
|
||||
QByteArray out;
|
||||
if (type == GetConf) {
|
||||
out = QByteArray("GETCONF");
|
||||
out = "GETCONF";
|
||||
} else if (type == GetInfo) {
|
||||
out = QByteArray("GETINFO");
|
||||
out = "GETINFO";
|
||||
} else {
|
||||
throw std::runtime_error("Unsupported build type in GetConfCommand");
|
||||
Q_ASSERT(false);
|
||||
return out;
|
||||
}
|
||||
|
||||
for(const QByteArray& key: keys)
|
||||
{
|
||||
out += (' ');
|
||||
out += key;
|
||||
foreach (const QByteArray &key, keys) {
|
||||
out.append(' ');
|
||||
out.append(key);
|
||||
}
|
||||
|
||||
out += std::string("\r\n");
|
||||
out.append("\r\n");
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -77,7 +74,7 @@ void GetConfCommand::onReply(int statusCode, const QByteArray &data)
|
||||
return;
|
||||
|
||||
int kep = data.indexOf('=');
|
||||
std::string key = QString::fromLatin1(data.mid(0, kep));
|
||||
QString key = QString::fromLatin1(data.mid(0, kep));
|
||||
QVariant value;
|
||||
if (kep >= 0)
|
||||
value = QString::fromLatin1(unquotedString(data.mid(kep + 1)));
|
||||
|
@ -34,16 +34,18 @@
|
||||
#define GETCONFCOMMAND_H
|
||||
|
||||
#include "TorControlCommand.h"
|
||||
#include <list>
|
||||
#include <QList>
|
||||
#include <QVariantMap>
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
|
||||
class GetConfCommand : public TorControlCommand
|
||||
{
|
||||
#ifdef NO_TOR_CONTROL_PROPERTIES
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(GetConfCommand)
|
||||
|
||||
Q_PROPERTY(QVariantMap results READ results CONSTANT)
|
||||
#endif
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
@ -55,7 +57,7 @@ public:
|
||||
GetConfCommand(Type type);
|
||||
|
||||
QByteArray build(const QByteArray &key);
|
||||
QByteArray build(const std::list<QByteArray> &keys);
|
||||
QByteArray build(const QList<QByteArray> &keys);
|
||||
|
||||
const QVariantMap &results() const { return m_results; }
|
||||
QVariant get(const QByteArray &key) const;
|
||||
@ -67,7 +69,7 @@ protected:
|
||||
|
||||
private:
|
||||
QVariantMap m_results;
|
||||
std::string m_lastKey;
|
||||
QString m_lastKey;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ void HiddenService::addTarget(quint16 servicePort, QHostAddress targetAddress, q
|
||||
m_targets.append(t);
|
||||
}
|
||||
|
||||
void HiddenService::setServiceId(const TorByteArray &sid)
|
||||
void HiddenService::setServiceId(const QByteArray& sid)
|
||||
{
|
||||
m_service_id = sid;
|
||||
m_hostname = sid + ".onion";
|
||||
|
@ -33,25 +33,28 @@
|
||||
#ifndef HIDDENSERVICE_H
|
||||
#define HIDDENSERVICE_H
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include "tor/CryptoKey.h"
|
||||
#include "tor/TorTypes.h"
|
||||
#include <QObject>
|
||||
#include <QHostAddress>
|
||||
#include <QList>
|
||||
#include "CryptoKey.h"
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
|
||||
class TorSocket;
|
||||
|
||||
class HiddenService : public NonCopiable
|
||||
class HiddenService : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(HiddenService)
|
||||
|
||||
friend class TorControlPrivate;
|
||||
|
||||
public:
|
||||
struct Target
|
||||
{
|
||||
TorHostAddress targetAddress;
|
||||
unsigned short servicePort, targetPort;
|
||||
QHostAddress targetAddress;
|
||||
quint16 servicePort, targetPort;
|
||||
};
|
||||
|
||||
enum Status
|
||||
@ -61,25 +64,24 @@ public:
|
||||
Online /* Published */
|
||||
};
|
||||
|
||||
HiddenService();
|
||||
HiddenService(const std::string& dataPath);
|
||||
HiddenService(const CryptoKey& privateKey, const std::string& dataPath = std::string());
|
||||
HiddenService(QObject *parent = 0);
|
||||
HiddenService(const QString &dataPath, QObject *parent = 0);
|
||||
HiddenService(const CryptoKey &privateKey, const QString &dataPath = QString(), QObject *parent = 0);
|
||||
|
||||
Status status() const { return m_status; }
|
||||
|
||||
const std::string& hostname() const { return m_hostname; }
|
||||
const std::string serviceId() const { return std::string(m_service_id.data()); }
|
||||
const std::string& dataPath() const { return m_dataPath; }
|
||||
const QString& hostname() const { return m_hostname; }
|
||||
const QString serviceId() const { return QString(m_service_id); }
|
||||
const QString& dataPath() const { return m_dataPath; }
|
||||
|
||||
CryptoKey privateKey() { return m_privateKey; }
|
||||
void setPrivateKey(const CryptoKey &privateKey);
|
||||
void setServiceId(const TorByteArray& sid);
|
||||
void setServiceId(const QByteArray& sid);
|
||||
|
||||
const std::list<Target>& targets() const { return m_targets; }
|
||||
const QList<Target> &targets() const { return m_targets; }
|
||||
void addTarget(const Target &target);
|
||||
void addTarget(unsigned short servicePort, TorHostAddress targetAddress, unsigned short targetPort);
|
||||
void addTarget(quint16 servicePort, QHostAddress targetAddress, quint16 targetPort);
|
||||
|
||||
#ifdef NO_TOR_CONTROL_SIGNALS
|
||||
signals:
|
||||
void statusChanged(int newStatus, int oldStatus);
|
||||
void serviceOnline();
|
||||
@ -88,15 +90,14 @@ signals:
|
||||
|
||||
private slots:
|
||||
void servicePublished();
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::string m_dataPath;
|
||||
std::list<Target> m_targets;
|
||||
std::string m_hostname;
|
||||
QString m_dataPath;
|
||||
QList<Target> m_targets;
|
||||
QString m_hostname;
|
||||
Status m_status;
|
||||
CryptoKey m_privateKey;
|
||||
TorByteArray m_service_id;
|
||||
QByteArray m_service_id;
|
||||
|
||||
void loadPrivateKey();
|
||||
void setStatus(Status newStatus);
|
||||
|
@ -33,17 +33,8 @@
|
||||
#ifndef PROTOCOLINFOCOMMAND_H
|
||||
#define PROTOCOLINFOCOMMAND_H
|
||||
|
||||
#include <retroshare/rsflags.h>
|
||||
#include "TorControlCommand.h"
|
||||
|
||||
enum class AuthMethods: uint8_t
|
||||
{
|
||||
AuthUnknown = 0x0,
|
||||
AuthNull = 0x1,
|
||||
AuthHashedPassword = 0x2,
|
||||
AuthCookie = 0x4
|
||||
};
|
||||
RS_REGISTER_ENUM_FLAGS_TYPE(AuthMethods)
|
||||
#include <QFlags>
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
@ -52,13 +43,25 @@ class TorControl;
|
||||
|
||||
class ProtocolInfoCommand : public TorControlCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ProtocolInfoCommand)
|
||||
|
||||
public:
|
||||
enum AuthMethod
|
||||
{
|
||||
AuthUnknown = 0,
|
||||
AuthNull = 0x1,
|
||||
AuthHashedPassword = 0x2,
|
||||
AuthCookie = 0x4
|
||||
};
|
||||
Q_DECLARE_FLAGS(AuthMethods, AuthMethod)
|
||||
|
||||
ProtocolInfoCommand(TorControl *manager);
|
||||
QByteArray build();
|
||||
|
||||
AuthMethods authMethods() const { return m_authMethods; }
|
||||
std::string torVersion() const { return m_torVersion; }
|
||||
std::string cookieFile() const { return m_cookieFile; }
|
||||
QString torVersion() const { return m_torVersion; }
|
||||
QString cookieFile() const { return m_cookieFile; }
|
||||
|
||||
protected:
|
||||
virtual void onReply(int statusCode, const QByteArray &data);
|
||||
@ -66,8 +69,8 @@ protected:
|
||||
private:
|
||||
TorControl *manager;
|
||||
AuthMethods m_authMethods;
|
||||
std::string m_torVersion;
|
||||
std::string m_cookieFile;
|
||||
QString m_torVersion;
|
||||
QString m_cookieFile;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -31,12 +31,10 @@
|
||||
*/
|
||||
|
||||
#include "SecureRNG.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
#include <limits.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <wtypes.h>
|
||||
@ -84,7 +82,7 @@ bool SecureRNG::seed()
|
||||
#else
|
||||
if (!RAND_poll())
|
||||
{
|
||||
std::cerr << "OpenSSL RNG seed failed:" << ERR_get_error();
|
||||
qWarning() << "OpenSSL RNG seed failed:" << ERR_get_error();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@ -96,16 +94,11 @@ bool SecureRNG::seed()
|
||||
return true;
|
||||
}
|
||||
|
||||
void SecureRNG::random(unsigned char *buf, int size)
|
||||
void SecureRNG::random(char *buf, int size)
|
||||
{
|
||||
int r = RAND_bytes(buf, size);
|
||||
|
||||
int r = RAND_bytes(reinterpret_cast<unsigned char*>(buf), size);
|
||||
if (r <= 0)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "RNG failed: " << ERR_get_error() ;
|
||||
throw std::runtime_error(s.str());
|
||||
}
|
||||
qFatal("RNG failed: %lu", ERR_get_error());
|
||||
}
|
||||
|
||||
QByteArray SecureRNG::random(int size)
|
||||
@ -118,7 +111,7 @@ QByteArray SecureRNG::random(int size)
|
||||
QByteArray SecureRNG::randomPrintable(int length)
|
||||
{
|
||||
QByteArray re(length, 0);
|
||||
for (uint32_t i = 0; i < re.size(); i++)
|
||||
for (int i = 0; i < re.size(); i++)
|
||||
re[i] = randomInt(95) + 32;
|
||||
return re;
|
||||
}
|
||||
@ -130,24 +123,24 @@ unsigned SecureRNG::randomInt(unsigned max)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
random(reinterpret_cast<unsigned char*>(&value), sizeof(value));
|
||||
random(reinterpret_cast<char*>(&value), sizeof(value));
|
||||
if (value < cutoff)
|
||||
return value % max;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX ((uint64_t)-1)
|
||||
#define UINT64_MAX ((quint64)-1)
|
||||
#endif
|
||||
|
||||
uint64_t SecureRNG::randomInt64(uint64_t max)
|
||||
quint64 SecureRNG::randomInt64(quint64 max)
|
||||
{
|
||||
uint64_t cutoff = UINT64_MAX - (UINT64_MAX % max);
|
||||
uint64_t value = 0;
|
||||
quint64 cutoff = UINT64_MAX - (UINT64_MAX % max);
|
||||
quint64 value = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
random(reinterpret_cast<unsigned char*>(value), sizeof(value));
|
||||
random(reinterpret_cast<char*>(value), sizeof(value));
|
||||
if (value < cutoff)
|
||||
return value % max;
|
||||
}
|
||||
|
@ -33,19 +33,19 @@
|
||||
#ifndef SECURERNG_H
|
||||
#define SECURERNG_H
|
||||
|
||||
#include "TorTypes.h"
|
||||
#include <QByteArray>
|
||||
|
||||
class SecureRNG
|
||||
{
|
||||
public:
|
||||
static bool seed();
|
||||
|
||||
static void random(unsigned char *buf, int size);
|
||||
static Tor::TorByteArray random(int size);
|
||||
static void random(char *buf, int size);
|
||||
static QByteArray random(int size);
|
||||
|
||||
static Tor::TorByteArray randomPrintable(int length);
|
||||
static QByteArray randomPrintable(int length);
|
||||
static unsigned randomInt(unsigned max);
|
||||
static uint64_t randomInt64(uint64_t max);
|
||||
static quint64 randomInt64(quint64 max);
|
||||
};
|
||||
|
||||
#endif // SECURERNG_H
|
||||
|
@ -37,9 +37,9 @@ QByteArray quotedString(const QByteArray& string)
|
||||
QByteArray out;
|
||||
out.reserve(string.size() * 2);
|
||||
|
||||
out += '"';
|
||||
out.append('"');
|
||||
|
||||
for (uint32_t i = 0; i < string.size(); ++i)
|
||||
for (int i = 0; i < string.size(); ++i)
|
||||
{
|
||||
switch (string[i])
|
||||
{
|
||||
@ -67,7 +67,7 @@ QByteArray unquotedString(const QByteArray &string)
|
||||
QByteArray out;
|
||||
out.reserve(string.size() - 2);
|
||||
|
||||
for (uint32_t i = 1; i < string.size(); ++i)
|
||||
for (int i = 1; i < string.size(); ++i)
|
||||
{
|
||||
switch (string[i])
|
||||
{
|
||||
@ -85,9 +85,9 @@ QByteArray unquotedString(const QByteArray &string)
|
||||
return out;
|
||||
}
|
||||
|
||||
std::list<QByteArray> splitQuotedStrings(const QByteArray &input, char separator)
|
||||
QList<QByteArray> splitQuotedStrings(const QByteArray &input, char separator)
|
||||
{
|
||||
std::list<QByteArray> out;
|
||||
QList<QByteArray> out;
|
||||
bool inquote = false;
|
||||
int start = 0;
|
||||
|
||||
|
@ -33,14 +33,14 @@
|
||||
#ifndef STRINGUTIL_H
|
||||
#define STRINGUTIL_H
|
||||
|
||||
#include "TorTypes.h"
|
||||
#include <list>
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
|
||||
QByteArray quotedString(const QByteArray &string);
|
||||
|
||||
/* Return the unquoted contents of a string, either until an end quote or an unescaped separator character. */
|
||||
QByteArray unquotedString(const QByteArray &string);
|
||||
|
||||
std::list<QByteArray> splitQuotedStrings(const QByteArray &input, char separator);
|
||||
QList<QByteArray> splitQuotedStrings(const QByteArray &input, char separator);
|
||||
|
||||
#endif // STRINGUTIL_H
|
||||
|
@ -33,31 +33,32 @@
|
||||
#ifndef TORCONTROLCOMMAND_H
|
||||
#define TORCONTROLCOMMAND_H
|
||||
|
||||
#include <vector>
|
||||
#include "tor/TorTypes.h"
|
||||
#include <QObject>
|
||||
#include <QByteArray>
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
class TorControlCommand : public NonCopiable
|
||||
|
||||
class TorControlCommand : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(TorControlCommand)
|
||||
|
||||
friend class TorControlSocket;
|
||||
|
||||
public:
|
||||
TorControlCommand();
|
||||
virtual ~TorControlCommand() {}
|
||||
|
||||
int statusCode() const { return m_finalStatus; }
|
||||
|
||||
#ifdef NO_TOR_CONTROL_SIGNALS
|
||||
signals:
|
||||
void replyLine(int statusCode, const TorByteArray& data);
|
||||
void replyLine(int statusCode, const QByteArray &data);
|
||||
void finished();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void onReply(int statusCode, const TorByteArray& data);
|
||||
virtual void onReply(int statusCode, const QByteArray &data);
|
||||
virtual void onFinished(int statusCode);
|
||||
virtual void onDataLine(const TorByteArray& data);
|
||||
virtual void onDataLine(const QByteArray &data);
|
||||
virtual void onDataFinished();
|
||||
|
||||
private:
|
||||
|
@ -118,11 +118,6 @@ TorProcess *TorManager::process()
|
||||
return d->process;
|
||||
}
|
||||
|
||||
bool TorManager::isTorAvailable()
|
||||
{
|
||||
return !instance()->d->torExecutablePath().isNull();
|
||||
}
|
||||
|
||||
QString TorManager::torDataDirectory() const
|
||||
{
|
||||
return d->dataDir;
|
||||
@ -524,3 +519,47 @@ void TorManagerPrivate::setError(const QString &message)
|
||||
|
||||
#include "TorManager.moc"
|
||||
|
||||
bool RsTor::isTorAvailable()
|
||||
{
|
||||
return !instance()->d->torExecutablePath().isNull();
|
||||
}
|
||||
|
||||
bool RsTor::getHiddenServiceInfo(std::string& service_id,
|
||||
std::string& service_onion_address,
|
||||
uint16_t& service_port,
|
||||
std::string& service_target_address,
|
||||
uint16_t& target_port)
|
||||
{
|
||||
QString sid;
|
||||
QString soa;
|
||||
QHostAddress sta;
|
||||
|
||||
if(!instance()->getHiddenServiceInfo(sid,soa,service_port,sta,target_port))
|
||||
return false;
|
||||
|
||||
service_id = sid.toStdString();
|
||||
service_onion_address = soa.toStdString();
|
||||
service_target_address = sta.toString().toStdString();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::list<std::string> RsTor::logMessages()
|
||||
{
|
||||
QStringList qs = instance()->logMessages();
|
||||
|
||||
std::list<std::string> s;
|
||||
for(auto& ss:qs)
|
||||
s.push_back(ss.toStdString());
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string RsTor::socksAddress()
|
||||
{
|
||||
return instance()->control()->socksAddress().toString().toStdString();
|
||||
}
|
||||
uint16_t RsTor::socksPort()
|
||||
{
|
||||
return instance()->control()->socksPort();
|
||||
}
|
||||
|
@ -35,6 +35,8 @@
|
||||
#ifndef TORMANAGER_H
|
||||
#define TORMANAGER_H
|
||||
|
||||
#include "retroshare/rstor.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QHostAddress>
|
||||
@ -48,7 +50,8 @@ class TorManagerPrivate;
|
||||
|
||||
/* Run/connect to an instance of Tor according to configuration, and manage
|
||||
* UI interaction, first time configuration, etc. */
|
||||
class TorManager : public QObject
|
||||
|
||||
class TorManager : public QObject, public RsTor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -61,7 +64,6 @@ class TorManager : public QObject
|
||||
Q_PROPERTY(QString torDataDirectory READ torDataDirectory WRITE setTorDataDirectory)
|
||||
|
||||
public:
|
||||
static bool isTorAvailable() ;
|
||||
static TorManager *instance();
|
||||
|
||||
TorProcess *process();
|
||||
@ -103,6 +105,7 @@ signals:
|
||||
private:
|
||||
explicit TorManager(QObject *parent = 0);
|
||||
TorManagerPrivate *d;
|
||||
friend class RsTor;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
@ -18,7 +20,13 @@ private:
|
||||
class TorByteArray: public std::vector<unsigned char>
|
||||
{
|
||||
public:
|
||||
TorByteArray(const std::string& s = std::string())
|
||||
TorByteArray(const unsigned char *data,uint32_t len)
|
||||
{
|
||||
clear();
|
||||
for(uint32_t i=0;i<len;++i)
|
||||
push_back(data[i]);
|
||||
}
|
||||
explicit TorByteArray(const std::string& s)
|
||||
{
|
||||
clear();
|
||||
for(uint32_t i=0;i<s.length();++i)
|
||||
@ -29,13 +37,14 @@ public:
|
||||
clear();
|
||||
resize(s,c);
|
||||
}
|
||||
TorByteArray() { clear() ; }
|
||||
|
||||
bool startsWith(const std::string& s) const
|
||||
bool startsWith(const TorByteArray& s) const
|
||||
{
|
||||
if(s.length() > size())
|
||||
if(s.size() > size())
|
||||
return false;
|
||||
|
||||
for(uint32_t i=0;i<s.length();++i)
|
||||
for(uint32_t i=0;i<s.size();++i)
|
||||
if(s[i] != data()[i])
|
||||
return false;
|
||||
|
||||
@ -68,7 +77,7 @@ public:
|
||||
push_back(t.data()[i]);
|
||||
return *this;
|
||||
}
|
||||
const TorByteArray& append(const std::string& s) { return operator+=(s); }
|
||||
const TorByteArray& append(const std::string& s) { return operator+=(TorByteArray(s)); }
|
||||
const TorByteArray& append(char s) { return operator+=(s); }
|
||||
|
||||
TorByteArray operator+(const TorByteArray& t) const
|
||||
@ -105,8 +114,29 @@ public:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
TorByteArray mid(uint32_t start,int length=-1) const
|
||||
{
|
||||
if(length==-1)
|
||||
return TorByteArray(data()+start,size()-start);
|
||||
|
||||
if(length < 0 || start + length > size())
|
||||
throw std::runtime_error("Length out of range in TorByteArray::mid()");
|
||||
|
||||
TorByteArray b;
|
||||
for(uint32_t i=0;i<(uint32_t)length;++i)
|
||||
b.push_back(data()[i+start]);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static TorByteArray number(uint64_t n)
|
||||
{
|
||||
std::ostringstream o;
|
||||
o << n ;
|
||||
return TorByteArray(o.str());
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::string TorHostAddress;
|
||||
}
|
||||
typedef Tor::TorByteArray QByteArray; // to be removed
|
||||
|
@ -33,15 +33,15 @@
|
||||
|
||||
#include <rshare.h>
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "TorControl/TorManager.h"
|
||||
#include "util/misc.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include <retroshare/rsinit.h>
|
||||
#include <retroshare/rsnotify.h>
|
||||
#include <rsserver/rsaccounts.h>
|
||||
#include <util/rsrandom.h>
|
||||
#include "retroshare/rstor.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "retroshare/rsnotify.h"
|
||||
#include "rsserver/rsaccounts.h"
|
||||
#include "util/rsrandom.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
@ -66,7 +66,7 @@ CrashStackTrace gCrashStackTrace;
|
||||
# include "gui/settings/JsonApiPage.h"
|
||||
#endif // RS_JSONAPI
|
||||
|
||||
#include "TorControl/TorManager.h"
|
||||
#include "retroshare/rstor.h"
|
||||
#include "TorControl/TorControlWindow.h"
|
||||
|
||||
#include "retroshare/rsidentity.h"
|
||||
|
Loading…
Reference in New Issue
Block a user