p11-glue / p11-kit

Provides a way to load and enumerate PKCS#11 modules.
https://p11-glue.github.io/p11-glue/p11-kit.html
Other
151 stars 95 forks source link

Lists of mechanisms are different on local and remote SoftHSM2 #618

Closed nkosmynin closed 10 months ago

nkosmynin commented 10 months ago

I have installed SoftHSM v.2 on Rocky Linux and trying to access it remotely with p11-kit according to the instructions in p11-kit remoting/forwarding. The remote access works as described there.

However, the lists of mechanisms retrieved locally by p11tool (from gnutls-untils package) from SoftHSM and remotely from the client are different, the list from client is much shorter. My understanding is that the lists shall be the same, I would appreciate feedback on this issue.

Packages are installed from default repositories of Rocky Linux 8.7.

$ yum rq --installed p11-kit gnutls-utils softhsm
gnutls-utils-0:3.6.16-8.el8_9.x86_64
p11-kit-0:0.23.22-1.el8.x86_64
softhsm-0:2.6.1-5.el8.1.x86_64

Server host

$ p11tool --list-mechanisms  --provider /usr/lib64/pkcs11/libsofthsm2.so
[0x1082] CKM_AES_CBC keysize range (16, 32) encrypt decrypt wrap
[0x1105] CKM_AES_CBC_ENCRYPT_DATA derive
[0x1085] CKM_AES_CBC_PAD keysize range (16, 32) hw encrypt decrypt
[0x108a] CKM_AES_CMAC keysize range (16, 32) sign verify
[0x1086] CKM_AES_CTR keysize range (16, 32) hw encrypt decrypt
[0x1081] CKM_AES_ECB keysize range (16, 32) hw encrypt decrypt
[0x1104] CKM_AES_ECB_ENCRYPT_DATA derive
[0x1087] CKM_AES_GCM keysize range (16, 32) hw encrypt decrypt
[0x1080] CKM_AES_KEY_GEN keysize range (16, 32) generate
[0x2109] CKM_AES_KEY_WRAP keysize range (16, 2147483648) wrap unwrap
[0x210a] CKM_AES_KEY_WRAP_PAD keysize range (1, 2147483648) wrap unwrap
[0x0130] CKM_DES2_KEY_GEN generate
[0x0133] CKM_DES3_CBC encrypt decrypt wrap
[0x1103] CKM_DES3_CBC_ENCRYPT_DATA derive
[0x0136] CKM_DES3_CBC_PAD hw encrypt decrypt
[0x0138] CKM_DES3_CMAC sign verify
[0x0132] CKM_DES3_ECB hw encrypt decrypt
[0x1102] CKM_DES3_ECB_ENCRYPT_DATA derive
[0x0131] CKM_DES3_KEY_GEN generate
[0x0122] CKM_DES_CBC encrypt decrypt wrap
[0x1101] CKM_DES_CBC_ENCRYPT_DATA derive
[0x0125] CKM_DES_CBC_PAD encrypt decrypt wrap
[0x0121] CKM_DES_ECB encrypt decrypt wrap
[0x1100] CKM_DES_ECB_ENCRYPT_DATA derive
[0x0120] CKM_DES_KEY_GEN generate
[0x0021] CKM_DH_PKCS_DERIVE keysize range (512, 10000) derive
[0x0020] CKM_DH_PKCS_KEY_PAIR_GEN keysize range (512, 10000) generate_key_pair
[0x2001] CKM_DH_PKCS_PARAMETER_GEN keysize range (512, 10000) generate
[0x0011] CKM_DSA keysize range (512, 1024) sign verify
[0x0010] CKM_DSA_KEY_PAIR_GEN keysize range (512, 1024) generate_key_pair
[0x2000] CKM_DSA_PARAMETER_GEN keysize range (512, 1024) generate
[0x0012] CKM_DSA_SHA1 keysize range (512, 1024) sign verify
[0x0013] CKM_DSA_SHA224 keysize range (512, 1024) sign verify
[0x0014] CKM_DSA_SHA256 keysize range (512, 1024) sign verify
[0x0015] CKM_DSA_SHA384 keysize range (512, 1024) sign verify
[0x0016] CKM_DSA_SHA512 keysize range (512, 1024) sign verify
[0x1050] CKM_ECDH1_DERIVE keysize range (112, 521) derive
[0x1041] CKM_ECDSA keysize range (112, 521) sign verify ec_f_p ec_namedcurve ec_uncompress
[0x1055] CKM_EC_EDWARDS_KEY_PAIR_GEN keysize range (256, 456) generate_key_pair
[0x1040] CKM_ECDSA_KEY_PAIR_GEN keysize range (112, 521) generate_key_pair ec_f_p ec_namedcurve ec_uncompress
[0x1057] CKM_EDDSA keysize range (256, 456) sign verify
[0x0350] CKM_GENERIC_SECRET_KEY_GEN keysize range (1, 2147483648) generate
[0x0210] CKM_MD5 digest
[0x0211] CKM_MD5_HMAC keysize range (16, 512) sign verify
[0x0005] CKM_MD5_RSA_PKCS keysize range (512, 16384) sign verify
[0x0001] CKM_RSA_PKCS keysize range (512, 16384) encrypt decrypt sign verify wrap unwrap
[0x0000] CKM_RSA_PKCS_KEY_PAIR_GEN keysize range (512, 16384) generate_key_pair
[0x0009] CKM_RSA_PKCS_OAEP keysize range (512, 16384) encrypt decrypt wrap unwrap
[0x000d] CKM_RSA_PKCS_PSS keysize range (512, 16384) sign verify
[0x0003] CKM_RSA_X_509 keysize range (512, 16384) encrypt decrypt sign verify
[0x0006] CKM_SHA1_RSA_PKCS keysize range (512, 16384) sign verify
[0x000e] CKM_SHA1_RSA_PKCS_PSS keysize range (512, 16384) sign verify
[0x0255] CKM_SHA224 digest
[0x0256] CKM_SHA224_HMAC keysize range (28, 512) sign verify
[0x0046] CKM_SHA224_RSA_PKCS keysize range (512, 16384) sign verify
[0x0047] CKM_SHA224_RSA_PKCS_PSS keysize range (512, 16384) sign verify
[0x0250] CKM_SHA256 digest
[0x0251] CKM_SHA256_HMAC keysize range (32, 512) sign verify
[0x0040] CKM_SHA256_RSA_PKCS keysize range (512, 16384) sign verify
[0x0043] CKM_SHA256_RSA_PKCS_PSS keysize range (512, 16384) sign verify
[0x0260] CKM_SHA384 digest
[0x0261] CKM_SHA384_HMAC keysize range (48, 512) sign verify
[0x0041] CKM_SHA384_RSA_PKCS keysize range (512, 16384) sign verify
[0x0044] CKM_SHA384_RSA_PKCS_PSS keysize range (512, 16384) sign verify
[0x0270] CKM_SHA512 digest
[0x0271] CKM_SHA512_HMAC keysize range (64, 512) sign verify
[0x0042] CKM_SHA512_RSA_PKCS keysize range (512, 16384) sign verify
[0x0045] CKM_SHA512_RSA_PKCS_PSS keysize range (512, 16384) sign verify
[0x0220] CKM_SHA_1 digest
[0x0221] CKM_SHA_1_HMAC keysize range (20, 512) sign verify

