mini2fa 0.2.3__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. mini2fa-0.3.0/PKG-INFO +144 -0
  2. mini2fa-0.3.0/README.md +122 -0
  3. mini2fa-0.3.0/pyproject.toml +46 -0
  4. mini2fa-0.3.0/src/mini2fa/__init__.py +35 -0
  5. mini2fa-0.3.0/src/mini2fa/_cli.py +1212 -0
  6. {mini2fa-0.2.3 → mini2fa-0.3.0}/src/mini2fa/config.py +74 -50
  7. mini2fa-0.3.0/src/mini2fa/crypto.py +401 -0
  8. mini2fa-0.3.0/src/mini2fa/errors.py +92 -0
  9. mini2fa-0.3.0/src/mini2fa/fsutil.py +106 -0
  10. {mini2fa-0.2.3 → mini2fa-0.3.0}/src/mini2fa/models.py +33 -33
  11. mini2fa-0.3.0/src/mini2fa/scanner.py +156 -0
  12. mini2fa-0.3.0/src/mini2fa/storage.py +729 -0
  13. mini2fa-0.3.0/src/mini2fa/totp.py +150 -0
  14. mini2fa-0.3.0/src/mini2fa/ui.py +255 -0
  15. mini2fa-0.3.0/src/mini2fa/validation.py +204 -0
  16. mini2fa-0.3.0/src/mini2fa.egg-info/PKG-INFO +144 -0
  17. {mini2fa-0.2.3 → mini2fa-0.3.0}/src/mini2fa.egg-info/SOURCES.txt +3 -0
  18. {mini2fa-0.2.3 → mini2fa-0.3.0}/src/mini2fa.egg-info/requires.txt +6 -2
  19. {mini2fa-0.2.3 → mini2fa-0.3.0}/tests/test_crypto.py +790 -792
  20. {mini2fa-0.2.3 → mini2fa-0.3.0}/tests/test_scanner.py +435 -435
  21. {mini2fa-0.2.3 → mini2fa-0.3.0}/tests/test_storage.py +701 -700
  22. {mini2fa-0.2.3 → mini2fa-0.3.0}/tests/test_totp.py +219 -216
  23. mini2fa-0.2.3/PKG-INFO +0 -69
  24. mini2fa-0.2.3/README.md +0 -49
  25. mini2fa-0.2.3/pyproject.toml +0 -31
  26. mini2fa-0.2.3/src/mini2fa/__init__.py +0 -9
  27. mini2fa-0.2.3/src/mini2fa/_cli.py +0 -996
  28. mini2fa-0.2.3/src/mini2fa/crypto.py +0 -328
  29. mini2fa-0.2.3/src/mini2fa/scanner.py +0 -189
  30. mini2fa-0.2.3/src/mini2fa/storage.py +0 -414
  31. mini2fa-0.2.3/src/mini2fa/totp.py +0 -119
  32. mini2fa-0.2.3/src/mini2fa/ui.py +0 -182
  33. mini2fa-0.2.3/src/mini2fa.egg-info/PKG-INFO +0 -69
  34. {mini2fa-0.2.3 → mini2fa-0.3.0}/LICENSE +0 -0
  35. {mini2fa-0.2.3 → mini2fa-0.3.0}/setup.cfg +0 -0
  36. {mini2fa-0.2.3 → mini2fa-0.3.0}/src/mini2fa/__main__.py +0 -0
  37. {mini2fa-0.2.3 → mini2fa-0.3.0}/src/mini2fa.egg-info/dependency_links.txt +0 -0
  38. {mini2fa-0.2.3 → mini2fa-0.3.0}/src/mini2fa.egg-info/entry_points.txt +0 -0
  39. {mini2fa-0.2.3 → mini2fa-0.3.0}/src/mini2fa.egg-info/top_level.txt +0 -0
  40. {mini2fa-0.2.3 → mini2fa-0.3.0}/tests/test_cli.py +0 -0
  41. {mini2fa-0.2.3 → mini2fa-0.3.0}/tests/test_config.py +0 -0
  42. {mini2fa-0.2.3 → mini2fa-0.3.0}/tests/test_models.py +0 -0
  43. {mini2fa-0.2.3 → mini2fa-0.3.0}/tests/test_ui.py +0 -0
