delete.c revision 7711facfe58561dd91d6ece0f5f41150c3956c83
/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file implements the token object delete operation for this tool.
* It loads the PKCS#11 modules, finds the object to delete, deletes it,
* and cleans up. User must be R/W logged into the token.
*/
#include <stdio.h>
#include <string.h>
#include <cryptoutil.h>
#include <security/cryptoki.h>
#include "common.h"
/*
* Delete token objects.
*/
int
{
int opt;
extern int optind;
extern char *optarg;
char *token_name = NULL;
char full_name[FULL_NAME_LEN];
int obj_type = 0x00;
int i;
cryptodebug("inside pk_delete");
EOF) {
switch (opt) {
case 'p': /* private objects */
break;
case 'P': /* public objects */
break;
case 'l': /* objects with specific label */
if (object_label)
return (PK_ERR_USAGE);
break;
default:
return (PK_ERR_USAGE);
break;
}
}
/* At least one of public, private, or object label is required. */
return (PK_ERR_USAGE);
/*
* delete all objects with that label.
*/
/* No additional args allowed. */
if (argc)
return (PK_ERR_USAGE);
/* Done parsing command line options. */
/* Delete operation only supported on softtoken. */
if (token_name == NULL)
/* Find the slot with token. */
"Unable to find token %s (%s)."), full_name,
return (PK_ERR_PK11);
}
/* Always get the user's PIN for delete operations. */
"Unable to get token passphrase (%s)."),
return (PK_ERR_PK11);
}
/* Log the user R/W into the token. */
CKR_OK) {
return (PK_ERR_PK11);
}
CKR_OK) {
return (PK_ERR_PK11);
}
if (num_objs == 0) {
return (0);
}
if (num_objs != 1) {
"Warning: %d matching objects found, deleting all.\n"),
num_objs);
return (0);
}
}
/* Destroy the objects if found. */
for (i = 0; i < num_objs; i++) {
/*
* To give nice feedback to the user, get the object's
* label before deleting it.
*/
cryptodebug("calling C_GetAttributeValue for label");
label.ulValueLen = 0;
label.ulValueLen != 0 &&
1) != CKR_OK) {
label.ulValueLen = 0;
}
} else {
label.ulValueLen = 0;
}
}
cryptodebug("calling C_DestroyObject");
"Unable to delete object #%d \"%.*s\" "
else
"Unable to delete object #%d (%s)."),
} else {
"\"%.*s\" successfully deleted.\n"),
else
"Object #%d successfully deleted.\n"), i+1);
}
}
/* Clean up. */
return (0);
}