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

utf-8 decode error #39

Open
herkhinah opened this issue Aug 18, 2023 · 3 comments
Open

utf-8 decode error #39

herkhinah opened this issue Aug 18, 2023 · 3 comments

Comments

@herkhinah
Copy link

Apparently pass_secret_service expects the field value to be utf-8 encoded and fails if not.

ERROR fractal::login: Couldn't store session: DBus error zbus error com.dubstepdish.dbus.next.ServiceError: The service interface raised an error: 'utf-8' codec can't decode byte 0xCensored in position 0: invalid start byte.
['  File "/nix/store/ya7xzm8nv5da12h0yg9k27siqjgfav1l-python3.10-dbus-next-0.2.3/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 351, in done\n    result = fut.result()\n', '  File "/nix/store/dx9p05bpjklrg9k8315d6fssik9a1w3f-pass-secret-service-unstable-2022-07-18/lib/python3.10/site-packages/pass_secret_service/interfaces/collection.py", line 117, in CreateItem\n    password = await self.service._decode_secret(secret)\n', '  File "/nix/store/dx9p05bpjklrg9k8315d6fssik9a1w3f-pass-secret-service-unstable-2022-07-18/lib/python3.10/site-packages/pass_secret_service/interfaces/service.py", line 106, in _decode_secret\n    return await session._decode_secret(secret)\n', '  File "/nix/store/dx9p05bpjklrg9k8315d6fssik9a1w3f-pass-secret-service-unstable-2022-07-18/lib/python3.10/site-packages/pass_secret_service/common/tools.py", line 7, in wraps\n    return await loop.run_in_executor(None, lambda: f(*args, **kwargs))\n', '  File "/nix/store/2c7sgx69p6mmp76cvmi5j6c72dj76jj8-python3-3.10.12/lib/python3.10/concurrent/futures/thread.py", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n', '  File "/nix/store/dx9p05bpjklrg9k8315d6fssik9a1w3f-pass-secret-service-unstable-2022-07-18/lib/python3.10/site-packages/pass_secret_service/common/tools.py", line 7, in <lambda>\n    return await loop.run_in_executor(None, lambda: f(*args, **kwargs))\n', '  File "/nix/store/dx9p05bpjklrg9k8315d6fssik9a1w3f-pass-secret-service-unstable-2022-07-18/lib/python3.10/site-packages/pass_secret_service/interfaces/session.py", line 59, in _decode_secret\n    return bytearray(password).decode("utf8")\n']
@Lykos153
Copy link

I'm having the same issue. (Adding some readability to the stacktrace)

2024-01-12T08:39:06.444856Z ERROR fractal::login: Could not store session: DBus error service error org.freedesktop.zbus.Error: The service interface raised an error: 'utf-8' codec can't decode byte ... in position 0: invalid start byte.
  File "/nix/store/bph8ns8lvhzlw2m26az7idcwp123ps47-python3.11-dbus-next-0.2.3/lib/python3.11/site-packages/dbus_next/aio/message_bus.py", line 351, in done
    result = fut.result()
             ^^^^^^^^^^^^
  File "/nix/store/1w4vidjk2d43vlp62bkjd91v9b8xjkrn-pass-secret-service-unstable-2022-07-18/lib/python3.11/site-packages/pass_secret_service/interfaces/collection.py", line 117, in CreateItem
    password = await self.service._decode_secret(secret)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/1w4vidjk2d43vlp62bkjd91v9b8xjkrn-pass-secret-service-unstable-2022-07-18/lib/python3.11/site-packages/pass_secret_service/interfaces/service.py", line 106, in _decode_secret
    return await session._decode_secret(secret)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/1w4vidjk2d43vlp62bkjd91v9b8xjkrn-pass-secret-service-unstable-2022-07-18/lib/python3.11/site-packages/pass_secret_service/common/tools.py", line 7, in wraps
    return await loop.run_in_executor(None, lambda: f(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/5k91mg4qjylxbfvrv748smfh51ppjq0g-python3-3.11.6/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/1w4vidjk2d43vlp62bkjd91v9b8xjkrn-pass-secret-service-unstable-2022-07-18/lib/python3.11/site-packages/pass_secret_service/common/tools.py", line 7, in <lambda>
    return await loop.run_in_executor(None, lambda: f(*args, **kwargs))
                                                    ^^^^^^^^^^^^^^^^^^
  File "/nix/store/1w4vidjk2d43vlp62bkjd91v9b8xjkrn-pass-secret-service-unstable-2022-07-18/lib/python3.11/site-packages/pass_secret_service/interfaces/session.py", line 59, in _decode_secret
    return bytearray(password).decode("utf8")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@Lykos153
Copy link

Lykos153 commented Jan 12, 2024

I don't think it expects the value to be utf-8 encoded. The password gets encoded first, then later decoded, but there is an optional encryption logic. To me it looks more like it gets encoded and encrypted, but the decoder isn't aware of the AES key (yet), so it tries to decode without decrypting.

def _encode_secret(self, password):

    # secrethelper
    @run_in_executor
    def _encode_secret(self, password):
        aes_iv = b""
        password = password.encode("utf8")
        if self.aes_key:
            aes_iv = os.urandom(0x10)
            padder = PKCS7(0x80).padder()
            password = padder.update(password) + padder.finalize()
            encryptor = Cipher(AES(self.aes_key), CBC(aes_iv), default_backend()).encryptor()
            password = encryptor.update(password) + encryptor.finalize()
        return [self.path, aes_iv, password, "text/plain"]

    @run_in_executor
    def _decode_secret(self, secret):
        password = secret[2]
        if self.aes_key:
            aes_iv = bytes(secret[1])
            decryptor = Cipher(AES(self.aes_key), CBC(aes_iv), default_backend()).decryptor()
            password = decryptor.update(password) + decryptor.finalize()
            unpadder = PKCS7(0x80).unpadder()
            password = unpadder.update(password) + unpadder.finalize()
        return bytearray(password).decode("utf8")

@tamis-laan
Copy link

This also happens to me while nextcloud tries to get the login credentials but the GPG key hasn't been unlocked yet.

What should happen is GPG should open pinentry so we can unlock the key.

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