pktool.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file comprises the main driver for this tool.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include <libgen.h>
#include <errno.h>
#include <cryptoutil.h>
#include <security/cryptoki.h>
#include "common.h"
/*
* The verbcmd construct allows genericizing information about a verb so
* that it is easier to manipulate. Makes parsing code easier to read,
* fix, and extend with new verbs.
*/
typedef struct verbcmd_s {
char *verb;
int (*action)(int, char *[]);
int mode; /* reserved */
char *synopsis; /* reserved */
} verbcmd;
/* External declarations for supported verb actions. */
};
static char *prog;
static void usage(void);
/*
* Usage information. This function must be updated when new verbs or
* options are added.
*/
static void
usage(void)
{
}
/*
* MAIN() -- where all the action is
*/
int
/* ARGSUSED2 */
{
int i, found = -1;
int rv;
int pk_argc = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D. */
#endif
(void) textdomain(TEXT_DOMAIN);
/* Get program base name and move pointer over 0th arg. */
/* Set up for debug and error output. */
/* There must be one remaining arg at this point */
if (argc == 0) {
usage();
return (1);
}
/*
* By default, metaslot is enabled, and pkcs11_softtoken is
* the keystore, so, pkcs11_softtoken is hidden.
* Always turns off Metaslot so that we can see pkcs11_softtoken.
*/
pk11_errno = errno;
gettext("Disabling metaslot failed: %s"),
return (1);
}
/* Begin parsing command line. */
/* Check for valid verb */
found = -1;
for (i = 0; i < num_cmds; i++) {
if (found < 0) {
found = i;
break;
}
}
}
/* Stop here if no valid verb found. */
if (found < 0) {
return (1);
}
/* Get to work! */
switch (rv) {
case PK_ERR_NONE:
break; /* Command succeeded, do nothing. */
case PK_ERR_USAGE:
usage();
break;
case PK_ERR_QUIT:
exit(0);
/* NOTREACHED */
case PK_ERR_PK11INIT:
gettext("Unable to initialize PKCS#11"),
cryptodebug("C_Initialize failed (%s)",
break;
case PK_ERR_PK11SLOTS:
gettext("Failed to find PKCS#11 slots"),
cryptodebug("C_GetSlotList failed (%s)",
break;
case PK_ERR_PK11SESSION:
gettext("Unable to open PKCS#11 session"),
cryptodebug("C_OpenSession failed (%s)",
break;
case PK_ERR_PK11LOGIN:
if (pk11_errno == CKR_PIN_INCORRECT)
else {
gettext("PKCS#11 authentication failed"),
cryptodebug("C_Login failed (%s)",
}
break;
case PK_ERR_PK11SETPIN:
break;
case PK_ERR_NOSLOTS:
break;
case PK_ERR_NOMEMORY:
break;
case PK_ERR_NOTFOUND:
break;
case PK_ERR_PASSPHRASE:
gettext("Unable to get token PIN"));
break;
case PK_ERR_NEWPIN:
break;
case PK_ERR_PINCONFIRM:
gettext("Failed to confirm new PIN"));
break;
case PK_ERR_PINMATCH:
break;
case PK_ERR_CHANGEPIN:
break;
default:
break;
}
return (rv);
}