diff --git a/core/Kernel.cpp b/core/Kernel.cpp index cfe1202..b61ecff 100644 --- a/core/Kernel.cpp +++ b/core/Kernel.cpp @@ -40,7 +40,16 @@ bool NaiveProxyKernel::StartKernel() url.setUserName(username); url.setPassword(password); } - url.setHost(host); + if (!sni.isEmpty()) + { + // ### Hack : SNI is used for proxychains + url.setHost(sni); + arguments << QString("--host-resolver-rules=MAP %1 127.0.0.1").arg(sni); + } + else + { + url.setHost(host); + } url.setPort(port); arguments << QString("--proxy=%1").arg(url.url()); } @@ -70,6 +79,7 @@ bool NaiveProxyKernel::StartKernel() void NaiveProxyKernel::SetConnectionSettings(const QMap &options, const QJsonObject &settings) { + sni.clear(); this->listenIp = options[KERNEL_LISTEN_ADDRESS].toString(); this->socksPort = options[KERNEL_SOCKS_ENABLED].toBool() ? options[KERNEL_SOCKS_PORT].toInt() : 0; this->httpPort = options[KERNEL_HTTP_ENABLED].toBool() ? options[KERNEL_HTTP_PORT].toInt() : 0; @@ -79,16 +89,21 @@ void NaiveProxyKernel::SetConnectionSettings(const QMappassword = settings["password"].toString(); this->protocol = settings["protocol"].toString(); this->padding = settings["padding"].toBool(); + // + // Special SNI option + if (settings.contains("sni")) + sni = settings["sni"].toString(); + // if (this->protocol != "https" && this->protocol != "quic") { - emit OnKernelLogAvailable(QString("warning: outbound protocol %1 is falled back to https")); + emit OnKernelLogAvailable("warning: outbound protocol falled back to https"); this->protocol = "https"; } if (this->port <= 0 || this->port >= 65536) { - emit OnKernelLogAvailable(QString("warning: outbound port %1 is falled back to 443")); + emit OnKernelLogAvailable("warning: outbound port falled back to 443"); this->port = 443; } } diff --git a/core/Kernel.hpp b/core/Kernel.hpp index 546b910..02004a8 100644 --- a/core/Kernel.hpp +++ b/core/Kernel.hpp @@ -21,6 +21,8 @@ class NaiveProxyKernel : public Qv2rayPlugin::PluginKernel bool padding; int port; QProcess process; + // + QString sni; private: bool isStarted = false; diff --git a/core/Serializer.cpp b/core/Serializer.cpp index 927b7f4..97e278b 100644 --- a/core/Serializer.cpp +++ b/core/Serializer.cpp @@ -2,8 +2,8 @@ #include -const QString NaiveProxyOutboundHandler::SerializeOutbound(const QString &, const QString &alias, const QString &, - const QJsonObject &object) const +const QString NaiveProxyOutboundHandler::SerializeOutbound(const QString &, const QString &alias, const QString &, const QJsonObject &object, + const QJsonObject &) const { QUrl url; if (const auto protocol = object["protocol"].toString(); protocol != "https" && protocol != "quic") @@ -32,6 +32,19 @@ const QString NaiveProxyOutboundHandler::SerializeOutbound(const QString &, cons return url.toString(); } +const void NaiveProxyOutboundHandler::SetOutboundInfo(const QString &protocol, const Qv2rayPlugin::OutboundInfoObject &info, + QJsonObject &outbound) const +{ + if (protocol != "naive") + return; + if (info.contains(Qv2rayPlugin::INFO_SERVER)) + outbound["host"] = info[Qv2rayPlugin::INFO_SERVER].toString(); + if (info.contains(Qv2rayPlugin::INFO_SERVER)) + outbound["port"] = info[Qv2rayPlugin::INFO_PORT].toInt(); + if (info.contains(Qv2rayPlugin::INFO_SNI)) + outbound["sni"] = info[Qv2rayPlugin::INFO_SNI].toString(); +} + const QPair NaiveProxyOutboundHandler::DeserializeOutbound(const QString &link, QString *alias, QString *errorMessage) const { @@ -66,6 +79,7 @@ const Qv2rayPlugin::OutboundInfoObject NaiveProxyOutboundHandler::GetOutboundInf return { // { Qv2rayPlugin::INFO_PROTOCOL, protocol }, { Qv2rayPlugin::INFO_SERVER, outbound["host"].toString() }, - { Qv2rayPlugin::INFO_PORT, outbound["port"].toInt() } + { Qv2rayPlugin::INFO_PORT, outbound["port"].toInt() }, + { Qv2rayPlugin::INFO_SNI, outbound["sni"].toString() } }; } diff --git a/core/Serializer.hpp b/core/Serializer.hpp index e87c3ef..318c0b8 100644 --- a/core/Serializer.hpp +++ b/core/Serializer.hpp @@ -7,14 +7,16 @@ class NaiveProxyOutboundHandler : public Qv2rayPlugin::PluginOutboundHandler { public: explicit NaiveProxyOutboundHandler() : Qv2rayPlugin::PluginOutboundHandler(){}; - const QString SerializeOutbound(const QString &protocol, // - const QString &alias, // - const QString &groupName, // - const QJsonObject &object) const override; + const QString SerializeOutbound(const QString &protocol, // + const QString &alias, // + const QString &groupName, // + const QJsonObject &object, // + const QJsonObject &) const override; const QPair DeserializeOutbound(const QString &link, // QString *alias, // QString *errorMessage) const override; const Qv2rayPlugin::OutboundInfoObject GetOutboundInfo(const QString &protocol, const QJsonObject &outbound) const override; + const void SetOutboundInfo(const QString &protocol, const Qv2rayPlugin::OutboundInfoObject &info, QJsonObject &outbound) const override; const QList SupportedProtocols() const override { return { "naive" }; diff --git a/interface b/interface index 5f0a270..b20a461 160000 --- a/interface +++ b/interface @@ -1 +1 @@ -Subproject commit 5f0a270874d5d1ec1b02bc7d8fe069628c562dbd +Subproject commit b20a4613e5331db73099c44433af3a9544eeb82e