1
0
mirror of https://github.com/opencryptoki/opencryptoki.git synced 2026-10-24 05:39:17 +03:00

1520 Commits

Author SHA1 Message Date
Eduardo Barretto
ddba657e94 Bumping up to version-3.9.0
Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
v3.9.0
2018-02-21 14:56:46 -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
Eduardo Barretto
efe6dea553 Fix conditional man pages
Some of the man pages should be built only if they were enabled during
compilation.

Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
2018-02-20 16:19:35 -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
刘群
be1e3dc999 Update opencryptoki-howto.md
Fix broken README links

Signed-off-by: Liu Qun (liuqun) <qunliu@zyhx-group.com>
2018-02-09 10:20:00 -02:00
Ingo Franzki
7eed41f33e EP11: Editorial changes for the pkcsep11_session man page
Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 15:22:26 -02:00
Ingo Franzki
e4864698d4 Fix testcase after max number of slots managed was increased
The multi instance token support patch series also increased the
maximum number of tokens managed (NUMBER_SLOTS_MANAGED in slotmgr.h)
from 6 to 1024. The testcase gen_purpose passes a slot-id that
is supposed to be out of range to functions C_GetSlotInfo, C_GetTokenInfo,
C_GetMechanismList, and C_InitToken and expects CKR_SLOT_ID_INVALID
to be returned. With the increased number of managed slots, the
slot-id used by the testcase (i.e,. 999) is no longer out of range.

This commit changes the testcase to use slot-id 9999, so that it is
out of range again.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:39:35 -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
707e1fe9a3 EP11: Testcase for DH key import
Enhance the DH testcase to import a public and private DH key.
After import, the keys are used to derive a generic secret
key to ensure that imported key is usable.

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
78c367c836 EP11: Testcase for DSA key import
Enhance the DSA testcase to import a public and private
DSA key. After import, the keys are used to sign and verify
some data to ensure that imported key is usable.

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
e656b403ea Update rsa testcase to test SHA224_RSA_PKCS_PSS mechanism
The rsa testcase (rsa_func.c) will now also test
mechanism CKM_SHA224_RSA_PKCS_PSS.

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
Ingo Franzki
b8db846b96 Update rsa testcase to test SHA224_RSA_PKCS mechanism
The rsa testcase (rsa_func.c) will now also test
mechanism CKM_SHA224_RSA_PKCS.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
9eef2136a0 Add SHA224_RSA_PKCS mechanism to common code and EP11 token
Add mechanisms CKM_SHA224_RSA_PKCS 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
ad3c195ccd Update ec testcase to test ECDSA_SHA224 mechanism
The ec testcase (ec_func.c) will now also test
mechanism CKM_ECDSA_SHA224.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
98ee8e868d Add ECDSA_SHA224 mechanism to common code, CCA and EP11 tokens
Add mechanisms CKM_ECDSA_SHA224 to common code, the CCA token,
and the EP11 token.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
a2efbdc80f Update digest testcase to test SHA224 mechanisms
The digest testcase (digest_func.c) will now also test
mechanisms CKM_SHA224, CKM_SHA224_HMAC, and
CKM_SHA224_HMAC_GENERAL.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Ingo Franzki
80304ceb9e Add SHA224 mechanisms to common code, CCA and EP11 tokens
Add mechanisms CKM_SHA224, CKM_SHA224_HMAC, and CKM_SHA224_HMAC_GENERAL
to common code, the CCA token, and the EP11 token.

Note that some SHA-2 related defines in defs.h need to be changed
to avoid a name clash. Defines for SHA-256 are named SHA2_xxx, defines
for SHA-384 are named SHA3_xxx and defines for SHA-512 are named
SHA5_xxx. The names of those defines are changed for 2 reasons:
1.) How would the defines for SHA-224 by named? SHA2_xxx is misleading here.
2.) There is already a SHA-3. So SHA3_xxx is misleading as well.
The defines are changed to SHA256_xxx, SHA384_xxx, and SHA512_xxx.
Also new defines for SHA224_xxx are added.
This change requires changes in several files where these defines are used.

Signed-off-by: Ingo Franzki <ifranzki@linux.vnet.ibm.com>
2018-01-31 10:20:07 -02:00
Eduardo Barretto
30fbe64352 Define CK_FALSE and CK_TRUE macros
PKCS#11 v2.20 defines two macros (CK_TRUE and CK_FALSE) for use with
values of type CK_BBOOL. For backwards compatibility, we keep defining
TRUE and FALSE and CK_DISABLE_TRUE_VENDOR which may be set by the
application vendor.
Fix #23.

Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
2017-12-21 15:14:18 -02:00
Ingo Tuchscherer
254c944c1e EP11 EC Key import [PATCH 08/08]
Added test cases for EC key import (functional part).

Signed-off-by: Ingo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com>
2017-12-19 15:14:29 -02:00
Ingo Tuchscherer
1d37514ca0 EP11 EC Key import [PATCH 07/08]
Added test cases for EC key import (header/definitions).

Signed-off-by: Ingo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com>
2017-12-19 15:14:29 -02:00
Ingo Tuchscherer
7046d1fd0d EP11 EC Key import [PATCH 06/08]
Added test cases for EC key import (common part).

Signed-off-by: Ingo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com>
2017-12-19 15:14:29 -02:00
Ingo Tuchscherer
60032d4417 EP11 EC Key import [PATCH 05/08]
Support for EC secure key import in EP11 token.

Signed-off-by: Ingo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com>
2017-12-19 15:14:29 -02:00