Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support reality #1710

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/base/models/CoreObjectModels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ namespace Qv2ray::base::objects
JSONSTRUCT_COMPARE(XTLSObject, serverName, allowInsecure, enableSessionResumption, disableSystemRoot, alpn, certificates)
JSONSTRUCT_REGISTER(XTLSObject, F(serverName, allowInsecure, enableSessionResumption, disableSystemRoot, alpn, certificates))
};
struct REALITYObject
{
QString serverName;
bool allowInsecure = false;
bool enableSessionResumption = false;
bool disableSystemRoot = false;
bool show = false;
QString fingerprint = "chrome";
QString publicKey;
QString shortId;
QString spiderX;
JSONSTRUCT_COMPARE(REALITYObject, serverName, allowInsecure, enableSessionResumption, disableSystemRoot, show, fingerprint, publicKey, shortId, spiderX)
JSONSTRUCT_REGISTER(REALITYObject, F(serverName, allowInsecure, enableSessionResumption, disableSystemRoot, show, fingerprint, publicKey, shortId, spiderX))
};
} // namespace transfer
//
//
Expand All @@ -348,10 +362,11 @@ namespace Qv2ray::base::objects
transfer::DomainSocketObject dsSettings;
transfer::QuicObject quicSettings;
transfer::gRPCObject grpcSettings;
transfer::REALITYObject realitySettings;
JSONSTRUCT_COMPARE(StreamSettingsObject, network, security, sockopt, //
tcpSettings, tlsSettings, xtlsSettings, kcpSettings, wsSettings, httpSettings, dsSettings, quicSettings, grpcSettings)
tcpSettings, tlsSettings, xtlsSettings, kcpSettings, wsSettings, httpSettings, dsSettings, quicSettings, grpcSettings, realitySettings)
JSONSTRUCT_REGISTER(StreamSettingsObject, F(network, security, sockopt),
F(tcpSettings, tlsSettings, xtlsSettings, kcpSettings, wsSettings, httpSettings, dsSettings, quicSettings, grpcSettings))
F(tcpSettings, tlsSettings, xtlsSettings, kcpSettings, wsSettings, httpSettings, dsSettings, quicSettings, grpcSettings, realitySettings))
};

struct FakeDNSObject
Expand Down
5 changes: 3 additions & 2 deletions src/core/connection/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Generation.hpp"
#include "core/handler/ConfigHandler.hpp"
#include "base/Qv2rayLog.hpp"

