账号体系: 注册/登录/注销 CLI + rotate_key 轮换密钥 + config.py --regenerate-key(--yes); TUI 菜单 12 项

This commit is contained in:
lou
2026-08-10 15:27:43 +08:00
parent 0f7231e982
commit 214c943c07
4 changed files with 120 additions and 5 deletions
+33 -1
View File
@@ -152,8 +152,40 @@ def main() -> int:
ap.add_argument("--path", default=str(DEFAULT_CONFIG), help="配置文件路径")
ap.add_argument("--set-server", metavar="URL", help="更新 server.url 并保存")
ap.add_argument("--set-token", metavar="TOKEN", help="更新 server.token 并保存")
ap.add_argument("--regenerate-key", action="store_true",
help="重新生成密钥 (红色警告 + 二次确认, 旧密文将无法解密)")
ap.add_argument("--yes", action="store_true",
help="跳过交互确认 (TUI 已确认时用, 需配 --regenerate-key)")
args = ap.parse_args()
if args.regenerate_key:
cfg = AppConfig(args.path)
cfg.load()
engine = cfg.build_crypto()
if not args.yes:
print()
print("\033[91m" + "" * 52 + "\033[0m")
print("\033[91m ⚠ 危险操作警告\033[0m")
print()
print("\033[91m 重新生成密钥 = 丢弃当前密钥!\033[0m")
print("\033[91m · 当前密钥加密的已上传文件将永久无法解密\033[0m")
print("\033[91m · 建议先导出旧密钥备份 (TUI 菜单 7)\033[0m")
print("\033[91m · 执行后仅新上传的文件可用新密钥解密\033[0m")
print("\033[91m" + "" * 52 + "\033[0m")
print()
c1 = input("是否了解风险并继续? (输入 yes 继续): ").strip().lower()
if c1 != "yes":
print("[取消] 未重新生成")
return 0
c2 = input("再次确认: 输入 CONFIRM 才执行: ").strip()
if c2 != "CONFIRM":
print("[取消] 未重新生成")
return 0
engine.rotate_key()
print(f"[完成] 密钥已重新生成 (keyring: {engine.keyring_path})")
print("[提示] 旧密文已不可解; 需保留旧数据请从备份恢复旧密钥")
return 0
if args.init:
path = Path(args.path)
if path.exists():
@@ -170,7 +202,7 @@ def main() -> int:
"max_retries": 3,
"retry_delay": 1.0,
},
"crypto": {"key_id": "default_key", "keyring_path": "config/keyring.json"},
"crypto": {"key_id": "default_key", "keyring_path": ""},
"splitter": {"chunk_size_mb": 10},
"state": {"db_path": "config/tasks.db", "cleanup_days": 7},
},