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, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "@(#)adm_metaslot.c 1.3 05/06/08 SMI"
28
29 /*
30 * Administration for metaslot
31 *
32 * All the "list" operations will call functions in libpkcs11.so
33 * Normally, it doesn't make sense to call functions in libpkcs11.so directly
34 * because libpkcs11.so depends on the configuration file (pkcs11.conf) the
35 * cryptoadm command is trying to administer. However, since metaslot
36 * is part of the framework, it is not possible to get information about
37 * it without actually calling functions in libpkcs11.so.
38 *
39 * So, for the listing operation, which won't modify the value of pkcs11.conf
40 * it is safe to call libpkcs11.so.
41 *
42 * For other operations that modifies the pkcs11.conf file, libpkcs11.so
43 * will not be called.
44 *
45 */
46
47 #include <cryptoutil.h>
152 if (rv != CKR_OK) {
153 cryptodebug("failed to call C_GetFunctionList in "
154 "framework library");
155 rc = FAILURE;
156 goto finish;
157 }
158
159 /* Initialize this provider */
160 rv = funcs->C_Initialize(NULL_PTR);
161 if (rv != CKR_OK) {
162 cryptodebug("C_Initialize failed with error code 0x%x\n", rv);
163 rc = FAILURE;
164 goto finish;
165 } else {
166 lib_initialized = B_TRUE;
167 }
168
169 /*
170 * We know for sure that metaslot is slot 0 in the framework,
171 * so, we will do a C_GetSlotInfo() trying to see if it works.
172 * If it failes with CKR_SLOT_ID_INVALID, we know that metaslot
173 * is not really enabled.
174 */
175 rv = funcs->C_GetSlotInfo(METASLOT_ID, &slot_info);
176 if (rv == CKR_SLOT_ID_INVALID) {
177 (void) printf(gettext("actual status: disabled.\n"));
178 /*
179 * Even if the -m and -v flag is supplied, there's nothing
180 * interesting to display about metaslot since it is disabled,
181 * so, just stop right here.
182 */
183 goto finish;
184 }
185
186 if (rv != CKR_OK) {
187 cryptodebug("C_GetSlotInfo failed with error "
188 "code 0x%x\n", rv);
189 rc = FAILURE;
190 goto finish;
191 }
192
267 }
268 }
269 } else {
270 rc = convert_mechlist(&pmech_list, &mech_count, mechlist);
271 if (rc != SUCCESS) {
272 goto finish;
273 }
274 }
275
276 (void) printf(gettext("Mechanisms:\n"));
277 if (mech_count == 0) {
278 /* should never be this case */
279 (void) printf(gettext("No mechanisms\n"));
280 goto finish;
281 }
282 if (verbose) {
283 display_verbose_mech_header();
284 }
285
286 for (i = 0; i < mech_count; i++) {
287 (void) printf("%-29s", pkcs11_mech2str(pmech_list[i]));
288 if (verbose) {
289 CK_MECHANISM_INFO mech_info;
290 rv = funcs->C_GetMechanismInfo(METASLOT_ID,
291 pmech_list[i], &mech_info);
292 if (rv != CKR_OK) {
293 cryptodebug("C_GetMechanismInfo failed with "
294 "error code 0x%x\n", rv);
295 rc = FAILURE;
296 goto finish;
297 }
298 display_mech_info(&mech_info);
299 }
300 (void) printf("\n");
301 }
302
303 finish:
304
305 if ((rc == FAILURE) && (show_mechs)) {
306 (void) printf(gettext(
307 "metaslot: failed to retrieve the mechanism list.\n"));
308 }
309
310 if (lib_initialized) {
311 (void) funcs->C_Finalize(NULL_PTR);
|
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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #pragma ident "@(#)adm_metaslot.c 1.4 08/06/27 SMI"
27
28 /*
29 * Administration for metaslot
30 *
31 * All the "list" operations will call functions in libpkcs11.so
32 * Normally, it doesn't make sense to call functions in libpkcs11.so directly
33 * because libpkcs11.so depends on the configuration file (pkcs11.conf) the
34 * cryptoadm command is trying to administer. However, since metaslot
35 * is part of the framework, it is not possible to get information about
36 * it without actually calling functions in libpkcs11.so.
37 *
38 * So, for the listing operation, which won't modify the value of pkcs11.conf
39 * it is safe to call libpkcs11.so.
40 *
41 * For other operations that modifies the pkcs11.conf file, libpkcs11.so
42 * will not be called.
43 *
44 */
45
46 #include <cryptoutil.h>
151 if (rv != CKR_OK) {
152 cryptodebug("failed to call C_GetFunctionList in "
153 "framework library");
154 rc = FAILURE;
155 goto finish;
156 }
157
158 /* Initialize this provider */
159 rv = funcs->C_Initialize(NULL_PTR);
160 if (rv != CKR_OK) {
161 cryptodebug("C_Initialize failed with error code 0x%x\n", rv);
162 rc = FAILURE;
163 goto finish;
164 } else {
165 lib_initialized = B_TRUE;
166 }
167
168 /*
169 * We know for sure that metaslot is slot 0 in the framework,
170 * so, we will do a C_GetSlotInfo() trying to see if it works.
171 * If it fails with CKR_SLOT_ID_INVALID, we know that metaslot
172 * is not really enabled.
173 */
174 rv = funcs->C_GetSlotInfo(METASLOT_ID, &slot_info);
175 if (rv == CKR_SLOT_ID_INVALID) {
176 (void) printf(gettext("actual status: disabled.\n"));
177 /*
178 * Even if the -m and -v flag is supplied, there's nothing
179 * interesting to display about metaslot since it is disabled,
180 * so, just stop right here.
181 */
182 goto finish;
183 }
184
185 if (rv != CKR_OK) {
186 cryptodebug("C_GetSlotInfo failed with error "
187 "code 0x%x\n", rv);
188 rc = FAILURE;
189 goto finish;
190 }
191
266 }
267 }
268 } else {
269 rc = convert_mechlist(&pmech_list, &mech_count, mechlist);
270 if (rc != SUCCESS) {
271 goto finish;
272 }
273 }
274
275 (void) printf(gettext("Mechanisms:\n"));
276 if (mech_count == 0) {
277 /* should never be this case */
278 (void) printf(gettext("No mechanisms\n"));
279 goto finish;
280 }
281 if (verbose) {
282 display_verbose_mech_header();
283 }
284
285 for (i = 0; i < mech_count; i++) {
286 CK_MECHANISM_TYPE mech = pmech_list[i];
287
288 if (mech > CKM_VENDOR_DEFINED) {
289 (void) printf("%#lx", mech);
290 } else {
291 (void) printf("%-29s", pkcs11_mech2str(mech));
292 }
293
294 if (verbose) {
295 CK_MECHANISM_INFO mech_info;
296 rv = funcs->C_GetMechanismInfo(METASLOT_ID,
297 mech, &mech_info);
298 if (rv != CKR_OK) {
299 cryptodebug("C_GetMechanismInfo failed with "
300 "error code 0x%x\n", rv);
301 rc = FAILURE;
302 goto finish;
303 }
304 display_mech_info(&mech_info);
305 }
306 (void) printf("\n");
307 }
308
309 finish:
310
311 if ((rc == FAILURE) && (show_mechs)) {
312 (void) printf(gettext(
313 "metaslot: failed to retrieve the mechanism list.\n"));
314 }
315
316 if (lib_initialized) {
317 (void) funcs->C_Finalize(NULL_PTR);
|