A wrong size during manual HMAC calculation causes that the
returned signature is wrong. This happens for the ICA token,
since it does not provide a token specific HMAC_Sign function.
Also remove an unnecessary second check for the token specific
HMAC-Sign function. This check is already done a few lines above and
is not needed again. If we reach there, there is no token specific
HMAC-Sign function.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
A break is missing in a loop to find the beginning of the
output data. This causes C_Verify to fail with
CKR_SIGNATURE_INVALID when mechanism CKM_RSA_X_509 is used.
This function was introduced in 2012 with commit
e745e536f7 and could
never have worked since then.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Add support for SHA224 based mechanisms:
CKM_SHA224, CKM_SHA224_HMAC, CKM_SHA224_HMAC_GENERAL,
CKM_SHA224_RSA_PKCS_PSS
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
SHA224 support is missing in function get_mgf_mech(),
used for RSA-OAEP.
This fixes failing RSA testcases for the SOFT and ICA token.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
When DestroyObject is called, we first get a write lock, and then, on
the same thread, we try to get a read lock and later on a write lock.
This fixes the logic so we avoid unlocking in wrong places.
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
When some application call C_CopyObject and passes a null template and a
count of 0 then we should be able to continue and execute the copy, but
this was failing because of some wrong checks.
As a consequence I've also added a testcase to copyobjects to try to
copy an object when we pass a null template and check if the new object
matches the old object.
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
Corrected the length of the returned bitstring in routine
ep11_spki_key. Note that the ep11token supports
CKM_ECDH1_DERIVE according to the PKCS#11 v2.20 spec
(because of the ep11 host lib), while the icatoken
supports v2.40!
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
This update provides EC key import and handling of
compressed / uncompressed EC public keys. This is needed
for the key import and key transport testcases.
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
icatoken now implements token specific EC key generate,
EC sign/verify, and ECDH derive. This code is based on
previous commit (ECC updates in common code).
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
The ecdh_derive function is new in all tokens, so we must
add a function entry for it in all token specific structs
and initialize it with NULL. Also, a function prototype
must be added to the common token structs. ECDH mechanism
related structs and defines are added to pkcs11types.h.
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
Removed a misleading pkcsslotd log message that was causing wrong
interpretations and also because it is not necessary. Created a new
informational log message to inform when PID file is created. This will
help in the future to know about systemd timing issues.
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
Monotonic Counters have read-only attributes. If during CreateObject the
supplied template specifies a value for any of the read-only attributes,
then the attempt should fail with the error code CKR_ATTRIBUTE_READ_ONLY.
Fixed tests that created Monotonic counters objects.
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
The trace was showing session id 0 on tracing file for tokens that use
common/new_host.c, because we were not setting the handle of session
objects.
Also added better tracing when a session id is not valid.
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
During a token reinitialization, to set up a SO PIN or a User PIN again,
the operation would fail mentioning that the hash of the old PIN doesn't
match the entered old PIN. This happens because during InitToken
operation we are resetting the NV data, and with this we are loosing the
hash and md5 of the old PIN.
To fix this, instead of calling init_token_data on every InitToken, we
do a load_token_data, that will check if we have a NV data already
created. If yes, it just loads it. If not, it calls init_token_data.
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
On RHEL the compiler flagged 'for' loop initial declarations in macro
RETRY_START, because this is are only allowed in C99 mode.
Change the macro to use a do { ... } while (0) construct around the
for loop and declare the variable outside of the for loop.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
The check_user_and_group function checks for Root or effetive Root as
mentioned on the code comment, but the way that it is implemented it is
checking for Root AND effective Root, which is a totally different
logic.
Fix proposed by Red Hat.
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
While performing RSA OpenSSL speed test it was resulting on segmentation
fault when using ICA token for RSA key lengths bigger than 512. Increased the
MAX_RSA_KEYLEN to 1920 so we are able to perform RSA speed test
successfully.
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
For security reasons it is not a good idea to use environment variables
to pass the PKCS#11 pins to the tools. This patch changes the two EP11
related tools pkcsep11_migrate and pkcsep11_session to prompt for the
pins instead of using environment variables.
All other tools provided as part of the Opencryptoki package already
prompt for pins, so this patch makes the EP11 related tools to behave
the same way as the other tools.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
Currently the strict session mode and/or VHSM mode is only
available for RW-User sessions, because the code needs to
create a special token object to store the EP11 session.
On read-only sessions token objects can not be created.
To circumvent this problem, and allow strict session mode
and/or VHSM mode also for read-only user sessions, a temporary
helper RW-USER session is created for storing the token object,
when logging in a RO-USER session. The helper session is closed
right after storing the token object.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
When vHSM mode is enabled via config option VHSM_MODE
in EP1 config file, all objects are bound to a pin blob
(obtained via m_Login) that is derived from the card pin.
That way, other EP11 token instances using the same EP11
adapters can not use objects created by this instance,
provided that each instance uses a different card pin.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
The cardpin command of pkcsep11_session allows to set a cardpin
for an EP11 token. A cardpin is required to enable the virtual
HSM (vHSM) mode.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
The pkcsep11_session performs EP11 session management functions,
such as logging out left over EP11 sessions from processes that
terminate unexpectedly, without logging out properly when strict
mode is enabled.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
When keys are used that are bound to an EP11 session, all EP11
library functions that deal with such keys may return return code
CKR_SESSION_CLOSED when the adapter where the EP11 function is routed
to does not yet know the session the key is bound to. This can happen
when new EP11 adapters come online dynamically.
The retry logic then performs a m_Login again on all available EP11
adapters, and then retries the original function.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
The EP11 session pinblob obtained from m_Login when strict
mode is enabled is passed to m_GenerateKey, m_GenerateKeyPair,
m_UnwrapKey, and m_DeriveKey functions of the EP11 library
to bind the returned key objects to the EP11 session.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
In order to allow the token specific object add routine
to use information that is anchored in the session structure,
the session needs to be passed to the token specific object
add routine.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
When strict mode is enabled via config option STRICT_MODE
in EP1 config file, use m_Login/m_Logout to login/logout
an EP11 session whenever a PKCS#11 session logs in/out.
During Login processing, the EP11 session (pinblob) is
stored in a private and hidden token object of class
CKO_HW_FEATURE with a vendor specific HW-feature type.
During Logout processing this token object is deleted.
When the program abends without performing a logout, the
EP11 session object is kept. This left over EP11 session
can then be logged out at later time using a to be
developed command line tool.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
Add a void pointer field named private_data into the
SESSION structure. This allows tokens to anchor some
private session information into the session structure.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
Add a new config option named "STRICT_MODE" to be specified
in the EP11 token configuration file ep11tok.conf.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
Cleanup the use of CKR_FUNCTION_FAILED return code in EP11
(and obj_mgr.c in common code). When CKR_FUNCTION_FAILED is
returned the caller usually can obtain the device error using
C_GetSessionInfo (field ulDeviceError in CK_SESSION_INFO).
After the cleanup only one error case returns CKR_FUNCTION_FAILED:
When BER handling fails (errors other than CKR_HOST_MEMORY).
Because of this, there is no need to provide a reason code
in ulDeviceError in the session info structure.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
Improved the error handling during EP11 token initialization.
Any error that hinders the token from being initialized properly
now also issues a syslog message with an descriptive message.
That way users can find out what is going wrong without the need
to enable the trace and inspect the trace file.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
The EP11 CP-filter config file is is used to associate certain
control points with mechanisms that are dependent on these
control points.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
The list of mechanisms returned by C_GetMechanismList
filtered according to the CP-Filter config file. Only
those mechanisms are reported where the associated control
points are set. Also C_GetMechanismInfo will return
CKR_MECHANISM_INVALID when the mechanism to get info for
is restricted by the current control point setting.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
The list of mechanisms returned by C_GetMechanismList is
filtered using the control point settings of the used crypto
adapters.The EP11 CP-filter config file is used to
associate certain control points with mechanisms that are
dependent on these control points. The default CP-filter
config file is 'ep11cpfilter.conf' located in the same
directory as this EP11 token configuration file.
You can optionally specify the name and/or location of the
CP-filter file in the EP 11 Token Config file with keyword
CPFILTER:
CPFILTER /etc/opencryptoki/ep11cpfilter.conf
The syntax of the CP-Filter file is as follows:
cp: mech1, mech2, ...
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
Add a set of functions to query the control points of EP11
cards. If the ep11 config file uses APQN_ANY, then sysfs is
used to determine all available EP11 cards.
If an APQN_WHIELIST is used, then only those cards in the
white list are used.
When the cards have different control points settings, a
warning message is issued to syslog, and the minimum
control point setting of all cards is returned.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
When option FORCE_SENSITIVE is specified in the ep11 config
file, then for secret keys (CKA_CLASS = CKO_SECRET_KEY) the
attribute CKA_SENSITIVE is set to CK_TRUE if it is not explicitly
specified in the template.
This applies to C_GenerateKey, C_GenerateKeyPair, C_UnwrapKey,
and C_DeriveKey.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
Add mechanisms CKM_SHA512_224, CKM_SHA512_224_HMAC, CKM_SHA512_224_HMAC_GENERAL
CKM_SHA512_256, CKM_SHA512_256_HMAC, and CKM_SHA512_256_HMAC_GENERAL
to common code and the EP11 token.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
Add mechanisms CKM_SHA224_KEY_DERIVATION, CKM_SHA384_KEY_DERIVATION,
and CKM_SHA512_KEY_DERIVATION to common code and EP11.
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>