1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _METAGLOBAL_H 27 #define _METAGLOBAL_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 /* 32 * This file contains all the data structures used for the meta slot 33 */ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #include <pthread.h> 40 #include <synch.h> 41 #include <unistd.h> 42 #include <security/cryptoki.h> 43 #include <stdio.h> 44 #include <cryptoutil.h> 45 #include <pkcs11Session.h> 46 #include <pkcs11Slot.h> 47 #include <sys/crypto/ioctl.h> 48 49 /* 50 * In "generic_attr_t", attributes that are not CK_BBOOL and 51 * CK_ULONG, the data will be stored in generic_data. 52 * Currently, 16 bytes will be pre-allocated for this. 53 * This is just a _WILD_ guess. If actual 54 * experience shows that 16 bytes is too small for most of the 55 * data that will be stored here, and cause this 56 * memory to be reallocated all the time, this should be increased. 57 */ 58 #define INITIAL_ATTR_LEN 16 59 60 /* We provide one slot, with the following arbitrary identifier. */ 61 #define METASLOT_SLOTID 42 62 63 /* Metaslot is always the first slot in the framdwork, with slotID=0 */ 64 #define METASLOT_FRAMEWORK_ID 0 65 66 /* 67 * These are the 2 acceptable string values for ${METASLOT_ENABLE} and 68 * ${METASLOT_AUTO_KEY_MIGRATE} environment variable 69 */ 70 #define TRUE_STRING "true" 71 #define FALSE_STRING "false" 72 73 /* Magic values for different data structures */ 74 #define METASLOT_SESSION_MAGIC 0xECF00004 75 #define METASLOT_SESSION_BADMAGIC 0xBAD00004 76 #define METASLOT_OBJECT_MAGIC 0xECF0B004 77 #define METASLOT_OBJECT_BADMAGIC 0xBAD0B004 78 #define METASLOT_OPSTATE_MAGIC 0xECF09004 79 #define METASLOT_OPSTATE_BADMAGIC 0xBAD09004 80 81 #define IS_READ_ONLY_SESSION(session_flag) \ 82 (!(session_flag & CKF_RW_SESSION)) 83 84 /* 85 * Operation modes passed to meta_do_operation() 86 * MODE_UPDATE_WITHKEY is only used for C_DigestKey. 87 */ 88 #define MODE_SINGLE 0x0100 89 #define MODE_UPDATE 0x0200 90 #define MODE_UPDATE_WITHKEY 0x0400 91 #define MODE_FINAL 0x1000 92 93 94 /* CK_INFO: Information about cryptoki */ 95 #define METASLOT_CRYPTOKI_VERSION_MAJOR 2 96 #define METASLOT_CRYPTOKI_VERSION_MINOR 11 97 #define METASLOT_MANUFACTURER_ID "Sun Microsystems, Inc. " 98 #define METASLOT_LIBRARY_DESCRIPTION "Sun Metaslot " 99 #define METASLOT_LIBRARY_VERSION_MAJOR 1 100 #define METASLOT_LIBRARY_VERSION_MINOR 1 101 102 /* CK_SLOT_INFO */ 103 #define METASLOT_SLOT_DESCRIPTION "Sun Metaslot " \ 104 " " 105 #define METASLOT_HARDWARE_VERSION_MAJOR 0 106 #define METASLOT_HARDWARE_VERSION_MINOR 0 107 #define METASLOT_FIRMWARE_VERSION_MAJOR 0 108 #define METASLOT_FIRMWARE_VERSION_MINOR 0 109 110 /* CK_TOKEN_INFO: More information about token */ 111 #define METASLOT_TOKEN_LABEL "Sun Metaslot " 112 #define METASLOT_TOKEN_MODEL "1.0 " 113 #define RANDOM_DEVICE "/dev/urandom" 114 115 /* 116 * Maximum number of objects and sessions to queue up before actually 117 * freeing them using the free() system. This is necessary to workaround 118 * a problem in which applications re-uses handles that are no longer valid 119 */ 120 #define MAX_OBJ_TO_BE_FREED 300 121 #define MAX_SESSION_TO_BE_FREED 300 122 123 /* 124 * The following 2 functions deals with inserting and deleting 125 * from double linked lists. It can work with any data structure 126 * that have "prev" and "next" defined. 127 */ 128 129 /* This always inserts into the head of the list */ 130 #define INSERT_INTO_LIST(list, item) \ 131 { \ 132 if ((list) == NULL) { \ 133 (item)->prev = NULL; \ 134 (item)->next = NULL; \ 135 (list) = (item); \ 136 } else { \ 137 (item)->next = (list); \ 138 (item)->prev = NULL; \ 139 (list)->prev = (item); \ 140 (list) = (item); \ 141 } \ 142 } 143 144 145 /* 146 * Remove item from list 147 */ 148 #define REMOVE_FROM_LIST(list, item) \ 149 { \ 150 if ((list) == item) { \ 151 if ((item)->next == NULL) { \ 152 (list) = NULL; \ 153 } else { \ 154 (item)->next->prev = NULL; \ 155 (list) = (item)->next; \ 156 } \ 157 } else { \ 158 if ((item)->next) { \ 159 (item)->next->prev = item->prev; \ 160 (item)->prev->next = (item)->next; \ 161 } else { \ 162 (item)->prev->next = NULL; \ 163 } \ 164 } \ 165 } 166 167 /* 168 * OBJRELEASE 169 * 170 * Signal that a metaobject is no longer in use (but is still valid). 171 */ 172 #define OBJRELEASE(object) \ 173 if (object != NULL) { \ 174 (void) pthread_rwlock_unlock(&object->object_lock); \ 175 } 176 177 /* 178 * REFRELEASE 179 * 180 * Signal that a metasession is no longer in use (but is still valid). 181 * 182 */ 183 #define REFRELEASE(session) \ 184 if (session != NULL) { \ 185 (void) pthread_rwlock_unlock(&session->session_lock); \ 186 } 187 188 /* FreeObject/FreeToken Enumeration */ 189 typedef enum { 190 FREE_UNCHECKED = 0, /* Has not been checked */ 191 FREE_DISABLED = 1, /* No supported provider or key type */ 192 FREE_ALLOWED_KEY = 2, /* Supported key type */ 193 FREE_ENABLED = 3 /* FreeObject/Token enabled */ 194 } freeobject_state_t; 195 196 197 /* Generic attribute type, for storing and managing PKCS#11 attributes. */ 198 typedef struct _attr { 199 CK_ATTRIBUTE attribute; 200 201 boolean_t isMalloced; 202 203 /* attr is necessary for creating a clone of the object */ 204 boolean_t isCloneAttr; 205 206 /* 207 * depends on the PKCS#11 implementation, this attr might or might 208 * not have a value. It's OK for it to not have a value 209 * (ie: the default value is empty) 210 */ 211 boolean_t canBeEmptyValue; 212 213 boolean_t hasValueForClone; 214 215 CK_BBOOL generic_bbool; 216 CK_ULONG generic_ulong; 217 CK_BYTE generic_data[INITIAL_ATTR_LEN]; 218 } generic_attr_t; 219 220 /* 221 * These need to be defined here before the actual structures are defined 222 * because they are used in some of the structure definitions. 223 */ 224 typedef struct slotobject slot_object_t; 225 typedef struct metasession meta_session_t; 226 typedef struct metaobject meta_object_t; 227 typedef struct metaopstate meta_opstate_t; 228 229 /* 230 * slot_session_t 231 * 232 * Wrapper for a session on a provider. This structure is only used internally 233 * in metaslot; it is never revealed to applications. 234 */ 235 typedef struct slotsession { 236 CK_ULONG slotnum; 237 CK_SLOT_ID fw_st_id; /* used for accessing framework's slottable */ 238 CK_SESSION_HANDLE hSession; 239 240 boolean_t is_dualop_capable; 241 CK_FLAGS session_flags; /* what type of session */ 242 243 struct slotsession *next; 244 struct slotsession *prev; 245 246 pthread_rwlock_t object_list_lock; 247 slot_object_t *object_list_head; 248 } slot_session_t; 249 250 251 /* 252 * slot_object_t 253 * 254 * Wrapper for an object on a provider. This structure is only used internally 255 * in metaslot; it is never revealed to applications. 256 */ 257 struct slotobject { 258 CK_OBJECT_HANDLE hObject; 259 260 struct slotobject *next; 261 struct slotobject *prev; 262 263 slot_session_t *creator_session; 264 265 boolean_t isToken; 266 }; 267 268 269 /* 270 * mechinfo_t 271 * 272 * A mechinfo_t is created for each mechanism on a slot. 273 * 274 * This information is used for selecting which slots support the given 275 * mechanism for a crypto operation. 276 * 277 */ 278 typedef struct mechinfo { 279 CK_ULONG slotnum; 280 281 boolean_t initialized; 282 boolean_t supported; 283 CK_MECHANISM_INFO mechanism_info; 284 } mechinfo_t; 285 286 287 /* 288 * operation_info_t 289 * 290 * Part of a meta_session_t, used to track active operations. 291 */ 292 typedef struct opinfo { 293 CK_FLAGS type; 294 slot_session_t *session; 295 mechinfo_t *stats; 296 } operation_info_t; 297 298 typedef struct find_objs_info { 299 boolean_t op_active; /* Indicate whether FindObjects is active */ 300 meta_object_t **matched_objs; 301 int num_matched_objs; 302 int next_result_index; /* index of next object to be returned */ 303 } find_objs_info_t; 304 305 typedef struct mech_support_info { 306 CK_MECHANISM_TYPE mech; 307 /* Array of mechinfo_t allocated based on number of slots */ 308 mechinfo_t **supporting_slots; 309 unsigned long num_supporting_slots; 310 } mech_support_info_t; 311 312 typedef struct crypto_init { 313 CK_FLAGS optype; /* place holder for init parameters */ 314 struct metasession *session; /* place holder for init parameters */ 315 CK_MECHANISM *pMech; /* place holder for init parameters */ 316 struct metaobject *key; /* place holder for init parameters */ 317 CK_ULONG slotnum; /* slot where the init operation took place */ 318 boolean_t done; /* set when the real init is done */ 319 boolean_t app; /* set when C_xxxInit is called by app */ 320 } crypto_init_t; 321 322 /* 323 * meta_session_t 324 * 325 * The internal state for a meta-session is kept here. The session handles 326 * given to applications are always pointers to a structure of this type. 327 * 328 */ 329 struct metasession { 330 ulong_t magic_marker; 331 pthread_rwlock_t session_lock; 332 333 pthread_mutex_t isClosingSession_lock; 334 boolean_t isClosingSession; 335 336 struct metasession *next; 337 struct metasession *prev; 338 339 CK_FLAGS session_flags; 340 341 /* 342 * Could have just declared this as "op", but declaring it as 343 * op1 so that "op2" can be easily added when dual-op support 344 * is implemented in the future 345 */ 346 operation_info_t op1; 347 348 /* 349 * This is for keeping track of which slots support a particular 350 * mechanism. This information doesn't 351 * have to be kept on a per session bases, but having the 352 * memory pre-allocated per session would make things much simpiler, 353 * because memory doesn't need to be allocated/deallocated everytime 354 * we do an operation. 355 */ 356 mech_support_info_t mech_support_info; 357 358 359 /* Session objects created by this session. */ 360 pthread_rwlock_t object_list_lock; 361 meta_object_t *object_list_head; 362 363 /* C_FindObjects support. */ 364 find_objs_info_t find_objs_info; 365 366 /* deferred init to be used by digest, encrypt, decrypt */ 367 crypto_init_t init; 368 }; 369 370 371 /* 372 * meta_object_t 373 * 374 * The internal state for a meta-object is kept here. The object handles 375 * given to applications are always pointers to a structure of this type. 376 */ 377 struct metaobject { 378 ulong_t magic_marker; 379 pthread_rwlock_t object_lock; 380 381 pthread_mutex_t isClosingObject_lock; 382 boolean_t isClosingObject; 383 384 struct metaobject *next; 385 struct metaobject *prev; 386 387 meta_session_t *creator_session; /* Only set for session objects */ 388 389 boolean_t isToken; /* alias for CKA_TOKEN */ 390 boolean_t isPrivate; /* alias for CKA_PRIVATE */ 391 boolean_t isSensitive; /* alias for CKA_SENSITIVE */ 392 boolean_t isExtractable; /* alias for CKA_EXTRACTABLE */ 393 394 freeobject_state_t isFreeToken; 395 freeobject_state_t isFreeObject; 396 397 CK_ULONG master_clone_slotnum; /* set when object is created */ 398 slot_object_t **clones; 399 /* indicate if tried to create clone object in a slot */ 400 boolean_t *tried_create_clone; 401 402 pthread_rwlock_t attribute_lock; 403 size_t num_attributes; 404 generic_attr_t *attributes; 405 406 pthread_mutex_t clone_create_lock; 407 size_t clone_template_size; /* 0 if not yet known. */ 408 CK_ATTRIBUTE *clone_template; /* NULL if not yet known. */ 409 }; 410 411 412 /* 413 * struct metaopstate 414 * 415 * Used as the format for the operation state returned via 416 * C_GetOperationState. 417 */ 418 typedef struct opstate_data { 419 CK_FLAGS op_type; 420 CK_ULONG op_slotnum; 421 CK_ULONG op_state_len; 422 boolean_t op_init_app; 423 boolean_t op_init_done; 424 } opstate_data_t; 425 426 struct metaopstate { 427 ulong_t magic_marker; 428 /* 429 * Could have just declared this as "state", but declaring it like this 430 * so that when dual-op support is implemented in the future, the 431 * changes will be simplier. 432 */ 433 struct opstate_data state[1]; 434 }; 435 436 437 /* 438 * session_pool_t 439 * 440 * Used to cache open sessions in a slot. 441 */ 442 typedef struct sessionpool { 443 pthread_mutex_t list_lock; 444 445 /* list of sessions that's currently in use */ 446 slot_session_t *active_list_head; 447 448 /* 449 * list of sessions that are not in use, but can't be deleted because 450 * either session/token objects are created using these sessions 451 * or we need to have one session left with the provider to maintain 452 * the logged in state. Any of these sessions could be re-used if 453 * a session is needed to be established with a provider. 454 */ 455 slot_session_t *persist_list_head; 456 457 /* 458 * List of sessions that are not in use at the moment. We keep 459 * a list of sessions with a particular provider instead of 460 * creating a new session everytime for efficiency 461 */ 462 slot_session_t *idle_list_head; 463 boolean_t keep_one_alive; 464 int num_idle_sessions; /* number of sessions in "idle_list_head" */ 465 } session_pool_t; 466 467 468 /* 469 * slot_data_t 470 * 471 * Each slot has a session pool, a collection of persistant sessions to 472 * allow for more efficient operation. Specifically, to allow reuse of 473 * previously session objects (which need the creating session to stick 474 * around), as well as being frugal with creating/closing sessions. 475 */ 476 typedef struct slotdata { 477 CK_SLOT_ID fw_st_id; /* framework slot table ID */ 478 479 session_pool_t session_pool; 480 481 pthread_rwlock_t tokenobject_list_lock; 482 slot_object_t *tokenobject_list_head; 483 } slot_data_t; 484 485 486 typedef enum { 487 ALL_TOKEN = 0, 488 PUBLIC_TOKEN = 1, 489 PRIVATE_TOKEN = 2 490 } token_obj_type_t; 491 492 /* 493 * metaslot_config_t 494 * 495 * This holds the configuration information for meta slot. 496 * It will first be filled with values that users defined 497 * in environment variables. Any value not defined by the user 498 * will be filled with values from the system wide configuration file. 499 */ 500 typedef struct _metaslot_config { 501 /* token to be used as the keystore for metaslot */ 502 boolean_t keystore_token_specified; 503 CK_UTF8CHAR keystore_token[TOKEN_LABEL_SIZE + 1]; 504 505 /* slot to be used as the keystore for metaslot */ 506 boolean_t keystore_slot_specified; 507 CK_UTF8CHAR keystore_slot[SLOT_DESCRIPTION_SIZE + 1]; 508 509 /* should meta slot be enabled or not */ 510 boolean_t enabled_specified; 511 boolean_t enabled; 512 513 /* should auto migration of sensitive token objects be enabled or not */ 514 boolean_t auto_key_migrate_specified; 515 boolean_t auto_key_migrate; 516 } metaslot_config_t; 517 518 /* 519 * The following 2 structures are used to link the to-be-freed 520 * meta sessions and meta objects into linked lists. 521 * The items on these linked list have not yet been freed via free(); instead 522 * they are added to this list. The actual free will take place when 523 * the number of objects queued reaches MAX_OBJ_TO_BE_FREED or 524 * MAX_SESSION_TO_BE_FREED, at which time the first object in the 525 * list will be freed. 526 */ 527 typedef struct obj_to_be_freed_list { 528 meta_object_t *first; /* points to first obj in the list */ 529 meta_object_t *last; /* points to last obj in the list */ 530 uint32_t count; /* current total objs in the list */ 531 pthread_mutex_t obj_to_be_free_mutex; 532 } object_to_be_freed_list_t; 533 534 typedef struct ses_to_be_freed_list { 535 meta_session_t *first; /* points to first session in the list */ 536 meta_session_t *last; /* points to last session in the list */ 537 uint32_t count; /* current total session in the list */ 538 pthread_mutex_t ses_to_be_free_mutex; 539 } ses_to_be_freed_list_t; 540 541 typedef struct cipher_mechs_threshold { 542 int mech_type; 543 uint32_t mech_threshold; 544 } cipher_mechs_threshold_t; 545 546 /* Global variables */ 547 extern metaslot_config_t metaslot_config; 548 extern boolean_t metaslot_enabled; 549 extern CK_SLOT_ID metaslot_keystore_slotid; 550 extern boolean_t metaslot_auto_key_migrate; 551 extern struct CK_FUNCTION_LIST metaslot_functionList; 552 extern int meta_urandom_seed_fd; 553 extern pthread_mutex_t initmutex; 554 555 extern ses_to_be_freed_list_t ses_delay_freed; 556 extern object_to_be_freed_list_t obj_delay_freed; 557 extern void (*Tmp_GetThreshold)(void *); 558 559 extern CK_BBOOL falsevalue; 560 extern CK_BBOOL truevalue; 561 562 /* --- Prototypes --- */ 563 564 CK_RV meta_slotManager_initialize(); 565 void meta_slotManager_finalize(); 566 void meta_slotManager_find_object_token(); 567 CK_RV meta_get_slot_session(CK_ULONG slotnum, slot_session_t **session, 568 CK_FLAGS flags); 569 void meta_release_slot_session(slot_session_t *session); 570 571 CK_RV meta_mechManager_initialize(); 572 void meta_mechManager_finalize(); 573 CK_RV meta_mechManager_get_mechs(CK_MECHANISM_TYPE *list, CK_ULONG *listsize); 574 CK_RV meta_mechManager_get_slots(mech_support_info_t *mech_support_info, 575 boolean_t force_update, CK_MECHANISM_INFO *mech_info); 576 CK_RV meta_mechManager_slot_supports_mech(CK_MECHANISM_TYPE mechanism, 577 CK_ULONG slotnum, boolean_t *supports, mechinfo_t **slot_info, 578 boolean_t force_update, CK_MECHANISM_INFO *mech_info); 579 580 CK_RV meta_operation_init(CK_FLAGS optype, meta_session_t *session, 581 CK_MECHANISM *pMechanism, meta_object_t *key); 582 CK_RV meta_operation_init_defer(CK_FLAGS optype, meta_session_t *session, 583 CK_MECHANISM *pMechanism, meta_object_t *key); 584 CK_RV meta_do_operation(CK_FLAGS optype, int mode, 585 meta_session_t *session, meta_object_t *object, 586 CK_BYTE *in, CK_ULONG inLen, CK_BYTE *out, CK_ULONG *outLen); 587 588 void meta_operation_cleanup(meta_session_t *session, CK_FLAGS optype, 589 boolean_t finished_normally); 590 591 CK_RV meta_generate_keys(meta_session_t *session, CK_MECHANISM *pMechanism, 592 CK_ATTRIBUTE *k1Template, CK_ULONG k1AttrCount, meta_object_t *key1, 593 CK_ATTRIBUTE *k2Template, CK_ULONG k2AttrCount, meta_object_t *key2); 594 595 CK_RV meta_wrap_key(meta_session_t *session, 596 CK_MECHANISM *pMechanism, meta_object_t *wrappingkey, 597 meta_object_t *inputkey, 598 CK_BYTE *wrapped_key, CK_ULONG *wrapped_key_len); 599 600 CK_RV meta_unwrap_key(meta_session_t *session, 601 CK_MECHANISM *pMechanism, meta_object_t *unwrapping_key, 602 CK_BYTE *wrapped_key, CK_ULONG wrapped_key_len, 603 CK_ATTRIBUTE *template, CK_ULONG template_size, 604 meta_object_t *unwrapped_key); 605 606 CK_RV meta_derive_key(meta_session_t *session, CK_MECHANISM *pMech, 607 meta_object_t *basekey1, meta_object_t *basekey2, 608 CK_OBJECT_HANDLE *phBaseKey2, 609 CK_ATTRIBUTE *pTemplate, CK_ULONG ulAttributeCount, 610 meta_object_t *newKey1, meta_object_t *newKey2, 611 meta_object_t *newKey3, meta_object_t *newKey4); 612 613 void get_user_metaslot_config(); 614 615 CK_RV meta_sessionManager_initialize(); 616 void meta_sessionManager_finalize(); 617 CK_RV meta_handle2session(CK_SESSION_HANDLE hSession, 618 meta_session_t **session_p); 619 CK_RV meta_session_alloc(meta_session_t **newSession); 620 CK_RV meta_session_activate(meta_session_t *session); 621 CK_RV meta_session_deactivate(meta_session_t *session, 622 boolean_t have_sessionlist_lock); 623 void meta_session_dealloc(meta_session_t *session); 624 void meta_session_delay_free(meta_session_t *sp); 625 626 CK_RV meta_objectManager_initialize(); 627 void meta_objectManager_finalize(); 628 CK_RV meta_handle2object(CK_OBJECT_HANDLE hObject, meta_object_t **object); 629 CK_RV meta_object_alloc(meta_session_t *session, meta_object_t **object); 630 CK_RV meta_object_get_attr(slot_session_t *slot_session, 631 CK_OBJECT_HANDLE hObject, meta_object_t *object); 632 void meta_object_activate(meta_object_t *object); 633 CK_RV meta_object_deactivate(meta_object_t *object, boolean_t have_list_lock, 634 boolean_t have_object_lock); 635 CK_RV meta_object_dealloc(meta_object_t *object, boolean_t nukeSourceObj); 636 CK_RV meta_slot_object_alloc(slot_object_t **object); 637 void meta_slot_object_activate(slot_object_t *object, slot_session_t *session, 638 boolean_t isToken); 639 void meta_slot_object_deactivate(slot_object_t *object); 640 void meta_slot_object_dealloc(slot_object_t *object); 641 CK_RV meta_object_copyin(meta_object_t *object); 642 CK_RV meta_object_get_clone(meta_object_t *object, 643 CK_ULONG slot_num, slot_session_t *slot_session, 644 slot_object_t **clone); 645 meta_object_t *meta_object_find_by_handle(CK_OBJECT_HANDLE hObject, 646 CK_ULONG slotnum, boolean_t token_only); 647 CK_RV meta_token_object_deactivate(token_obj_type_t token_type); 648 void meta_object_delay_free(meta_object_t *objp); 649 boolean_t meta_freeobject_set(meta_object_t *object, CK_ATTRIBUTE *tmpl, 650 CK_ULONG tmpl_len, boolean_t create); 651 CK_RV meta_freetoken_set(CK_ULONG slot_num, CK_BBOOL *current_value, 652 CK_ATTRIBUTE *tmpl, CK_ULONG tmpl_len); 653 boolean_t meta_freeobject_check(meta_session_t *session, meta_object_t *obj, 654 CK_MECHANISM *pMech, CK_ATTRIBUTE *tmpl, CK_ULONG tmpl_len, 655 CK_KEY_TYPE keytype); 656 boolean_t meta_freeobject_clone(meta_session_t *session, meta_object_t *object); 657 658 CK_RV get_master_attributes_by_object(slot_session_t *session, 659 slot_object_t *slot_object, generic_attr_t **attributes, 660 size_t *num_attributes); 661 CK_RV get_master_attributes_by_template( 662 CK_ATTRIBUTE *template, CK_ULONG template_size, 663 generic_attr_t **attributes, size_t *num_attributes); 664 CK_RV get_master_template_by_type(CK_OBJECT_CLASS class, CK_ULONG subtype, 665 generic_attr_t **attributes, size_t *num_attributes); 666 CK_RV get_master_attributes_by_type(CK_OBJECT_CLASS class, CK_ULONG subtype, 667 generic_attr_t **attributes, size_t *num_attributes); 668 CK_RV get_master_attributes_by_duplication( 669 generic_attr_t *src_attrs, size_t num_src_attrs, 670 generic_attr_t **dst_attrs, size_t *num_dst_attrs); 671 void dealloc_attributes(generic_attr_t *attributes, size_t num_attributes); 672 CK_RV attribute_set_value(CK_ATTRIBUTE *new_attr, 673 generic_attr_t *attributes, size_t num_attributes); 674 boolean_t get_template_ulong(CK_ATTRIBUTE_TYPE type, CK_ATTRIBUTE *attributes, 675 CK_ULONG num_attributes, CK_ULONG *result); 676 boolean_t get_template_boolean(CK_ATTRIBUTE_TYPE type, 677 CK_ATTRIBUTE *attributes, CK_ULONG num_attributes, boolean_t *result); 678 int set_template_boolean(CK_ATTRIBUTE_TYPE type, 679 CK_ATTRIBUTE *attributes, CK_ULONG num_attributes, boolean_t local, 680 CK_BBOOL *value); 681 CK_ULONG get_keystore_slotnum(void); 682 CK_ULONG get_softtoken_slotnum(void); 683 CK_SLOT_ID meta_slotManager_get_framework_table_id(CK_ULONG slotnum); 684 CK_ULONG meta_slotManager_get_slotcount(void); 685 boolean_t meta_slotManager_token_write_protected(void); 686 boolean_t metaslot_logged_in(); 687 void metaslot_set_logged_in_flag(boolean_t value); 688 689 int looping_read(int, void *, int); 690 int looping_write(int, void *, int); 691 692 /* 693 * Prototypes for the various meta_Foo implementations of C_Foo. 694 * 695 */ 696 CK_RV meta_GetFunctionList(CK_FUNCTION_LIST_PTR_PTR ppFunctionList); 697 CK_RV meta_Initialize(CK_VOID_PTR pInitArgs); 698 CK_RV meta_Finalize(CK_VOID_PTR pReserved); 699 CK_RV meta_GetInfo(CK_INFO_PTR pInfo); 700 CK_RV meta_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, 701 CK_ULONG_PTR pulCount); 702 CK_RV meta_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo); 703 CK_RV meta_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo); 704 CK_RV meta_GetMechanismList(CK_SLOT_ID slotID, 705 CK_MECHANISM_TYPE_PTR pMechanismList, CK_ULONG_PTR pulCount); 706 CK_RV meta_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, 707 CK_MECHANISM_INFO_PTR pInfo); 708 CK_RV meta_InitToken(CK_SLOT_ID slotID, CK_UTF8CHAR_PTR pPin, 709 CK_ULONG ulPinLen, CK_UTF8CHAR_PTR pLabel); 710 CK_RV meta_InitPIN(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pPin, 711 CK_ULONG ulPinLen); 712 CK_RV meta_SetPIN(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin, 713 CK_ULONG ulOldPinLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen); 714 CK_RV meta_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, 715 CK_VOID_PTR pApplication, CK_NOTIFY Notify, 716 CK_SESSION_HANDLE_PTR phSession); 717 CK_RV meta_CloseSession(CK_SESSION_HANDLE hSession); 718 CK_RV meta_CloseAllSessions(CK_SLOT_ID slotID); 719 CK_RV meta_GetSessionInfo(CK_SESSION_HANDLE hSession, 720 CK_SESSION_INFO_PTR pInfo); 721 CK_RV meta_GetOperationState(CK_SESSION_HANDLE hSession, 722 CK_BYTE_PTR pOperationState, CK_ULONG_PTR pulOperationStateLen); 723 CK_RV meta_SetOperationState(CK_SESSION_HANDLE hSession, 724 CK_BYTE_PTR pOperationState, CK_ULONG ulOperationStateLen, 725 CK_OBJECT_HANDLE hEncryptionKey, CK_OBJECT_HANDLE hAuthenticationKey); 726 CK_RV meta_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, 727 CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen); 728 CK_RV meta_Logout(CK_SESSION_HANDLE hSession); 729 CK_RV meta_CreateObject(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, 730 CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phObject); 731 CK_RV meta_CopyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, 732 CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, 733 CK_OBJECT_HANDLE_PTR phNewObject); 734 CK_RV meta_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject); 735 CK_RV meta_GetObjectSize(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, 736 CK_ULONG_PTR pulSize); 737 CK_RV meta_GetAttributeValue(CK_SESSION_HANDLE hSession, 738 CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); 739 CK_RV meta_SetAttributeValue(CK_SESSION_HANDLE hSession, 740 CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); 741 CK_RV meta_FindObjectsInit(CK_SESSION_HANDLE hSession, 742 CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount); 743 CK_RV meta_FindObjects(CK_SESSION_HANDLE hSession, 744 CK_OBJECT_HANDLE_PTR phObject, CK_ULONG ulMaxObjectCount, 745 CK_ULONG_PTR pulObjectCount); 746 CK_RV meta_FindObjectsFinal(CK_SESSION_HANDLE hSession); 747 CK_RV meta_EncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 748 CK_OBJECT_HANDLE hKey); 749 CK_RV meta_Encrypt(CK_SESSION_HANDLE hSession, 750 CK_BYTE_PTR pData, CK_ULONG ulDataLen, 751 CK_BYTE_PTR pEncryptedData, CK_ULONG_PTR pulEncryptedDataLen); 752 CK_RV meta_EncryptUpdate(CK_SESSION_HANDLE hSession, 753 CK_BYTE_PTR pPart, CK_ULONG ulPartLen, 754 CK_BYTE_PTR pEncryptedPart, CK_ULONG_PTR pulEncryptedPartLen); 755 CK_RV meta_EncryptFinal(CK_SESSION_HANDLE hSession, 756 CK_BYTE_PTR pLastEncryptedPart, CK_ULONG_PTR pulLastEncryptedPartLen); 757 CK_RV meta_DecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 758 CK_OBJECT_HANDLE hKey); 759 CK_RV meta_Decrypt(CK_SESSION_HANDLE hSession, 760 CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDataLen, 761 CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen); 762 CK_RV meta_DecryptUpdate(CK_SESSION_HANDLE hSession, 763 CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, 764 CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen); 765 CK_RV meta_DecryptFinal(CK_SESSION_HANDLE hSession, 766 CK_BYTE_PTR pLastPart, CK_ULONG_PTR pulLastPartLen); 767 CK_RV meta_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism); 768 CK_RV meta_Digest(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, 769 CK_ULONG ulDataLen, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen); 770 CK_RV meta_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, 771 CK_ULONG ulPartLen); 772 CK_RV meta_DigestKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey); 773 CK_RV meta_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest, 774 CK_ULONG_PTR pulDigestLen); 775 CK_RV meta_SignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 776 CK_OBJECT_HANDLE hKey); 777 CK_RV meta_Sign(CK_SESSION_HANDLE hSession, 778 CK_BYTE_PTR pData, CK_ULONG ulDataLen, 779 CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen); 780 CK_RV meta_SignUpdate(CK_SESSION_HANDLE hSession, 781 CK_BYTE_PTR pPart, CK_ULONG ulPartLen); 782 CK_RV meta_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, 783 CK_ULONG_PTR pulSignatureLen); 784 CK_RV meta_SignRecoverInit(CK_SESSION_HANDLE hSession, 785 CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey); 786 CK_RV meta_SignRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, 787 CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen); 788 CK_RV meta_VerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 789 CK_OBJECT_HANDLE hKey); 790 CK_RV meta_Verify(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, 791 CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen); 792 CK_RV meta_VerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, 793 CK_ULONG ulPartLen); 794 CK_RV meta_VerifyFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, 795 CK_ULONG ulSignatureLen); 796 CK_RV meta_VerifyRecoverInit(CK_SESSION_HANDLE hSession, 797 CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey); 798 CK_RV meta_VerifyRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, 799 CK_ULONG ulSignatureLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen); 800 CK_RV meta_DigestEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, 801 CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart, 802 CK_ULONG_PTR pulEncryptedPartLen); 803 CK_RV meta_DecryptDigestUpdate(CK_SESSION_HANDLE hSession, 804 CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, 805 CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen); 806 CK_RV meta_SignEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, 807 CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart, 808 CK_ULONG_PTR pulEncryptedPartLen); 809 CK_RV meta_DecryptVerifyUpdate(CK_SESSION_HANDLE hSession, 810 CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, 811 CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen); 812 CK_RV meta_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 813 CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phKey); 814 CK_RV meta_GenerateKeyPair(CK_SESSION_HANDLE hSession, 815 CK_MECHANISM_PTR pMechanism, CK_ATTRIBUTE_PTR pPublicKeyTemplate, 816 CK_ULONG ulPublicKeyAttributeCount, CK_ATTRIBUTE_PTR pPrivateKeyTemplate, 817 CK_ULONG ulPrivateKeyAttributeCount, CK_OBJECT_HANDLE_PTR phPublicKey, 818 CK_OBJECT_HANDLE_PTR phPrivateKey); 819 CK_RV meta_WrapKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 820 CK_OBJECT_HANDLE hWrappingKey, CK_OBJECT_HANDLE hKey, 821 CK_BYTE_PTR pWrappedKey, CK_ULONG_PTR pulWrappedKeyLen); 822 CK_RV meta_UnwrapKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 823 CK_OBJECT_HANDLE hUnwrappingKey, CK_BYTE_PTR pWrappedKey, 824 CK_ULONG ulWrappedKeyLen, CK_ATTRIBUTE_PTR pTemplate, 825 CK_ULONG ulAttributeCount, CK_OBJECT_HANDLE_PTR phKey); 826 CK_RV meta_DeriveKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 827 CK_OBJECT_HANDLE hBaseKey, CK_ATTRIBUTE_PTR pTemplate, 828 CK_ULONG ulAttributeCount, CK_OBJECT_HANDLE_PTR phKey); 829 CK_RV meta_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, 830 CK_ULONG ulSeedLen); 831 CK_RV meta_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pRandomData, 832 CK_ULONG ulRandomLen); 833 CK_RV meta_GetFunctionStatus(CK_SESSION_HANDLE hSession); 834 CK_RV meta_CancelFunction(CK_SESSION_HANDLE hSession); 835 CK_RV meta_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, 836 CK_VOID_PTR pReserved); 837 838 #ifdef __cplusplus 839 } 840 #endif 841 842 #endif /* _METAGLOBAL_H */ 843