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

[BUG] Selection of 2FA method #2

Open
rantabuz opened this issue Jun 14, 2024 · 0 comments
Open

[BUG] Selection of 2FA method #2

rantabuz opened this issue Jun 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@rantabuz
Copy link

Odoo Task Id

No response

Odoo Helpdesk Ticket Id

No response

External URL

No response

Environnement

Local

Description

When logging in to Bitwarden with 2FA enabled, after entering the master password, a prompt is shown to select between Authenticator App or Email, which disrupts the login flow (which at this point expects the prompt 'Two-step login code:') and the communication with the server timeouts.

The unexpected Bitwarden CLI prompt looks as follows:

? Two-step login method: (Use arrow keys)
❯ Authenticator App 
  Email 
  ──────────────
  Cancel 

The following patch solved the problem for me:

diff --git a/src/s6r_bitwarden_cli/bitwarden.py b/src/s6r_bitwarden_cli/bitwarden.py
index 558382c..39e1d85 100644
--- a/src/s6r_bitwarden_cli/bitwarden.py
+++ b/src/s6r_bitwarden_cli/bitwarden.py
@@ -98,7 +98,18 @@ class BitwardenCli:
         child.sendline(self.username)
         child.expect('Master password')
         child.sendline(self.password)
-        i = child.expect(['Two-step login code:', pexpect.EOF])
+        # Allow choosing 2FA method when the folloing prompt is shown:
+        # ? Two-step login method: (Use arrow keys)
+        # ❯ Authenticator App 
+        #   Email 
+        #   ──────────────
+        #   Cancel 
+        i = child.expect(['Two-step login code:', pexpect.EOF, 'Two-step login method'])
+        if i == 2:
+            # Assumes 'Authenticator App' is the default 2FA method and is selected by just sending an empty line
+            assert '❯ Authenticator App' in child.buffer, 'Authenticator App not the default 2FA method'
+            child.sendline('')
+            i = child.expect(['Two-step login code:', pexpect.EOF])
         if i == 0:
             child.sendline(input('Bitwarden two-step login code:'))
             child.expect(pexpect.EOF)

Error

RUN bw status
SPAWN bw login --raw
Traceback (most recent call last):
  File "/Users/rbuz/Documents/code/infostud/bw_credentials.py", line 72, in <module>
    is_creds = bw_infostud_credentials()
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rbuz/Documents/code/infostud/bw_credentials.py", line 68, in bw_infostud_credentials
    istud_credentials = bw_get_credentials(BW_ITEM_NAME)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rbuz/Documents/code/infostud/bw_credentials.py", line 45, in bw_get_credentials
    bw.login()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/bitwarden/lib/python3.12/site-packages/s6r_bitwarden_cli/bitwarden.py", line 78, in login
    self.login_with_password()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/bitwarden/lib/python3.12/site-packages/s6r_bitwarden_cli/bitwarden.py", line 101, in login_with_password
    i = child.expect(['Two-step login code:', pexpect.EOF])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/bitwarden/lib/python3.12/site-packages/pexpect/spawnbase.py", line 354, in expect
    return self.expect_list(compiled_pattern_list,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/bitwarden/lib/python3.12/site-packages/pexpect/spawnbase.py", line 383, in expect_list
    return exp.expect_loop(timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/bitwarden/lib/python3.12/site-packages/pexpect/expect.py", line 181, in expect_loop
    return self.timeout(e)
           ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/bitwarden/lib/python3.12/site-packages/pexpect/expect.py", line 144, in timeout
    raise exc
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x1068f3470>
command: /opt/homebrew/bin/bw
args: [b'/opt/homebrew/bin/bw', b'login', b'--raw']
buffer (last 100 chars): 'w keys)\x1b[22m\r\n\x1b[36m❯ Authenticator App\x1b[39m \r\n  Email \r\n  \x1b[2m──────────────\x1b[22m\r\n  Cancel \x1b[9D\x1b[9C'
before (last 100 chars): 'w keys)\x1b[22m\r\n\x1b[36m❯ Authenticator App\x1b[39m \r\n  Email \r\n  \x1b[2m──────────────\x1b[22m\r\n  Cancel \x1b[9D\x1b[9C'
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 79743
child_fd: 7
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
    0: re.compile('Two-step login code:')
    1: EOF
@rantabuz rantabuz added the bug Something isn't working label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant