t_dst.c revision 1bdc3fd29a6f615a2c1361613c36768e478c0cc2
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* 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 DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM 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.
*/
#include <config.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> /* XXX */
#include <isc/assertions.h>
static void t1(void);
static void t2(void);
/*
* adapted from the original dst_test.c program
*/
static void
return;
}
continue;
continue;
}
}
}
return;
}
static void
char *data = "This is some data";
unsigned char sig[512];
if (ret != exp_result) {
t_info("dst_sign(%d) returned (%s) expected (%s)\n",
++*nfails;
return;
}
if (ret != exp_result) {
t_info("dst_verify(%d) returned (%s) expected (%s)\n",
++*nfails;
}
}
static void
int rval;
char *p;
if (p == NULL) {
++*nprobs;
return;
}
if (ret != DST_R_SUCCESS) {
++*nfails;
return;
}
if (p == NULL) {
++*nprobs;
return;
}
if (rval != 0) {
++*nprobs;
return;
}
++*nprobs;
return;
}
if (ret != 0) {
++*nfails;
return;
}
++*nprobs;
return;
}
}
static void
if (ret != DST_R_SUCCESS) {
++*nfails;
return;
}
}
#define DBUFSIZ 25
static void
get_random(int *nfails) {
unsigned int i;
if (ret != DST_R_SUCCESS) {
++*nfails;
return;
}
if (ret != DST_R_SUCCESS) {
++*nfails;
return;
}
/* weak test, but better than nought */
t_info("data not random\n");
++*nfails;
}
if (T_debug) {
for (i = 0; i < sizeof(data1); i++)
for (i = 0; i < sizeof(data2); i++)
}
}
static char *a1 =
"the dst module provides the capability to "
"generate, store and retrieve public and private keys, "
"sign and verify data using the RSA, DSA and MD5 algorithms, "
"and generate random number sequences.";
static void
t1() {
int nfails;
int nprobs;
int result;
nfails = 0;
nprobs = 0;
if (isc_result != ISC_R_SUCCESS) {
return;
}
t_info("testing use of stored keys\n");
t_info("testing use of generated keys\n");
t_info("testing random number sequence generation\n");
get_random(&nfails);
else if (nfails)
}
#define T_SIGMAX 512
#ifdef NEWSIG
/* write a sig in buf to file at path */
static int
int rval;
int fd;
int len;
int nprobs;
int cnt;
unsigned char c;
unsigned char val;
cnt = 0;
nprobs = 0;
if (fd < 0) {
return(1);
}
while (len) {
c = (unsigned char) isc_buffer_getuint8(buf);
else
if (rval != 1) {
++nprobs;
break;
}
val = (c & 0x0f);
else
if (rval != 1) {
++nprobs;
break;
}
--len;
++cnt;
if ((cnt % 16) == 0) {
val = '\n';
if (rval != 1) {
++nprobs;
break;
}
}
}
val = '\n';
if (rval != 1) {
++nprobs;
}
return(nprobs);
}
#endif /* NEWSIG */
/* read sig in file at path to buf */
static int
int rval;
int len;
int fd;
unsigned char val;
char *p;
char *buf;
if (rval != 0) {
return(1);
}
return(1);
}
if (fd < 0) {
return(1);
}
p = buf;
while (len) {
if (rval > 0) {
p += rval;
}
else {
return(1);
}
}
p = buf;
while(len) {
if (*p == '\n') {
++p;
--len;
continue;
}
if (('0' <= *p) && (*p <= '9'))
val = *p - '0';
else
++p;
val <<= 4;
--len;
if (('0' <= *p) && (*p <= '9'))
val |= (*p - '0');
else
++p;
--len;
}
return(0);
}
static void
int rval;
int len;
int fd;
int exp_res;
unsigned char *p;
unsigned char *data;
/* read data from file in a form usable by dst_verify */
if (rval != 0) {
++*nprobs;
return;
}
++*nprobs;
return;
}
if (fd < 0) {
++*nprobs;
return;
}
p = data;
do {
if (rval > 0) {
p += rval;
}
} while (len);
/* read key from file in a form usable by dst_verify */
if (dns_result != DNS_R_SUCCESS) {
t_info("dst_key_fromfile failed %s\n",
++*nprobs;
return;
}
#ifdef NEWSIG
/*
* if we're generating a signature for the first time,
* sign the data and save the signature to a file
*/
if (dns_result != DNS_R_SUCCESS) {
(void) dst_key_free(key);
++*nprobs;
return;
}
if (rval != 0) {
t_info("sig_tofile failed\n");
++*nprobs;
(void) dst_key_free(key);
return;
}
#endif /* NEWSIG */
/* read precomputed signature from file in a form usable by dst_verify */
if (rval != 0) {
t_info("sig_fromfile failed\n");
(void) dst_key_free(key);
++*nprobs;
return;
}
/* verify that the key signed the data */
exp_res = 0;
exp_res = 1;
t_info("dst_verify returned %s, expected %s\n",
++*nfails;
}
(void) dst_key_free(key);
return;
}
/*
* the astute observer will note that t1() signs then verifies data
* during the test but that t2() verifies data that has been
* signed at some earlier time, possibly with an entire different
* version or implementation of the DSA and RSA algorithms
*/
static char *a2 =
"the dst module provides the capability to "
"verify data signed with the RSA and DSA algorithms";
/* av == datafile, sigpath, keyname, keyid, alg, exp_result */
static int
char *datapath;
char *sigpath;
char *keyname;
char *key;
int keyid;
char *alg;
int algid;
char *exp_result;
int nfails;
int nprobs;
int result;
exp_result = *av++;
nfails = 0;
nprobs = 0;
algid = DST_ALG_DSA;
algid = DST_ALG_RSA;
else {
return(T_UNRESOLVED);
}
if (isc_result != ISC_R_SUCCESS) {
return(T_UNRESOLVED);
}
t_info("testing %s, %s, %s, %s, %s, %s\n",
if (nfails)
return(result);
}
static void
t2() {
int result;
}
testspec_t T_testlist[] = {
{ t1, "basic dst module verification" },
{ t2, "signature ineffability" },
};