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
52321aa36Sda73024 * Common Development and Distribution License (the "License").
62321aa36Sda73024 * 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 /*
222321aa36Sda73024 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * Administration for metaslot
287c478bd9Sstevel@tonic-gate *
297c478bd9Sstevel@tonic-gate * All the "list" operations will call functions in libpkcs11.so
307c478bd9Sstevel@tonic-gate * Normally, it doesn't make sense to call functions in libpkcs11.so directly
317c478bd9Sstevel@tonic-gate * because libpkcs11.so depends on the configuration file (pkcs11.conf) the
327c478bd9Sstevel@tonic-gate * cryptoadm command is trying to administer. However, since metaslot
337c478bd9Sstevel@tonic-gate * is part of the framework, it is not possible to get information about
347c478bd9Sstevel@tonic-gate * it without actually calling functions in libpkcs11.so.
357c478bd9Sstevel@tonic-gate *
367c478bd9Sstevel@tonic-gate * So, for the listing operation, which won't modify the value of pkcs11.conf
377c478bd9Sstevel@tonic-gate * it is safe to call libpkcs11.so.
387c478bd9Sstevel@tonic-gate *
397c478bd9Sstevel@tonic-gate * For other operations that modifies the pkcs11.conf file, libpkcs11.so
407c478bd9Sstevel@tonic-gate * will not be called.
417c478bd9Sstevel@tonic-gate *
427c478bd9Sstevel@tonic-gate */
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #include <cryptoutil.h>
457c478bd9Sstevel@tonic-gate #include <stdio.h>
467c478bd9Sstevel@tonic-gate #include <libintl.h>
477c478bd9Sstevel@tonic-gate #include <dlfcn.h>
487c478bd9Sstevel@tonic-gate #include <link.h>
497c478bd9Sstevel@tonic-gate #include <strings.h>
507c478bd9Sstevel@tonic-gate #include <security/cryptoki.h>
517c478bd9Sstevel@tonic-gate #include <cryptoutil.h>
527c478bd9Sstevel@tonic-gate #include "cryptoadm.h"
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate #define METASLOT_ID 0
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate int
list_metaslot_info(boolean_t show_mechs,boolean_t verbose,mechlist_t * mechlist)577c478bd9Sstevel@tonic-gate list_metaslot_info(boolean_t show_mechs, boolean_t verbose,
587c478bd9Sstevel@tonic-gate mechlist_t *mechlist)
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate int rc = SUCCESS;
617c478bd9Sstevel@tonic-gate CK_RV rv;
627c478bd9Sstevel@tonic-gate CK_SLOT_INFO slot_info;
637c478bd9Sstevel@tonic-gate CK_TOKEN_INFO token_info;
647c478bd9Sstevel@tonic-gate CK_MECHANISM_TYPE_PTR pmech_list = NULL;
657c478bd9Sstevel@tonic-gate CK_ULONG mech_count;
667c478bd9Sstevel@tonic-gate int i;
677c478bd9Sstevel@tonic-gate CK_RV (*Tmp_C_GetFunctionList)(CK_FUNCTION_LIST_PTR_PTR);
687c478bd9Sstevel@tonic-gate CK_FUNCTION_LIST_PTR funcs;
697c478bd9Sstevel@tonic-gate void *dldesc = NULL;
707c478bd9Sstevel@tonic-gate boolean_t lib_initialized = B_FALSE;
717c478bd9Sstevel@tonic-gate uentry_t *puent;
727c478bd9Sstevel@tonic-gate char buf[128];
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate * Display the system-wide metaslot settings as specified
777c478bd9Sstevel@tonic-gate * in pkcs11.conf file.
787c478bd9Sstevel@tonic-gate */
797c478bd9Sstevel@tonic-gate if ((puent = getent_uef(METASLOT_KEYWORD)) == NULL) {
807c478bd9Sstevel@tonic-gate cryptoerror(LOG_STDERR,
817c478bd9Sstevel@tonic-gate gettext("metaslot entry doesn't exist."));
827c478bd9Sstevel@tonic-gate return (FAILURE);
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate (void) printf(gettext("System-wide Meta Slot Configuration:\n"));
867c478bd9Sstevel@tonic-gate /*
87*0a85b835SDaniel Anderson * TRANSLATION_NOTE
887c478bd9Sstevel@tonic-gate * Strictly for appearance's sake, this line should be as long as
897c478bd9Sstevel@tonic-gate * the length of the translated text above.
907c478bd9Sstevel@tonic-gate */
917c478bd9Sstevel@tonic-gate (void) printf(gettext("------------------------------------\n"));
927c478bd9Sstevel@tonic-gate (void) printf(gettext("Status: %s\n"), puent->flag_metaslot_enabled ?
937c478bd9Sstevel@tonic-gate gettext("enabled") : gettext("disabled"));
947c478bd9Sstevel@tonic-gate (void) printf(gettext("Sensitive Token Object Automatic Migrate: %s\n"),
957c478bd9Sstevel@tonic-gate puent->flag_metaslot_auto_key_migrate ? gettext("enabled") :
967c478bd9Sstevel@tonic-gate gettext("disabled"));
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate bzero(buf, sizeof (buf));
997c478bd9Sstevel@tonic-gate if (memcmp(puent->metaslot_ks_slot, buf, SLOT_DESCRIPTION_SIZE) != 0) {
1007c478bd9Sstevel@tonic-gate (void) printf(gettext("Persistent object store slot: %s\n"),
1017c478bd9Sstevel@tonic-gate puent->metaslot_ks_slot);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate if (memcmp(puent->metaslot_ks_token, buf, TOKEN_LABEL_SIZE) != 0) {
1057c478bd9Sstevel@tonic-gate (void) printf(gettext("Persistent object store token: %s\n"),
1067c478bd9Sstevel@tonic-gate puent->metaslot_ks_token);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate if ((!verbose) && (!show_mechs)) {
1107c478bd9Sstevel@tonic-gate return (SUCCESS);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate if (verbose) {
1147c478bd9Sstevel@tonic-gate (void) printf(gettext("\nDetailed Meta Slot Information:\n"));
1157c478bd9Sstevel@tonic-gate /*
116*0a85b835SDaniel Anderson * TRANSLATION_NOTE
1177c478bd9Sstevel@tonic-gate * Strictly for appearance's sake, this line should be as
1187c478bd9Sstevel@tonic-gate * long as the length of the translated text above.
1197c478bd9Sstevel@tonic-gate */
1207c478bd9Sstevel@tonic-gate (void) printf(gettext("-------------------------------\n"));
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * Need to actually make calls to libpkcs11.so to get
1257c478bd9Sstevel@tonic-gate * information about metaslot.
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate dldesc = dlopen(UEF_FRAME_LIB, RTLD_NOW);
1297c478bd9Sstevel@tonic-gate if (dldesc == NULL) {
1307c478bd9Sstevel@tonic-gate char *dl_error;
1317c478bd9Sstevel@tonic-gate dl_error = dlerror();
1327c478bd9Sstevel@tonic-gate cryptodebug("Cannot load PKCS#11 framework library. "
1337c478bd9Sstevel@tonic-gate "dlerror:%s", dl_error);
1347c478bd9Sstevel@tonic-gate return (FAILURE);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate /* Get the pointer to library's C_GetFunctionList() */
1387c478bd9Sstevel@tonic-gate Tmp_C_GetFunctionList = (CK_RV(*)())dlsym(dldesc, "C_GetFunctionList");
1397c478bd9Sstevel@tonic-gate if (Tmp_C_GetFunctionList == NULL) {
1407c478bd9Sstevel@tonic-gate cryptodebug("Cannot get the address of the C_GetFunctionList "
1417c478bd9Sstevel@tonic-gate "from framework");
1427c478bd9Sstevel@tonic-gate rc = FAILURE;
1437c478bd9Sstevel@tonic-gate goto finish;
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate /* Get the provider's function list */
1487c478bd9Sstevel@tonic-gate rv = Tmp_C_GetFunctionList(&funcs);
1497c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
1507c478bd9Sstevel@tonic-gate cryptodebug("failed to call C_GetFunctionList in "
1517c478bd9Sstevel@tonic-gate "framework library");
1527c478bd9Sstevel@tonic-gate rc = FAILURE;
1537c478bd9Sstevel@tonic-gate goto finish;
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate /* Initialize this provider */
1577c478bd9Sstevel@tonic-gate rv = funcs->C_Initialize(NULL_PTR);
1587c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
1597c478bd9Sstevel@tonic-gate cryptodebug("C_Initialize failed with error code 0x%x\n", rv);
1607c478bd9Sstevel@tonic-gate rc = FAILURE;
1617c478bd9Sstevel@tonic-gate goto finish;
1627c478bd9Sstevel@tonic-gate } else {
1637c478bd9Sstevel@tonic-gate lib_initialized = B_TRUE;
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate * We know for sure that metaslot is slot 0 in the framework,
1687c478bd9Sstevel@tonic-gate * so, we will do a C_GetSlotInfo() trying to see if it works.
1692321aa36Sda73024 * If it fails with CKR_SLOT_ID_INVALID, we know that metaslot
1707c478bd9Sstevel@tonic-gate * is not really enabled.
1717c478bd9Sstevel@tonic-gate */
1727c478bd9Sstevel@tonic-gate rv = funcs->C_GetSlotInfo(METASLOT_ID, &slot_info);
1737c478bd9Sstevel@tonic-gate if (rv == CKR_SLOT_ID_INVALID) {
1747c478bd9Sstevel@tonic-gate (void) printf(gettext("actual status: disabled.\n"));
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate * Even if the -m and -v flag is supplied, there's nothing
1777c478bd9Sstevel@tonic-gate * interesting to display about metaslot since it is disabled,
1787c478bd9Sstevel@tonic-gate * so, just stop right here.
1797c478bd9Sstevel@tonic-gate */
1807c478bd9Sstevel@tonic-gate goto finish;
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
1847c478bd9Sstevel@tonic-gate cryptodebug("C_GetSlotInfo failed with error "
1857c478bd9Sstevel@tonic-gate "code 0x%x\n", rv);
1867c478bd9Sstevel@tonic-gate rc = FAILURE;
1877c478bd9Sstevel@tonic-gate goto finish;
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate if (!verbose) {
1917c478bd9Sstevel@tonic-gate goto display_mechs;
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate (void) printf(gettext("actual status: enabled.\n"));
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate (void) printf(gettext("Description: %.64s\n"),
1977c478bd9Sstevel@tonic-gate slot_info.slotDescription);
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate (void) printf(gettext("Token Present: %s\n"),
2007c478bd9Sstevel@tonic-gate (slot_info.flags & CKF_TOKEN_PRESENT ?
2017c478bd9Sstevel@tonic-gate gettext("True") : gettext("False")));
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate rv = funcs->C_GetTokenInfo(METASLOT_ID, &token_info);
2047c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
2057c478bd9Sstevel@tonic-gate cryptodebug("C_GetTokenInfo failed with error "
2067c478bd9Sstevel@tonic-gate "code 0x%x\n", rv);
2077c478bd9Sstevel@tonic-gate rc = FAILURE;
2087c478bd9Sstevel@tonic-gate goto finish;
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate (void) printf(gettext("Token Label: %.32s\n"
2127c478bd9Sstevel@tonic-gate "Manufacturer ID: %.32s\n"
2137c478bd9Sstevel@tonic-gate "Model: %.16s\n"
2147c478bd9Sstevel@tonic-gate "Serial Number: %.16s\n"
2157c478bd9Sstevel@tonic-gate "Hardware Version: %d.%d\n"
2167c478bd9Sstevel@tonic-gate "Firmware Version: %d.%d\n"
2177c478bd9Sstevel@tonic-gate "UTC Time: %.16s\n"
2187f3340f0SDarren Moffat "PIN Min Length: %d\n"
2197f3340f0SDarren Moffat "PIN Max Length: %d\n"),
2207c478bd9Sstevel@tonic-gate token_info.label,
2217c478bd9Sstevel@tonic-gate token_info.manufacturerID,
2227c478bd9Sstevel@tonic-gate token_info.model,
2237c478bd9Sstevel@tonic-gate token_info.serialNumber,
2247c478bd9Sstevel@tonic-gate token_info.hardwareVersion.major,
2257c478bd9Sstevel@tonic-gate token_info.hardwareVersion.minor,
2267c478bd9Sstevel@tonic-gate token_info.firmwareVersion.major,
2277c478bd9Sstevel@tonic-gate token_info.firmwareVersion.minor,
2287c478bd9Sstevel@tonic-gate token_info.utcTime,
2297c478bd9Sstevel@tonic-gate token_info.ulMinPinLen,
2307c478bd9Sstevel@tonic-gate token_info.ulMaxPinLen);
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate display_token_flags(token_info.flags);
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate if (!show_mechs) {
2357c478bd9Sstevel@tonic-gate goto finish;
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate display_mechs:
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate if (mechlist == NULL) {
2417c478bd9Sstevel@tonic-gate rv = funcs->C_GetMechanismList(METASLOT_ID, NULL_PTR,
2427c478bd9Sstevel@tonic-gate &mech_count);
2437c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
2447c478bd9Sstevel@tonic-gate cryptodebug("C_GetMechanismList failed with error "
2457c478bd9Sstevel@tonic-gate "code 0x%x\n", rv);
2467c478bd9Sstevel@tonic-gate rc = FAILURE;
2477c478bd9Sstevel@tonic-gate goto finish;
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate if (mech_count > 0) {
2517c478bd9Sstevel@tonic-gate pmech_list = malloc(mech_count *
2527c478bd9Sstevel@tonic-gate sizeof (CK_MECHANISM_TYPE));
2537c478bd9Sstevel@tonic-gate if (pmech_list == NULL) {
2547c478bd9Sstevel@tonic-gate cryptodebug("out of memory");
2557c478bd9Sstevel@tonic-gate rc = FAILURE;
2567c478bd9Sstevel@tonic-gate goto finish;
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate rv = funcs->C_GetMechanismList(METASLOT_ID, pmech_list,
2597c478bd9Sstevel@tonic-gate &mech_count);
2607c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
2617c478bd9Sstevel@tonic-gate cryptodebug("C_GetMechanismList failed with "
2627c478bd9Sstevel@tonic-gate "error code 0x%x\n", rv);
2637c478bd9Sstevel@tonic-gate rc = FAILURE;
2647c478bd9Sstevel@tonic-gate goto finish;
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate } else {
2687c478bd9Sstevel@tonic-gate rc = convert_mechlist(&pmech_list, &mech_count, mechlist);
2697c478bd9Sstevel@tonic-gate if (rc != SUCCESS) {
2707c478bd9Sstevel@tonic-gate goto finish;
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate (void) printf(gettext("Mechanisms:\n"));
2757c478bd9Sstevel@tonic-gate if (mech_count == 0) {
2767c478bd9Sstevel@tonic-gate /* should never be this case */
2777c478bd9Sstevel@tonic-gate (void) printf(gettext("No mechanisms\n"));
2787c478bd9Sstevel@tonic-gate goto finish;
2797c478bd9Sstevel@tonic-gate }
2807c478bd9Sstevel@tonic-gate if (verbose) {
2817c478bd9Sstevel@tonic-gate display_verbose_mech_header();
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate for (i = 0; i < mech_count; i++) {
2852321aa36Sda73024 CK_MECHANISM_TYPE mech = pmech_list[i];
2862321aa36Sda73024
28776d1b5a9Sda73024 if (mech >= CKM_VENDOR_DEFINED) {
2882321aa36Sda73024 (void) printf("%#lx", mech);
2892321aa36Sda73024 } else {
2902321aa36Sda73024 (void) printf("%-29s", pkcs11_mech2str(mech));
2912321aa36Sda73024 }
2922321aa36Sda73024
2937c478bd9Sstevel@tonic-gate if (verbose) {
2947c478bd9Sstevel@tonic-gate CK_MECHANISM_INFO mech_info;
2957c478bd9Sstevel@tonic-gate rv = funcs->C_GetMechanismInfo(METASLOT_ID,
2962321aa36Sda73024 mech, &mech_info);
2977c478bd9Sstevel@tonic-gate if (rv != CKR_OK) {
2987c478bd9Sstevel@tonic-gate cryptodebug("C_GetMechanismInfo failed with "
2997c478bd9Sstevel@tonic-gate "error code 0x%x\n", rv);
3007c478bd9Sstevel@tonic-gate rc = FAILURE;
3017c478bd9Sstevel@tonic-gate goto finish;
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate display_mech_info(&mech_info);
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate (void) printf("\n");
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate finish:
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate if ((rc == FAILURE) && (show_mechs)) {
3117c478bd9Sstevel@tonic-gate (void) printf(gettext(
3127c478bd9Sstevel@tonic-gate "metaslot: failed to retrieve the mechanism list.\n"));
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate if (lib_initialized) {
3167c478bd9Sstevel@tonic-gate (void) funcs->C_Finalize(NULL_PTR);
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate if (dldesc != NULL) {
3207c478bd9Sstevel@tonic-gate (void) dlclose(dldesc);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate if (pmech_list != NULL) {
3247c478bd9Sstevel@tonic-gate (void) free(pmech_list);
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate return (rc);
3287c478bd9Sstevel@tonic-gate }
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate int
list_metaslot_policy()3317c478bd9Sstevel@tonic-gate list_metaslot_policy()
3327c478bd9Sstevel@tonic-gate {
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate uentry_t *puent;
3357c478bd9Sstevel@tonic-gate int rc;
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate if ((puent = getent_uef(METASLOT_KEYWORD)) == NULL) {
3387c478bd9Sstevel@tonic-gate cryptoerror(LOG_STDERR,
3397c478bd9Sstevel@tonic-gate gettext("metaslot entry doesn't exist."));
3407c478bd9Sstevel@tonic-gate return (FAILURE);
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate rc = display_policy(puent);
3447c478bd9Sstevel@tonic-gate (void) printf("\n");
3457c478bd9Sstevel@tonic-gate free_uentry(puent);
3467c478bd9Sstevel@tonic-gate return (rc);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate * disable metaslot and some of its configuration options
3517c478bd9Sstevel@tonic-gate *
3527c478bd9Sstevel@tonic-gate * If mechlist==NULL, and the other 2 flags are false, just disabled
3537c478bd9Sstevel@tonic-gate * the metaslot feature.
3547c478bd9Sstevel@tonic-gate *
3557c478bd9Sstevel@tonic-gate * mechlist: list of mechanisms to disable
3567c478bd9Sstevel@tonic-gate * allflag: if true, indicates all mechanisms should be disabled.
3577c478bd9Sstevel@tonic-gate * auto_key_migrate_flag: if true, indicates auto key migrate should be disabled
3587c478bd9Sstevel@tonic-gate */
3597c478bd9Sstevel@tonic-gate int
disable_metaslot(mechlist_t * mechlist,boolean_t allflag,boolean_t auto_key_migrate_flag)3607c478bd9Sstevel@tonic-gate disable_metaslot(mechlist_t *mechlist, boolean_t allflag,
3617c478bd9Sstevel@tonic-gate boolean_t auto_key_migrate_flag)
3627c478bd9Sstevel@tonic-gate {
3637c478bd9Sstevel@tonic-gate uentry_t *puent;
3647c478bd9Sstevel@tonic-gate int rc = SUCCESS;
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate if ((puent = getent_uef(METASLOT_KEYWORD)) == NULL) {
3677c478bd9Sstevel@tonic-gate cryptoerror(LOG_STDERR,
3687c478bd9Sstevel@tonic-gate gettext("metaslot entry doesn't exist."));
3697c478bd9Sstevel@tonic-gate return (FAILURE);
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate if ((mechlist == NULL) && (!auto_key_migrate_flag) && (!allflag)) {
3747c478bd9Sstevel@tonic-gate /* disable metaslot */
3757c478bd9Sstevel@tonic-gate puent->flag_metaslot_enabled = B_FALSE;
3767c478bd9Sstevel@tonic-gate goto write_to_file;
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate if (auto_key_migrate_flag) {
3807c478bd9Sstevel@tonic-gate /* need to disable auto_key_migrate */
3817c478bd9Sstevel@tonic-gate puent->flag_metaslot_auto_key_migrate = B_FALSE;
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate if ((mechlist == NULL) && (!allflag)) {
3857c478bd9Sstevel@tonic-gate goto write_to_file;
3867c478bd9Sstevel@tonic-gate }
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate /* disable specified mechanisms */
3897c478bd9Sstevel@tonic-gate if (allflag) {
3907c478bd9Sstevel@tonic-gate free_umechlist(puent->policylist);
3917c478bd9Sstevel@tonic-gate puent->policylist = NULL;
3927c478bd9Sstevel@tonic-gate puent->count = 0;
3937c478bd9Sstevel@tonic-gate puent->flag_enabledlist = B_TRUE;
3947c478bd9Sstevel@tonic-gate rc = SUCCESS;
3957c478bd9Sstevel@tonic-gate } else {
3967c478bd9Sstevel@tonic-gate if (puent->flag_enabledlist == B_TRUE) {
3977c478bd9Sstevel@tonic-gate /*
3987c478bd9Sstevel@tonic-gate * The current default policy mode
3997c478bd9Sstevel@tonic-gate * is "all are disabled, except ...", so if a
4007c478bd9Sstevel@tonic-gate * specified mechanism is in the exception list
4017c478bd9Sstevel@tonic-gate * (the policylist), delete it from the policylist.
4027c478bd9Sstevel@tonic-gate */
4037c478bd9Sstevel@tonic-gate rc = update_policylist(puent, mechlist, DELETE_MODE);
4047c478bd9Sstevel@tonic-gate } else {
4057c478bd9Sstevel@tonic-gate /*
4067c478bd9Sstevel@tonic-gate * The current default policy mode of this library
4077c478bd9Sstevel@tonic-gate * is "all are enabled", so if a specified mechanism
4087c478bd9Sstevel@tonic-gate * is not in the exception list (policylist), add
4097c478bd9Sstevel@tonic-gate * it into the policylist.
4107c478bd9Sstevel@tonic-gate */
4117c478bd9Sstevel@tonic-gate rc = update_policylist(puent, mechlist, ADD_MODE);
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate
4157c478bd9Sstevel@tonic-gate if (rc != SUCCESS) {
4167c478bd9Sstevel@tonic-gate goto finish;
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate /* If all mechanisms are disabled, metaslot will be disabled as well */
4207c478bd9Sstevel@tonic-gate if ((puent->flag_enabledlist) && (puent->count == 0)) {
4217c478bd9Sstevel@tonic-gate puent->flag_metaslot_enabled = B_FALSE;
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate write_to_file:
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate rc = update_pkcs11conf(puent);
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate finish:
4297c478bd9Sstevel@tonic-gate free_uentry(puent);
4307c478bd9Sstevel@tonic-gate return (rc);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate /*
4347c478bd9Sstevel@tonic-gate * enable metaslot and some of its configuration options
4357c478bd9Sstevel@tonic-gate *
4367c478bd9Sstevel@tonic-gate * If mechlist==NULL, and the other flags are false, or not specified,
4377c478bd9Sstevel@tonic-gate * just enable the metaslot feature.
4387c478bd9Sstevel@tonic-gate *
4397c478bd9Sstevel@tonic-gate * token: if specified, indicate label of token to be used as keystore.
4407c478bd9Sstevel@tonic-gate * slot: if specified, indicate slot to be used as keystore.
4417c478bd9Sstevel@tonic-gate * use_default: if true, indicate to use the default keystore. It should
4427c478bd9Sstevel@tonic-gate * not be specified if either token or slot is specified.
4437c478bd9Sstevel@tonic-gate * mechlist: list of mechanisms to enable
4447c478bd9Sstevel@tonic-gate * allflag: if true, indicates all mechanisms should be enabled.
4457c478bd9Sstevel@tonic-gate * auto_key_migrate_flag: if true, indicates auto key migrate should be enabled
4467c478bd9Sstevel@tonic-gate */
4477c478bd9Sstevel@tonic-gate int
enable_metaslot(char * token,char * slot,boolean_t use_default,mechlist_t * mechlist,boolean_t allflag,boolean_t auto_key_migrate_flag)4487c478bd9Sstevel@tonic-gate enable_metaslot(char *token, char *slot, boolean_t use_default,
4497c478bd9Sstevel@tonic-gate mechlist_t *mechlist, boolean_t allflag, boolean_t auto_key_migrate_flag)
4507c478bd9Sstevel@tonic-gate {
4517c478bd9Sstevel@tonic-gate uentry_t *puent;
4527c478bd9Sstevel@tonic-gate int rc = SUCCESS;
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate if ((puent = getent_uef(METASLOT_KEYWORD)) == NULL) {
4557c478bd9Sstevel@tonic-gate cryptoerror(LOG_STDERR,
4567c478bd9Sstevel@tonic-gate gettext("metaslot entry doesn't exist."));
4577c478bd9Sstevel@tonic-gate return (FAILURE);
4587c478bd9Sstevel@tonic-gate }
4597c478bd9Sstevel@tonic-gate
4607c478bd9Sstevel@tonic-gate puent->flag_metaslot_enabled = B_TRUE;
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate if (auto_key_migrate_flag) {
4637c478bd9Sstevel@tonic-gate /* need to enable auto_key_migrate */
4647c478bd9Sstevel@tonic-gate puent->flag_metaslot_auto_key_migrate = B_TRUE;
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate if (allflag) {
4687c478bd9Sstevel@tonic-gate /*
4697c478bd9Sstevel@tonic-gate * If enabling all, what needs to be done are cleaning up the
4707c478bd9Sstevel@tonic-gate * policylist and setting the "flag_enabledlist" flag to
4717c478bd9Sstevel@tonic-gate * B_FALSE.
4727c478bd9Sstevel@tonic-gate */
4737c478bd9Sstevel@tonic-gate free_umechlist(puent->policylist);
4747c478bd9Sstevel@tonic-gate puent->policylist = NULL;
4757c478bd9Sstevel@tonic-gate puent->count = 0;
4767c478bd9Sstevel@tonic-gate puent->flag_enabledlist = B_FALSE;
4777c478bd9Sstevel@tonic-gate rc = SUCCESS;
4787c478bd9Sstevel@tonic-gate } else {
4797c478bd9Sstevel@tonic-gate if (mechlist) {
4807c478bd9Sstevel@tonic-gate if (puent->flag_enabledlist == B_TRUE) {
4817c478bd9Sstevel@tonic-gate /*
4827c478bd9Sstevel@tonic-gate * The current default policy mode of this
4837c478bd9Sstevel@tonic-gate * library is "all are disabled, except ...",
4847c478bd9Sstevel@tonic-gate * so if a specified mechanism is not in the
4857c478bd9Sstevel@tonic-gate * exception list (policylist), add it.
4867c478bd9Sstevel@tonic-gate */
4877c478bd9Sstevel@tonic-gate rc = update_policylist(puent, mechlist,
4887c478bd9Sstevel@tonic-gate ADD_MODE);
4897c478bd9Sstevel@tonic-gate } else {
4907c478bd9Sstevel@tonic-gate /*
4917c478bd9Sstevel@tonic-gate * The current default policy mode of this
4927c478bd9Sstevel@tonic-gate * library is "all are enabled, except", so if
4937c478bd9Sstevel@tonic-gate * a specified mechanism is in the exception
4947c478bd9Sstevel@tonic-gate * list (policylist), delete it.
4957c478bd9Sstevel@tonic-gate */
4967c478bd9Sstevel@tonic-gate rc = update_policylist(puent, mechlist,
4977c478bd9Sstevel@tonic-gate DELETE_MODE);
4987c478bd9Sstevel@tonic-gate }
4997c478bd9Sstevel@tonic-gate }
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate if (rc != SUCCESS) {
5037c478bd9Sstevel@tonic-gate goto finish;
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate
5067c478bd9Sstevel@tonic-gate if (!use_default && !token && !slot) {
5077c478bd9Sstevel@tonic-gate /* no need to change metaslot keystore */
5087c478bd9Sstevel@tonic-gate goto write_to_file;
5097c478bd9Sstevel@tonic-gate }
5107c478bd9Sstevel@tonic-gate
5117c478bd9Sstevel@tonic-gate (void) bzero((char *)puent->metaslot_ks_token, TOKEN_LABEL_SIZE);
5127c478bd9Sstevel@tonic-gate (void) bzero((char *)puent->metaslot_ks_slot, SLOT_DESCRIPTION_SIZE);
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate if (use_default) {
5157c478bd9Sstevel@tonic-gate (void) strlcpy((char *)puent->metaslot_ks_token,
5167c478bd9Sstevel@tonic-gate SOFT_TOKEN_LABEL, TOKEN_LABEL_SIZE);
5177c478bd9Sstevel@tonic-gate (void) strlcpy((char *)puent->metaslot_ks_slot,
5187c478bd9Sstevel@tonic-gate SOFT_SLOT_DESCRIPTION, SLOT_DESCRIPTION_SIZE);
5197c478bd9Sstevel@tonic-gate } else {
5207c478bd9Sstevel@tonic-gate
5217c478bd9Sstevel@tonic-gate if (token) {
5227c478bd9Sstevel@tonic-gate (void) strlcpy((char *)puent->metaslot_ks_token, token,
5237c478bd9Sstevel@tonic-gate TOKEN_LABEL_SIZE);
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate
5267c478bd9Sstevel@tonic-gate if (slot) {
5277c478bd9Sstevel@tonic-gate (void) strlcpy((char *)puent->metaslot_ks_slot, slot,
5287c478bd9Sstevel@tonic-gate SLOT_DESCRIPTION_SIZE);
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate write_to_file:
5347c478bd9Sstevel@tonic-gate
5357c478bd9Sstevel@tonic-gate rc = update_pkcs11conf(puent);
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate finish:
5387c478bd9Sstevel@tonic-gate free_uentry(puent);
5397c478bd9Sstevel@tonic-gate return (rc);
5407c478bd9Sstevel@tonic-gate }
541