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

Got exception "binascii.Error" on every start, fixed with a hack... #143

Open
WegDamit opened this issue Sep 15, 2023 · 3 comments
Open

Comments

@WegDamit
Copy link

on mac i get this after starting openconnect-sso:

Traceback (most recent call last):
  File "/Users/ar/.local/pipx/venvs/openconnect-sso/lib/python3.11/site-packages/openconnect_sso/config.py", line 129, in totp
    return pyotp.TOTP(totpsecret).now() if totpsecret else None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ar/.local/pipx/venvs/openconnect-sso/lib/python3.11/site-packages/pyotp/totp.py", line 64, in now
    return self.generate_otp(self.timecode(datetime.datetime.now()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ar/.local/pipx/venvs/openconnect-sso/lib/python3.11/site-packages/pyotp/otp.py", line 35, in generate_otp
    hasher = hmac.new(self.byte_secret(), self.int_to_bytestring(input), self.digest)
                      ^^^^^^^^^^^^^^^^^^
  File "/Users/ar/.local/pipx/venvs/openconnect-sso/lib/python3.11/site-packages/pyotp/otp.py", line 52, in byte_secret
    return base64.b32decode(secret, casefold=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/base64.py", line 254, in b32decode
    return _b32decode(_b32alphabet, s, casefold, map01)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/base64.py", line 236, in _b32decode
    raise binascii.Error('Non-base32 digit found') from None
binascii.Error: Non-base32 digit found

fix was modifing config.py:

import binascii
# ...

    @property
    def totp(self):
        try:
            totpsecret = keyring.get_password(APP_NAME, "totp/" + self.username)
            return pyotp.TOTP(totpsecret).now() if totpsecret else None
        except (keyring.errors.KeyringError, binascii.Error):   # <-- added new exception
            logger.info("Cannot retrieve saved totp info from keyring.")
            return ""

in my pipx installed files, so... no PR, sorry.

Seems like a new issue with newer pythons or something.

PS:
No i get a endless loop on M$ 2FA windows, because of confusion if app or code is used. Different topic...

@tomm87
Copy link

tomm87 commented Oct 16, 2023

I had the same problem, and this solution worked for me. Thanks WegDamit!

@tomm87
Copy link

tomm87 commented Oct 23, 2023

It just occurred to me that I could add some detail to make the above comment more useful.

  • It was on Debian 12 that I had this problem, with Python 3.11.2 as packaged by Debian.
  • Networking is configured via ifupdown (/etc/network/interfaces), rather than Network Manager or something else.
  • And that's all the detail I can think to add.

WegDamit's fix is working fine for me, so this isn't meant as a nudge for a response.

@tbfisher
Copy link

@WegDamit thank you, this worked for me as well.

I'm on ubuntu 22.04 with python 3.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants