From ed0605f4cd7a8b43f70ede2b9641ca7ff2e25a71 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 23:32:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial plan * Add certificate file and password support for VPN connection Co-authored-by: chenx-dust <16610294+chenx-dust@users.noreply.github.com> * Update certificate file placeholder to mention both p12 and pfx formats Co-authored-by: chenx-dust <16610294+chenx-dust@users.noreply.github.com> * Complete certificate-based VPN connection support implementation Co-authored-by: chenx-dust <16610294+chenx-dust@users.noreply.github.com> * 修改 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chenx-dust <16610294+chenx-dust@users.noreply.github.com> Co-authored-by: Chenx Dust --- _codeql_detected_source_root | 1 + settingwindow/settingwindow.cpp | 24 ++++++++ settingwindow/settingwindow.ui | 59 +++++++++++++++++-- zjuconnectcontroller/zjuconnectcontroller.cpp | 14 +++++ zjuconnectcontroller/zjuconnectcontroller.h | 2 + zjuconnectmode.cpp | 2 + 6 files changed, 97 insertions(+), 5 deletions(-) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/settingwindow/settingwindow.cpp b/settingwindow/settingwindow.cpp index 272201a..8dbeac2 100644 --- a/settingwindow/settingwindow.cpp +++ b/settingwindow/settingwindow.cpp @@ -117,6 +117,24 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : ui->totpSecretLineEdit->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password); }); + connect(ui->certPasswordVisibleCheckBox, &QCheckBox::checkStateChanged, + [&](Qt::CheckState state) + { + ui->certPasswordLineEdit->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password); + }); + + connect(ui->certFileBrowseButton, &QPushButton::clicked, + [&]() + { + QString filename = QFileDialog::getOpenFileName(this, "选择证书文件", + QStandardPaths::writableLocation(QStandardPaths::HomeLocation), + "P12 Certificate(*.p12 *.pfx);;All Files(*.*)"); + if (!filename.isEmpty()) + { + ui->certFileLineEdit->setText(filename); + } + }); + connect(ui->authSelectPushButton, &QPushButton::clicked, this, [&]() { authInfoWindow = new AuthInfoWindow(this); connect(authInfoWindow, &AuthInfoWindow::finishAuthInfo, this, @@ -151,6 +169,10 @@ void SettingWindow::loadSettings() QByteArray::fromBase64(settings->value("Credential/Password").toString().toUtf8()) ); ui->totpSecretLineEdit->setText(settings->value("Credential/TOTPSecret").toString()); + ui->certFileLineEdit->setText(settings->value("Credential/CertFile").toString()); + ui->certPasswordLineEdit->setText( + QByteArray::fromBase64(settings->value("Credential/CertPassword").toString().toUtf8()) + ); ui->autoStartCheckBox->setChecked(settings->value("Common/AutoStart").toBool()); ui->connectAfterStartCheckBox->setChecked(settings->value("Common/ConnectAfterStart").toBool()); @@ -219,6 +241,8 @@ void SettingWindow::applySettings() settings->setValue("Credential/Username", ui->usernameLineEdit->text()); settings->setValue("Credential/Password", QString(ui->passwordLineEdit->text().toUtf8().toBase64())); settings->setValue("Credential/TOTPSecret", ui->totpSecretLineEdit->text()); + settings->setValue("Credential/CertFile", ui->certFileLineEdit->text()); + settings->setValue("Credential/CertPassword", QString(ui->certPasswordLineEdit->text().toUtf8().toBase64())); settings->setValue("Common/AutoStart", ui->autoStartCheckBox->isChecked()); settings->setValue("Common/ConnectAfterStart", ui->connectAfterStartCheckBox->isChecked()); diff --git a/settingwindow/settingwindow.ui b/settingwindow/settingwindow.ui index 5c3f5ef..2603475 100644 --- a/settingwindow/settingwindow.ui +++ b/settingwindow/settingwindow.ui @@ -364,7 +364,7 @@ 保存的信息 - + QLineEdit::EchoMode::Password @@ -381,7 +381,7 @@ - + QLineEdit::EchoMode::Password @@ -391,14 +391,14 @@ - + - + VPN 账号 @@ -428,7 +428,7 @@ - + @@ -442,6 +442,51 @@ + + + + 证书文件 + + + + + + + 可选,p12/pfx 证书文件路径 + + + + + + + 浏览 + + + + + + + 证书密码 + + + + + + + QLineEdit::EchoMode::Password + + + 可选,证书密码 + + + + + + + + + + @@ -741,6 +786,10 @@ tabWidget usernameLineEdit passwordLineEdit + totpSecretLineEdit + certFileLineEdit + certFileBrowseButton + certPasswordLineEdit serverAddressLineEdit serverPortSpinBox dnsLineEdit diff --git a/zjuconnectcontroller/zjuconnectcontroller.cpp b/zjuconnectcontroller/zjuconnectcontroller.cpp index 3d66b25..b9b6cb3 100644 --- a/zjuconnectcontroller/zjuconnectcontroller.cpp +++ b/zjuconnectcontroller/zjuconnectcontroller.cpp @@ -123,6 +123,8 @@ void ZjuConnectController::start( const QString& udpPortForwarding, const QString& customDNS, const QString& customProxyDomain, + const QString& certFile, + const QString& certPassword, const QString& extraArguments ) { @@ -333,6 +335,18 @@ void ZjuConnectController::start( credentialList.append(totpSecret); } + if (!certFile.isEmpty()) + { + args.append("-cert-file"); + args.append(certFile); + } + + if (!certPassword.isEmpty()) + { + args.append("-cert-password"); + args.append(certPassword); + } + zjuConnectProcess->start(program, credentialList + args); zjuConnectProcess->waitForStarted(); if (zjuConnectProcess->state() == QProcess::NotRunning) diff --git a/zjuconnectcontroller/zjuconnectcontroller.h b/zjuconnectcontroller/zjuconnectcontroller.h index a36422c..6793f3c 100644 --- a/zjuconnectcontroller/zjuconnectcontroller.h +++ b/zjuconnectcontroller/zjuconnectcontroller.h @@ -60,6 +60,8 @@ public: const QString& udpPortForwarding, const QString& customDNS, const QString& customProxyDomain, + const QString& certFile, + const QString& certPassword, const QString& extraArguments ); diff --git a/zjuconnectmode.cpp b/zjuconnectmode.cpp index a273483..d866d0d 100644 --- a/zjuconnectmode.cpp +++ b/zjuconnectmode.cpp @@ -183,6 +183,8 @@ void MainWindow::initZjuConnect() settings->value("ZJUConnect/UdpPortForwarding").toString(), settings->value("ZJUConnect/CustomDNS", "").toString(), settings->value("ZJUConnect/CustomProxyDomain", "").toString(), + settings->value("Credential/CertFile", "").toString(), + QByteArray::fromBase64(settings->value("Credential/CertPassword", "").toString().toUtf8()), settings->value("ZJUConnect/ExtraArguments", "").toString()); };