17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*d3a28a55Sdinak * Common Development and Distribution License (the "License").
6*d3a28a55Sdinak * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*d3a28a55Sdinak * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * Slot and Token Management functions
307c478bd9Sstevel@tonic-gate * (as defined in PKCS#11 spec section 11.5)
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include "metaGlobal.h"
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate extern CK_ULONG num_meta_sessions;
397c478bd9Sstevel@tonic-gate extern CK_ULONG num_rw_meta_sessions;
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate * meta_GetSlotList
437c478bd9Sstevel@tonic-gate *
447c478bd9Sstevel@tonic-gate * For the metaslot, this is a trivial function. The metaslot module,
457c478bd9Sstevel@tonic-gate * by defination, provides exactly one slot. The token is always present.
467c478bd9Sstevel@tonic-gate *
477c478bd9Sstevel@tonic-gate * This function is actually not called.
487c478bd9Sstevel@tonic-gate */
497c478bd9Sstevel@tonic-gate /* ARGSUSED */
507c478bd9Sstevel@tonic-gate CK_RV
meta_GetSlotList(CK_BBOOL tokenPresent,CK_SLOT_ID_PTR pSlotList,CK_ULONG_PTR pulCount)517c478bd9Sstevel@tonic-gate meta_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList,
527c478bd9Sstevel@tonic-gate CK_ULONG_PTR pulCount)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate CK_RV rv;
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate if (pulCount == NULL)
577c478bd9Sstevel@tonic-gate return (CKR_ARGUMENTS_BAD);
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate if (pSlotList == NULL) {
607c478bd9Sstevel@tonic-gate *pulCount = 1;
617c478bd9Sstevel@tonic-gate return (CKR_OK);
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate if (*pulCount < 1) {
657c478bd9Sstevel@tonic-gate rv = CKR_BUFFER_TOO_SMALL;
667c478bd9Sstevel@tonic-gate } else {
677c478bd9Sstevel@tonic-gate pSlotList[0] = METASLOT_SLOTID;
687c478bd9Sstevel@tonic-gate rv = CKR_OK;
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate *pulCount = 1;
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate return (rv);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate * meta_GetSlotInfo
787c478bd9Sstevel@tonic-gate *
797c478bd9Sstevel@tonic-gate * Returns basic information about the metaslot.
807c478bd9Sstevel@tonic-gate *
817c478bd9Sstevel@tonic-gate * The slotID argument is ignored.
827c478bd9Sstevel@tonic-gate */
837c478bd9Sstevel@tonic-gate /*ARGSUSED*/
847c478bd9Sstevel@tonic-gate CK_RV
meta_GetSlotInfo(CK_SLOT_ID slotID,CK_SLOT_INFO_PTR pInfo)857c478bd9Sstevel@tonic-gate meta_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate CK_SLOT_INFO slotinfo;
887c478bd9Sstevel@tonic-gate CK_SLOT_ID true_id;
897c478bd9Sstevel@tonic-gate CK_RV rv;
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate if (!metaslot_enabled) {
927c478bd9Sstevel@tonic-gate return (CKR_SLOT_ID_INVALID);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate if (pInfo == NULL) {
967c478bd9Sstevel@tonic-gate return (CKR_ARGUMENTS_BAD);
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate /* Provide information about the slot in the provided buffer */
1007c478bd9Sstevel@tonic-gate (void) memcpy(pInfo->slotDescription, METASLOT_SLOT_DESCRIPTION, 64);
1017c478bd9Sstevel@tonic-gate (void) memcpy(pInfo->manufacturerID, METASLOT_MANUFACTURER_ID, 32);
1027c478bd9Sstevel@tonic-gate pInfo->hardwareVersion.major = METASLOT_HARDWARE_VERSION_MAJOR;
1037c478bd9Sstevel@tonic-gate pInfo->hardwareVersion.minor = METASLOT_HARDWARE_VERSION_MINOR;
1047c478bd9Sstevel@tonic-gate pInfo->firmwareVersion.major = METASLOT_FIRMWARE_VERSION_MAJOR;
1057c478bd9Sstevel@tonic-gate pInfo->firmwareVersion.minor = METASLOT_FIRMWARE_VERSION_MINOR;
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate /* Find out token is present in the underlying keystore */
1087c478bd9Sstevel@tonic-gate true_id = TRUEID(metaslot_keystore_slotid);
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate rv = FUNCLIST(metaslot_keystore_slotid)->C_GetSlotInfo(true_id,
1117c478bd9Sstevel@tonic-gate &slotinfo);
1127c478bd9Sstevel@tonic-gate if ((rv == CKR_OK) && (slotinfo.flags & CKF_TOKEN_PRESENT)) {
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate * store the token present flag if it is successfully
1157c478bd9Sstevel@tonic-gate * received from the keystore slot.
1167c478bd9Sstevel@tonic-gate * If not, this flag will not be set.
1177c478bd9Sstevel@tonic-gate */
1187c478bd9Sstevel@tonic-gate pInfo->flags = CKF_TOKEN_PRESENT;
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate return (CKR_OK);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate * meta_GetTokenInfo
1277c478bd9Sstevel@tonic-gate *
1287c478bd9Sstevel@tonic-gate * Returns basic information about the metaslot "token."
1297c478bd9Sstevel@tonic-gate *
1307c478bd9Sstevel@tonic-gate * The slotID argument is ignored.
1317c478bd9Sstevel@tonic-gate *
1327c478bd9Sstevel@tonic-gate */
1337c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1347c478bd9Sstevel@tonic-gate CK_RV
meta_GetTokenInfo(CK_SLOT_ID slotID,CK_TOKEN_INFO_PTR pInfo)1357c478bd9Sstevel@tonic-gate meta_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate CK_RV rv;
1387c478bd9Sstevel@tonic-gate CK_TOKEN_INFO metainfo;
1397c478bd9Sstevel@tonic-gate CK_SLOT_ID true_id;
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate if (!metaslot_enabled) {
1427c478bd9Sstevel@tonic-gate return (CKR_SLOT_ID_INVALID);
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate if (pInfo == NULL)
1467c478bd9Sstevel@tonic-gate return (CKR_ARGUMENTS_BAD);
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate true_id = TRUEID(metaslot_keystore_slotid);
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate rv = FUNCLIST(metaslot_keystore_slotid)->C_GetTokenInfo(true_id,
1517c478bd9Sstevel@tonic-gate &metainfo);
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate * If we could not get information about the object token, use
1557c478bd9Sstevel@tonic-gate * default values. This allows metaslot to be used even if there
1567c478bd9Sstevel@tonic-gate * are problems with the object token (eg, it's not present).
1577c478bd9Sstevel@tonic-gate */
1587c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
1597c478bd9Sstevel@tonic-gate metainfo.ulTotalPublicMemory = CK_UNAVAILABLE_INFORMATION;
1607c478bd9Sstevel@tonic-gate metainfo.ulFreePublicMemory = CK_UNAVAILABLE_INFORMATION;
1617c478bd9Sstevel@tonic-gate metainfo.ulTotalPrivateMemory = CK_UNAVAILABLE_INFORMATION;
1627c478bd9Sstevel@tonic-gate metainfo.ulFreePrivateMemory = CK_UNAVAILABLE_INFORMATION;
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate metainfo.flags = CKF_WRITE_PROTECTED;
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate metainfo.ulMaxPinLen = 0;
1677c478bd9Sstevel@tonic-gate metainfo.ulMinPinLen = 0;
1687c478bd9Sstevel@tonic-gate metainfo.hardwareVersion.major =
1697c478bd9Sstevel@tonic-gate METASLOT_HARDWARE_VERSION_MAJOR;
1707c478bd9Sstevel@tonic-gate metainfo.hardwareVersion.minor =
1717c478bd9Sstevel@tonic-gate METASLOT_HARDWARE_VERSION_MINOR;
1727c478bd9Sstevel@tonic-gate metainfo.firmwareVersion.major =
1737c478bd9Sstevel@tonic-gate METASLOT_FIRMWARE_VERSION_MAJOR;
1747c478bd9Sstevel@tonic-gate metainfo.firmwareVersion.minor =
1757c478bd9Sstevel@tonic-gate METASLOT_FIRMWARE_VERSION_MINOR;
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate * Override some values that the object token may have set. They
1807c478bd9Sstevel@tonic-gate * can be inappropriate/misleading when used in the context of
1817c478bd9Sstevel@tonic-gate * metaslot.
1827c478bd9Sstevel@tonic-gate */
1837c478bd9Sstevel@tonic-gate (void) memcpy(metainfo.label, METASLOT_TOKEN_LABEL, 32);
1847c478bd9Sstevel@tonic-gate (void) memcpy(metainfo.manufacturerID,
1857c478bd9Sstevel@tonic-gate METASLOT_MANUFACTURER_ID, 32);
1867c478bd9Sstevel@tonic-gate (void) memcpy(metainfo.model, METASLOT_TOKEN_MODEL, 16);
1877c478bd9Sstevel@tonic-gate (void) memset(metainfo.serialNumber, ' ', 16);
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate metainfo.ulMaxSessionCount = CK_EFFECTIVELY_INFINITE;
1907c478bd9Sstevel@tonic-gate metainfo.ulSessionCount = num_meta_sessions;
1917c478bd9Sstevel@tonic-gate metainfo.ulMaxRwSessionCount = CK_EFFECTIVELY_INFINITE;
1927c478bd9Sstevel@tonic-gate metainfo.ulRwSessionCount = num_rw_meta_sessions;
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate metainfo.flags |= CKF_RNG;
1957c478bd9Sstevel@tonic-gate metainfo.flags &= ~CKF_RESTORE_KEY_NOT_NEEDED;
1967c478bd9Sstevel@tonic-gate metainfo.flags |= CKF_TOKEN_INITIALIZED;
1977c478bd9Sstevel@tonic-gate metainfo.flags &= ~CKF_SECONDARY_AUTHENTICATION;
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate /* Clear the time field if the token does not have a clock. */
2007c478bd9Sstevel@tonic-gate if (!(metainfo.flags & CKF_CLOCK_ON_TOKEN))
2017c478bd9Sstevel@tonic-gate (void) memset(metainfo.utcTime, ' ', 16);
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate *pInfo = metainfo;
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate return (CKR_OK);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate * meta_WaitForSlotEvent
2117c478bd9Sstevel@tonic-gate *
2127c478bd9Sstevel@tonic-gate * The metaslot never generates events, so this function doesn't do anything
2137c478bd9Sstevel@tonic-gate * useful. We do not pass on provider events because we want to hide details
2147c478bd9Sstevel@tonic-gate * of the providers.
2157c478bd9Sstevel@tonic-gate *
2167c478bd9Sstevel@tonic-gate * If CKF_DONT_BLOCK flag is turned on, CKR_NO_EVENT will be return.
2177c478bd9Sstevel@tonic-gate * Otherwise, return CKR_FUNCTION_FAILED.
2187c478bd9Sstevel@tonic-gate *
2197c478bd9Sstevel@tonic-gate */
2207c478bd9Sstevel@tonic-gate /* ARGSUSED */
2217c478bd9Sstevel@tonic-gate CK_RV
meta_WaitForSlotEvent(CK_FLAGS flags,CK_SLOT_ID_PTR pSlot,CK_VOID_PTR pReserved)2227c478bd9Sstevel@tonic-gate meta_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot,
2237c478bd9Sstevel@tonic-gate CK_VOID_PTR pReserved)
2247c478bd9Sstevel@tonic-gate {
2257c478bd9Sstevel@tonic-gate if (flags & CKF_DONT_BLOCK) {
2267c478bd9Sstevel@tonic-gate return (CKR_NO_EVENT);
2277c478bd9Sstevel@tonic-gate } else {
2287c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_FAILED);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate * meta_GetMechanismList
2357c478bd9Sstevel@tonic-gate *
2367c478bd9Sstevel@tonic-gate * The slotID argument is not used.
2377c478bd9Sstevel@tonic-gate *
2387c478bd9Sstevel@tonic-gate */
2397c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2407c478bd9Sstevel@tonic-gate CK_RV
meta_GetMechanismList(CK_SLOT_ID slotID,CK_MECHANISM_TYPE_PTR pMechanismList,CK_ULONG_PTR pulCount)2417c478bd9Sstevel@tonic-gate meta_GetMechanismList(CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMechanismList,
2427c478bd9Sstevel@tonic-gate CK_ULONG_PTR pulCount)
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate CK_RV rv;
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate if (!metaslot_enabled) {
2477c478bd9Sstevel@tonic-gate return (CKR_SLOT_ID_INVALID);
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate if (pulCount == NULL)
2517c478bd9Sstevel@tonic-gate return (CKR_ARGUMENTS_BAD);
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate rv = meta_mechManager_get_mechs(pMechanismList, pulCount);
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate if ((rv == CKR_BUFFER_TOO_SMALL) && (pMechanismList == NULL)) {
2567c478bd9Sstevel@tonic-gate /*
2577c478bd9Sstevel@tonic-gate * if pMechanismList is not provided, just need to
2587c478bd9Sstevel@tonic-gate * return count
2597c478bd9Sstevel@tonic-gate */
2607c478bd9Sstevel@tonic-gate rv = CKR_OK;
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate return (rv);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate * meta_GetMechanismInfo
2687c478bd9Sstevel@tonic-gate *
2697c478bd9Sstevel@tonic-gate * The slotID argument is not used.
2707c478bd9Sstevel@tonic-gate */
2717c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2727c478bd9Sstevel@tonic-gate CK_RV
meta_GetMechanismInfo(CK_SLOT_ID slotID,CK_MECHANISM_TYPE type,CK_MECHANISM_INFO_PTR pInfo)2737c478bd9Sstevel@tonic-gate meta_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type,
2747c478bd9Sstevel@tonic-gate CK_MECHANISM_INFO_PTR pInfo)
2757c478bd9Sstevel@tonic-gate {
2767c478bd9Sstevel@tonic-gate CK_RV rv;
2777c478bd9Sstevel@tonic-gate mechinfo_t **slots = NULL;
2787c478bd9Sstevel@tonic-gate unsigned long i, slotCount = 0;
2797c478bd9Sstevel@tonic-gate mech_support_info_t mech_support_info;
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate if (!metaslot_enabled) {
2827c478bd9Sstevel@tonic-gate return (CKR_SLOT_ID_INVALID);
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate if (pInfo == NULL) {
2867c478bd9Sstevel@tonic-gate return (CKR_ARGUMENTS_BAD);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate mech_support_info.supporting_slots =
2907c478bd9Sstevel@tonic-gate malloc(meta_slotManager_get_slotcount() * sizeof (mechinfo_t *));
2917c478bd9Sstevel@tonic-gate if (mech_support_info.supporting_slots == NULL) {
2927c478bd9Sstevel@tonic-gate return (CKR_HOST_MEMORY);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate mech_support_info.mech = type;
2967c478bd9Sstevel@tonic-gate
297*d3a28a55Sdinak rv = meta_mechManager_get_slots(&mech_support_info, TRUE, NULL);
2987c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
2997c478bd9Sstevel@tonic-gate free(mech_support_info.supporting_slots);
3007c478bd9Sstevel@tonic-gate return (rv);
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate slotCount = mech_support_info.num_supporting_slots;
3047c478bd9Sstevel@tonic-gate slots = mech_support_info.supporting_slots;
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate /* Merge mechanism info from all slots. */
3077c478bd9Sstevel@tonic-gate (void) memcpy(pInfo, &(slots[0]->mechanism_info),
3087c478bd9Sstevel@tonic-gate sizeof (CK_MECHANISM_INFO));
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate /* no need to look at index 0, since that's what we started with */
3117c478bd9Sstevel@tonic-gate for (i = 1; i < slotCount; i++) {
3127c478bd9Sstevel@tonic-gate CK_ULONG thisValue;
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate /* MinKeySize should be smallest of all slots. */
3157c478bd9Sstevel@tonic-gate thisValue = slots[i]->mechanism_info.ulMinKeySize;
3167c478bd9Sstevel@tonic-gate if (thisValue < pInfo->ulMinKeySize) {
3177c478bd9Sstevel@tonic-gate pInfo->ulMinKeySize = thisValue;
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate /* MaxKeySize should be largest of all slots. */
3217c478bd9Sstevel@tonic-gate thisValue = slots[i]->mechanism_info.ulMaxKeySize;
3227c478bd9Sstevel@tonic-gate if (thisValue > pInfo->ulMaxKeySize) {
3237c478bd9Sstevel@tonic-gate pInfo->ulMaxKeySize = thisValue;
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate pInfo->flags |= slots[i]->mechanism_info.flags;
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate /* Clear the CKF_HW flag. We might select a software provider later. */
3307c478bd9Sstevel@tonic-gate pInfo->flags &= ~CKF_HW;
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate /* Clear the extenstion flag. Spec says is should never even be set. */
3337c478bd9Sstevel@tonic-gate pInfo->flags &= ~CKF_EXTENSION;
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate free(mech_support_info.supporting_slots);
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate return (CKR_OK);
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate /*
3427c478bd9Sstevel@tonic-gate * meta_InitToken
3437c478bd9Sstevel@tonic-gate *
3447c478bd9Sstevel@tonic-gate * Not supported. The metaslot "token" is always initialized. The token object
3457c478bd9Sstevel@tonic-gate * token must already be initialized. Other vendors don't seem to support
3467c478bd9Sstevel@tonic-gate * this anyway.
3477c478bd9Sstevel@tonic-gate */
3487c478bd9Sstevel@tonic-gate /* ARGSUSED */
3497c478bd9Sstevel@tonic-gate CK_RV
meta_InitToken(CK_SLOT_ID slotID,CK_UTF8CHAR_PTR pPin,CK_ULONG ulPinLen,CK_UTF8CHAR_PTR pLabel)3507c478bd9Sstevel@tonic-gate meta_InitToken(CK_SLOT_ID slotID, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen,
3517c478bd9Sstevel@tonic-gate CK_UTF8CHAR_PTR pLabel)
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_NOT_SUPPORTED);
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate /*
3587c478bd9Sstevel@tonic-gate * meta_InitPIN
3597c478bd9Sstevel@tonic-gate *
3607c478bd9Sstevel@tonic-gate * Not supported. Same reason as C_InitToken.
3617c478bd9Sstevel@tonic-gate */
3627c478bd9Sstevel@tonic-gate /* ARGSUSED */
3637c478bd9Sstevel@tonic-gate CK_RV
meta_InitPIN(CK_SESSION_HANDLE hSession,CK_UTF8CHAR_PTR pPin,CK_ULONG ulPinLen)3647c478bd9Sstevel@tonic-gate meta_InitPIN(CK_SESSION_HANDLE hSession,
3657c478bd9Sstevel@tonic-gate CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen)
3667c478bd9Sstevel@tonic-gate {
3677c478bd9Sstevel@tonic-gate return (CKR_FUNCTION_NOT_SUPPORTED);
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate /*
3727c478bd9Sstevel@tonic-gate * meta_SetPIN
3737c478bd9Sstevel@tonic-gate *
3747c478bd9Sstevel@tonic-gate * This is basically just a pass-thru to the object token. No need to
3757c478bd9Sstevel@tonic-gate * even check the arguments, since we don't use them.
3767c478bd9Sstevel@tonic-gate */
3777c478bd9Sstevel@tonic-gate CK_RV
meta_SetPIN(CK_SESSION_HANDLE hSession,CK_UTF8CHAR_PTR pOldPin,CK_ULONG ulOldPinLen,CK_UTF8CHAR_PTR pNewPin,CK_ULONG ulNewPinLen)3787c478bd9Sstevel@tonic-gate meta_SetPIN(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin,
3797c478bd9Sstevel@tonic-gate CK_ULONG ulOldPinLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen)
3807c478bd9Sstevel@tonic-gate {
3817c478bd9Sstevel@tonic-gate CK_RV rv;
3827c478bd9Sstevel@tonic-gate meta_session_t *session;
3837c478bd9Sstevel@tonic-gate slot_session_t *slot_session;
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate rv = meta_handle2session(hSession, &session);
3867c478bd9Sstevel@tonic-gate if (rv != CKR_OK)
3877c478bd9Sstevel@tonic-gate return (rv);
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate if (IS_READ_ONLY_SESSION(session->session_flags)) {
3907c478bd9Sstevel@tonic-gate REFRELEASE(session);
3917c478bd9Sstevel@tonic-gate return (CKR_SESSION_READ_ONLY);
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate rv = meta_get_slot_session(get_keystore_slotnum(), &slot_session,
3957c478bd9Sstevel@tonic-gate session->session_flags);
3967c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
3977c478bd9Sstevel@tonic-gate REFRELEASE(session);
3987c478bd9Sstevel@tonic-gate return (rv);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate rv = FUNCLIST(slot_session->fw_st_id)->C_SetPIN(slot_session->hSession,
4027c478bd9Sstevel@tonic-gate pOldPin, ulOldPinLen, pNewPin, ulNewPinLen);
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate meta_release_slot_session(slot_session);
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate REFRELEASE(session);
4077c478bd9Sstevel@tonic-gate return (rv);
4087c478bd9Sstevel@tonic-gate }
409