Client host

$ p11tool --list-mechanisms  --provider /usr/lib64/pkcs11/p11-kit-client.so
[0x1081] CKM_AES_ECB keysize range (16, 32) encrypt decrypt verify_recover generate ec_uncompress
[0x1080] CKM_AES_KEY_GEN keysize range (16, 32) generate
[0x0130] CKM_DES2_KEY_GEN generate
[0x0132] CKM_DES3_ECB encrypt decrypt verify_recover generate ec_uncompress
[0x0131] CKM_DES3_KEY_GEN generate
[0x0121] CKM_DES_ECB encrypt decrypt wrap
[0x0120] CKM_DES_KEY_GEN generate
[0x0020] CKM_DH_PKCS_KEY_PAIR_GEN keysize range (512, 10000) generate_key_pair
[0x2001] CKM_DH_PKCS_PARAMETER_GEN keysize range (512, 10000) generate
[0x0011] CKM_DSA keysize range (512, 1024) sign verify
[0x0010] CKM_DSA_KEY_PAIR_GEN keysize range (512, 1024) generate_key_pair
[0x2000] CKM_DSA_PARAMETER_GEN keysize range (512, 1024) generate
[0x0012] CKM_DSA_SHA1 keysize range (512, 1024) sign verify
[0x1041] CKM_ECDSA keysize range (112, 521) sign verify ec_f_p ec_namedcurve ec_uncompress
[0x1040] CKM_ECDSA_KEY_PAIR_GEN keysize range (112, 521) generate_key_pair ec_f_p ec_namedcurve ec_uncompress
[0x0350] CKM_GENERIC_SECRET_KEY_GEN keysize range (1, 2147483648) generate
[0x0210] CKM_MD5 digest
[0x0211] CKM_MD5_HMAC keysize range (16, 512) sign verify
[0x0005] CKM_MD5_RSA_PKCS keysize range (512, 16384) sign verify
[0x0001] CKM_RSA_PKCS keysize range (512, 16384) encrypt decrypt sign verify wrap unwrap
[0x0000] CKM_RSA_PKCS_KEY_PAIR_GEN keysize range (512, 16384) generate_key_pair
[0x0009] CKM_RSA_PKCS_OAEP keysize range (512, 16384) encrypt decrypt wrap unwrap
[0x000d] CKM_RSA_PKCS_PSS keysize range (512, 16384) sign verify
[0x0003] CKM_RSA_X_509 keysize range (512, 16384) encrypt decrypt sign verify
[0x0006] CKM_SHA1_RSA_PKCS keysize range (512, 16384) sign verify
[0x0250] CKM_SHA256 digest
[0x0251] CKM_SHA256_HMAC keysize range (32, 512) sign verify
[0x0040] CKM_SHA256_RSA_PKCS keysize range (512, 16384) sign verify
[0x0260] CKM_SHA384 digest
[0x0261] CKM_SHA384_HMAC keysize range (48, 512) sign verify
[0x0041] CKM_SHA384_RSA_PKCS keysize range (512, 16384) sign verify
[0x0270] CKM_SHA512 digest
[0x0271] CKM_SHA512_HMAC keysize range (64, 512) sign verify
[0x0042] CKM_SHA512_RSA_PKCS keysize range (512, 16384) sign verify
[0x0220] CKM_SHA_1 digest
[0x0221] CKM_SHA_1_HMAC keysize range (20, 512) sign verify
ueno commented 10 months ago

This is on purpose as the client code filters the mechanism list, though it might be an opportunity to review the list. Do you have any use-case of a filtered mechanism?

nkosmynin commented 10 months ago

My use cases utilize AES-CBC encryption, which are missing on client side.

nkosmynin commented 10 months ago

Looking into code, I see that AES_CBC is defined among p11_rpc_mechanism_serializers (added already 2 years ago), which is checked against mechanism_has_sane_parameters(). So it shall not be purged by the client. I will try to compile and test with the latest p11-kit version, maybe the version is repository is too old

nkosmynin commented 10 months ago

After compiling and installing the latest p11-kit from github, my problem is solved - AES-CBC is stated in the mechanisms list by client.