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.
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.
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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * This file implements the token list operation for this tool.
30 * It loads the PKCS#11 modules, gets the list of slots with
31 * tokens in them, displays the list, and cleans up.
36 #include <cryptoutil.h>
37 #include <security/cryptoki.h>
41 * Lists all slots with tokens in them.
44 pk_tokens(int argc
, char *argv
[])
46 CK_SLOT_ID_PTR slots
= NULL
;
47 CK_ULONG slot_count
= 0;
48 CK_TOKEN_INFO token_info
;
49 const char *fmt
= NULL
;
54 /* Get rid of subcommand word "tokens". */
58 /* No additional args allowed. */
60 return (PK_ERR_USAGE
);
61 /* Done parsing command line options. */
63 /* Get the list of slots with tokens in them. */
64 if ((rv
= get_token_slots(&slots
, &slot_count
)) != CKR_OK
) {
65 cryptoerror(LOG_STDERR
,
66 gettext("Unable to get token slot list (%s)."),
71 /* Make sure we have something to display. */
72 if (slot_count
== 0) {
73 cryptoerror(LOG_STDERR
, gettext("No slots with tokens found."));
77 /* Display the list. */
78 fmt
= "%-30.30s %-15.15s %-15.15s %-10.10s\n"; /* No I18N/L10N. */
79 (void) fprintf(stdout
, fmt
, gettext("Token Label"), gettext("Manuf ID"),
80 gettext("Serial No"), gettext("PIN State"));
81 for (i
= 0; i
< slot_count
; i
++) {
82 if ((rv
= C_GetTokenInfo(slots
[i
], &token_info
)) != CKR_OK
) {
83 cryptoerror(LOG_STDERR
,
84 gettext("Unable to get slot %d token info (%s)."),
85 i
, pkcs11_strerror(rv
));
89 (void) fprintf(stdout
, fmt
, token_info
.label
,
90 token_info
.manufacturerID
, token_info
.serialNumber
,
91 (token_info
.flags
& CKF_USER_PIN_TO_BE_CHANGED
) ?
92 gettext("default") : gettext("user set"));
97 (void) C_Finalize(NULL
);