namespace Qv2ray::core::connection
{
Expand All @@ -10,12 +11,12 @@ namespace Qv2ray::core::connection
QList<std::pair<QString, CONFIGROOT>> ConvertConfigFromString(const QString &link, QString *aliasPrefix, QString *errMessage,
QString *newGroup)
{

const auto TLSOptionsFilter = [](QJsonObject &conf) {
const auto disableSystemRoot = GlobalConfig.advancedConfig.disableSystemRoot;
for (const QString &prefix : { "tls", "xtls" })
for (const QString &prefix : { "tls", "xtls", "reality" })
QJsonIO::SetValue(conf, disableSystemRoot, { "outbounds", 0, "streamSettings", prefix + "Settings", "disableSystemRoot" });
};

QList<std::pair<QString, CONFIGROOT>> connectionConf;
if (link.startsWith("vmess://") && link.contains("@"))
{
Expand Down
31 changes: 29 additions & 2 deletions src/core/connection/serialization/vless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "core/connection/Generation.hpp"
#include "core/connection/Serialization.hpp"
#include "utils/QvHelpers.hpp"
#include "base/Qv2rayLog.hpp"

#define QV_MODULE_NAME "VLESSImporter"

Expand Down Expand Up @@ -160,7 +161,7 @@ namespace Qv2ray::core::connection
// tls-wise settings
const auto hasSecurity = query.hasQueryItem("security");
const auto security = hasSecurity ? query.queryItemValue("security") : "none";
const auto tlsKey = security == "xtls" ? "xtlsSettings" : "tlsSettings";
const auto tlsKey = security == "xtls" ? "xtlsSettings" : ( security == "tls" ? "tlsSettings" : "realitySettings" );
if (security != "none")
{
QJsonIO::SetValue(stream, security, "security");
Expand All @@ -181,12 +182,38 @@ namespace Qv2ray::core::connection
QJsonIO::SetValue(stream, alpnArray, { tlsKey, "alpn" });
}
// xtls-specific
if (security == "xtls")
if (security == "xtls" || security == "reality")
{
const auto flow = query.queryItemValue("flow");
QJsonIO::SetValue(outbound, flow, { "settings", "vnext", 0, "users", 0, "flow" });
}

if ( security == "reality" )
{
if (query.hasQueryItem("fp"))
{
const auto fp = QUrl::fromPercentEncoding(query.queryItemValue("fp").toUtf8());
QJsonIO::SetValue(stream, fp, { "realitySettings", "fingerprint" });
}
if (query.hasQueryItem("pbk"))
{
const auto pbk = QUrl::fromPercentEncoding(query.queryItemValue("pbk").toUtf8());
QJsonIO::SetValue(stream, pbk, { "realitySettings", "publicKey" });
}
if (query.hasQueryItem("spiderX"))
{
const auto spiderX = QUrl::fromPercentEncoding(query.queryItemValue("spiderX").toUtf8());
QJsonIO::SetValue(stream, spiderX, { "realitySettings", "spiderX" });
}
if (query.hasQueryItem("sid"))
{
const auto sid = QUrl::fromPercentEncoding(query.queryItemValue("sid").toUtf8());
QJsonIO::SetValue(stream, sid, { "realitySettings", "shortId" });
}
}



// assembling config
CONFIGROOT root;
outbound["streamSettings"] = stream;
Expand Down
7 changes: 4 additions & 3 deletions src/core/kernel/V2RayKernelInteractions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ namespace Qv2ray::core::kernel
process.start(kernelPath, { "-test", "-config", path }, QIODevice::ReadWrite | QIODevice::Text);
#endif
process.waitForFinished();

if (process.exitCode() != 0)
const auto retcode = process.exitCode();
DEBUG("process.exitCode:::",retcode);
if (retcode != 0)
{
QString output = QString(process.readAllStandardOutput());
QString output = QString(process.readAllStandardOutput());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary spaces?

QvMessageBoxWarn(nullptr, tr("Configuration Error"), output.mid(output.indexOf("anti-censorship.") + 17));
return std::nullopt;
}
Expand Down
1 change: 0 additions & 1 deletion src/core/settings/SettingsBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ namespace Qv2ray::core::config
{
// Use the config path found by the checks above
SetConfigDirPath(configPath);
LOG("Using ", QV2RAY_CONFIG_DIR, " as the config path.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a good reason for removing this line?

}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/protocols/core/OutboundHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const QString BuiltinSerializer::SerializeOutbound(const QString &protocol, cons
query.addQueryItem("mode", "multi");
}
// -------- TLS RELATED --------
const auto tlsKey = security == "xtls" ? "xtlsSettings" : "tlsSettings";
const auto tlsKey = security == "xtls" ? "xtlsSettings" : ( security == "tls" ? "tlsSettings" : "realitySettings" );

const auto sni = QJsonIO::GetValue(objStream, { tlsKey, "serverName" }).toString();
if (!sni.isEmpty())
Expand All @@ -175,7 +175,7 @@ const QString BuiltinSerializer::SerializeOutbound(const QString &protocol, cons
query.addQueryItem("alpn", QUrl::toPercentEncoding(alpnList.join(",")));

// -------- XTLS Flow --------
if (security == "xtls")
if (security == "xtls" || security == "reality")
{
const auto flow = QJsonIO::GetValue(obj, "vnext", 0, "users", 0, "flow").toString();
query.addQueryItem("flow", flow);
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/protocols/ui/outbound/vless.ui
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
<property name="text">
<string notr="true">xtls-rprx-origin-udp443</string>
</property>
<property name="text">
<string notr="true">xtls-rprx-vision</string>
</property>
</item>
</widget>
</item>
Expand Down
49 changes: 44 additions & 5 deletions src/ui/widgets/widgets/StreamSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ void StreamSettingsWidget::SetStreamObject(const StreamSettingsObject &sso)
{
stream = sso;
transportCombo->setCurrentText(stream.network);
// TLS XTLS
const auto security = stream.security;
// TLS XTLS REALITY
{
const static QMap<QString, int> securityIndexMap{ { "none", 0 }, { "tls", 1 }, { "xtls", 2 } };
if (securityIndexMap.contains(stream.security))
securityTypeCB->setCurrentIndex(securityIndexMap[stream.security]);
const static QMap<QString, int> securityIndexMap{ { "none", 0 }, { "tls", 1 }, { "xtls", 2 }, { "reality", 3 } };
if (securityIndexMap.contains(security))
securityTypeCB->setCurrentIndex(securityIndexMap[security]);
else
LOG("Unsupported Security Type:", stream.security);
LOG("Unsupported Security Type:", security);

#define tls_xtls_process(prefix) \
{ \
Expand All @@ -50,10 +51,25 @@ void StreamSettingsWidget::SetStreamObject(const StreamSettingsObject &sso)
alpnTxt->setText(stream.prefix##Settings.alpn.join("|")); \
}

#define reality_porcess(prefix) \
{ \
serverNameTxt->setText(stream.prefix##Settings.serverName); \
allowInsecureCB->setChecked(stream.prefix##Settings.allowInsecure); \
enableSessionResumptionCB->setChecked(stream.prefix##Settings.enableSessionResumption); \
disableSystemRoot->setChecked(stream.prefix##Settings.disableSystemRoot); \
printDebugLog->setChecked(stream.prefix##Settings.show); \
fingerprint->setText(stream.prefix##Settings.fingerprint); \
publicKey->setText(stream.prefix##Settings.publicKey); \
shortId->setText(stream.prefix##Settings.shortId); \
spiderX->setText(stream.prefix##Settings.spiderX); \
}

tls_xtls_process(tls);

if (stream.security == "xtls")
tls_xtls_process(xtls);
if (stream.security == "reality")
reality_porcess(reality)
}
// TCP
{
Expand Down Expand Up @@ -326,6 +342,7 @@ void StreamSettingsWidget::on_disableSystemRoot_stateChanged(int arg1)
{
stream.tlsSettings.disableSystemRoot = arg1;
stream.xtlsSettings.disableSystemRoot = arg1;
stream.realitySettings.disableSystemRoot = arg1;
}

void StreamSettingsWidget::on_openCertEditorBtn_clicked()
Expand Down Expand Up @@ -393,3 +410,25 @@ void StreamSettingsWidget::on_httpHeadersEditBtn_clicked()
json["headers"] = rJson;
stream.httpSettings.headers = HttpObject::fromJson(json).headers;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that you didn't format your codebase with clang-format, please consider doing so.


void StreamSettingsWidget::on_printDebugLog_stateChanged(int arg1)
{
stream.realitySettings.show = arg1;
}
void StreamSettingsWidget::on_fingerprint_textEdited(const QString &arg1)
{
stream.realitySettings.fingerprint = arg1;
}
void StreamSettingsWidget::on_publicKey_textEdited(const QString &arg1)
{
stream.realitySettings.publicKey = arg1;
}
void StreamSettingsWidget::on_shortId_textEdited(const QString &arg1)
{
stream.realitySettings.shortId = arg1;
}
void StreamSettingsWidget::on_spiderX_textEdited(const QString &arg1)
{
stream.realitySettings.spiderX = arg1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, add a newline before EOF

8 changes: 7 additions & 1 deletion src/ui/widgets/widgets/StreamSettingsWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class StreamSettingsWidget
void on_quicKeyTxt_textEdited(const QString &arg1);
void on_quicSecurityCB_currentIndexChanged(int arg1);

// TLS/XTLS
// TLS/XTLS/REALITY
void on_allowInsecureCB_stateChanged(int arg1);
void on_alpnTxt_textEdited(const QString &arg1);
void on_enableSessionResumptionCB_stateChanged(int arg1);
Expand All @@ -55,6 +55,12 @@ class StreamSettingsWidget
void on_disableSystemRoot_stateChanged(int arg1);
void on_openCertEditorBtn_clicked();

void on_printDebugLog_stateChanged(int arg1);
void on_fingerprint_textEdited(const QString &arg1);
void on_publicKey_textEdited(const QString &arg1);
void on_shortId_textEdited(const QString &arg1);
void on_spiderX_textEdited(const QString &arg1);

// TCP
void on_tcpFastOpenCB_stateChanged(int arg1);
void on_tcpHeaderTypeCB_currentIndexChanged(int arg1);
Expand Down
63 changes: 63 additions & 0 deletions src/ui/widgets/widgets/StreamSettingsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,11 @@
<property name="text">
<string notr="true">XTLS</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">REALITY</string>
</property>
</item>
</widget>
</item>
Expand Down Expand Up @@ -1033,10 +1038,68 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="reality">
<attribute name="title">
<string>REALITY Options</string>
</attribute>
<layout class="QFormLayout" name="formLayout_8">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="printDebugLog">
<property name="text">
<string>Print debug log</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_34">
<property name="text">
<string>Fingerprint</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="fingerprint"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_35">
<property name="text">
<string>Svr public key</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="publicKey"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_36">
<property name="text">
<string>Short id</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="shortId"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_37">
<property name="text">
<string>SpiderX</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="spiderX"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>

<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>transportCombo</tabstop>
Expand Down
3 changes: 2 additions & 1 deletion src/ui/widgets/windows/w_MainWindow_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ void MainWindow::MWSetSystemProxy()
LOG("ProxyAddress: " + proxyAddress);
LOG("HTTP Port: " + QSTRN(httpPort));
LOG("SOCKS Port: " + QSTRN(socksPort));
SetSystemProxy(proxyAddress, httpPort, socksPort);
// If you need to automatically set up the system proxy function,you can enable the handle commented out below
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not related to REALITY, please consider removing it from the PR

// SetSystemProxy(proxyAddress, httpPort, socksPort);
qvAppTrayIcon->setIcon(Q_TRAYICON("tray-systemproxy"));
if (!GlobalConfig.uiConfig.quietMode)
{
Expand Down
25 changes: 25 additions & 0 deletions translations/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3292,6 +3292,31 @@ Maybe you have downloaded the wrong core?</source>
<source>TCP Keepalive Interval</source>
<translation>TCP保留存活间隔</translation>
</message>
<message>
<source>REALITY Options</source>
<translation>REALITY 设置</translation>
</message>

<message>
<source>Print debug log</source>
<translation>打印调试信息</translation>
</message>
<message>
<source>Fingerprint</source>
<translation>指纹模拟</translation>
</message>
<message>
<source>Svr public key</source>
<translation>服务器公钥</translation>
</message>
<message>
<source>Short id</source>
<translation>短ID(不一定支持)</translation>
</message>
<message>
<source>SpiderX</source>
<translation>初始路径(不一定支持)</translation>
</message>
Comment on lines +3312 to +3319
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translations are done on https://crowdin.com/project/qv2ray

</context>
<context>
<name>w_GroupManager</name>
Expand Down