1
0
mirror of https://github.com/opencryptoki/opencryptoki.git synced 2026-10-28 18:37:25 +03:00

1141 Commits

Author SHA1 Message Date
Eduardo Barretto
a8976e082b Bumping up to version-3.10.0
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
2018-06-06 16:55:55 -03:00
Ingo Franzki
363f465755 Fix a bug in sha512_hmac_sign()
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>
2018-06-06 14:35:30 -03:00
Ingo Franzki
02a5840afe ICA: Fix token_specific_rsa_x509_verify() function
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>
2018-06-06 10:14:12 -03:00
Ingo Franzki
38fc3e5c56 SOFT: Add SHA224 support
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>
2018-06-06 10:14:12 -03:00
Ingo Franzki
f5e5519474 Fix get_mgf_mech() to support SHA224
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>
2018-06-06 10:14:12 -03:00
Eduardo Barretto
36df7abe4c Fix warning about misalignment
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
2018-06-05 11:12:40 -03:00
Eduardo Barretto
44a1479513 Fix warnings regarding format overflow
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
2018-06-05 11:12:40 -03:00
Eduardo Barretto
4ed3aa73a1 Fix logic on picking locks when deleting an object
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>
2018-06-05 11:12:40 -03:00
Joerg Schmidbauer
15fb19180b Common code: Check rc from digest_from_kdf
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2018-06-04 09:23:54 -03:00
Joerg Schmidbauer
4f1f83f699 ica_token: Fix compile problem with older libica without ECC support
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2018-05-30 12:54:33 -03:00
Eduardo Barretto
d51164d1b6 Fix copy object when template is null
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>
2018-05-25 15:51:31 -03:00
Joerg Schmidbauer
b5be44aeba ECC support bugfix for ep11 token.
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>
2018-05-25 10:13:17 -03:00
Joerg Schmidbauer
fbb98b3dca ECC updates for cca token.
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>
2018-05-25 10:13:17 -03:00
Joerg Schmidbauer
96415d7633 ECC updates for icatoken.
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>
2018-05-25 10:13:17 -03:00
Joerg Schmidbauer
31f3379a31 Updates for ECC support in common code.
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2018-05-25 10:13:17 -03:00
Joerg Schmidbauer
e55c80ea46 Update token structs for ECC support in icatoken.
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>
2018-05-25 10:13:17 -03:00
Eduardo Barretto
c0b3f198aa Improve pkcsslotd logging
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>
2018-05-16 17:35:37 -03:00
Eduardo Barretto
f55886b7fa Fix Hardware Feature Object validation and tests
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>
2018-03-13 17:08:14 -03:00
Eduardo Barretto
cce990f366 Fix tracing of session id
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>
2018-03-08 11:18:03 -03:00
Eduardo Barretto
f7c1e31529 Fix token reinitialization
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>
2018-02-20 17:16:37 -03:00
Ingo Franzki
a40c60493a EP11: pkcsep11_session: Add missing \n to error messages
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-02-15 09:07:34 -02:00
Ingo Franzki
308d54fba1 EP11: Fix compile error on RHEL distros
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>
2018-02-15 09:07:34 -02:00
Eduardo Barretto
71360afa7d Fix check for user or effective user
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>
2018-02-14 09:16:04 -02:00
Eduardo Barretto
bb2fb162ea Increase RSA max key length
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>
2018-02-12 10:08:30 -02:00
Ingo Franzki
a3ab54e1b6 EP11: pkcsep11_*: Prompt for pins instead of using environment variables
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
ad9e13840d EP11: Support strict/VHSM mode also for RO-USER sessions
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
aea5ba3bdb EP11: Add virtual HSM (vHSM) mode
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
848e1f1539 EP11: pkcsep11_session: Add cardpin command
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
263e264c4e EP11: Add pkcsep11_session tool
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
8ca43c2539 EP11: Add retry logic when EP11 function returns CKR_SESSION_CLOSED
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
e59b27abf4 EP11: Pass EP11 pinblob for session objects in strict mode
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
5c6ac36562 Pass session to token specific object add routine
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
5217798828 EP11: Perform EP11 login when strict mode is enabled
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
01b36b4d53 Add private_data field into SESSION structure
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
be7657d415 EP11: Add STRICT_MODE config option
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
aa32d071cd EP11: Add key import for DH keys
Allow to import private and public DH keys via
C_CreateObject.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
06d07722f1 EP11: Add key import for DSA keys
Allow to import private and public DSA keys via
C_CreateObject.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
efb5c4930c EP11: Cleanup the use of CKR_FUNCTION_FAILED return code
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
31b9189a59 EP11: Improved error handling during token initialization
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
60fdf86dce EP11: Provide a CP-filter config file
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
3bb03f6c60 EP11: Filter list of mechanisms based on control points
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
81562c4b38 EP11: Add function to parse CP-filter config file
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
39750087ff EP11: Add functions to query control points of EP11 cards
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
92b53128c6 EP11: Close config file after reading it
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
6ace3eef1d Add some vendor defined attributes
Add the following vendor (IBM) defined attributes: CKA_IBM_RESTRICTABLE,
CKA_IBM_NEVER_MODIFIABLE, CKA_IBM_RETAINKEY, CKA_IBM_ATTRBOUND,
CKA_IBM_KEYTYPE, CKA_IBM_CV, CKA_IBM_MACKEY, CKA_IBM_USE_AS_DATA,
CKA_IBM_STRUCT_PARAMS, and CKA_IBM_STD_COMPLIANCE1

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
41b507a83d EP11: Make CKA_SENSITIVE default to TRUE for secret keys
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
25455537fa Add SHA512_224/256 mechanisms to common code and EP11 token
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
889154856c EP11: Additional vendor (IBM) defined mechanisms and cleanup
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
e4e77e5eff Add SHA-2 based key derivation mechanisms to common code and EP11
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>
2018-01-31 10:20:07 -02:00
Ingo Franzki
099c8f8fd3 Add SHA224_RSA_PKCS_PSS mechanism to common code and EP11 token
Add mechanisms CKM_SHA224_RSA_PKCS_PSS to common code, and the EP11 token.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00