dst_parse.c revision 499b34cea04a46823d003d4c0520c8b03e8513cb
/*
* Portions Copyright (C) 1999-2001 Internet Software Consortium.
* Portions Copyright (C) 1995-2000 by Network Associates, Inc.
*
* Permission to use, copy, modify, and distribute this software for any
* 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 INTERNET SOFTWARE CONSORTIUM AND
* NETWORK ASSOCIATES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE CONSORTIUM OR NETWORK
* ASSOCIATES 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.27 2001/01/09 21:55:30 bwelling 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:"
#define RSA_STR "RSA"
#define DH_STR "DH"
#define DSA_STR "DSA"
#define HMACMD5_STR "HMAC_MD5"
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:"},
{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
return (-1);
return (-1);
return (0);
}
static int
switch (alg) {
case DST_ALG_RSAMD5:
case DST_ALG_DH:
case DST_ALG_DSA:
case DST_ALG_HMACMD5:
return (check_hmac_md5(priv));
default:
return (DST_R_UNSUPPORTEDALG);
}
}
void
int i;
return;
continue;
}
}
int
{
isc_buffer_t b;
unsigned int opt = ISC_LEXOPT_EOL;
char *newfilename;
return (DST_R_INVALIDPRIVATEKEY);
if (newfilename == NULL)
return (ISC_R_NOMEMORY);
if (ret != ISC_R_SUCCESS)
return (ret);
if (ret != ISC_R_SUCCESS)
goto fail;
{ \
if (ret != ISC_R_SUCCESS) \
goto fail; \
}
do { \
/*
* 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;
unsigned char *data;
isc_region_t r;
break;
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);
}
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 */
switch (dst_key_alg(key)) {
}
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);
}