[openssl-users] How to override methods in EVP_PKEY_METHOD structure that is attached to a EVP_PKEY_CTX?
jb-openssl at wisemo.com
Fri Feb 17 17:43:19 UTC 2017
On 17/02/2017 16:21, Stephan Mühlstrasser wrote:
> Am 17.02.17 um 16:09 schrieb Jakob Bohm:
>> On 17/02/2017 15:25, Stephan Mühlstrasser wrote:
>>> we use OpenSSL 1.0.2 together with PKCS#11 tokens by plugging methods
>>> into the RSA_METHOD structure that interface with the PKCS#11 token,
>>> and this works fine so far. However, for creating RSA signatures with
>>> PSS padding this strategy doesn't work anymore, because OpenSSL wants
>>> to directly encrypt with the private key in this case, which is not
>>> possible in PKCS#11.
>> I believe some PKCS#11 tokens can do this by using CKM_RSA_X_509
> How could that work? If I understand the PKCS#11 specification
> correctly it is not possible in principle to use private keys for
> encryption via the C_EncryptInit() and C_Encrypt() functions, for the
> following reasons:
> 1) Private keys are not allowed to have the CKA_ENCRYPT attribute (see
> "Table 30, Common Private Key Attributes" in the PKCS#11
> specification, which does not list the CKA_ENCRYPT attribute).
> 2) For the C_EncryptInit() to succeed the key must have the attribute
> From the PKCS#11 documentation of C_EncryptInit():
> "The CKA_ENCRYPT attribute of the encryption key, which indicates
> whether the key supports encryption, must be CK_TRUE."
Some token keys on some tokens (think e-mail decryption private keys or
TLS server private keys) intentionally support decryption of a wrapped
symmetric key via PKCS#11 mechanisms such as the one from PKCS1v1.5 or OAEP.
The precise set of such public key operations available is given by the set
of "mechanisms" enumerated by the pkcs11 driver for the individual token.
One of the defined mechanisms (the one confusingly named "X509") appears to
actually be the raw RSA operation, thus allowing it to be repurposed to
implement any RSA scheme (such as PSS, or SHA-256 signatures) that might
be missing on the token iteself. But this obviously only works for those
tokens that allow this, which varies by token model, token configuration
and PKCS11-driver version.
This obviously isn't possible for all tokens, and thus in general doesn't
solve your original problem for those tokens that support PSS signatures
natively, but not the raw RSA operation. But it can be helpful for those
tokens that do support the raw RSA operation and expose this ability
their PKCS#11 drivers.
Jakob Bohm, CIO, Partner, WiseMo A/S. https://www.wisemo.com
Transformervej 29, 2860 Søborg, Denmark. Direct +45 31 13 16 10
This public discussion message is non-binding and may contain errors.
WiseMo - Remote Service Management for PCs, Phones and Embedded
More information about the openssl-users