Files
SimpleRemoter/server/2015Remote/CPasswordDlg.h
T
yuanyuanxianganddeepseek-flash 2b26f22d27 Feature: add tooltips to the password input dialog
The passcode input dialog now explains every control the operator can
use on hover, using the same MFC built-in tooltip mechanism as the
generate-passcode dialog (EnableToolTips + OnToolHitTest + TTN_NEEDTEXT,
with the max tip width applied when the tip is requested).

The passcode tip carries the main point: the value must match the
current serial and binding mode, and a passcode that was tampered with,
cracked or forged is invalid. The OK tip says the authorization check
verifies the passcode after saving rather than claiming the dialog
checks it. The checksum tip reflects that V2 verifies the passcode
signature while V1 checks the passcode itself, and the root-credential
tip notes that clearing the box does not delete the stored credential.

While here, the TTN_NEEDTEXT handlers keep idFrom in UINT_PTR: on x64
the old UINT intermediate could truncate a control HWND. The same fix
is applied to the generate-passcode dialog.

All 6 texts are translated in the en_US, de_DE and zh_TW packs.

Co-Authored-By: deepseek-flash
2026-12-06 22:39:08 +01:00

195 lines
7.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <afx.h>
#include <afxwin.h>
#include <map>
#include <mutex>
#include "Resource.h"
#include "common/commands.h"
#include "LangManager.h"
// 全局 licenses.ini 互斥锁(Meyers singleton,跨翻译单元共享)。
// 所有读写 licenses.ini 的函数入口必须加锁,否则在心跳并发下会出现
// read-modify-write 丢更新(典型受害者:PendingQuota / IP 列表)。
// 使用 recursive_mutex 是因为部分函数会嵌套调用(如 DecrementPendingQuota → ClearPendingRenewal)。
std::recursive_mutex& LicensesIniMutex();
// 让 UpdateLicenseActivity 内部缓存里某个 SN 的 entry 失效。
// 必须在外部修改了授权(删除 / 重新创建 section)后调用,否则 cache 命中策略
// 会跳过本应触发的"既往授权自动加入"路径,导致 disk 上的 section 不会重建。
// 实现在 CPasswordDlg.cpp,需持 LicensesIniMutex(内部会自行加锁,可在已加锁线程嵌套调用)。
void InvalidateLicenseActivityCache(const std::string& deviceID);
// CPasswordDlg 对话框
namespace TcpClient {
std::string ObfuscateAuthorization(const std::string& auth);
std::string DeobfuscateAuthorization(const std::string& obfuscated);
bool IsAuthorizationValid(const std::string& authObfuscated);
}
void WriteHash(const char* pwdHash, const char* upperHash);
std::string getUpperHash();
std::string GetUpperHash();
std::string GetFinderString(const char* buf);
// 获取密码哈希值
std::string GetPwdHash();
const Validation* GetValidation(int offset=100);
std::string GetMasterId();
std::string GetHMAC(int offset=100);
void SetHMAC(const std::string str, int offset=100);
bool IsPwdHashValid(const char* pwdHash = nullptr);
bool WritePwdHash(char* target, const std::string& pwdHash, const Validation &verify);
class CPasswordDlg : public CDialogLangEx
{
DECLARE_DYNAMIC(CPasswordDlg)
public:
CPasswordDlg(CWnd* pParent = nullptr); // 标准构造函数
virtual ~CPasswordDlg();
enum { IDD = IDD_DIALOG_PASSWORD };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 控件悬浮提示(MFC 内建工具提示):OnToolHitTest 按控件矩形命中,
// TTN_NEEDTEXT 按控件 ID 取多行文本。隐藏控件的提示自动跳过。
virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
BOOL OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult);
std::map<UINT, CString> m_tips; // 控件 ID -> 提示文本
DECLARE_MESSAGE_MAP()
public:
HICON m_hIcon;
CEdit m_EditDeviceID;
CEdit m_EditPassword;
CString m_sDeviceID;
CString m_sPassword;
virtual BOOL OnInitDialog();
CComboBox m_ComboBinding;
afx_msg void OnCbnSelchangeComboBind();
CEdit m_EditPasscodeHmac;
CString m_sPasscodeHmac;
CEdit m_EditRootCert;
CString m_sRootCert;
int m_nBindType;
virtual void OnOK();
};
// 授权信息保存辅助函数
std::string GetLicensesPath();
bool SaveLicenseInfo(const std::string& deviceID, const std::string& passcode,
const std::string& hmac, const std::string& remark = "",
const std::string& authorization = "",
const std::string& frpConfig = "");
bool LoadLicenseInfo(const std::string& deviceID, std::string& passcode,
std::string& hmac, std::string& remark);
// 加载授权的 FRP 配置
std::string LoadLicenseFrpConfig(const std::string& deviceID);
// 加载授权的 Authorization(用于 V2 授权返回给第一层)
std::string LoadLicenseAuthorization(const std::string& deviceID);
// 更新授权的 Authorization(V2 续期时更新)
// authorization: 混淆后的 Authorization 字符串
bool UpdateLicenseAuthorization(const std::string& deviceID, const std::string& authorization);
// 更新授权活跃信息(IP、位置、最后活跃时间)
// 如果授权不存在则自动创建记录
// machineName: 机器名,用于区分同一公网IP下的不同机器
bool UpdateLicenseActivity(const std::string& deviceID, const std::string& passcode,
const std::string& hmac, const std::string& ip = "",
const std::string& location = "", const std::string& machineName = "");
// 检查授权是否已被撤销
bool IsLicenseRevoked(const std::string& deviceID);
// 构建 V1 Authorization(第一层/下级返回给下级)
// sn: 用于日志输出的设备标识
// 返回混淆后的 Authorization,失败返回空字符串
std::string BuildV1Authorization(const std::string& sn = "", bool heartbeat = false);
class CPwdGenDlg : public CDialogLangEx
{
DECLARE_DYNAMIC(CPwdGenDlg)
public:
CPwdGenDlg(CWnd* pParent = nullptr); // 标准构造函数
virtual ~CPwdGenDlg();
enum {
IDD = IDD_DIALOG_KEYGEN
};
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 控件悬浮提示(MFC 内建工具提示):OnToolHitTest 按控件矩形命中,
// TTN_NEEDTEXT 按控件 ID 取多行文本。隐藏控件的提示自动跳过。
virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
BOOL OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult);
std::map<UINT, CString> m_tips; // 控件 ID -> 提示文本
DECLARE_MESSAGE_MAP()
public:
HICON m_hIcon;
CEdit m_EditDeviceID;
CEdit m_EditPassword;
CEdit m_EditUserPwd;
CString m_sDeviceID;
CString m_sPassword;
CString m_sUserPwd;
afx_msg void OnBnClickedButtonGenkey();
afx_msg void OnBnClickedButtonSaveLicense();
CDateTimeCtrl m_PwdExpireDate;
COleDateTime m_ExpireTm;
CDateTimeCtrl m_StartDate;
COleDateTime m_StartTm;
virtual BOOL OnInitDialog();
CEdit m_EditHostNum;
int m_nHostNum;
CEdit m_EditHMAC;
CButton m_BtnSaveLicense;
BOOL m_bIsLocalDevice; // 是否为本机授权
CString m_sHMAC; // HMAC 值
CEdit m_EditAuthorization; // 多层授权显示框
CString m_sAuthorization; // 多层授权: Authorization 字段
// V2 Authorization 下级并发数限制
CEdit m_EditAuthHostNum; // 下级并发数输入框
int m_nAuthHostNum; // 下级并发数值
BOOL m_bAuthHostNumManual; // 是否手动修改过
afx_msg void OnEnChangeEditHostNum(); // 连接数变化时同步
afx_msg void OnEnChangeEditAuthHostNum(); // 下级并发数手动修改
// V2 授权相关
CComboBox m_ComboVersion; // 版本选择下拉框
CEdit m_EditPrivateKey; // 私钥文件路径
CButton m_BtnBrowseKey; // 浏览私钥文件按钮
CButton m_BtnGenKeyPair; // 生成密钥对按钮
int m_nVersion; // 0=V1(HMAC), 1=V2(ECDSA)
CString m_sPrivateKeyPath; // 私钥文件路径
afx_msg void OnCbnSelchangeComboVersion(); // 版本切换事件
afx_msg void OnBnClickedButtonBrowseKey(); // 浏览私钥文件事件
afx_msg void OnBnClickedButtonGenKeypair(); // 生成密钥对事件
// FRP 代理相关
CButton m_CheckFrpProxy; // FRP 代理复选框
CEdit m_EditFrpRemotePort; // FRP 远程端口
CButton m_BtnFrpAutoPort; // 自动分配端口按钮
CStatic m_StaticFrpInfo; // FRPS 信息显示
int m_nFrpRemotePort; // FRP 远程端口值
std::string m_sFrpConfig; // 生成的 FRP 配置字符串
afx_msg void OnBnClickedCheckFrpProxy(); // FRP 复选框点击
afx_msg void OnBnClickedBtnFrpAutoPort(); // 自动分配端口按钮
void UpdateFrpControlStates(); // 更新 FRP 控件状态
};