adm_kef_ioctl.c revision 32e0ab73531b6e6e8957e9ecdbbd42603865f2d0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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
*/
/*
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <locale.h>
#include <libgen.h>
#include <zone.h>
#include "cryptoadm.h"
#define DEFAULT_DEV_NUM 5
#define DEFAULT_SOFT_NUM 10
#define NUM_FIPS_SW_PROV \
(sizeof (fips_sw_providers) / sizeof (char *))
static char *fips_sw_providers[] = {
"des",
"aes",
"ecc",
"sha1",
"sha2",
"rsa",
"swrand"
};
static crypto_get_soft_info_t *setup_get_soft_info(char *, int);
static void
fips_sw_printf(const char *format, ...)
{
char message[1024];
int i;
message);
for (i = 0; i < NUM_FIPS_SW_PROV; i++) {
fips_sw_providers[i], message);
}
}
/*
* Prepare the argument for the LOAD_SOFT_CONFIG ioctl call for the
* provider pointed by pent. Return NULL if out of memory.
*/
{
size_t extra_mech_size = 0;
int i;
return (NULL);
}
if (sup_count > 1) {
extra_mech_size = sizeof (crypto_mech_name_t) *
(sup_count - 1);
}
if (pload_soft_conf == NULL) {
cryptodebug("out of memory.");
return (NULL);
}
i = 0;
while (i < sup_count) {
}
return (pload_soft_conf);
}
/*
* Prepare the argument for the LOAD_SOFT_DISABLED ioctl call for the
* provider pointed by pent. Return NULL if out of memory.
*/
{
size_t extra_mech_size = 0;
int i;
return (NULL);
}
if (dis_count > 1) {
extra_mech_size = sizeof (crypto_mech_name_t) *
(dis_count - 1);
}
if (pload_soft_dis == NULL) {
cryptodebug("out of memory.");
return (NULL);
}
i = 0;
while (i < dis_count) {
}
return (pload_soft_dis);
}
/*
* Prepare the argument for the LOAD_DEV_DISABLED ioctl call for the
* provider pointed by pent. Return NULL if out of memory.
*/
{
size_t extra_mech_size = 0;
int i;
char pname[MAXNAMELEN];
int inst_num;
return (NULL);
}
/* get the device name and the instance number */
return (NULL);
}
/* allocate space for pload_dev_des */
if (dis_count > 1) {
extra_mech_size = sizeof (crypto_mech_name_t) *
(dis_count - 1);
}
if (pload_dev_dis == NULL) {
cryptodebug("out of memory.");
return (NULL);
}
/* set the values for pload_dev_dis */
i = 0;
while (i < dis_count) {
}
return (pload_dev_dis);
}
/*
* Prepare the calling argument of the UNLOAD_SOFT_MODULE ioctl call for the
* provider pointed by pent. Return NULL if out of memory.
*/
{
return (NULL);
}
if (punload_soft == NULL) {
cryptodebug("out of memory.");
return (NULL);
}
return (punload_soft);
}
/*
* Prepare the calling argument for the GET_SOFT_INFO call for the provider
* with the number of mechanisms specified in the second argument.
*
* Called by get_soft_info().
*/
static crypto_get_soft_info_t *
{
size_t extra_mech_size = 0;
return (NULL);
}
if (count > 1) {
}
if (psoft_info == NULL) {
cryptodebug("out of memory.");
return (NULL);
}
return (psoft_info);
}
/*
* Get the device list from kernel.
*/
int
{
int fd = -1;
int count = DEFAULT_DEV_NUM;
cryptodebug("out of memory.");
return (FAILURE);
}
return (FAILURE);
}
cryptodebug("CRYPTO_GET_DEV_LIST ioctl failed: %s",
return (FAILURE);
}
/* BUFFER is too small, get the number of devices and retry it. */
cryptodebug("out of memory.");
return (FAILURE);
}
cryptodebug("CRYPTO_GET_DEV_LIST ioctl failed: %s",
return (FAILURE);
}
}
cryptodebug("CRYPTO_GET_DEV_LIST ioctl failed, "
return (FAILURE);
}
return (SUCCESS);
}
/*
* Get all the mechanisms supported by the hardware provider.
* The result will be stored in the second argument.
*/
int
{
int fd = -1;
int i;
int rc;
cryptodebug("get_dev_info(): devname is NULL or bogus count");
return (FAILURE);
}
/* Set up the argument for the CRYPTO_GET_DEV_INFO ioctl call */
cryptodebug("out of memory.");
return (FAILURE);
}
/* Open the ioctl device */
return (FAILURE);
}
cryptodebug("CRYPTO_GET_DEV_INFO ioctl failed: %s",
return (FAILURE);
}
cryptodebug("CRYPTO_GET_DEV_INFO ioctl failed, "
return (FAILURE);
}
break;
} else {
} else {
}
}
}
*ppmechlist = phead;
} else {
}
return (rc);
}
/*
* Get the supported mechanism list of the software provider from kernel.
*
* Parameters phardlist and psoftlist are supplied by get_kcfconf_info().
* If NULL, this function calls get_kcfconf_info() internally.
*/
int
{
int count;
int fd = -1;
int rc;
int i;
return (FAILURE);
}
if (getzoneid() == GLOBAL_ZONEID) {
/* use kcf.conf for kernel software providers in global zone */
NULL) {
/* No kcf.conf entry for this provider */
== FAILURE) {
return (FAILURE);
return (FAILURE);
}
/*
* Set mech count to 1. It will be reset to the
* correct value later if the setup buffer is too small.
*/
count = 1;
} else {
}
} else {
/*
* kcf.conf not there in non-global zone: set mech count to 1.
* It will be reset to the correct value later if the setup
* buffer is too small.
*/
count = 1;
}
return (FAILURE);
}
return (FAILURE);
}
/* make GET_SOFT_INFO ioctl call */
cryptodebug("CRYPTO_GET_SOFT_INFO ioctl failed: %s",
return (FAILURE);
}
/* BUFFER is too small, get the number of mechanisms and retry it. */
== NULL) {
return (FAILURE);
} else {
if (rc == -1) {
cryptodebug("CRYPTO_GET_SOFT_INFO ioctl "
return (FAILURE);
}
}
}
cryptodebug("CRYPTO_GET_SOFT_INFO ioctl failed, "
return (FAILURE);
}
/* Build the mechanism linked list and return it */
for (i = 0; i < psoft_info->si_count; i++) {
break;
} else {
} else {
}
}
}
} else {
*ppmechlist = phead;
}
return (rc);
}
/*
* Get the kernel software provider list from kernel.
*/
int
{
int count = DEFAULT_SOFT_NUM;
int len;
int fd = -1;
return (FAILURE);
}
cryptodebug("out of memory.");
return (FAILURE);
}
cryptodebug("CRYPTO_GET_SOFT_LIST ioctl failed: %s",
return (FAILURE);
}
/*
* if BUFFER is too small, get the number of software providers and
* the minimum length needed for names and length and retry it.
*/
cryptodebug("out of memory.");
return (FAILURE);
}
cryptodebug("CRYPTO_GET_SOFT_LIST ioctl failed:"
return (FAILURE);
}
}
cryptodebug("CRYPTO_GET_SOFT_LIST ioctl failed, "
return (FAILURE);
}
*ppsoftlist = psoftlist;
return (SUCCESS);
}
/*
* Perform the FIPS related actions
*/
int
{
int fd;
int pkcs11_fips_mode = 0;
/* Get FIPS-140 status from pkcs11.conf */
if (action == FIPS140_STATUS) {
else
return (SUCCESS);
}
if (caller == NOT_REFRESH) {
/* Is it a duplicate operation? */
if ((action == FIPS140_ENABLE) &&
"been enabled."));
return (FAILURE);
}
if ((action == FIPS140_DISABLE) &&
"been disabled."));
return (FAILURE);
}
/* Update pkcs11.conf */
return (rc);
}
/* No need to inform kernel */
if (action == FIPS140_ENABLE) {
"successfully."));
} else {
"successfully."));
}
return (SUCCESS);
}
/* This is refresh, need to inform kernel */
return (FAILURE);
}
switch (action) {
case FIPS140_ENABLE:
/* make CRYPTO_FIPS_SET ioctl call */
cryptodebug("CRYPTO_FIPS140_ENABLE ioctl failed: %s",
goto out;
}
cryptodebug("CRYPTO_FIPS140_ENABLE ioctl failed, "
"return_value = %d",
}
break;
case FIPS140_DISABLE:
/* make CRYPTO_FIPS140_SET ioctl call */
cryptodebug("CRYPTO_FIPS140_DISABLE ioctl failed: %s",
goto out;
}
cryptodebug("CRYPTO_FIPS140_DISABLE ioctl failed, "
"return_value = %d",
}
break;
default:
break;
};
out:
return (rc);
}