Skip to content

UTF-8 passphrases fail with latin-1 encoding exception during encryption #277

Description

@Neverous

Describe the bug

When using python-gnupg with Deja Dup / Duplicity (which switched to this library recently in version 3.2.0), passphrases containing non-Latin-1 characters or Unicode symbols fail with: Thread exception: 'latin-1' codec can't encode character '***' in position *: ordinal not in range(256)

This occurs because self.encoding hardcodes latin-1: https://github.com/vsajip/python-gnupg/blob/master/gnupg.py#L1155

The only way to override it is externally on the instance, but it's unclear if that is the intended solution. I noticed an old comment suggesting an external override is expected, but shouldn't it be configurable via constructor arguments?

To Reproduce

import gnupg

gpg = gnupg.GPG()
# Passphrase containing non-Latin-1 / Unicode characters
status = gpg.encrypt("Test payload", recipients=None, symmetric=True, passphrase="błąd")
print(status.status)
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)

...
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1-2: ordinal not in range(256)

Expected behavior

python-gnupg should gracefully handle utf-8 encoded non-Latin-1 inputs and passphrases without failing on latin-1 encoding limitations.

Screenshots

N/A

Environment

  • OS, including version: Arch Linux
  • Version of this library: 0.5.6
  • Version of GnuPG: gpg (GnuPG) 2.4.9

Additional information

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions