diff --git a/lib/cipher.cpp b/lib/cipher.cpp index 6485da1..561d677 100644 --- a/lib/cipher.cpp +++ b/lib/cipher.cpp @@ -80,7 +80,7 @@ Cipher::Cipher(const std::string& method, } #ifndef USE_BOTAN2 else if (method.find("chacha20") != std::string::npos) { - chacha.reset(new ChaCha(key, iv)); + chacha.reset(new ChaCha(m_key, m_iv)); return; } #endif @@ -184,7 +184,7 @@ std::string Cipher::randomIv(const std::string &method) CipherInfo cipherInfo = cipherInfoMap.at(method); if (cipherInfo.type == AEAD) { return std::string(cipherInfo.ivLen, static_cast(0)); - } + } return randomIv(cipherInfo.ivLen); } diff --git a/lib/controller.cpp b/lib/controller.cpp index 40e748c..99a281c 100644 --- a/lib/controller.cpp +++ b/lib/controller.cpp @@ -110,11 +110,14 @@ bool Controller::start() if (isLocal) { qInfo("Running in local mode."); + QHostAddress localAddress = profile.httpProxy() + ? QHostAddress::LocalHost + : getLocalAddr(); listen_ret = tcpServer->listen( - getLocalAddr(), + localAddress, profile.httpProxy() ? 0 : profile.localPort()); if (listen_ret) { - listen_ret = udpRelay->listen(getLocalAddr(), profile.localPort()); + listen_ret = udpRelay->listen(localAddress, profile.localPort()); if (profile.httpProxy() && listen_ret) { QDebug(QtMsgType::QtInfoMsg) << "SOCKS5 port is" << tcpServer->serverPort(); diff --git a/lib/encryptor.cpp b/lib/encryptor.cpp index 9cb8ada..7aef5f3 100644 --- a/lib/encryptor.cpp +++ b/lib/encryptor.cpp @@ -75,7 +75,7 @@ void Encryptor::reset() void Encryptor::initEncipher(std::string *header) { - const std::string iv = Cipher::randomIv(m_method); + std::string iv = Cipher::randomIv(m_method); std::string key; #ifdef USE_BOTAN2 if (cipherInfo.type == Cipher::CipherType::AEAD) { @@ -89,7 +89,7 @@ void Encryptor::initEncipher(std::string *header) #ifdef USE_BOTAN2 } #endif - enCipher = std::make_unique(m_method, key, iv, true); + enCipher = std::make_unique(m_method, std::move(key), std::move(iv), true); } void Encryptor::initDecipher(const char *data, size_t length, size_t *offset) @@ -114,7 +114,7 @@ void Encryptor::initDecipher(const char *data, size_t length, size_t *offset) #ifdef USE_BOTAN2 } #endif - deCipher = std::make_unique(m_method, key, iv, false); + deCipher = std::make_unique(m_method, std::move(key), std::move(iv), false); } std::string Encryptor::encrypt(const std::string &in)