dst_parse.c revision aaaf8d4f4873d21e55c3ffb4f656203d08339865
/*
* Portions Copyright (C) 2004-2011 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.29 2011/08/18 23:46:35 tbox 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:"
static const char *timetags[TIMING_NTAGS] = {
"Created:",
"Publish:",
"Activate:",
"Revoke:",
"Inactive:",
"Delete:",
"DSPublish:"
};
static const char *numerictags[NUMERIC_NTAGS] = {
"Predecessor:",
"Successor:",
"MaxTTL:",
"RollPeriod:"
};
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_RSA_ENGINE, "Engine:" },
{TAG_RSA_LABEL, "Label:" },
{TAG_RSA_PIN, "PIN:" },
{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_GOST_PRIVASN1, "GostAsn1:"},
{TAG_ECDSA_PRIVATEKEY, "PrivateKey:"},
{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;
}
return (-1);
}
static const char *
int i;
for (i = 0; ; i++) {
return (NULL);
}
}
static int
int i;
for (i = 0; i < ntags; i++) {
if (strcasecmp(s, tags[i]) == 0)
return (i);
}
return (-1);
}
static int
find_timedata(const char *s) {
}
static int
find_numericdata(const char *s) {
}
static int
int i, j;
unsigned int mask;
for (i = 0; i < RSA_NTAGS; i++)
for (i = 0; i < RSA_NTAGS; i++)
break;
if (i == RSA_NTAGS)
return (-1);
}
mask = ~0;
else
return (ok ? 0 : -1 );
}
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
return (-1);
return (-1);
return (0);
}
static int
return (-1);
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_ECCGOST:
return (check_gost(priv));
case DST_ALG_ECDSA256:
return (check_ecdsa(priv));
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;
}
}
{
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 > DST_MAJOR_VERSION) {
goto fail;
}
/*
* Store the private key format version number
*/
/*
* 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;
}
/* Numeric metadata */
if (tag >= 0) {
goto fail;
}
goto next;
}
/* Timing metadata */
if (tag >= 0) {
goto fail;
}
if (ret != ISC_R_SUCCESS)
goto fail;
goto next;
}
/* Key data */
goto next;
else if (tag < 0) {
goto fail;
}
goto fail;
if (ret != ISC_R_SUCCESS)
goto fail;
isc_buffer_usedregion(&b, &r);
next:
}
done:
goto fail;
return (ISC_R_SUCCESS);
fail:
return (ret);
}
const char *directory)
{
int ret, i;
char filename[ISC_DIR_NAMEMAX];
isc_buffer_t b;
isc_region_t r;
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_NSEC3RSASHA1:
break;
case DST_ALG_NSEC3DSA:
break;
case DST_ALG_RSASHA256:
break;
case DST_ALG_RSASHA512:
break;
case DST_ALG_ECCGOST:
break;
case DST_ALG_ECDSA256:
break;
case DST_ALG_ECDSA384:
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;
}
const char *s;
if (result != ISC_R_SUCCESS) {
return (DST_R_INVALIDPRIVATEKEY);
}
isc_buffer_usedregion(&b, &r);
}
/* Add the metadata tags */
for (i = 0; i < NUMERIC_NTAGS; i++) {
if (result != ISC_R_SUCCESS)
continue;
}
for (i = 0; i < TIMING_NTAGS; i++) {
if (result != ISC_R_SUCCESS)
continue;
if (result != ISC_R_SUCCESS) {
return (DST_R_INVALIDPRIVATEKEY);
}
isc_buffer_usedregion(&b, &r);
r.base);
}
}
return (result);
}
/*! \file */