/*
* 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 <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <libintl.h>
#include <locale.h>
#include <strings.h>
#include <errno.h>
#include <wanbootutil.h>
#include <sys/sysmacros.h>
#include <sys/wanboot_impl.h>
/* Return codes */
#define ENCR_SUCCESS 0
/* Private buffer length */
/* Encryption algorithm 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>
*
* This routine will pass the value of the suboption back in the
* supplied arguments, 'ka'.
*
* Returns:
* ENCR_SUCCESS or ENCR_ERROR.
*/
static int
{
char *value;
while (*arg != '\0') {
case TYPE:
/*
* Key type.
*/
if (ret != WBKU_SUCCESS) {
return (ENCR_ERROR);
}
break;
default:
return (ENCR_ERROR);
}
}
return (ENCR_SUCCESS);
}
/*
* This routine is used to find the key of type defined by 'ka' and
* return it in 'key'. The key file should have been opened by the
* caller and the handle passed in 'key_fp'.
*
* Returns:
* ENCR_SUCCESS, ENCR_ERROR or ENCR_NOKEY.
*/
static int
{
/*
* Find the client key, if it exists.
*/
if (ret != WBKU_SUCCESS) {
if (ret == WBKU_NOKEY)
return (ENCR_NOKEY);
else
return (ENCR_ERROR);
}
return (ENCR_SUCCESS);
}
/*
* This routine is the common encryption routine used to encrypt data
* using the CBC handle initialized by the calling routine. The data
* to be encrypted is read from stdin and the encrypted data is written to
* stdout.
*
* Returns:
* ENCR_SUCCESS or ENCR_ERROR.
*/
static int
{
int read_size;
ssize_t i, j, k;
/*
* Use a random number as the IV
*/
wbku_printerr("Cannot generate initialization vector");
return (ENCR_ERROR);
}
/*
* Output the IV to stdout.
*/
wbku_printerr("Write error encountered\n");
return (ENCR_ERROR);
}
/*
* Try to read in multiple of block_size as CBC requires
* that data be encrypted in block_size chunks.
*/
/*
* If data received is not a multiple of the block size,
* try to receive more. If reach EOF, pad the rest with
* 0.
*/
/*
* Determine how more data need to be received to
* fill out the buffer so that it contains a
* multiple of block_size chunks.
*/
k = j;
/*
* Try to fill the gap.
*
*/
j != 0) {
bufp += j;
k -= j;
j = k;
}
/*
* This is the total length of the buffer.
*/
if (j == 0) {
/* EOF, do padding. */
} else if (j > 0) {
/* The gap has been filled in */
} else {
/* Oops. */
wbku_printerr("Input error");
return (ENCR_ERROR);
}
} else {
/* A multiple of the block size was received */
}
wbku_printerr("Write error encountered\n");
return (ENCR_ERROR);
}
}
return (ENCR_SUCCESS);
}
/*
* This routine initializes a CBC handle for 3DES and calls the
* common encryption routine to encrypt data.
*
* Returns:
* ENCR_SUCCESS or ENCR_ERROR.
*/
static int
{
void *eh;
int ret;
/*
* Initialize a 3DES handle.
*/
return (ENCR_ERROR);
}
/*
* Initialize the CBC handle.
*/
/*
* Encrypt the data.
*/
/*
* Free the 3DES resources.
*/
return (ret);
}
/*
* This routine initializes a CBC handle for AES and calls the
* common encryption routine to encrypt data.
*
* Returns:
* ENCR_SUCCESS or ENCR_ERROR.
*/
static int
{
void *eh;
int ret;
/*
* Initialize an AES handle.
*/
return (ENCR_ERROR);
}
/*
* Initialize the CBC handle.
*/
/*
* Encrypt the data.
*/
/*
* Free the AES resources.
*/
return (ret);
}
/*
* Prints usage().
*/
static void
{
gettext("Usage: %s -o type=<%s|%s> -k key_file\n"),
}
/*
* This program is used to encrypt data read from stdin and print it to
* stdout. The path to the key file and the algorithm to use are
* provided by the user.
*
* Returns:
* ENCR_SUCCESS, ENCR_ERROR or ENCR_NOKEY.
*/
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]);
/*
* Should be five arguments.
*/
if (argc < 5) {
return (ENCR_ERROR);
}
/*
* Parse the options.
*/
switch (c) {
case 'o':
/*
* Suboptions.
*/
if (ret != ENCR_SUCCESS) {
return (ret);
}
break;
case 'k':
/*
* Path to key file.
*/
break;
default:
return (ENCR_ERROR);
}
}
/*
* Gotta have a key file.
*/
if (keyfile_name == NULL) {
wbku_printerr("Must specify the key_file\n");
return (ENCR_ERROR);
}
/*
* Gotta have a key type.
*/
wbku_printerr("Unsupported encryption algorithm\n");
return (ENCR_ERROR);
}
/*
* Open the key file for reading.
*/
return (ENCR_ERROR);
}
/*
* Get the key from the key file and call the right
* encryption routine.
*/
if (ret == ENCR_SUCCESS) {
case WBKU_KEY_3DES:
break;
case WBKU_KEY_AES_128:
break;
default:
}
}
return (ret);
}