Skip to content

copy.copy broken for Ed25519PublicKey in 41.0.3 (works in 38.0.4) #9403

@dkg

Description

@dkg

Using python 3.11, with a venv containing python-cryptography 41.0.3 backed by OpenSSL 3.1.2, an attempt to copy an Ed25519PublicKey object yields this error:

  File "…/venv/lib/python3.11/site-packages/pgpy/packet/packets.py", line 1639, in pubkey
    self._extract_pubkey(pk)
  File ".../venv/lib/python3.11/site-packages/pgpy/packet/packets.py", line 1588, in _extract_pubkey
    pk.keymaterial._raw_pubkey = copy.copy(self.keymaterial._raw_pubkey)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/copy.py" line 92, in copy
    rv = reductor(4)
         ^^^^^^^^^^^
TypeError: cannot pickle 'cryptography.hazmat.bindings._rust.openssl.ed25519.Ed25519PublicKey' object

This looks similar to the concerns in #7587.

You should be able to replicate this with:

import copy
from cryptography.hazmat.primitives.asymmetric import ed25519
privkey = ed25519.Ed25519PrivateKey.generate()
pubkey = privkey.public_key()
newpub = copy.copy(pubkey)

When i try it with python-cryptography 38.0.4 i do not see this failure. Is copy.copy meant to work, or should i be using something like the following instead?

pubkey.from_public_bytes(pubkey.public_bytes(serialization.Encoding.Raw, serialization.PublicFormat.Raw))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions