/*
* 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 <strings.h>
#include <stdarg.h>
#include <errno.h>
#include <libintl.h>
#include <sys/wanboot_impl.h>
#include "key_xdr.h"
#include "key_util.h"
/*
* Size of 'empty' pkcs12 key file (with no key in it) plus 1
* This is the minimum length for our RSA keys, because we
* only use RSA keys that are stored in PKCS12 format.
*/
/*
* Program name to be used by wbku_printerr()
*/
/*
* Note: must be kept in sync with codes in <key_util.h>
*/
/* 0 WBKU_SUCCESS */ "Success",
/* 1 WBKU_INTERNAL_ERR */ "Internal error",
/* 2 WBKU_WRITE_ERR */ "Keystore write error",
/* 3 WBKU_NOKEY */ "Key does not exist in keystore",
/* 4 WBKU_BAD_KEYTYPE */ "Invalid keytype specified"
};
/*
* Initialize library for calls to wbku_printerr().
*/
void
{
if (wbku_pname == NULL)
wbku_pname = arg0;
else
wbku_pname++;
}
/*
* Print an error message to standard error and optionally
* append a system error.
*/
/*PRINTFLIKE1*/
void
{
if (wbku_pname != NULL)
/*
* Note that gettext() is used in order to obtain the
* message from the consumer's domain.
*/
}
/*
* Return the appropriate message for a given WBKU return code.
*/
const char *
{
}
/*
* This routine is a simple helper routine that initializes a
* wbku_key_attr_t object.
*/
static void
{
}
/*
* This routine is used to build a key attribute structure of the type
* defined by 'str' and 'flag'. This structure, 'attr', is the common
* structure used by the utilities that defines the attributes of a
* specific key type.
*
* Returns:
* WBKU_SUCCESS or WBKU_BAD_KEYTYPE.
*/
{
return (WBKU_BAD_KEYTYPE);
if (flag & WBKU_ENCR_KEY) {
return (WBKU_SUCCESS);
}
return (WBKU_SUCCESS);
}
return (WBKU_SUCCESS);
}
}
if (flag & WBKU_HASH_KEY) {
return (WBKU_SUCCESS);
}
}
return (WBKU_BAD_KEYTYPE);
}
/*
* This routine is used to search a key file (whose handle, fp, has been
* initialized by the caller) for the key of type 'ka'. The search is further
* constrained by the 'master' argument which is used to signify that the
* key being searched for is the master key.
*
* This routine may be used for a number of purposes:
* - Check for the existence of key of type foo.
* - Get the value for the key of type foo.
* - Return the file position of the key of type foo.
*
* To faciliate the uses above, both 'ppos' and 'ekey' will only be
* returned if they are not NULL pointers.
*
* Returns:
* WBKU_SUCCESS, WBKU_INTERNAL_ERR or WBKU_NOKEY.
*/
{
int keyno;
int ret;
/*
* Always, start at the beginning.
*/
/*
* Initialize the XDR stream.
*/
return (WBKU_INTERNAL_ERR);
}
/*
* The XDR routines may examine the content of the keyobj
* structure to determine whether or not to provide memory
* resources. Since XDR does not provide an init routine
* for XDR generated objects, it seems that the safest thing
* to do is to bzero() the object as a means of initialization.
*/
/*
* Read a key and check to see if matches the criteria.
*/
/*
* Returning the file position is conditional.
*/
break;
}
}
/*
* Read the key. Unfortuantely, XDR does not provide
* the ability to tell an EOF from some other IO error.
* Therefore, a faliure to read is assumed to be EOF.
*/
ret = WBKU_NOKEY;
break;
}
/*
* Check this key against the criteria.
*/
/*
* Conditionally return the key value and file
* position.
*/
}
}
ret = WBKU_SUCCESS;
break;
}
}
xdr_destroy(&xdrs);
return (ret);
}
/*
* This routine writes a key object to the key file at the location
* specified by the caller.
*
* Returns:
* WBKU_SUCCESS, WBKU_INTERNAL_ERR or WBKU_WRITE_ERR.
*/
{
/*
* Set the file position as specified by the caller.
*/
return (WBKU_INTERNAL_ERR);
}
/*
* Initialize the XDR stream.
*/
return (WBKU_INTERNAL_ERR);
}
/*
* Build the key object.
*/
/*
* Write it.
*/
xdr_destroy(&xdrs);
return (WBKU_WRITE_ERR);
}
/*
* Free the stream and return success.
*/
xdr_destroy(&xdrs);
return (WBKU_SUCCESS);
}
/*
* This routine reads the contents of one keystore file and copies it to
* another, omitting the key of the type defined by 'ka'.
*
* Returns:
* WBKU_SUCCESS, WBKU_INTERNAL_ERR or WBKU_WRITE_ERR.
*/
{
int keyno;
int ret;
/*
* Always, start at the beginning.
*/
/*
* Initialize the XDR streams.
*/
return (WBKU_INTERNAL_ERR);
}
return (WBKU_INTERNAL_ERR);
}
/*
* The XDR routines may examine the content of the keyobj
* structure to determine whether or not to provide memory
* resources. Since XDR does not provide an init routine
* for XDR generated objects, it seems that the safest thing
* to do is to bzero() the object as a means of initialization.
*/
/*
* Read a key and check to see if matches the criteria.
*/
ret = WBKU_SUCCESS;
/*
* Read the key. Unfortuantely, XDR does not provide
* the ability to tell an EOF from some other IO error.
* Therefore, a faliure to read is assumed to be EOF.
*/
break;
}
/*
* If this isn't the key to skip, then write it.
*/
/*
* Write this to the copy.
*/
break;
}
}
}
return (ret);
}