예제 #1
0
async def set_google_auth(message: types.Message):
    increase_message_counter()
    chat_id = message.chat.id
    text = _(
        "https://telegra.ph/Passcypher-Google-Authenticator-06-02") + "\n\n"
    if has_g_auth(chat_id):
        if enabled_g_auth(chat_id):
            await bot.send_message(
                chat_id,
                text +
                _("Here you can enable and disable your Google Authenticator settings"
                  ),
                reply_markup=ListOfButtons(text=[_("Turn off")],
                                           callback=["turn 0"
                                                     ]).inline_keyboard)
        else:

            await bot.send_message(
                chat_id,
                text +
                _("Here you can enable and disable your Google Authenticator settings"
                  ),
                reply_markup=ListOfButtons(text=[_("Turn on")],
                                           callback=["turn 1"
                                                     ]).inline_keyboard)
    else:
        await bot.send_message(
            chat_id,
            _("Google Authenticator is not set for you. Press /g_auth_info"))
예제 #2
0
async def decode_start(message: types.Message, state: FSMContext):
    increase_message_counter()
    chat_id = message.chat.id
    text = message.text
    expression = re.compile(f"{OtherTexts.START}(.*){OtherTexts.END}")
    try:
        extract_encoded = expression.findall(text)[0]

    except IndexError:
        await bot.send_message(chat_id, _("Error. Wrong file"))
        return
    expression = re.compile(f"{OtherTexts.END}(.*){OtherTexts.END_CODE}")
    code = expression.findall(text)[0]

    await state.update_data(password=extract_encoded, code=code)
    if not enabled_g_auth(chat_id):
        await bot.send_message(
            chat_id,
            _("""
Please enter your master password.
You can make everything faster with Google Authenticator! 
Press /g_auth_info

"""))
    else:
        await bot.send_message(chat_id, _("Enter the code from the app"))
    await Decode.MASTER_PASSWORD.set()
예제 #3
0
async def encode_saved(call: types.CallbackQuery, state: FSMContext):
    chat_id = call.from_user.id
    password_message = call.message.reply_to_message
    password = password_message.text
    await call.message.delete()
    async with state.proxy() as data:
        data["encrypt_from_saved"] = True
        data["to_encrypt"] = password

        await password_message.delete()

    if not enabled_g_auth(chat_id):
        await bot.send_message(
            chat_id,
            _("""
Please enter your master password.
You can make everything faster with Google Authenticator! 
Press /g_auth_info

"""))
        await Encode.MASTER_PASSWORD.set()
    else:

        master_pass = get_google_auth(chat_id)

        if len(password) > 400:
            await bot.send_message(
                chat_id,
                _("Error has occurred... Too long phrase. Try to enter a phrase \
under 400 characters."))
            return
        elif not master_pass:
            await bot.send_message(chat_id, _("Master Password not found."))
            await state.finish()
            return

        text, code = encode(password.replace("\n", "\\n"), master_pass)
        hint = "Google Authenticator"
        await bot.send_message(
            chat_id,
            _("""<code>----------------------------
ENCRYPTION STARTS HERE
----------------------------
{passw}
----------------------------
ENCRYPTION ENDS HERE
----------------------------
CODE
{code}
----------------------------
</code>

Hint: {hint}
Save this message wherever you want and forward it to the bot should you need to decode it.
""").format(passw=text, code=code, hint=f"{hint}"))
        await state.finish()
        increase_message_counter(password=True)

    await asyncio.sleep(10)
예제 #4
0
async def decode_1(message: types.Message, state: FSMContext):
    increase_message_counter()

    chat_id = message.chat.id
    en_password = (await state.get_data()).get("password")
    code = (await state.get_data())["code"]
    if not enabled_g_auth(chat_id):
        master = message.text
    else:
        if not has_g_auth(chat_id):
            await message.reply(
                _("An error has occurred, you lost the Google authenticator settings\n"
                  "Please re-configure it once again /g_auth_info"))
            await state.finish()

            return
        try:
            if verify(chat_id, message.text):
                master = get_google_auth(chat_id)
            else:
                await bot.send_message(
                    chat_id, _("Code is incorrect, try again or /cancel"))
                return
        except binascii.Error:
            await bot.send_message(
                chat_id, _("Code is incorrect, try again or /cancel"))
            return

    password = (decode(master, en_password, code)).replace("\\n", "\n")

    if (await state.get_data()).get("doc"):

        with open("decoded.txt", "w") as file:
            file.write(password.replace("\\n", "\n"))
        await bot.send_document(chat_id, open("decoded.txt", "rb"))
        with open("decoded.txt", "w") as file:
            file.write(" ")
    else:
        await bot.send_message(
            chat_id,
            _("""
Your decoded password is inside citation marks '<code>{password}</code>'""").
            format(password=password))
    await state.finish()

    await asyncio.sleep(10)
    await message.delete()
