/*
* 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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <alloca.h>
#include <unistd.h>
#include <strings.h>
#include <stdlib.h>
#include <libintl.h>
#include <locale.h>
#include <limits.h>
#include <libgen.h>
#include <errno.h>
#include <ctype.h>
#include <wanbootutil.h>
#include <sys/sysmacros.h>
#include <sys/wanboot_impl.h>
/* Return codes */
#define KEYMGMT_SUCCESS 0
/* Suboption. */
#define TYPE 0
/*
* This routine is used to parse the suboptions of '-o' option.
*
* The option should be of the form: type=<3des|aes|sha1|rsa>
*
* This routine will pass the value of the suboption back in the
* supplied arguments, 'ka'.
*
* Returns:
* KEYMGMT_SUCCESS or KEYMGMT_ERROR.
*/
static int
{
char *value;
while (*arg != '\0') {
case TYPE:
/*
* Key type.
*/
if (ret != WBKU_SUCCESS) {
return (KEYMGMT_ERROR);
}
break;
default:
return (KEYMGMT_ERROR);
}
}
/*
* Success.
*/
return (KEYMGMT_SUCCESS);
}
/*
* This routine extracts a key of type 'ka' from the keystore named
* 'keystore_name' and writes it the the file identified by 'name'.
*
* Returns:
* KEYMGMT_SUCCESS or KEYMGMT_ERROR.
*/
static int
{
size_t i;
/*
* Open the keystore for reading.
*/
return (KEYMGMT_ERROR);
}
/*
* Find the client key.
*/
if (ret != WBKU_SUCCESS) {
if (ret == WBKU_NOKEY) {
wbku_printerr("The client %s key does not exist\n",
} else {
}
(void) fclose(keystore_fp);
return (KEYMGMT_ERROR);
}
(void) fclose(keystore_fp);
/*
* Open the output file.
*/
(void) fclose(keystore_fp);
return (KEYMGMT_ERROR);
}
/*
* Dump the key to the output file.
*/
return (KEYMGMT_ERROR);
}
/*
* Success.
*/
return (KEYMGMT_SUCCESS);
}
/*
* There is a key which needs to be removed from the keystore. Given basic
* information about the key to be deleted, go through the keystore and
* remove it. The steps are:
* 1) create a temp file in the same directory as the keystore.
* 2) copy the existing keystore to the temp file, omitting the key being
* removed.
* 3) shuffle files. Close the keystore and move it aside. Close the
* temp file and move in to the keystore.
*
* Returns:
* B_TRUE on success
* B_FALSE on error
*/
static boolean_t
const wbku_key_attr_t *ka)
{
char *tmp_path;
int tmp_fd;
int len;
/*
* Allocate storage for the temporary path from the stack.
*/
/*
* Make the temp working file where a new store will be created.
*/
return (B_FALSE);
}
/*
* Need to reference this file as a stream.
*/
return (B_FALSE);
}
/*
* Copy the existing keystore to the temp one, omitting the
* key being deleted.
*/
if (ret != WBKU_SUCCESS) {
return (B_FALSE);
}
/*
* Shuffle files.
*/
wbku_printerr("Error moving new keystore file from %s to %s",
return (B_FALSE);
}
return (B_TRUE);
}
/*
* This routine reads a key of type 'ka' from the file identified 'name' and
* inserts it into the keystore named 'keystore_name'.
*
* Returns:
* KEYMGMT_SUCCESS or KEYMGMT_ERROR.
*/
static int
{
int fd;
int inlen;
/*
* If the file already exists, then open the file for update.
* Otherwise, create it and open it for writing.
*/
if (fd < 0) {
}
} else {
}
}
if (keystore_fp == NULL) {
return (KEYMGMT_ERROR);
}
/*
* Open the input file.
*/
(void) fclose(keystore_fp);
return (KEYMGMT_ERROR);
}
/*
* Read the key from the file.
*/
(void) fclose(keystore_fp);
return (KEYMGMT_ERROR);
}
wbku_printerr("Key length is not valid\n");
(void) fclose(keystore_fp);
return (KEYMGMT_ERROR);
}
/*
* If the keystore exists, search for a key of the type
* being inserted. If found, note its file position.
*/
ret = WBKU_NOKEY;
if (!newfile) {
(void) fclose(keystore_fp);
return (KEYMGMT_ERROR);
}
/*
* Unfortuantely, RSA keys have variable lengths. If
* the one being inserted is a different length than
* than the one that already exists in the file, then
* the key must be removed from the keystore and then
* readded.
*/
keystore_fp, ka)) {
wbku_printerr("Insertion required compression"
" of keystore, but compression failed\n"
"Key was not inserted\n");
(void) fclose(keystore_fp);
return (KEYMGMT_ERROR);
}
/*
* The original keystore is history. Close the
* stream and open a stream to the new keystore.
*/
(void) fclose(keystore_fp);
if (keystore_fp == NULL) {
return (KEYMGMT_ERROR);
}
/* Force new key to end of file */
ret = WBKU_NOKEY;
}
}
/*
* If wbku_find_key() did not find the key position for us,
* then we should set position to the end of the file.
*/
wbku_printerr("Internal error");
(void) fclose(keystore_fp);
return (KEYMGMT_ERROR);
}
/*
* Write the key to the keystore.
*/
(void) fclose(keystore_fp);
if (ret != WBKU_SUCCESS) {
return (KEYMGMT_ERROR);
}
/*
* Success.
*/
return (KEYMGMT_SUCCESS);
}
/*
* Prints usage().
*/
static void
{
" -i -k <key_file> -s <keystore> -o type=<%s|%s|%s|%s>\n"
" %s -x -f <out_file> -s <keystore> -o"
" type=<%s|%s|%s|%s>\n"),
}
/*
* This program is used to insert and extract WAN boot encryption and
* hash keys into and from keystores. The paths to the keystores are
* provided by the user as are the input and output files.
*
* Note:
* This program assumes all keys being inserted or extracted
* are client keys. There is no way for a user to insert or
* extract a master key using this program.
*
* We do not do any file locking scheme. This means that if two
* keymgmt commands are run concurrently, results can be disastrous.
*
* Returns:
* KEYMGMT_SUCCESS or KEYMGMT_ERROR.
*/
int
{
int c;
int ret;
/*
* Do the necessary magic for localization support.
*/
#if !defined(TEXT_DOMAIN)
#endif
(void) textdomain(TEXT_DOMAIN);
/*
* Initialize program name for use by wbku_printerr().
*/
wbku_errinit(argv[0]);
/*
* At the very least, we'll need one arg.
*/
if (argc < 2) {
return (KEYMGMT_ERROR);
}
/*
* Parse the options.
*/
switch (c) {
case 'i':
break;
case 'x':
is_extract = B_TRUE;
break;
case 'o':
/*
* Suboptions.
*/
return (KEYMGMT_ERROR);
}
break;
case 's':
/*
* Keystore path.
*/
break;
case 'f':
/*
* Input file.
*/
return (KEYMGMT_ERROR);
}
break;
case 'k':
/*
* Input file.
*/
return (KEYMGMT_ERROR);
}
break;
default:
return (KEYMGMT_ERROR);
}
}
/*
* Must be inserting or extracting a key and we must have a
* key type, keystore filename and an input or output filename.
*/
return (KEYMGMT_ERROR);
}
/*
* Insert or extract the key.
*/
if (is_insert) {
} else {
}
return (ret);
}