Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Running python-pkcs11 in Docker - DeviceError

Aperta
#220 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
docker, python

Direzione di ricerca

Start with the failing private_key.decrypt call in the Python snippet and compare the Docker run configuration with the host setup, including the bound pcscd socket, USB device access, and installed ykcs11 library. Use pcsc_scan as the baseline, then determine what differs during decryption; done means the same RSA_PKCS_OAEP operation succeeds inside the Ubuntu 22.04 container.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When I try to execute PKCS#11 functions (with python-pkcs11 and ykcs11) inside a Docker (ubuntu 22.04) container, it fails in decrypt with DeviceError.

This is the code:

# Use the YubiKey PKCS#11 library.
PKCS11_LIB = "/usr/lib/x86_64-linux-gnu/libykcs11.so"
lib = pkcs11.lib(PKCS11_LIB)

with lib.get_token().open(user_pin=pin) as session:
        private_key = session.get_key(object_class=ObjectClass.PRIVATE_KEY, key_type=KeyType.RSA, id=KEY_ID)
        private_key.decrypt(encrypted_aes_key, mechanism=Mechanism.RSA_PKCS_OAEP)  # Fails with error below 

The error:

  File "/usr/local/lib/python3.10/dist-packages/pkcs11/types.py", line 970, in decrypt
    return self._decrypt(data, **kwargs)
  File "pkcs11/_pkcs11.pyx", line 1631, in pkcs11._pkcs11.DecryptMixin._decrypt
  File "pkcs11/_pkcs11.pyx", line 1634, in pkcs11._pkcs11.DecryptMixin._decrypt
  File "pkcs11/_pkcs11.pyx", line 1562, in pkcs11._pkcs11.DataCryptOperation.crypt_process_fully
  File "pkcs11/_pkcs11.pyx", line 693, in pkcs11._pkcs11.OperationWithBinaryOutput.process_fully
  File "pkcs11/_pkcs11.pyx", line 583, in pkcs11._pkcs11.OperationContext._handle_final_retval
  File "pkcs11/_pkcs11.pyx", line 47, in pkcs11._pkcs11.assertRV
pkcs11.exceptions.DeviceError

If I run the same command with the same installed tools on the host machine (ubuntu 22.04), it just works.

This is the docker command I use:

sudo docker run -it --rm \
    --device /dev/bus/usb:/dev/bus/usb \
    --mount type=bind,source=/run/pcscd/pcscd.comm,target=/run/pcscd/pcscd.comm \
    --privileged \
    $IMAGE

How to solve this issue?

pcsc_scan does find the YubiKey inside the docker without problem, with all properties.

Lingua principale
Python
Stelle
170
Fork
79
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pyauth/python-pkcs11

Tutte le issue di pyauth/python-pkcs11

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.