fixed a few bugs in new TorManager

This commit is contained in:
csoler 2021-12-09 22:19:00 +01:00
parent a757419d65
commit 7c77cfd603
7 changed files with 23 additions and 15 deletions

View File

@ -82,7 +82,7 @@ bool CryptoKey::loadFromFile(const std::string& path)
ByteArray data ;
int c;
while(EOF != (c=fgetc(file)))
data.append((unsigned char)c);
data.push_back((unsigned char)c);
fclose(file);

View File

@ -58,7 +58,7 @@ ByteArray GetConfCommand::build(const std::list<std::string> &keys)
}
for(const ByteArray &key: keys) {
out.append(' ');
out.push_back(' ');
out.append(key);
}

View File

@ -37,7 +37,7 @@ ByteArray quotedString(const ByteArray &string)
ByteArray out;
out.reserve(string.size() * 2);
out.append('"');
out.push_back('"');
for (uint i = 0; i < string.size(); ++i)
{
@ -50,12 +50,12 @@ ByteArray quotedString(const ByteArray &string)
out.append("\\\\");
break;
default:
out.append(string[i]);
out.push_back(string[i]);
break;
}
}
out.append('"');
out.push_back('"');
return out;
}
@ -73,12 +73,12 @@ ByteArray unquotedString(const ByteArray& string)
{
case '\\':
if (++i < string.size())
out.append(string[i]);
out.push_back(string[i]);
break;
case '"':
return out;
default:
out.append(string[i]);
out.push_back(string[i]);
}
}

View File

@ -168,13 +168,14 @@ bool TorManager::setupHiddenService()
}
std::cerr << "Using legacy dir: " << legacyDir << std::endl;
auto key_path = RsDirUtil::makePath(legacyDir,"/private_key");
if (!legacyDir.empty() && RsDirUtil::fileExists(RsDirUtil::makePath(legacyDir,"/private_key")))
if (!legacyDir.empty() && RsDirUtil::fileExists(key_path))
{
std::cerr << "Attempting to load key from legacy filesystem format in " << legacyDir << std::endl;
std::cerr << "Attempting to load key from legacy filesystem format from file \"" << key_path << "\"" << std::endl;
CryptoKey key;
if (!key.loadFromFile(RsDirUtil::makePath(legacyDir , "/private_key")))
if (!key.loadFromFile(key_path))
{
RsWarn() << "Cannot load legacy format key from" << legacyDir << "for conversion";
return false;

View File

@ -46,9 +46,10 @@ using namespace Tor;
static const int INTERVAL_BETWEEN_CONTROL_PORT_READ_TRIES = 5; // try every 5 secs.
TorProcess::TorProcess(TorProcessClient *client)
: m_client(client), mLastTryReadControlPort(0)
: m_client(client), mState(TorProcess::NotStarted), mControlPort(0), mLastTryReadControlPort(0)
{
mControlPortReadNbTries=0;
}
TorProcess::~TorProcess()

View File

@ -32,6 +32,8 @@ public:
void append(const ByteArray& b) { for(auto c:b) push_back(c); }
void append(const char *b) { for(uint32_t n=0;b[n]!=0;++n) push_back(b[n]); }
template<class T> void append(const T) = delete;// Prevents any implicit when calling the preceding functions which actually causes real bugs.
ByteArray& operator+=(const ByteArray& b) { for(auto c:b) push_back(c); return *this; }
ByteArray& operator+=(const char *b) { for(uint32_t n=0;b[n]!=0;++n) push_back(b[n]); return *this;}

View File

@ -139,8 +139,12 @@ double RsRandom::random_f64()
/*static*/ std::string RsRandom::printable(uint32_t length)
{
std::string ret(length, 0);
random_bytes(reinterpret_cast<uint8_t*>(&ret[0]), length);
for(uint32_t i=0; i<length; ++i) ret[i] = (ret[i] % 94) + 33;
return ret;
std::string res;
RsTemporaryMemory mem(length);
random_bytes(mem,length);
for(uint32_t i=0; i<length; ++i)
res += (char)(( ((int) ((uint8_t*)mem)[i]) % 94 ) + 33);
return res;
}