Skip to content

Fix PKCS#11 usage on slot zero#17

Merged
cipherboy merged 1 commit intoopenbao:mainfrom
cipherboy:fix-pkcs11-slot-zero
Feb 9, 2025
Merged

Fix PKCS#11 usage on slot zero#17
cipherboy merged 1 commit intoopenbao:mainfrom
cipherboy:fix-pkcs11-slot-zero

Conversation

@cipherboy
Copy link
Member

When using a HSM that supports allocating on slot zero, we fail to allow its use because we expect a non-zero slot value. This violates PKCS#11, which says:

A priori, any value of CK_SLOT_ID can be a valid slot identifier—in
particular, a system may have a slot identified by the value 0. It
need not have such a slot, however.

Because of the type def:

typedef CK_ULONG CK_SLOT_ID;

we cannot use -1 as a valid number, so we have to convert slot to be a pointer type to know whether or not it has been set.

See also: http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/csprd01/pkcs11-base-v2.40-csprd01.html#_Toc72656028

Thanks to gris-gris for reporting this on Matrix.


cc: @glatigny

When using a HSM that supports allocating on slot zero, we fail to allow
its use because we expect a non-zero slot value. This violates PKCS#11,
which says:

>  A priori, any value of CK_SLOT_ID can be a valid slot identifier—in
> particular, a system may have a slot identified by the value 0.  It
> need not have such a slot, however.

Because of the type def:

> ```
> typedef CK_ULONG CK_SLOT_ID;
> ```

we cannot use -1 as a valid number, so we have to convert slot to be a
pointer type to know whether or not it has been set.

See also: http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/csprd01/pkcs11-base-v2.40-csprd01.html#_Toc72656028

Thanks to gris-gris for reporting this on Matrix.

Signed-off-by: Alexander Scheel <ascheel@gitlab.com>
@cipherboy cipherboy requested review from DanGhita and JanMa February 8, 2025 12:23
@cipherboy cipherboy added the bug Something isn't working label Feb 8, 2025
Copy link
Member

@JanMa JanMa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cipherboy cipherboy merged commit 116ab97 into openbao:main Feb 9, 2025
14 of 15 checks passed
tomek-securosys added a commit to securosys-com/go-kms-wrapping that referenced this pull request Oct 28, 2025
When using a HSM that supports allocating on slot zero, we fail to allow
its use because we expect a non-zero slot value. This violates PKCS#11,
which says:

>  A priori, any value of CK_SLOT_ID can be a valid slot identifier—in
> particular, a system may have a slot identified by the value 0.  It
> need not have such a slot, however.

Because of the type def:

> ```
> typedef CK_ULONG CK_SLOT_ID;
> ```

we cannot use -1 as a valid number, so we have to convert slot to be a
pointer type to know whether or not it has been set.

See also: http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/csprd01/pkcs11-base-v2.40-csprd01.html#_Toc72656028

Thanks to gris-gris for reporting this on Matrix.

Signed-off-by: Tomasz Madej <tomasz.madej@securosys.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants