3535#include "cryptoki.h"
3636
3737/* grammar version, for wrapped keys */
38- #define SUPPORTED_GRAMMAR_VERSION "2.1 "
39- #define TOOLKIT_VERSION_SUPPORTING_GRAMMAR "2.4 .0"
38+ #define SUPPORTED_GRAMMAR_VERSION "2.2 "
39+ #define TOOLKIT_VERSION_SUPPORTING_GRAMMAR "2.5 .0"
4040
4141/* Program Error Codes */
4242#define RC_OK 0x00
@@ -218,13 +218,15 @@ typedef enum {
218218} hash_alg_t ;
219219
220220
221- /* cmdLineCtx contains a context that can hold parameters describing attributes. */
222- /* it currently supports these grammars:
221+ /* attribCtx contains a context that can hold parameters parsed from command line
222+ that contains attributes.
223+ It currently supports these grammars:
223224 - CKA_DERIVE=true CKA_LABEL="label" CKA_UNWRAP_TEMPLATE={ CKA_EXTRACTABLE=false ... }
224225 - the attributes can be shortened by removing the "CKA_" prefix
225- - boolean attributes can be true/false, CK_TRUE/CK_FALSE, 1/0, yes/no
226+ - boolean attributes can be true/false, CK_TRUE/CK_FALSE, yes/no, on/off
226227 - boolean attributes without a value are set to CK_TRUE
227228 - boolean attributes prefixed with "no" are set to CK_FALSE
229+ - other attributes follow the same value syntax as for wrappedKeyCtx
228230 */
229231
230232typedef struct s_p11_attribctx {
@@ -242,7 +244,11 @@ typedef struct s_p11_attribctx {
242244 struct {
243245 CK_ATTRIBUTE * attrlist ;
244246 size_t attrnum ;
245- } attrs [4 ];
247+ } attrs [4 ];
248+
249+ /* the following two members keep track of allowed mechanisms, when specified */
250+ CK_MECHANISM_TYPE_PTR allowedmechs ;
251+ size_t allowedmechs_len ;
246252} attribCtx ;
247253
248254/* pkcs11_unwrap / pkcs11_wrap / pkcs11_wctx */
@@ -254,6 +260,11 @@ typedef struct s_p11_wrappedkeyctx {
254260 char * wrappedkeylabel ; /* inner key only - outer key will have random name and ID */
255261
256262 char * filename ; /* filename used to write wrapping file */
263+
264+ /* the following two members keep track of allowed mechanisms, when specified */
265+ CK_MECHANISM_TYPE_PTR allowedmechs ;
266+ size_t allowedmechs_len ;
267+
257268 struct { /* inner or outer but never both (by design) */
258269 CK_MECHANISM_TYPE aes_wrapping_mech ; /* used when wrapping_meth is w_rfc3394 or w_rfc5649 */
259270 CK_BYTE_PTR iv ; /* used for CKM_XXX_CBC_PAD and CKM_AES_KEY_WRAP_PAD */
@@ -644,6 +655,7 @@ CK_ATTRIBUTE_PTR pkcs11_get_attr_in_array ( CK_ATTRIBUTE_PTR array,
644655bool pkcs11_read_attr_from_handle ( pkcs11AttrList * attrlist , CK_OBJECT_HANDLE handle );
645656bool pkcs11_read_attr_from_handle_ext ( pkcs11AttrList * attrlist , CK_OBJECT_HANDLE handle , ... );
646657bool pkcs11_attr_is_template (CK_ATTRIBUTE_TYPE attrtype );
658+ bool pkcs11_attr_is_allowed_mechanisms (CK_ATTRIBUTE_TYPE attrtype );
647659
648660pkcs11AttrList * pkcs11_attrlist_extend (pkcs11AttrList * attrlist , CK_ATTRIBUTE_PTR attrs , CK_ULONG numattrs );
649661
@@ -712,10 +724,11 @@ CK_OBJECT_HANDLE pkcs11_import_component_final(KeyImportCtx *kctx);
712724
713725
714726/* info functions */
715- const char * get_mechanism_name (CK_MECHANISM_TYPE mech ); /* pkcs11_mechanism.c */
716- CK_ATTRIBUTE_TYPE get_attribute_type_from_name (char * name ); /* pkcs11_attrdesc.c */
717- const char * get_attribute_name_from_type (CK_ATTRIBUTE_TYPE attrtyp );
718-
727+ CK_MECHANISM_TYPE pkcs11_get_mechanism_type_from_name (char * name ); /* pkcs11_mechanism.c */
728+ const char * pkcs11_get_mechanism_name_from_type (CK_MECHANISM_TYPE mech ); /* pkcs11_mechanism.c */
729+ CK_ATTRIBUTE_TYPE pkcs11_get_attribute_type_from_name (char * name ); /* pkcs11_attrdesc.c */
730+ const char * pkcs11_get_attribute_name_from_type (CK_ATTRIBUTE_TYPE attrtyp ); /* pkcs11_attrdesc.c */
731+
719732func_rc pkcs11_info_library (pkcs11Context * p11Context );
720733func_rc pkcs11_info_slot (pkcs11Context * p11Context );
721734func_rc pkcs11_info_ecsupport (pkcs11Context * p11Context );
@@ -740,6 +753,10 @@ const CK_OBJECT_HANDLE pkcs11_get_publickeyhandle(wrappedKeyCtx *ctx);
740753
741754wrappedKeyCtx * pkcs11_new_wrappedkeycontext (pkcs11Context * p11Context );
742755void pkcs11_free_wrappedkeycontext (wrappedKeyCtx * wctx );
756+ CK_MECHANISM_TYPE_PTR pkcs11_wctx_get_allowed_mechanisms (wrappedKeyCtx * ctx );
757+ size_t pkcs11_wctx_get_allowed_mechanisms_len (wrappedKeyCtx * ctx );
758+ void pkcs11_wctx_free_mechanisms (wrappedKeyCtx * wctx ); /* to free allowed mechanisms */
759+ void pkcs11_wctx_forget_mechanisms (wrappedKeyCtx * wctx ); /* for transfer of ownership */
743760
744761/* pkcs11_attribctx */
745762attribCtx * pkcs11_new_attribcontext ();
@@ -749,6 +766,12 @@ CK_ATTRIBUTE_PTR pkcs11_get_attrlist_from_attribctx(attribCtx *ctx);
749766size_t pkcs11_get_attrnum_from_attribctx (attribCtx * ctx );
750767void pkcs11_adjust_attrnum_on_attribctx (attribCtx * ctx , size_t value );
751768
769+ func_rc pkcs11_attribctx_add_mechanism (attribCtx * ctx , CK_MECHANISM_TYPE attrtype );
770+ func_rc pkcs11_attribctx_free_mechanisms (attribCtx * ctx );
771+ void pkcs11_attribctx_forget_mechanisms (attribCtx * ctx );
772+ CK_MECHANISM_TYPE_PTR pkcs11_attribctx_get_allowed_mechanisms (attribCtx * ctx );
773+ size_t pkcs11_attribctx_get_allowed_mechanisms_len (attribCtx * ctx );
774+
752775
753776/* End - Function Prototypes */
754777
0 commit comments