Files
SimpleRemoter/server/2015Remote/TlsCertificateDlg.h
T
yuanyuanxianganddeepseek-flash cc9ce35c4d Feature: export the built-in TLS certificate from the settings dialog
The built-in certificate lives only inside the server config as base64
DER, so there was no way to take it elsewhere -- to install it as a
custom certificate on another machine, or to hand it to a proxy.

The TLS certificate dialog now has an Export Certificate button next to
the Built-in Certificate checkbox. It is enabled only while that box is
checked. Clicking it opens a save dialog and writes two PEM files: the
chosen .crt and a .key with the same base name in the same directory.
The key is PKCS#8 and unencrypted; the success message says so.

If the certificate has not been generated yet (box checked but the
dialog not applied), the export generates it first, the same way OK
does, then refreshes the expiry text. If the key cannot be written, the
certificate written just before it is deleted, so no half pair is left.

Translations added for en_US, zh_TW and de_DE; en_US and zh_TW are also
embedded resources, so the server was rebuilt.

Verified: Debug x64 server builds clean. Drove the dialog on a running
Debug instance over window messages -- the button, its label and its
enabled state track the checkbox. The PEM writer was checked against
OpenSSL (x509 -subject, pkey -check) using the same CryptoAPI flags.
The save dialog itself was not automated end to end.

Co-Authored-By: deepseek-flash
2026-11-06 12:13:07 +01:00

53 lines
1.9 KiB
C++

#pragma once
#include <afxwin.h>
#include <afxcmn.h>
#include <vector>
// 「TLS证书」配置对话框:启用服务端单向 TLS 加密 + 指定证书/私钥路径。
// 因 2015Remote.rc 为 UTF-16 编码、不宜手工编辑,参照 CMcpSettingsDlg 用
// InitModalIndirect + 内存 DLGTEMPLATE 程序化创建(见 docs/TransportTLS_MFCServer_Design.md §7.1)。
class CTlsCertificateDlg : public CDialog
{
public:
explicit CTlsCertificateDlg(CWnd* parent = nullptr);
virtual INT_PTR DoModal();
protected:
virtual BOOL OnInitDialog();
virtual void OnOK();
DECLARE_MESSAGE_MAP()
private:
enum CtrlId {
IDC_TLS_ENABLE = 2001, // 「启用加密」复选框
IDC_TLS_CERT = 2002, // 证书路径编辑框
IDC_TLS_CERT_BROWSE = 2003, // 证书路径「浏览...」按钮
IDC_TLS_KEY = 2004, // 私钥路径编辑框
IDC_TLS_KEY_BROWSE = 2005, // 私钥路径「浏览...」按钮
IDC_TLS_BUILTIN = 2006, // 「内置证书」复选框(缺省勾选)
IDC_TLS_BUILTIN_INFO= 2007, // 内置证书说明(只读静态文本)
IDC_TLS_BUILTIN_EXPORT = 2008, // 「导出证书」按钮(勾选内置证书时可用)
};
CButton m_btnEnable;
CButton m_btnBuiltin;
CButton m_btnExport;
CStatic m_lblBuiltinInfo;
CStatic m_lblCert, m_lblKey;
CEdit m_editCert, m_editKey;
CButton m_btnCertBrowse, m_btnKeyBrowse;
CButton m_btnOK, m_btnCancel;
std::vector<BYTE> m_Template; // 内存 DLGTEMPLATE 字节
void LayoutControls(int cx, int cy);
void OnBrowseCert();
void OnBrowseKey();
void OnBuiltinToggle(); // 勾选状态变化:置灰/恢复自定义证书控件
void OnExportBuiltin(); // 把内置证书导出为 .crt + .key
void UpdateBuiltinUi(); // 同步内置证书说明文本
};