foxkey 0.1.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.
- foxkey-0.1.0/LICENSE +21 -0
- foxkey-0.1.0/PKG-INFO +61 -0
- foxkey-0.1.0/README.md +49 -0
- foxkey-0.1.0/cli.py +246 -0
- foxkey-0.1.0/core/__init__.py +0 -0
- foxkey-0.1.0/core/crypto.py +36 -0
- foxkey-0.1.0/core/storage.py +85 -0
- foxkey-0.1.0/core/totp.py +36 -0
- foxkey-0.1.0/foxkey.egg-info/PKG-INFO +61 -0
- foxkey-0.1.0/foxkey.egg-info/SOURCES.txt +15 -0
- foxkey-0.1.0/foxkey.egg-info/dependency_links.txt +1 -0
- foxkey-0.1.0/foxkey.egg-info/entry_points.txt +2 -0
- foxkey-0.1.0/foxkey.egg-info/requires.txt +1 -0
- foxkey-0.1.0/foxkey.egg-info/top_level.txt +3 -0
- foxkey-0.1.0/foxkey.py +16 -0
- foxkey-0.1.0/pyproject.toml +24 -0
- foxkey-0.1.0/setup.cfg +4 -0
foxkey-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fox Hackerz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
foxkey-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: foxkey
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Secure, dependency-light TOTP 2FA manager with zero footguns.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Source, https://github.com/foxhackerzdevs/foxkey
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: cryptography>=42.0.0
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# 🦊 FoxKey — Secure TOTP Manager
|
|
14
|
+
|
|
15
|
+
Minimalist, secure terminal 2FA client with strong defaults and zero footguns.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
- Encrypted vault (Argon2id + ChaCha20-Poly1305)
|
|
19
|
+
- Plaintext label index (list without password)
|
|
20
|
+
- otpauth:// URI support
|
|
21
|
+
- Clipboard auto-clear + live countdown
|
|
22
|
+
- Export / Import encrypted backups
|
|
23
|
+
- Change master password
|
|
24
|
+
- BusyBox-style single script
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
**From PyPI**
|
|
29
|
+
```bash
|
|
30
|
+
pip install foxkey
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Single binary (recommended)**
|
|
34
|
+
```bash
|
|
35
|
+
pip install pyinstaller
|
|
36
|
+
pyinstaller --onefile --name foxkey foxkey.py
|
|
37
|
+
# Move dist/foxkey to ~/bin or /usr/local/bin
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Development**
|
|
41
|
+
```bash
|
|
42
|
+
git clone ... && cd foxkey
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
```bash
|
|
48
|
+
foxkey add github otpauth://totp/...
|
|
49
|
+
foxkey list
|
|
50
|
+
foxkey get github
|
|
51
|
+
foxkey export --file backup.enc
|
|
52
|
+
foxkey import backup.enc
|
|
53
|
+
foxkey change-password
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Security Notes
|
|
57
|
+
- Master password never touches CLI args
|
|
58
|
+
- Vault refuses weak operations
|
|
59
|
+
- Clipboard cleared after token lifetime
|
|
60
|
+
|
|
61
|
+
---
|
foxkey-0.1.0/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# 🦊 FoxKey — Secure TOTP Manager
|
|
2
|
+
|
|
3
|
+
Minimalist, secure terminal 2FA client with strong defaults and zero footguns.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
- Encrypted vault (Argon2id + ChaCha20-Poly1305)
|
|
7
|
+
- Plaintext label index (list without password)
|
|
8
|
+
- otpauth:// URI support
|
|
9
|
+
- Clipboard auto-clear + live countdown
|
|
10
|
+
- Export / Import encrypted backups
|
|
11
|
+
- Change master password
|
|
12
|
+
- BusyBox-style single script
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
**From PyPI**
|
|
17
|
+
```bash
|
|
18
|
+
pip install foxkey
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Single binary (recommended)**
|
|
22
|
+
```bash
|
|
23
|
+
pip install pyinstaller
|
|
24
|
+
pyinstaller --onefile --name foxkey foxkey.py
|
|
25
|
+
# Move dist/foxkey to ~/bin or /usr/local/bin
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Development**
|
|
29
|
+
```bash
|
|
30
|
+
git clone ... && cd foxkey
|
|
31
|
+
pip install -e .
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
```bash
|
|
36
|
+
foxkey add github otpauth://totp/...
|
|
37
|
+
foxkey list
|
|
38
|
+
foxkey get github
|
|
39
|
+
foxkey export --file backup.enc
|
|
40
|
+
foxkey import backup.enc
|
|
41
|
+
foxkey change-password
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Security Notes
|
|
45
|
+
- Master password never touches CLI args
|
|
46
|
+
- Vault refuses weak operations
|
|
47
|
+
- Clipboard cleared after token lifetime
|
|
48
|
+
|
|
49
|
+
---
|
foxkey-0.1.0/cli.py
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# cli.py
|
|
2
|
+
import argparse
|
|
3
|
+
import getpass
|
|
4
|
+
import sys
|
|
5
|
+
import time
|
|
6
|
+
import subprocess
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from urllib.parse import urlparse, parse_qs
|
|
9
|
+
from base64 import b32decode
|
|
10
|
+
import binascii
|
|
11
|
+
|
|
12
|
+
from core.storage import Vault
|
|
13
|
+
from core.totp import generate_totp
|
|
14
|
+
|
|
15
|
+
def sanitize_and_validate_secret(secret_input: str) -> dict:
|
|
16
|
+
"""Returns {'secret': str, 'algorithm': str, 'digits': int, 'period': int}."""
|
|
17
|
+
cleaned = secret_input.strip()
|
|
18
|
+
config = {"algorithm": "SHA1", "digits": 6, "period": 30}
|
|
19
|
+
|
|
20
|
+
if cleaned.lower().startswith("otpauth://"):
|
|
21
|
+
try:
|
|
22
|
+
parsed_url = urlparse(cleaned)
|
|
23
|
+
query_params = parse_qs(parsed_url.query)
|
|
24
|
+
if 'secret' not in query_params:
|
|
25
|
+
raise ValueError("The provided otpauth URI is missing a '?secret=' parameter.")
|
|
26
|
+
cleaned = query_params['secret'][0]
|
|
27
|
+
if 'algorithm' in query_params:
|
|
28
|
+
config["algorithm"] = query_params['algorithm'][0].upper()
|
|
29
|
+
if 'digits' in query_params:
|
|
30
|
+
config["digits"] = int(query_params['digits'][0])
|
|
31
|
+
if 'period' in query_params:
|
|
32
|
+
config["period"] = int(query_params['period'][0])
|
|
33
|
+
except Exception as e:
|
|
34
|
+
raise ValueError(f"Failed parsing token URI schema: {e}")
|
|
35
|
+
|
|
36
|
+
validation_target = cleaned.upper().replace(' ', '').replace('-', '')
|
|
37
|
+
missing_padding = len(validation_target) % 8
|
|
38
|
+
if missing_padding:
|
|
39
|
+
validation_target += '=' * (8 - missing_padding)
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
b32decode(validation_target)
|
|
43
|
+
except binascii.Error:
|
|
44
|
+
raise ValueError(
|
|
45
|
+
f"Invalid character signature found!\n"
|
|
46
|
+
f"Expected standard Base32 layout (A-Z, 2-7).\n"
|
|
47
|
+
f"Supplied raw string input was: {secret_input[:15]}..."
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if config["algorithm"] not in ("SHA1", "SHA256", "SHA512"):
|
|
51
|
+
raise ValueError(f"Unsupported algorithm '{config['algorithm']}'.")
|
|
52
|
+
if not (6 <= config["digits"] <= 10):
|
|
53
|
+
raise ValueError("Digits must be between 6 and 10.")
|
|
54
|
+
if config["period"] <= 0:
|
|
55
|
+
raise ValueError("Period must be a positive number of seconds.")
|
|
56
|
+
|
|
57
|
+
config["secret"] = cleaned
|
|
58
|
+
return config
|
|
59
|
+
|
|
60
|
+
def copy_to_clipboard(text: str):
|
|
61
|
+
try:
|
|
62
|
+
if sys.platform == "darwin":
|
|
63
|
+
subprocess.run(["pbcopy"], input=text.encode(), check=True)
|
|
64
|
+
elif sys.platform == "linux":
|
|
65
|
+
if subprocess.run(["which", "termux-clipboard-set"], capture_output=True).returncode == 0:
|
|
66
|
+
subprocess.run(["termux-clipboard-set", text], check=True)
|
|
67
|
+
else:
|
|
68
|
+
subprocess.run(["xclip", "-selection", "clipboard"], input=text.encode(), check=True)
|
|
69
|
+
elif sys.platform == "win32":
|
|
70
|
+
subprocess.run(["clip"], input=text.encode(), check=True)
|
|
71
|
+
except Exception:
|
|
72
|
+
pass
|
|
73
|
+
|
|
74
|
+
def clear_clipboard():
|
|
75
|
+
copy_to_clipboard("")
|
|
76
|
+
|
|
77
|
+
def draw_progress_bar(remaining_seconds: int, total_steps: int = 30, bar_width: int = 20):
|
|
78
|
+
"""Renders a clean standard output carriage-return visual progress monitor."""
|
|
79
|
+
remaining_seconds = max(0, remaining_seconds)
|
|
80
|
+
filled_length = int(round(bar_width * remaining_seconds / total_steps))
|
|
81
|
+
bar = 'â–ˆ' * filled_length + '-' * (bar_width - filled_length)
|
|
82
|
+
sys.stdout.write(f"\rTime Remaining: [{bar}] {remaining_seconds:2d}s before auto-wipe...")
|
|
83
|
+
sys.stdout.flush()
|
|
84
|
+
|
|
85
|
+
def main():
|
|
86
|
+
parser = argparse.ArgumentParser(prog="foxkey", description="Secure terminal 2FA manager.")
|
|
87
|
+
subparsers = parser.add_subparsers(dest="cmd", required=True)
|
|
88
|
+
|
|
89
|
+
subparsers.add_parser("list", help="List all vault service names.")
|
|
90
|
+
|
|
91
|
+
add_p = subparsers.add_parser("add", help="Add a new 2FA service credential.")
|
|
92
|
+
add_p.add_argument("name", help="Account or provider tracking name.")
|
|
93
|
+
add_p.add_argument("secret", help="Base32 seed or full otpauth:// URI.")
|
|
94
|
+
add_p.add_argument("--algorithm", choices=["SHA1", "SHA256", "SHA512"],
|
|
95
|
+
help="Override HMAC algorithm (default: SHA1, or value from otpauth URI).")
|
|
96
|
+
add_p.add_argument("--digits", type=int,
|
|
97
|
+
help="Override token length (default: 6, or value from otpauth URI).")
|
|
98
|
+
add_p.add_argument("--period", type=int,
|
|
99
|
+
help="Override time step in seconds (default: 30, or value from otpauth URI).")
|
|
100
|
+
|
|
101
|
+
get_p = subparsers.add_parser("get", help="Generate code and copy to clipboard.")
|
|
102
|
+
get_p.add_argument("name", help="Name of account target.")
|
|
103
|
+
|
|
104
|
+
rem_p = subparsers.add_parser("remove", help="Permanently drop a service key.")
|
|
105
|
+
rem_p.add_argument("name", help="Name of target account profile to erase.")
|
|
106
|
+
|
|
107
|
+
# NEW: Added change-password subparser
|
|
108
|
+
subparsers.add_parser("change-password", help="Update vault master password key.")
|
|
109
|
+
|
|
110
|
+
exp_p = subparsers.add_parser("export", help="Export encrypted vault backup.")
|
|
111
|
+
exp_p.add_argument("--file", default=str(Path.home() / "foxkey-backup.enc"))
|
|
112
|
+
|
|
113
|
+
imp_p = subparsers.add_parser("import", help="Import from encrypted backup.")
|
|
114
|
+
imp_p.add_argument("file", help="Backup file path.")
|
|
115
|
+
|
|
116
|
+
args = parser.parse_args()
|
|
117
|
+
|
|
118
|
+
if args.cmd == "add":
|
|
119
|
+
try:
|
|
120
|
+
totp_config = sanitize_and_validate_secret(args.secret)
|
|
121
|
+
except ValueError as err:
|
|
122
|
+
print(f"Validation Error: {err}", file=sys.stderr)
|
|
123
|
+
sys.exit(1)
|
|
124
|
+
if args.algorithm:
|
|
125
|
+
totp_config["algorithm"] = args.algorithm
|
|
126
|
+
if args.digits:
|
|
127
|
+
totp_config["digits"] = args.digits
|
|
128
|
+
if args.period:
|
|
129
|
+
totp_config["period"] = args.period
|
|
130
|
+
|
|
131
|
+
vault = Vault()
|
|
132
|
+
|
|
133
|
+
if args.cmd == "list":
|
|
134
|
+
labels = vault.get_public_labels()
|
|
135
|
+
if not labels:
|
|
136
|
+
print("Vault is entirely empty.")
|
|
137
|
+
for service in labels:
|
|
138
|
+
print(f"- {service}")
|
|
139
|
+
sys.exit(0)
|
|
140
|
+
|
|
141
|
+
# Prompt for current password first to unlock entries database
|
|
142
|
+
password = getpass.getpass("Master Password: ")
|
|
143
|
+
if not vault.load(password):
|
|
144
|
+
print("Error: Invalid master password.", file=sys.stderr)
|
|
145
|
+
sys.exit(1)
|
|
146
|
+
|
|
147
|
+
if args.cmd == "add":
|
|
148
|
+
if args.name in vault.entries:
|
|
149
|
+
confirm = input(f"'{args.name}' already exists — overwrite? [y/N]: ").strip().lower()
|
|
150
|
+
if confirm != "y":
|
|
151
|
+
print("Aborted: existing entry left unchanged.")
|
|
152
|
+
sys.exit(0)
|
|
153
|
+
vault.entries[args.name] = totp_config
|
|
154
|
+
vault.save(password)
|
|
155
|
+
print(f"Success: Validated credential for '{args.name}' successfully archived.")
|
|
156
|
+
|
|
157
|
+
elif args.cmd == "remove":
|
|
158
|
+
if args.name not in vault.entries:
|
|
159
|
+
print(f"Error: Profile name '{args.name}' not found.", file=sys.stderr)
|
|
160
|
+
sys.exit(1)
|
|
161
|
+
del vault.entries[args.name]
|
|
162
|
+
vault.save(password)
|
|
163
|
+
print(f"Success: Key profile '{args.name}' has been permanently dropped.")
|
|
164
|
+
|
|
165
|
+
# NEW: Added password mutation execution branch
|
|
166
|
+
elif args.cmd == "change-password":
|
|
167
|
+
new_password = getpass.getpass("Enter New Master Password: ")
|
|
168
|
+
confirm_password = getpass.getpass("Confirm New Master Password: ")
|
|
169
|
+
|
|
170
|
+
if new_password != confirm_password:
|
|
171
|
+
print("Error: Passwords do not match. Aborting mutation.", file=sys.stderr)
|
|
172
|
+
sys.exit(1)
|
|
173
|
+
|
|
174
|
+
if not new_password.strip():
|
|
175
|
+
print("Error: Password cannot be blank.", file=sys.stderr)
|
|
176
|
+
sys.exit(1)
|
|
177
|
+
|
|
178
|
+
# Write out using the confirmed new encryption key profile
|
|
179
|
+
vault.save(new_password)
|
|
180
|
+
print("Success: Vault re-encrypted under your fresh master password blueprint.")
|
|
181
|
+
|
|
182
|
+
elif args.cmd == "export":
|
|
183
|
+
try:
|
|
184
|
+
vault.export_backup(Path(args.file))
|
|
185
|
+
except FileNotFoundError as err:
|
|
186
|
+
print(f"Error: {err}", file=sys.stderr)
|
|
187
|
+
sys.exit(1)
|
|
188
|
+
|
|
189
|
+
elif args.cmd == "import":
|
|
190
|
+
existing_count = len(vault.entries)
|
|
191
|
+
if existing_count:
|
|
192
|
+
confirm = input(
|
|
193
|
+
f"Importing will overwrite your current vault ({existing_count} entries) "
|
|
194
|
+
f"with the contents of the backup. Continue? [y/N]: "
|
|
195
|
+
).strip().lower()
|
|
196
|
+
if confirm != "y":
|
|
197
|
+
print("Aborted: current vault left unchanged.")
|
|
198
|
+
sys.exit(0)
|
|
199
|
+
try:
|
|
200
|
+
vault.import_backup(Path(args.file), password)
|
|
201
|
+
except ValueError:
|
|
202
|
+
# Backup may be encrypted under a different password than the
|
|
203
|
+
# current vault (e.g. disaster recovery, or a stale backup).
|
|
204
|
+
backup_password = getpass.getpass("Backup Master Password: ")
|
|
205
|
+
try:
|
|
206
|
+
vault.import_backup(Path(args.file), backup_password)
|
|
207
|
+
except (FileNotFoundError, ValueError) as err:
|
|
208
|
+
print(f"Error: {err}", file=sys.stderr)
|
|
209
|
+
sys.exit(1)
|
|
210
|
+
except FileNotFoundError as err:
|
|
211
|
+
print(f"Error: {err}", file=sys.stderr)
|
|
212
|
+
sys.exit(1)
|
|
213
|
+
|
|
214
|
+
elif args.cmd == "get":
|
|
215
|
+
if args.name not in vault.entries:
|
|
216
|
+
print(f"Error: Profile name '{args.name}' not found.", file=sys.stderr)
|
|
217
|
+
sys.exit(1)
|
|
218
|
+
|
|
219
|
+
entry = vault.entries[args.name]
|
|
220
|
+
secret = entry["secret"]
|
|
221
|
+
algorithm = entry.get("algorithm", "SHA1")
|
|
222
|
+
digits = entry.get("digits", 6)
|
|
223
|
+
time_step = entry.get("period", 30)
|
|
224
|
+
|
|
225
|
+
token = generate_totp(secret, time_step=time_step, digits=digits, algorithm=algorithm)
|
|
226
|
+
|
|
227
|
+
copy_to_clipboard(token)
|
|
228
|
+
print(f"Token: {token}")
|
|
229
|
+
print("Note: Token copied directly to your clipboard ecosystem.")
|
|
230
|
+
|
|
231
|
+
try:
|
|
232
|
+
while True:
|
|
233
|
+
now = int(time.time())
|
|
234
|
+
remaining = time_step - (now % time_step)
|
|
235
|
+
draw_progress_bar(remaining, total_steps=time_step)
|
|
236
|
+
|
|
237
|
+
if remaining <= 1:
|
|
238
|
+
time.sleep(0.5)
|
|
239
|
+
draw_progress_bar(0, total_steps=time_step)
|
|
240
|
+
break
|
|
241
|
+
time.sleep(0.5)
|
|
242
|
+
except KeyboardInterrupt:
|
|
243
|
+
pass
|
|
244
|
+
finally:
|
|
245
|
+
clear_clipboard()
|
|
246
|
+
print("\nClipboard cleared. Token cycle window has successfully closed.")
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# core/crypto.py
|
|
2
|
+
import os
|
|
3
|
+
from cryptography.hazmat.primitives.kdf.argon2 import Argon2id
|
|
4
|
+
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
|
|
5
|
+
|
|
6
|
+
SALT_SIZE = 16
|
|
7
|
+
KEY_SIZE = 32
|
|
8
|
+
NONCE_SIZE = 12
|
|
9
|
+
|
|
10
|
+
def derive_key(master_password: str, salt: bytes = None) -> tuple[bytes, bytes]:
|
|
11
|
+
"""Derives a key from password using Argon2id, generating salt if missing."""
|
|
12
|
+
if salt is None:
|
|
13
|
+
salt = os.urandom(SALT_SIZE)
|
|
14
|
+
kdf = Argon2id(
|
|
15
|
+
length=KEY_SIZE,
|
|
16
|
+
salt=salt,
|
|
17
|
+
iterations=2,
|
|
18
|
+
memory_cost=64 * 1024, # 64 MiB (safe for mobile load profiles)
|
|
19
|
+
lanes=4
|
|
20
|
+
)
|
|
21
|
+
key = kdf.derive(master_password.encode('utf-8'))
|
|
22
|
+
return key, salt
|
|
23
|
+
|
|
24
|
+
def encrypt(data: bytes, key: bytes) -> bytes:
|
|
25
|
+
"""Encrypts payload using ChaCha20Poly1305 AEAD."""
|
|
26
|
+
nonce = os.urandom(NONCE_SIZE)
|
|
27
|
+
cipher = ChaCha20Poly1305(key)
|
|
28
|
+
ciphertext = cipher.encrypt(nonce, data, None)
|
|
29
|
+
return nonce + ciphertext
|
|
30
|
+
|
|
31
|
+
def decrypt(encrypted: bytes, key: bytes) -> bytes:
|
|
32
|
+
"""Decrypts payload using ChaCha20Poly1305 AEAD."""
|
|
33
|
+
nonce = encrypted[:NONCE_SIZE]
|
|
34
|
+
ciphertext = encrypted[NONCE_SIZE:]
|
|
35
|
+
cipher = ChaCha20Poly1305(key)
|
|
36
|
+
return cipher.decrypt(nonce, ciphertext, None)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# core/storage.py
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import struct
|
|
5
|
+
import shutil
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from cryptography.exceptions import InvalidTag
|
|
8
|
+
from .crypto import derive_key, encrypt, decrypt, SALT_SIZE
|
|
9
|
+
|
|
10
|
+
VAULT_PATH = Path.home() / ".foxkey" / "vault.enc"
|
|
11
|
+
|
|
12
|
+
class Vault:
|
|
13
|
+
def __init__(self):
|
|
14
|
+
self.entries = {}
|
|
15
|
+
|
|
16
|
+
def get_public_labels(self) -> list[str]:
|
|
17
|
+
if not VAULT_PATH.exists():
|
|
18
|
+
return []
|
|
19
|
+
try:
|
|
20
|
+
payload = VAULT_PATH.read_bytes()
|
|
21
|
+
if len(payload) < SALT_SIZE + 4:
|
|
22
|
+
return []
|
|
23
|
+
header_len = struct.unpack('>I', payload[SALT_SIZE:SALT_SIZE+4])[0]
|
|
24
|
+
header_bytes = payload[SALT_SIZE+4 : SALT_SIZE+4+header_len]
|
|
25
|
+
return json.loads(header_bytes.decode('utf-8'))
|
|
26
|
+
except Exception:
|
|
27
|
+
return []
|
|
28
|
+
|
|
29
|
+
def load(self, master_password: str, path: Path = None) -> bool:
|
|
30
|
+
path = path or VAULT_PATH
|
|
31
|
+
if not path.exists():
|
|
32
|
+
return True
|
|
33
|
+
payload = path.read_bytes()
|
|
34
|
+
if len(payload) < SALT_SIZE + 4:
|
|
35
|
+
raise ValueError("Corrupt vault file.")
|
|
36
|
+
|
|
37
|
+
salt = payload[:SALT_SIZE]
|
|
38
|
+
header_len = struct.unpack('>I', payload[SALT_SIZE:SALT_SIZE+4])[0]
|
|
39
|
+
encrypted_data = payload[SALT_SIZE + 4 + header_len:]
|
|
40
|
+
|
|
41
|
+
if not encrypted_data:
|
|
42
|
+
raise ValueError("Corrupt vault file: ciphertext block missing.")
|
|
43
|
+
|
|
44
|
+
key, _ = derive_key(master_password, salt)
|
|
45
|
+
try:
|
|
46
|
+
decrypted = decrypt(encrypted_data, key)
|
|
47
|
+
self.entries = json.loads(decrypted.decode('utf-8'))
|
|
48
|
+
return True
|
|
49
|
+
except InvalidTag:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
def save(self, master_password: str):
|
|
53
|
+
key, salt = derive_key(master_password, None)
|
|
54
|
+
labels = list(self.entries.keys())
|
|
55
|
+
header_bytes = json.dumps(labels).encode('utf-8')
|
|
56
|
+
header_len_bytes = struct.pack('>I', len(header_bytes))
|
|
57
|
+
|
|
58
|
+
raw_json = json.dumps(self.entries).encode('utf-8')
|
|
59
|
+
encrypted_data = encrypt(raw_json, key)
|
|
60
|
+
|
|
61
|
+
VAULT_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
62
|
+
VAULT_PATH.write_bytes(salt + header_len_bytes + header_bytes + encrypted_data)
|
|
63
|
+
|
|
64
|
+
def export_backup(self, backup_path: Path):
|
|
65
|
+
"""Simple secure export - just copy the encrypted vault."""
|
|
66
|
+
if not VAULT_PATH.exists():
|
|
67
|
+
raise FileNotFoundError("Nothing to export.")
|
|
68
|
+
backup_path.parent.mkdir(parents=True, exist_ok=True)
|
|
69
|
+
shutil.copy2(VAULT_PATH, backup_path)
|
|
70
|
+
print(f"✅ Vault exported to: {backup_path}")
|
|
71
|
+
|
|
72
|
+
def import_backup(self, backup_path: Path, master_password: str):
|
|
73
|
+
"""Import backup and re-encrypt under current (or new) password."""
|
|
74
|
+
if not backup_path.exists():
|
|
75
|
+
raise FileNotFoundError(f"Backup not found: {backup_path}")
|
|
76
|
+
|
|
77
|
+
temp = Vault()
|
|
78
|
+
success = temp.load(master_password, path=backup_path)
|
|
79
|
+
|
|
80
|
+
if not success:
|
|
81
|
+
raise ValueError("Invalid master password for this backup.")
|
|
82
|
+
|
|
83
|
+
self.entries = temp.entries
|
|
84
|
+
self.save(master_password)
|
|
85
|
+
print(f"✅ Successfully imported from {backup_path}")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# core/totp.py
|
|
2
|
+
import hashlib
|
|
3
|
+
import hmac
|
|
4
|
+
import struct
|
|
5
|
+
import time
|
|
6
|
+
from base64 import b32decode
|
|
7
|
+
|
|
8
|
+
_ALGORITHMS = {
|
|
9
|
+
"SHA1": hashlib.sha1,
|
|
10
|
+
"SHA256": hashlib.sha256,
|
|
11
|
+
"SHA512": hashlib.sha512,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
def generate_totp(secret: str, time_step: int = 30, digits: int = 6, algorithm: str = "SHA1") -> str:
|
|
15
|
+
"""Generates an RFC 6238 TOTP token with clean base32 padding."""
|
|
16
|
+
clean_secret = secret.upper().replace(' ', '')
|
|
17
|
+
missing_padding = len(clean_secret) % 8
|
|
18
|
+
if missing_padding:
|
|
19
|
+
clean_secret += '=' * (8 - missing_padding)
|
|
20
|
+
|
|
21
|
+
key = b32decode(clean_secret)
|
|
22
|
+
counter = int(time.time()) // time_step
|
|
23
|
+
return hotp(key, counter, digits, algorithm)
|
|
24
|
+
|
|
25
|
+
def hotp(key: bytes, counter: int, digits: int = 6, algorithm: str = "SHA1") -> str:
|
|
26
|
+
"""Generates an RFC 4226 HOTP token value."""
|
|
27
|
+
digestmod = _ALGORITHMS.get(algorithm.upper())
|
|
28
|
+
if digestmod is None:
|
|
29
|
+
raise ValueError(
|
|
30
|
+
f"Unsupported algorithm '{algorithm}'. Choose from: {', '.join(_ALGORITHMS)}"
|
|
31
|
+
)
|
|
32
|
+
counter_bytes = struct.pack('>Q', counter)
|
|
33
|
+
hmac_hash = hmac.new(key, counter_bytes, digestmod).digest()
|
|
34
|
+
offset = hmac_hash[-1] & 0x0F
|
|
35
|
+
binary = struct.unpack('>I', hmac_hash[offset:offset+4])[0] & 0x7FFFFFFF
|
|
36
|
+
return str(binary % (10 ** digits)).zfill(digits)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: foxkey
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Secure, dependency-light TOTP 2FA manager with zero footguns.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Source, https://github.com/foxhackerzdevs/foxkey
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: cryptography>=42.0.0
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# 🦊 FoxKey — Secure TOTP Manager
|
|
14
|
+
|
|
15
|
+
Minimalist, secure terminal 2FA client with strong defaults and zero footguns.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
- Encrypted vault (Argon2id + ChaCha20-Poly1305)
|
|
19
|
+
- Plaintext label index (list without password)
|
|
20
|
+
- otpauth:// URI support
|
|
21
|
+
- Clipboard auto-clear + live countdown
|
|
22
|
+
- Export / Import encrypted backups
|
|
23
|
+
- Change master password
|
|
24
|
+
- BusyBox-style single script
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
**From PyPI**
|
|
29
|
+
```bash
|
|
30
|
+
pip install foxkey
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Single binary (recommended)**
|
|
34
|
+
```bash
|
|
35
|
+
pip install pyinstaller
|
|
36
|
+
pyinstaller --onefile --name foxkey foxkey.py
|
|
37
|
+
# Move dist/foxkey to ~/bin or /usr/local/bin
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Development**
|
|
41
|
+
```bash
|
|
42
|
+
git clone ... && cd foxkey
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
```bash
|
|
48
|
+
foxkey add github otpauth://totp/...
|
|
49
|
+
foxkey list
|
|
50
|
+
foxkey get github
|
|
51
|
+
foxkey export --file backup.enc
|
|
52
|
+
foxkey import backup.enc
|
|
53
|
+
foxkey change-password
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Security Notes
|
|
57
|
+
- Master password never touches CLI args
|
|
58
|
+
- Vault refuses weak operations
|
|
59
|
+
- Clipboard cleared after token lifetime
|
|
60
|
+
|
|
61
|
+
---
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
cli.py
|
|
4
|
+
foxkey.py
|
|
5
|
+
pyproject.toml
|
|
6
|
+
core/__init__.py
|
|
7
|
+
core/crypto.py
|
|
8
|
+
core/storage.py
|
|
9
|
+
core/totp.py
|
|
10
|
+
foxkey.egg-info/PKG-INFO
|
|
11
|
+
foxkey.egg-info/SOURCES.txt
|
|
12
|
+
foxkey.egg-info/dependency_links.txt
|
|
13
|
+
foxkey.egg-info/entry_points.txt
|
|
14
|
+
foxkey.egg-info/requires.txt
|
|
15
|
+
foxkey.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cryptography>=42.0.0
|
foxkey-0.1.0/foxkey.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import sys
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
|
|
6
|
+
|
|
7
|
+
from cli import main
|
|
8
|
+
|
|
9
|
+
if __name__ == "__main__":
|
|
10
|
+
try:
|
|
11
|
+
main()
|
|
12
|
+
except KeyboardInterrupt:
|
|
13
|
+
print("\nOperation cancelled.")
|
|
14
|
+
sys.exit(1)
|
|
15
|
+
finally:
|
|
16
|
+
sys.path.pop(0)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "foxkey"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Secure, dependency-light TOTP 2FA manager with zero footguns."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"cryptography>=42.0.0",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
foxkey = "foxkey:main"
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
"Source" = "https://github.com/foxhackerzdevs/foxkey"
|
|
21
|
+
|
|
22
|
+
[tool.setuptools]
|
|
23
|
+
py-modules = ["foxkey", "cli"]
|
|
24
|
+
packages = ["core"]
|
foxkey-0.1.0/setup.cfg
ADDED