예제 #5
0
async def decode_start(message: types.Message, state: FSMContext):
    increase_message_counter()
    chat_id = message.chat.id
    file_id = message.document.file_id
    try:
        await bot.download_file_by_id(file_id, "to_decode.txt")
    except BadRequest:
        return await message.reply(_("INVALID FILE"))
    with open("to_decode.txt", "r") as file:
        try:
            text = file.read()
        except UnicodeDecodeError:
            await bot.send_message(chat_id, _("INVALID FILE"))
            return
    expression = re.compile(f"{OtherTexts.START}(.*){OtherTexts.END}")
    try:
        extract_encoded = expression.findall(text)[0]

    except IndexError:
        await bot.send_message(chat_id, _("Error. Wrong file"))
        return
    expression = re.compile(f"{OtherTexts.END}(.*){OtherTexts.END_CODE}")
    code = expression.findall(text)[0]
    await state.update_data(password=extract_encoded, code=code, doc=True)

    if not enabled_g_auth(chat_id):
        await bot.send_message(
            chat_id,
            _("""
Please enter your master password.
You can make everything faster with Google Authenticator! 
Press /g_auth_info

"""))
    else:
        await bot.send_message(chat_id, _("Enter the code from the app"))
    await Decode.MASTER_PASSWORD.set()

    await asyncio.sleep(10)
    await message.delete()
예제 #6
0
async def decode_start(message: types.Message, state: FSMContext):
    increase_message_counter()
    chat_id = message.chat.id
    enc = message.text.replace("\n", " ")
    try:
        encoded = re.findall("#encoded_pass: '******'.*#", enc)[0]
        code = re.findall("#key: '(.*)'", enc)[0]
    except IndexError:
        await bot.send_message(chat_id, _("Error"))
        return
    await state.update_data(password=encoded, code=code)
    if not enabled_g_auth(chat_id):
        await bot.send_message(
            chat_id,
            _("""
Please enter your master password.
You can make everything faster with Google Authenticator! 
Press /g_auth_info

"""))
    else:
        await bot.send_message(chat_id, _("Enter the code from the app"))
    await Decode.MASTER_PASSWORD.set()
예제 #7
0
async def encode_start(message: types.Message, state: FSMContext):
    increase_message_counter()
    chat_id = message.chat.id
    if not enabled_g_auth(chat_id):
        await bot.send_message(
            chat_id,
            _("""
Please enter your master password.
You can make everything faster with Google Authenticator! 
Press /g_auth_info

"""))
        await Encode.MASTER_PASSWORD.set()
    else:
        await state.update_data(master_pass=get_google_auth(chat_id))
        await Encode.PASSWORD.set()
        await bot.send_message(
            chat_id,
            _("""Enter phrase you want to encrypt.
It should be under 400 characters, for best results there should be only characters from this list:
<pre>{allowed_chars} </pre>
<b> THE BOT DELETES YOUR MESSAGES WITH PASSWORDS AFTER 10 SECONDS</b>
""").format(allowed_chars=allowed_chars))
예제 #8
0
async def info(message: types.Message):
    increase_message_counter()
    chat_id = message.chat.id
    if has_g_auth(chat_id):
        text = _(
            "Here you can enable and disable your Google Authenticator settings"
        )
        if enabled_g_auth(chat_id):
            await bot.send_message(chat_id,
                                   text,
                                   reply_markup=ListOfButtons(
                                       text=[_("Turn off")],
                                       callback=["turn 0"]).inline_keyboard)
        else:

            await bot.send_message(chat_id,
                                   text,
                                   reply_markup=ListOfButtons(
                                       text=[_("Turn on")],
                                       callback=["turn 1"]).inline_keyboard)
    else:
        await bot.send_message(
            chat_id,
            _("Google Authenticator is not set for you. Press /g_auth_info"))