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

Error while connecting with AuthKey #60

Open
chickysnail opened this issue Nov 11, 2022 · 3 comments
Open

Error while connecting with AuthKey #60

chickysnail opened this issue Nov 11, 2022 · 3 comments

Comments

@chickysnail
Copy link

When I connect to my mi band 4 without an auth key all works
However, when I add the auth key (no matter in the terminal or create the file auth_key.txt), it gives the following error:

python3 miband4_console.py -m <MAC> -k <AUTHKEY>
2022-11-11 23:01:54,391 miband (INFO) > Connecting to F8:08:75:B1:A6:3D
2022-11-11 23:01:55,589 miband (INFO) > Connected
2022-11-11 23:02:01,318 miband (INFO) > Enabling Auth Service notifications status...
2022-11-11 23:02:01,448 miband (INFO) > Requesting random number...
2022-11-11 23:02:01,468 miband (INFO) > Sending encrypted random number
Traceback (most recent call last):
  File "/home/artem-linux-usb/miband4/miband4_console.py", line 226, in <module>
    success = band.initialize()
  File "/home/artem-linux-usb/miband4/miband.py", line 242, in initialize
    self._req_rdn()
  File "/home/artem-linux-usb/miband4/miband.py", line 259, in _req_rdn
    self.waitForNotifications(self.timeout)
  File "/home/artem-linux-usb/.local/lib/python3.10/site-packages/bluepy/btle.py", line 560, in waitForNotifications
    resp = self._getResp(['ntfy','ind'], timeout)
  File "/home/artem-linux-usb/.local/lib/python3.10/site-packages/bluepy/btle.py", line 416, in _getResp
    self.delegate.handleNotification(hnd, data)
  File "/home/artem-linux-usb/miband4/miband.py", line 38, in handleNotification
    self.device._send_enc_rdn(random_nr)
  File "/home/artem-linux-usb/miband4/miband.py", line 263, in _send_enc_rdn
    cmd = self._send_enc_key + self._encrypt(data)
  File "/home/artem-linux-usb/miband4/miband.py", line 269, in _encrypt
    aes = AES.new(self.auth_key, AES.MODE_ECB)
  File "/home/artem-linux-usb/.local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 95, in new
    return AESCipher(key, *args, **kwargs)
  File "/home/artem-linux-usb/.local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/home/artem-linux-usb/.local/lib/python3.10/site-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

I checked that my phone is disconnected
I did not change anything in the code
How do I fix that?

Thanks

@chickysnail
Copy link
Author

General info about miband4:

Soft revision: V1.0.9.68
Hardware revision: V0.25.67.21
Serial: 674962bdd0f1
Battery: 86
Time: 2022-11-11T23:13:26

@asanghc
Copy link

asanghc commented Mar 27, 2023

I'm having what looks like the exact same issue.
This is on an arch linux derivative in case that matters.
6.2.8-zen1-1-zen

2023-03-27 22:02:27,923 miband (INFO) > Connecting to ZOINK
2023-03-27 22:02:30,451 miband (INFO) > Connected
2023-03-27 22:02:46,609 miband (INFO) > Enabling Auth Service notifications status...
2023-03-27 22:02:46,799 miband (INFO) > Requesting random number...
2023-03-27 22:02:46,878 miband (INFO) > Sending encrypted random number
Traceback (most recent call last):
File "/tmp/miband4/miband4_console.py", line 226, in
success = band.initialize()
File "/tmp/miband4/miband.py", line 242, in initialize
self._req_rdn()
File "/tmp/miband4/miband.py", line 259, in _req_rdn
self.waitForNotifications(self.timeout)
File "/home/user/.local/lib/python3.10/site-packages/bluepy/btle.py", line 560, in waitForNotifications
resp = self._getResp(['ntfy','ind'], timeout)
File "/home/user/.local/lib/python3.10/site-packages/bluepy/btle.py", line 416, in _getResp
self.delegate.handleNotification(hnd, data)
File "/tmp/miband4/miband.py", line 38, in handleNotification
self.device._send_enc_rdn(random_nr)
File "/tmp/miband4/miband.py", line 263, in _send_enc_rdn
cmd = self._send_enc_key + self._encrypt(data)
File "/tmp/miband4/miband.py", line 269, in _encrypt
aes = AES.new(self.auth_key, AES.MODE_ECB)
File "/home/user/.local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 95, in new
return AESCipher(key, *args, **kwargs)
File "/home/user/.local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 59, in init
blockalgo.BlockAlgo.init(self, _AES, key, *args, **kwargs)
File "/home/user/.local/lib/python3.10/site-packages/Crypto/Cipher/blockalgo.py", line 141, in init
self._cipher = factory.new(key, *args, **kwargs)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

@bkutasi
Copy link

bkutasi commented Dec 18, 2023

Im facing the same issue without an easy solution.

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