Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TinyDB, Added GUI (Credentials viewer), Credentials Encryption #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ config.json
credentials.txt
.ruff_cache
.mypy_cache
brave.exe
credentials.json
chromedriver.exe
93 changes: 63 additions & 30 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,10 @@
import argparse
import os
import sys
from typing import Tuple
import pyppeteer

from services.alive import keepalive
from services.upload import upload_file
from services.extract import extract_credentials
from utilities.fs import (
Config,
concrete_read_config,
read_config,
write_config,
write_default_config,
save_credentials,
)
from utilities.web import (
generate_mail,
type_name,
Expand All @@ -35,8 +25,15 @@
reinstall_tenacity,
check_for_updates,
delete_default,
get_matching_password,
)

from services.gui import CredentialsManager
from tinydb import TinyDB, Query

# Create an instance of the CredentialsManager class
cm = CredentialsManager()

# Spooky import to check if the correct version of tenacity is installed.
if sys.version_info.major == 3 and sys.version_info.minor <= 11:
try:
Expand Down Expand Up @@ -102,22 +99,34 @@
)

console_args = parser.parse_args()
config_db = TinyDB("config.json")


def setup() -> Tuple[str, Config]:
def setup() -> str:
"""Sets up the configs so everything runs smoothly."""

executable_path = ""
config = read_config()

if config is None:
write_default_config()
config = concrete_read_config()
if os.path.exists("config.json"):
s = config_db.all()
print(s)
account_format_exists = False
executable_path_exists = False
for item in s:
if "accountFormat" in item:
account_format_exists = True
if "executablePath" in item:
executable_path_exists = True
executable_path = item["executablePath"]
if not account_format_exists:
config_db.insert({"accountFormat": "{email}:{password}"})
if not executable_path_exists:
config_db.insert({"executablePath": ""})
else:
executable_path = config.executablePath
config_db.insert({"accountFormat": "{email}:{password}"})
config_db.insert({"executablePath": ""})
executable_path = ""

# If no Chromium based browser is found, ask the user for the path to one.
if not executable_path:
if not executable_path_exists:
p_print(
"Failed to find a Chromium based browser. Please make sure you have one installed.",
Colours.FAIL,
Expand All @@ -127,25 +136,29 @@ def setup() -> Tuple[str, Config]:
)
if os.path.exists(executable_path):
p_print("Found executable!", Colours.OKGREEN)
write_config("executablePath", executable_path, config)
config_db.update(
{"executablePath": executable_path}, Query().executablePath == ""
)
else:
p_print("Failed to find executable!", Colours.FAIL)
sys.exit(1)
elif executable_path_exists:
p_print("Found executable!", Colours.OKGREEN)

return executable_path, config
return executable_path


def loop_registrations(loop_count: int, executable_path: str, config: Config):
def loop_registrations(loop_count: int, executable_path: str):
"""Registers accounts in a loop."""
for _ in range(loop_count):
p_print(f"Loop {_ + 1}/{loop_count}", Colours.OKGREEN)
clear_tmp()

credentials = asyncio.run(generate_mail())
asyncio.run(register(credentials, executable_path, config))
asyncio.run(register(credentials, executable_path))


async def register(credentials: Credentials, executable_path: str, config: Config):
async def register(credentials: Credentials, executable_path: str):
"""Registers and verifies mega.nz account."""
browser = await pyppeteer.launch(
{
Expand Down Expand Up @@ -179,8 +192,21 @@ async def register(credentials: Credentials, executable_path: str, config: Confi
Colours.OKCYAN,
)

# Store the credentials using the CredentialsManager class
password = get_matching_password()

encrypted_credentials, salt = cm.encrypt_credentials(
password,
f"{credentials.email}:{credentials.emailPassword}:{credentials.id}:{credentials.password}",
)
encrypted_credentials_hex = encrypted_credentials.hex()
salt_hex = salt.hex()

cm.store_credentials(
password, credentials.email, encrypted_credentials_hex, salt_hex
)

delete_default(credentials)
save_credentials(credentials, config.accountFormat)

if console_args.file is not None:
file_size = os.path.getsize(console_args.file)
Expand All @@ -190,7 +216,13 @@ async def register(credentials: Credentials, executable_path: str, config: Confi
"File is larger than 5GB, mega.nz limits traffic to 5GB per IP.",
Colours.WARNING,
)
upload_file(console_args.public, console_args.file, credentials)
successful = upload_file(
console_args.public, console_args.file, credentials
)
if successful is not None:
successful = str(successful)
cm.update_account_mega(str(credentials.email), successful)

else:
p_print("File not found.", Colours.FAIL)
if console_args.loop is None or console_args.loop <= 1:
Expand All @@ -201,18 +233,19 @@ async def register(credentials: Credentials, executable_path: str, config: Confi
clear_console()
check_for_updates()

executable_path, config = setup()
executable_path = setup()
if not executable_path:
p_print("Failed while setting up!", Colours.FAIL)
sys.exit(1)

if console_args.extract:
extract_credentials(config.accountFormat)
...
# extract_credentials(config.accountFormat)
elif console_args.keepalive:
keepalive(console_args.verbose)
elif console_args.loop is not None and console_args.loop > 1:
loop_registrations(console_args.loop, executable_path, config)
loop_registrations(console_args.loop, executable_path)
else:
clear_tmp()
credentials = asyncio.run(generate_mail())
asyncio.run(register(credentials, executable_path, config))
asyncio.run(register(credentials, executable_path))
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ Faker>=13.11.1
pymailtm>=1.0.2
pyppeteer>=1.0.2
psutil>=5.9.3
mega.py>=1.0.8
mega.py>=1.0.8
cryptography>=42.0.8
tinydb>=4.8.0
Loading