mini2fa-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.1
2
+ Name: mini2fa
3
+ Version: 0.3.0
4
+ Summary: 安全的本地 TOTP 双因素认证管理工具
5
+ Author: Duroxi
6
+ License: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/Duroxi/Mini2FA
8
+ Project-URL: Repository, https://github.com/Duroxi/Mini2FA
9
+ Keywords: totp,2fa,otp,authenticator,security
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: End Users/Desktop
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Topic :: Security
16
+ Classifier: Topic :: Utilities
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ Provides-Extra: scan
20
+ Provides-Extra: dev
21
+ License-File: LICENSE
22
+
23
+ # Mini2FA 🔑
24
+
25
+ 安全的本地 TOTP 双因素认证管理工具 — Python 包。
26
+
27
+ ## 安装
28
+
29
+ ```bash
30
+ # 核心功能(TOTP、加密、list/get)
31
+ pip install mini2fa
32
+
33
+ # 需要从图片扫码添加账号时,安装扫码依赖
34
+ pip install "mini2fa[scan]"
35
+ ```
36
+
37
+ Linux 上 pyzbar 还需要系统库:
38
+
39
+ ```bash
40
+ sudo apt-get install libzbar0 # Debian/Ubuntu
41
+ sudo yum install zbar # CentOS/RHEL
42
+ brew install zbar # macOS
43
+ ```
44
+
45
+ ## 使用
46
+
47
+ ### 交互模式(TUI)
48
+
49
+ ```bash
50
+ mini2fa
51
+ ```
52
+
53
+ 在真实终端中运行时使用轻量 TUI(备用屏幕整屏重绘):退出后终端不留残留,
54
+ 查看验证码时进度条与剩余秒数每秒自动刷新。非交互环境(管道/脚本/CI)自动降级
55
+ 为纯文本输出;也可显式禁用:
56
+
57
+ ```bash
58
+ mini2fa --no-tui
59
+ # 空闲 5 分钟后自动锁定(0=关闭,默认关闭)
60
+ mini2fa --lock-timeout 300
61
+ ```
62
+
63
+ ### 命令行模式(给 Agent 使用)
64
+
65
+ ```bash
66
+ # 列出所有账号(ID + issuer + account)
67
+ mini2fa list -p <password>
68
+
69
+ # 获取验证码(简洁一行式)
70
+ mini2fa get -p <password> <id>
71
+ # 输出示例:GitHub - CharlesHahn: 681025 (12s)
72
+
73
+ # 机器可读输出
74
+ mini2fa list -p <password> --json
75
+ mini2fa get -p <password> <id> --json
76
+
77
+ # 诊断数据文件、格式版本、解密状态
78
+ mini2fa doctor -p <password> [--json]
79
+
80
+ # 显式升级旧格式(会先备份 DB + key)
81
+ mini2fa migrate -p <password> [--json]
82
+ ```
83
+
84
+ **设计原则**:
85
+
86
+ - 命令行版给 agent 使用,**零交互**(无任何提示词)
87
+ - 密码仍只通过 `-p` 传入;注意 argv 可能出现在 shell 历史、进程列表和 agent 日志中
88
+ - 只读接口(`list`/`get`/`doctor`);管理操作留在 TUI
89
+ - `migrate` 是显式写操作,不会被 `list`/`get` 静默触发
90
+
91
+ ### 作为库
92
+
93
+ ```python
94
+ from mini2fa import generate_totp
95
+
96
+ code = generate_totp('JBSWY3DPEHPK3PXP')
97
+ print(code) # 123456
98
+ ```
99
+
100
+ `mini2fa` 核心包不再强制依赖 pyzbar/Pillow;扫码 API 仍可从
101
+ `mini2fa.scanner` 导入,但需要安装 `mini2fa[scan]`。
102
+
103
+ ## 功能
104
+
105
+ - 📱 从图片扫码添加 2FA 账号(仅支持 TOTP)
106
+ - 🔑 生成符合 RFC 6238 的 TOTP 验证码
107
+ - 🔐 AES-256-GCM 双层加密(PBKDF2-SHA256 600k)
108
+ - 🧷 密文绑定账号身份(AAD),防止密文调包
109
+ - 💾 JSON 导入/导出备份(内嵌主密钥,支持跨机器迁移)
110
+ - 🔁 schema v1 → v2 / AAD 显式迁移,迁移前自动备份
111
+ - 🔒 修改主密码、密保提示
112
+ - 🖥️ 跨平台(Windows/Linux/macOS)
113
+ - 🤖 `list`/`get`/`doctor`/`migrate` 命令行接口,支持 `--json`
114
+
115
+ ## 升级到 0.3.0
116
+
117
+ 0.3.0 引入 schema v2 和带 AAD 的密文。旧 key/DB/备份仍可读,但建议升级:
118
+
119
+ ```bash
120
+ # 先备份 ~/.mini2fa(或使用 TUI 的导出备份)
121
+ mini2fa migrate -p <password>
122
+ ```
123
+
124
+ 迁移会:
125
+
126
+ 1. 在 `~/.mini2fa/backups/pre_migration_<timestamp>/` 备份 DB 和 key;
127
+ 2. 重建 schema v2(增加 `secret_version` 与 CHECK 约束);
128
+ 3. 把旧密文重加密为带 AAD 的 v2 格式。
129
+
130
+ 迁移后的数据库**旧版 mini2fa 无法读取**;如需回滚,使用迁移前备份。
131
+ TUI 启动时检测到旧格式也会提示迁移。
132
+
133
+ ## 安全说明
134
+
135
+ - 数据目录固定为 `~/.mini2fa/`,不读取环境变量。
136
+ - 目录权限 0700,key/DB/备份 0600(POSIX)。
137
+ - `master.key` 原子写入并保留 `master.key.bak`。
138
+ - 主密码丢失无法恢复;请定期导出备份。
139
+ - 命令行 `-p` 的密码可能被同用户进程或日志看到;不要在共享环境使用。
140
+
141
+ ## 项目
142
+
143
+ - GitHub: https://github.com/Duroxi/Mini2FA
144
+ - License: GPL-3.0-or-later
@@ -0,0 +1,122 @@
1
+ # Mini2FA 🔑
2
+
3
+ 安全的本地 TOTP 双因素认证管理工具 — Python 包。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ # 核心功能(TOTP、加密、list/get)
9
+ pip install mini2fa
10
+
11
+ # 需要从图片扫码添加账号时,安装扫码依赖
12
+ pip install "mini2fa[scan]"
13
+ ```
14
+
15
+ Linux 上 pyzbar 还需要系统库:
16
+
17
+ ```bash
18
+ sudo apt-get install libzbar0 # Debian/Ubuntu
19
+ sudo yum install zbar # CentOS/RHEL
20
+ brew install zbar # macOS
21
+ ```
22
+
23
+ ## 使用
24
+
25
+ ### 交互模式(TUI)
26
+
27
+ ```bash
28
+ mini2fa
29
+ ```
30
+
31
+ 在真实终端中运行时使用轻量 TUI(备用屏幕整屏重绘):退出后终端不留残留,
32
+ 查看验证码时进度条与剩余秒数每秒自动刷新。非交互环境(管道/脚本/CI)自动降级
33
+ 为纯文本输出;也可显式禁用:
34
+
35
+ ```bash
36
+ mini2fa --no-tui
37
+ # 空闲 5 分钟后自动锁定(0=关闭,默认关闭)
38
+ mini2fa --lock-timeout 300
39
+ ```
40
+
41
+ ### 命令行模式(给 Agent 使用)
42
+
43
+ ```bash
44
+ # 列出所有账号(ID + issuer + account)
45
+ mini2fa list -p <password>
46
+
47
+ # 获取验证码(简洁一行式)
48
+ mini2fa get -p <password> <id>
49
+ # 输出示例:GitHub - CharlesHahn: 681025 (12s)
50
+
51
+ # 机器可读输出
52
+ mini2fa list -p <password> --json
53
+ mini2fa get -p <password> <id> --json
54
+
55
+ # 诊断数据文件、格式版本、解密状态
56
+ mini2fa doctor -p <password> [--json]
57
+
58
+ # 显式升级旧格式(会先备份 DB + key)
59
+ mini2fa migrate -p <password> [--json]
60
+ ```
61
+
62
+ **设计原则**:
63
+
64
+ - 命令行版给 agent 使用,**零交互**(无任何提示词)
65
+ - 密码仍只通过 `-p` 传入;注意 argv 可能出现在 shell 历史、进程列表和 agent 日志中
66
+ - 只读接口(`list`/`get`/`doctor`);管理操作留在 TUI
67
+ - `migrate` 是显式写操作,不会被 `list`/`get` 静默触发
68
+
69
+ ### 作为库
70
+
71
+ ```python
72
+ from mini2fa import generate_totp
73
+
74
+ code = generate_totp('JBSWY3DPEHPK3PXP')
75
+ print(code) # 123456
76
+ ```
77
+
78
+ `mini2fa` 核心包不再强制依赖 pyzbar/Pillow;扫码 API 仍可从
79
+ `mini2fa.scanner` 导入,但需要安装 `mini2fa[scan]`。
80
+
81
+ ## 功能
82
+
83
+ - 📱 从图片扫码添加 2FA 账号(仅支持 TOTP)
84
+ - 🔑 生成符合 RFC 6238 的 TOTP 验证码
85
+ - 🔐 AES-256-GCM 双层加密(PBKDF2-SHA256 600k)
86
+ - 🧷 密文绑定账号身份(AAD),防止密文调包
87
+ - 💾 JSON 导入/导出备份(内嵌主密钥,支持跨机器迁移)
88
+ - 🔁 schema v1 → v2 / AAD 显式迁移,迁移前自动备份
89
+ - 🔒 修改主密码、密保提示
90
+ - 🖥️ 跨平台(Windows/Linux/macOS)
91
+ - 🤖 `list`/`get`/`doctor`/`migrate` 命令行接口,支持 `--json`
92
+
93
+ ## 升级到 0.3.0
94
+
95
+ 0.3.0 引入 schema v2 和带 AAD 的密文。旧 key/DB/备份仍可读,但建议升级:
96
+
97
+ ```bash
98
+ # 先备份 ~/.mini2fa(或使用 TUI 的导出备份)
99
+ mini2fa migrate -p <password>
100
+ ```
101
+
102
+ 迁移会:
103
+
104
+ 1. 在 `~/.mini2fa/backups/pre_migration_<timestamp>/` 备份 DB 和 key;
105
+ 2. 重建 schema v2(增加 `secret_version` 与 CHECK 约束);
106
+ 3. 把旧密文重加密为带 AAD 的 v2 格式。
107
+
108
+ 迁移后的数据库**旧版 mini2fa 无法读取**;如需回滚,使用迁移前备份。
109
+ TUI 启动时检测到旧格式也会提示迁移。
110
+
111
+ ## 安全说明
112
+
113
+ - 数据目录固定为 `~/.mini2fa/`,不读取环境变量。
114
+ - 目录权限 0700,key/DB/备份 0600(POSIX)。
115
+ - `master.key` 原子写入并保留 `master.key.bak`。
116
+ - 主密码丢失无法恢复;请定期导出备份。
117
+ - 命令行 `-p` 的密码可能被同用户进程或日志看到;不要在共享环境使用。
118
+
119
+ ## 项目
120
+
121
+ - GitHub: https://github.com/Duroxi/Mini2FA
122
+ - License: GPL-3.0-or-later
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mini2fa"
7
+ version = "0.3.0"
8
+ description = "安全的本地 TOTP 双因素认证管理工具"
9
+ readme = "README.md"
10
+ license = {text = "GPL-3.0-or-later"}
11
+ requires-python = ">=3.10"
12
+ authors = [{name = "Duroxi"}]
13
+ keywords = ["totp", "2fa", "otp", "authenticator", "security"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Environment :: Console",
17
+ "Intended Audience :: End Users/Desktop",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Topic :: Security",
21
+ "Topic :: Utilities",
22
+ ]
23
+ dependencies = [
24
+ "cryptography>=41.0.0",
25
+ "wcwidth>=0.2.0",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/Duroxi/Mini2FA"
30
+ Repository = "https://github.com/Duroxi/Mini2FA"
31
+
32
+ [project.scripts]
33
+ mini2fa = "mini2fa._cli:main"
34
+
35
+ [project.optional-dependencies]
36
+ scan = ["pyzbar>=0.1.9", "Pillow>=10.0.0"]
37
+ dev = [
38
+ "pytest",
39
+ "pytest-cov",
40
+ "qrcode[pil]",
41
+ "pyzbar>=0.1.9",
42
+ "Pillow>=10.0.0",
43
+ ]
44
+
45
+ [tool.setuptools.packages.find]
46
+ where = ["src"]
@@ -0,0 +1,35 @@
1
+ """Mini2FA - 安全的本地 TOTP 双因素认证管理工具"""
2
+
3
+ from .totp import generate_totp, verify_totp, get_remaining_seconds
4
+ from .crypto import CryptoManager, account_aad
5
+ from .storage import StorageManager
6
+ from .models import Account, OTPAccountInfo
7
+ from .errors import (
8
+ Mini2FAError, AuthError, BackupFormatError, KeyFileCorruptedError,
9
+ NotFoundError, UnsupportedOTPTypeError, ValidationError,
10
+ VaultCorruptedError, VaultLockedError,
11
+ )
12
+
13
+ __version__ = "0.3.0"
14
+
15
+ __all__ = [
16
+ "generate_totp", "verify_totp", "get_remaining_seconds",
17
+ "CryptoManager", "account_aad", "StorageManager", "Account",
18
+ "OTPAccountInfo", "Mini2FAError", "AuthError", "BackupFormatError",
19
+ "KeyFileCorruptedError", "NotFoundError", "UnsupportedOTPTypeError",
20
+ "ValidationError", "VaultCorruptedError", "VaultLockedError",
21
+ "__version__",
22
+ ]
23
+
24
+ _SCAN_EXPORTS = {
25
+ "scan_qrcode", "scan_qrcode_from_raw_data", "parse_otp_uri",
26
+ "preprocess_image",
27
+ }
28
+
29
+
30
+ def __getattr__(name):
31
+ """扫码 API 保持旧导入路径,但只在真正使用时加载 pyzbar/Pillow。"""
32
+ if name in _SCAN_EXPORTS:
33
+ from . import scanner
34
+ return getattr(scanner, name)
35
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")