QNetworkAccessManager with Socks5Proxy with HostNameLookupCapability error
-
I'm trying to use this way:
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName("127.0.0.1");
proxy.setPort(1111);
manager->setProxy(proxy)
auto req = QNetworkRequest(url);
manager->get(req);
manager emits signal QNetworkAccessManager::finished with error:
"SOCKS version 5 protocol error"
and debug message
"skipping hostname of len 11"
11 - is len of hostname in my url
Socks5 server working good and return right answer, curl with same url and proxy settings return correct answer
I found this debug message in qt sources:
https://github.com/qt/qtbase/blob/5.15.2/src/network/socket/qsocks5socketengine.cpp#L248
in this "if" branch hostname just skipped, and no "ret" value was set, "ret" stays -1, and this value mean error
How it was supposed to work? -
Hi,
I wonder if you may have found an issue.
Can you build just the qtbase module with that possibly missing line added to check if it does work ?
-
I just realized, are you sure that 127.0.0.1 is a valid value ? Wouldn't localhost be better ?
-
I just realized, are you sure that 127.0.0.1 is a valid value ? Wouldn't localhost be better ?
@SGaist i tried localhost too, it doesn't matter, 127.0.0.1 valid value, i tried same params with curl, curl return correct answer, as I wrote before. Firefox with this proxy params working good too. I tried to debug inside private qt network classes, proxy return correct answer with string hostname but it could not be stored in QHostAddress, qt network use it later to retireve connection.
-
Did you already check the bug report system to see if there's something related to that ?
-
Fake Server to reproduce. curl with params running ok "curl --socks5-hostname 127.0.0.1:80 http://domain/ --verbose --include"
#include <QCoreApplication>
#include <QTcpServer>
#include <QTcpSocket>
#include <QRunnable>
#include <QThreadPool>
#include <QNetworkAccessManager>
#include <QNetworkProxy>
#include <QNetworkReply>
class FakeSocks5Proxy : public QRunnable {
void run() override {
QTcpServer server;
server.listen(QHostAddress::Any, 80);
while (true) {
server.waitForNewConnection();
QTcpSocket* client = server.nextPendingConnection();
if (client) {
client->waitForReadyRead();
client->readAll();
client->write("\x05\x00", 2);
client->flush();
client->waitForReadyRead();
client->readAll();
client->write("\x05\x00\x00\x03\x06""domain\x00\x50", 13);
client->flush();
client->waitForReadyRead();
client->readAll();
client->write("HTTP/1.1 200 OK\r\n\r\n");
client->flush();
client->close();
delete client;
}
}
}
};int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);FakeSocks5Proxy s; QThreadPool::globalInstance()->start(&s); QNetworkAccessManager *manager = new QNetworkAccessManager(); QNetworkProxy proxy; proxy.setType(QNetworkProxy::Socks5Proxy); proxy.setHostName("127.0.0.1"); proxy.setPort(80); manager->setProxy(proxy); QObject::connect(manager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply){ qDebug() << reply->errorString(); }); manager->get(QNetworkRequest(QUrl("http://domain/"))); return a.exec();
}
-
Since you already built your own version of Qt, did you try to do it with
QSOCKS5SOCKETLAYER_DEBUG
defined to get more details about what is happening ?