Skip to content

PrivateKey and PublicKey objects missing sign/verify with NetHSM PKCS#11 backend #228

@ivaylo-yordanov

Description

@ivaylo-yordanov

When using python-pkcs11 with a NetHSM PKCS#11 backend, PrivateKey and PublicKey objects retrieved via session.get_key() do not expose sign or verify at runtime, despite SignMixin and VerifyMixin existing in the type hierarchy.

Steps to Reproduce

import pkcs11

lib = pkcs11.lib("/path/to/nethsm-pkcs11.so")
token = lib.get_token(token_label="mytoken")

with token.open(user_pin="mypin") as session:
    private_key = session.get_key(object_class=pkcs11.ObjectClass.PRIVATE_KEY, label="mykey")
    private_key.sign(b"hello", mechanism=pkcs11.Mechanism.SHA256_RSA_PKCS_PSS)

Expected Behavior

PrivateKey objects returned by session.get_key() should support .sign() and PublicKey objects should support .verify(), consistent with how other backends (e.g. SoftHSM2) behave.

Actual Behavior

private_key.sign(digest, mechanism=mechanism, mechanism_param=mechanism_param)
^^^^^^^^^^^^^^^^
AttributeError: 'PrivateKey' object has no attribute 'sign'

public_key.verify(digest, signature, mechanism=mechanism, mechanism_param=mechanism_param)
^^^^^^^^^^^^^^^^^
AttributeError: 'PublicKey' object has no attribute 'verify'

Environment

  • python-pkcs11: v0.9.4
  • OS: Windows 11
  • PKCS#11 backend: NetHSM v2.1.0 x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions