Skip to content

Commit

Permalink
Install CA certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
FrzMtrsprt committed Feb 20, 2023
1 parent d6e5345 commit f88ba45
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "src/third-party/server"]
path = src/third-party/server
url = git@github.com:UnblockNeteaseMusic/server.git
[submodule "src/third-party/SingleApplication"]
path = src/third-party/SingleApplication
url = git@github.com:itay-grudev/SingleApplication.git
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ qt_add_executable(QtUnblockNeteaseMusic

qt_add_resources(QtUnblockNeteaseMusic res
PREFIX /
FILES res/icon.png
FILES src/third-party/server/ca.crt res/icon.png
)

qt_add_translations(QtUnblockNeteaseMusic
Expand Down
29 changes: 17 additions & 12 deletions locale/QtUnblockNeteaseMusic_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</message>
<message>
<location filename="../src/mainwindow.ui" line="323"/>
<location filename="../src/mainwindow.cpp" line="180"/>
<location filename="../src/mainwindow.cpp" line="205"/>
<source>About</source>
<translation>关于</translation>
</message>
Expand Down Expand Up @@ -137,37 +137,42 @@
<translation>文件(&amp;F)</translation>
</message>
<message>
<location filename="../src/mainwindow.ui" line="283"/>
<location filename="../src/mainwindow.ui" line="284"/>
<source>&amp;Help</source>
<translation>帮助(&amp;H)</translation>
</message>
<message>
<location filename="../src/mainwindow.ui" line="290"/>
<location filename="../src/mainwindow.ui" line="291"/>
<source>&amp;View</source>
<translation>查看(&amp;V)</translation>
</message>
<message>
<location filename="../src/mainwindow.ui" line="294"/>
<location filename="../src/mainwindow.ui" line="295"/>
<source>&amp;Theme</source>
<translation>主题(&amp;T)</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="167"/>
<location filename="../src/mainwindow.ui" line="337"/>
<source>&amp;Install Certificate</source>
<translation>安装证书(&amp;I)</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="192"/>
<source>&lt;h3&gt;About %1&lt;/h3&gt;&lt;p&gt;Version %2&lt;/p&gt;</source>
<translation>&lt;h3&gt;关于 %1&lt;/h3&gt;&lt;p&gt;版本 %2&lt;/p&gt;</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="173"/>
<location filename="../src/mainwindow.cpp" line="198"/>
<source>&lt;p&gt;A desktop client for UnblockNeteaseMusic, made with Qt.&lt;/p&gt;&lt;p&gt;Copyright 2023 %1&lt;/p&gt;</source>
<translation>&lt;p&gt;适用于 UnblockNeteaseMusic 的桌面应用,使用 Qt 制作。&lt;/p&gt;&lt;p&gt;版权所有 2023 %1&lt;/p&gt;</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="120"/>
<location filename="../src/mainwindow.cpp" line="123"/>
<source>Error</source>
<translation>错误</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="122"/>
<location filename="../src/mainwindow.cpp" line="125"/>
<source>Failed to set system proxy.
Please check the server port and address, and try again.</source>
<translation>无法设置系统代理。
Expand All @@ -179,23 +184,23 @@ Please check the server port and address, and try again.</source>
<message>
<location filename="../src/server.cpp" line="65"/>
<source>Node.js is not installed.</source>
<translation type="unfinished">未安装 Node.js。</translation>
<translation>未安装 Node.js。</translation>
</message>
<message>
<location filename="../src/server.cpp" line="117"/>
<source>Server not found.</source>
<translation type="unfinished">未找到服务器。</translation>
<translation>未找到服务器。</translation>
</message>
<message>
<location filename="../src/server.cpp" line="135"/>
<source>Server error</source>
<translation type="unfinished">服务器错误</translation>
<translation>服务器错误</translation>
</message>
<message>
<location filename="../src/server.cpp" line="137"/>
<source>The UnblockNeteaseMusic server ran into an error.
Please change the arguments or check port usage and try again.</source>
<translation type="unfinished">UnblockNeteaseMusic 服务器出现错误。
<translation>UnblockNeteaseMusic 服务器出现错误。
请修改服务器参数或检查端口占用,然后重试。</translation>
</message>
</context>
Expand Down
25 changes: 25 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QCloseEvent>
#include <QDebug>
#include <QDesktopServices>
#include <QFile>
#include <QFontDatabase>
#include <QMessageBox>
#include <QRegularExpression>
Expand All @@ -29,6 +30,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->outText->setFont(font);

// connect MainWindow signals
connect(ui->actionInstallCA, &QAction::triggered,
this, &MainWindow::on_installCA);
connect(ui->actionExit, &QAction::triggered,
this, &MainWindow::exit);
connect(ui->actionAbout, &QAction::triggered,
Expand Down Expand Up @@ -155,6 +158,28 @@ void MainWindow::exit()
QApplication::exit();
}

void MainWindow::on_installCA()
{
const QString caPath = u"./ca.crt"_s;

QString ret;

QFile::copy(u":/res/ca.crt"_s, caPath);
#ifdef Q_OS_WIN
ret = WinUtils::installCA(caPath);
#endif
QFile::setPermissions(caPath, QFileDevice::WriteOwner);
QFile::remove(caPath);

QMessageBox *dlg = new QMessageBox(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setText(ret);
#ifdef Q_OS_WIN
WinUtils::setWindowFrame(dlg->winId(), dlg->style());
#endif
dlg->exec();
}

void MainWindow::on_about()
{
const QPixmap logo =
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public slots:
void updateSettings();

private slots:
void on_installCA();
void on_startup(const bool &enable);
void on_about();
void on_aboutQt();
Expand Down
9 changes: 7 additions & 2 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="actionInstallCA"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuHelp">
Expand Down Expand Up @@ -307,8 +308,7 @@
<widget class="QStatusBar" name="statusBar"/>
<action name="actionExit">
<property name="icon">
<iconset theme="application-exit">
<normaloff>.</normaloff>.</iconset>
<iconset theme="application-exit"/>
</property>
<property name="text">
<string>E&amp;xit</string>
Expand All @@ -332,6 +332,11 @@
<string>About Qt</string>
</property>
</action>
<action name="actionInstallCA">
<property name="text">
<string>&amp;Install Certificate</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
2 changes: 2 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class Server : public QProcess
{
Q_OBJECT

public:
Server(QTextEdit *output, Config *config);
~Server();
Expand Down
1 change: 1 addition & 0 deletions src/third-party/server
Submodule server added at 130be8
12 changes: 12 additions & 0 deletions src/utils/winutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QString>
#include <QStyle>
#include <QProcess>
#include <QWindow>

#include <Windows.h>
Expand All @@ -10,6 +11,8 @@
#include <uxtheme.h>
#include <wininet.h>

using namespace Qt::Literals::StringLiterals;

static PROCESS_POWER_THROTTLING_STATE Throttle{
PROCESS_POWER_THROTTLING_CURRENT_VERSION,
PROCESS_POWER_THROTTLING_EXECUTION_SPEED,
Expand Down Expand Up @@ -173,3 +176,12 @@ bool WinUtils::isSystemProxy(const QString &address, const QString &port)
}
return false;
}

// Install CA certificate and return the output
QString WinUtils::installCA(const QString &caPath)
{
QProcess process;
process.start(u"certutil"_s, {u"-addstore"_s, u"-f"_s, u"root"_s, caPath});
process.waitForFinished();
return QString::fromLocal8Bit(process.readAllStandardOutput());
}
1 change: 1 addition & 0 deletions src/utils/winutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class WinUtils
static void setWindowFrame(const WId &winId, const QStyle *style);
static bool setSystemProxy(const bool &enable, const QString &address, const QString &port);
static bool isSystemProxy(const QString &address, const QString &port);
static QString installCA(const QString &caPath);

private:
static bool setVisualStyleToWindow(const HWND &hWnd, const bool &enable);
Expand Down

0 comments on commit f88ba45

Please sign in to comment.