/*
* 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"
#include <sys/wanboot_impl.h>
#include <libinetutil.h>
#include <wanbootutil.h>
#include <libintl.h>
#include <locale.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <assert.h>
#include <sys/openpromio.h>
#define TYPE 0
static char *progopts[] = {
"type",
};
/*
* The key's handle is the name by which a user knows the key (i.e. the
* name specified on the command line. The keyname is the name this
* utility uses to store the keys and the name OBP and wanboot use to
* retrieve them.
*/
static struct keylist {
const char *handle;
const char *keyname;
} keylist[] = {
(DES3_KEY_SIZE * 2),
(AES_128_KEY_SIZE * 2),
(WANBOOT_HMAC_KEY_SIZE * 2)
};
static const struct keylist *knownkeytype(char *);
static void installkey(const struct keylist *);
static void usage(const char *) __NORETURN;
int
{
int i;
const struct keylist *k;
char *options;
char *value;
/*
* 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(av[0]);
switch (i) {
case 'd':
break;
case 'o':
while (*options != '\0') {
&value)) {
case TYPE:
typestring = value;
break;
default:
/* unknown token */
/* NOTREACHED */
}
}
break;
case '?':
/* NOTREACHED */
}
deletekey(k);
else
installkey(k);
return (0);
} else {
/* NOTREACHED */
}
}
static const struct keylist *
{
int i;
return (&keylist[i]);
}
return (NULL);
}
static void
{
int fd;
wbku_printerr("openpromio malloc (%d) failed\n",
sizeof (struct openpromio) +
sizeof (struct wankeyio));
exit(1);
}
if (fd == -1) {
wbku_printerr("open: /dev/openprom");
exit(1);
}
wbku_printerr("setkey: ioctl");
exit(1);
}
}
static void
{
char *keyptr;
int fd;
int err;
"internal error: hexascii_to_octet returned %d\n",
err);
exit(1);
wbku_printerr("internal error: key size mismatch\n");
exit(1);
}
sizeof (struct wankeyio));
wbku_printerr("openpromio malloc (%d) failed\n",
sizeof (struct openpromio) +
sizeof (struct wankeyio));
exit(1);
}
if (fd == -1) {
wbku_printerr("open: /dev/openprom");
exit(1);
}
wbku_printerr("setkey: ioctl");
exit(1);
}
} else {
exit(1);
}
}
static char *
{
char *p;
char *q;
int len;
p = getpassphrase(prompt);
if (p) {
/* skip over initial "0[xX]" */
if ((p[0] == '0') && (p[1] == 'x' || p[1] == 'X'))
p += 2;
"key length mismatch (expected %d, got %d)\n",
exit(1);
}
for (q = p; q < p + len; q++)
if (!isxdigit(*q)) {
"non-hexadecimal characters in key\n");
exit(1);
}
}
return (p);
}
static void
{
int i;
"usage: %s [ -d ] -o type=keytype\nwhere keytype is one of "),
progname);
exit(1);
}