dst_parse.c revision 5497de6931b5ac26f65c2343b0318614f73933ba
/*
* Portions Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (C) 1999-2002 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Portions Copyright (C) 1995-2000 by Network Associates, Inc.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*%
* Principal Author: Brian Wellington
* $Id: dst_parse.c,v 1.11 2008/01/22 01:34:15 marka Exp $
*/
#include <config.h>
#include <isc/fsaccess.h>
#include "dst_internal.h"
#include "dst_parse.h"
#define PRIVATE_KEY_STR "Private-key-format:"
#define ALGORITHM_STR "Algorithm:"
struct parse_map {
const int value;
const char *tag;
};
{TAG_RSA_MODULUS, "Modulus:"},
{TAG_RSA_PUBLICEXPONENT, "PublicExponent:"},
{TAG_RSA_PRIVATEEXPONENT, "PrivateExponent:"},
{TAG_RSA_PRIME1, "Prime1:"},
{TAG_RSA_PRIME2, "Prime2:"},
{TAG_RSA_EXPONENT1, "Exponent1:"},
{TAG_RSA_EXPONENT2, "Exponent2:"},
{TAG_RSA_COEFFICIENT, "Coefficient:"},
{TAG_DH_PRIME, "Prime(p):"},
{TAG_DH_GENERATOR, "Generator(g):"},
{TAG_DH_PRIVATE, "Private_value(x):"},
{TAG_DH_PUBLIC, "Public_value(y):"},
{TAG_DSA_PRIME, "Prime(p):"},
{TAG_DSA_SUBPRIME, "Subprime(q):"},
{TAG_DSA_BASE, "Base(g):"},
{TAG_DSA_PRIVATE, "Private_value(x):"},
{TAG_DSA_PUBLIC, "Public_value(y):"},
{TAG_HMACMD5_KEY, "Key:"},
{TAG_HMACMD5_BITS, "Bits:"},
{TAG_HMACSHA1_KEY, "Key:"},
{TAG_HMACSHA1_BITS, "Bits:"},
{TAG_HMACSHA224_KEY, "Key:"},
{TAG_HMACSHA224_BITS, "Bits:"},
{TAG_HMACSHA256_KEY, "Key:"},
{TAG_HMACSHA256_BITS, "Bits:"},
{TAG_HMACSHA384_KEY, "Key:"},
{TAG_HMACSHA384_BITS, "Bits:"},
{TAG_HMACSHA512_KEY, "Key:"},
{TAG_HMACSHA512_BITS, "Bits:"},
{0, NULL}
};
static int
find_value(const char *s, const unsigned int alg) {
int i;
for (i = 0; ; i++) {
return (-1);
}
}
static const char *
int i;
for (i = 0; ; i++) {
return (NULL);
}
}
static int
int i, j;
return (-1);
for (i = 0; i < RSA_NTAGS; i++) {
break;
return (-1);
}
return (0);
}
static int
int i, j;
return (-1);
for (i = 0; i < DH_NTAGS; i++) {
break;
return (-1);
}
return (0);
}
static int
int i, j;
return (-1);
for (i = 0; i < DSA_NTAGS; i++) {
break;
return (-1);
}
return (0);
}
static int
int i, j;
/*
* If this is a good old format and we are accepting
* the old format return success.
*/
return (0);
return (-1);
}
/*
* We must be new format at this point.
*/
for (i = 0; i < HMACMD5_NTAGS; i++) {
break;
return (-1);
}
return (0);
}
static int
unsigned int alg)
{
unsigned int i, j;
return (-1);
for (i = 0; i < ntags; i++) {
break;
return (-1);
}
return (0);
}
static int
{
/* XXXVIX this switch statement is too sparse to gen a jump table. */
switch (alg) {
case DST_ALG_RSAMD5:
case DST_ALG_RSASHA1:
case DST_ALG_DH:
case DST_ALG_DSA:
case DST_ALG_HMACMD5:
case DST_ALG_HMACSHA1:
case DST_ALG_HMACSHA224:
case DST_ALG_HMACSHA256:
case DST_ALG_HMACSHA384:
case DST_ALG_HMACSHA512:
default:
return (DST_R_UNSUPPORTEDALG);
}
}
void
int i;
return;
continue;
}
}
int
{
isc_buffer_t b;
unsigned int opt = ISC_LEXOPT_EOL;
do { \
if (ret != ISC_R_SUCCESS) \
goto fail; \
} while (0)
do { \
break; \
else if (ret != ISC_R_SUCCESS) \
goto fail; \
/*
* Read the description line.
*/
{
goto fail;
}
{
goto fail;
}
{
goto fail;
}
if (major > MAJOR_VERSION ||
{
goto fail;
}
/*
* Read the algorithm line.
*/
{
goto fail;
}
{
goto fail;
}
/*
* Read the key data.
*/
for (n = 0; n < MAXFIELDS; n++) {
int tag;
isc_region_t r;
do {
goto done;
if (ret != ISC_R_SUCCESS)
goto fail;
goto fail;
}
goto fail;
}
goto fail;
if (ret != ISC_R_SUCCESS)
goto fail;
isc_buffer_usedregion(&b, &r);
}
done:
goto fail;
return (ISC_R_SUCCESS);
fail:
return (ret);
}
int
const char *directory)
{
int ret, i;
char filename[ISC_DIR_NAMEMAX];
isc_buffer_t b;
return (DST_R_INVALIDPRIVATEKEY);
if (ret != ISC_R_SUCCESS)
return (ret);
return (DST_R_WRITEERROR);
access = 0;
&access);
/* XXXDCL return value should be checked for full filesystem */
/* XXXVIX this switch statement is too sparse to gen a jump table. */
switch (dst_key_alg(key)) {
case DST_ALG_RSAMD5:
break;
case DST_ALG_DH:
break;
case DST_ALG_DSA:
break;
case DST_ALG_RSASHA1:
break;
case DST_ALG_HMACMD5:
break;
case DST_ALG_HMACSHA1:
break;
case DST_ALG_HMACSHA224:
break;
case DST_ALG_HMACSHA256:
break;
case DST_ALG_HMACSHA384:
break;
case DST_ALG_HMACSHA512:
break;
default:
break;
}
isc_buffer_t b;
isc_region_t r;
const char *s;
if (iret != ISC_R_SUCCESS) {
return (DST_R_INVALIDPRIVATEKEY);
}
isc_buffer_usedregion(&b, &r);
}
return (ISC_R_SUCCESS);
}
/*! \file */