Skip to content

pycryptoki should promote safer practices #51

@freedge

Description

@freedge

There are some improvements that could be done in the code and the examples to promote safer practices.

One point is the default templates have CKA_EXTRACTABLE=True which looks like a big concern

CKA_EXTRACTABLE: True,

since partition policies by default allow to wrap and export those (also baffling). The default example is making use of the default template and generates extractable private keys (but the default partition policy prevent to wrap those so I guess it's not that bad)

Another point is that there is no example on how to securely provide the token pin, this is left as an exercise to the reader. The slot pin is provided either in the code in the example, or as a parameter on the command line which is also insecure since it is displayed on the process table which is visible by any locally authenticated user on the system. This remarks also applies for example to the "cmu" tool that allows a password on the command line which is bad.

Another point is that there is no check made on the permissions on private keys or Chrystoki.conf that contains an auth secret. This might not be a pycryptoki issue per se, but I'm bothered, as a user of pycryptoki, that the client just works when the setup is insecure. (if you compare with the ssh client, ssh client will refuse to load a private key that is world readable on the system, see https://github.com/openssh/openssh-portable/blob/1ec0a64c5dc57b8a2053a93b5ef0d02ff8598e5c/authfile.c#L90 You could argue that this is not the responsibility of the client but the benefit for the user is just evident).

A last thing is the default example makes use of c_initialize_ex/c_open_session_ex/login_ex and I think they should all be wrapped with try/finally structures or there is a risk that the first mistake in the code leaves a session opened on the system. The finally would reduce that risk.


Although while the password is hidden and replaced with " password: * ", the data to encrypt is shown in exceptions:

pycryptoki.exceptions.LunaCallException:
        Function: c_encrypt
        Error: CKR_DATA_LEN_RANGE
        Error Code: 0x21
        Arguments:
                h_session: 1
                h_key: 2
                data: b'1234567812345678123456781234567'
        mechanism:
                NullMech(mech_type: CKM_AES_ECB (0x00001081))
                output_buffer: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions