t_dst.c revision 446aa1ec8cb8f231d8649cfd705c90c6d0976143
/*
* Copyright (C) 1999, 2000 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 <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h> /* XXX */
#include <dns/fixedname.h>
/*
* Adapted from the original dst_test.c program.
*/
static void
return;
}
continue;
continue;
}
}
}
return;
}
static void
const char *data = "This is some data";
unsigned char sig[512];
if (ret != ISC_R_SUCCESS) {
t_info("dst_context_create(%d) returned (%s)\n",
++*nfails;
return;
}
if (ret != ISC_R_SUCCESS) {
t_info("dst_context_adddata(%d) returned (%s)\n",
++*nfails;
return;
}
if (ret != exp_result) {
t_info("dst_context_sign(%d) returned (%s) expected (%s)\n",
++*nfails;
return;
}
if (ret != ISC_R_SUCCESS) {
t_info("dst_context_create(%d) returned (%s)\n",
++*nfails;
return;
}
if (ret != ISC_R_SUCCESS) {
t_info("dst_context_adddata(%d) returned (%s)\n",
++*nfails;
return;
}
if (ret != exp_result) {
t_info("dst_context_verify(%d) returned (%s) expected (%s)\n",
++*nfails;
return;
}
}
static void
{
int rval;
char *p;
int alg = DST_ALG_DH;
if (p == NULL) {
++*nprobs;
return;
}
if (ret != ISC_R_SUCCESS) {
t_info("dst_key_fromfile(%d) returned: %s\n",
++*nfails;
return;
}
if (ret != ISC_R_SUCCESS) {
t_info("dst_key_fromfile(%d) returned: %s\n",
++*nfails;
return;
}
if (p == NULL) {
++*nprobs;
return;
}
if (rval != 0) {
++*nprobs;
return;
}
++*nprobs;
return;
}
if (ret != 0) {
t_info("dst_key_tofile(%d) returned: %s\n",
++*nfails;
return;
}
if (ret != 0) {
t_info("dst_key_tofile(%d) returned: %s\n",
++*nfails;
return;
}
++*nprobs;
return;
}
if (ret != 0) {
t_info("dst_computesecret() returned: %s\n",
++*nfails;
return;
}
if (ret != 0) {
t_info("dst_computesecret() returned: %s\n",
++*nfails;
return;
}
{
t_info("computed secrets don't match\n");
++*nfails;
return;
}
dst_key_free(&key1);
dst_key_free(&key2);
}
static void
{
int rval;
char *p;
if (p == NULL) {
++*nprobs;
return;
}
if (ret != ISC_R_SUCCESS) {
t_info("dst_key_fromfile(%d) returned: %s\n",
++*nfails;
return;
}
if (p == NULL) {
++*nprobs;
return;
}
if (rval != 0) {
++*nprobs;
return;
}
++*nprobs;
return;
}
if (ret != 0) {
t_info("dst_key_tofile(%d) returned: %s\n",
++*nfails;
return;
}
++*nprobs;
return;
}
dst_key_free(&key);
}
static void
if (ret != ISC_R_SUCCESS) {
++*nfails;
return;
}
if (alg != DST_ALG_DH)
dst_key_free(&key);
}
#define DBUFSIZ 25
static void
get_random(int *nfails) {
unsigned int i;
if (ret != ISC_R_SUCCESS) {
++*nfails;
return;
}
if (ret != ISC_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 const 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, "
"compute Diffie-Hellman shared secrets, "
"and generate random number sequences.";
static void
t1(void) {
int nfails;
int nprobs;
int result;
isc_buffer_t b;
nfails = 0;
nprobs = 0;
if (isc_result != ISC_R_SUCCESS) {
t_info("isc_mem_create failed %d\n",
return;
}
t_info("testing use of stored keys [1]\n");
isc_buffer_add(&b, 5);
t_info("testing use of stored keys [2]\n");
t_info("testing use of stored keys [3]\n");
t_info("testing use of stored keys [4]\n");
isc_buffer_add(&b, 3);
t_info("testing use of generated keys\n");
/*
* This one uses a constant.
*/
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;
t_info("buf: current %d used %d len %d\n",
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;
isc_buffer_t b;
/*
* 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 (isc_result != ISC_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 (isc_result != ISC_R_SUCCESS) {
t_info("dst_context_create(%d) failed %s\n",
dst_key_free(&key);
++*nprobs;
return;
}
if (isc_result != ISC_R_SUCCESS) {
t_info("dst_context_adddata(%d) failed %s\n",
dst_key_free(&key);
++*nprobs;
return;
}
if (isc_result != ISC_R_SUCCESS) {
t_info("dst_sign(%d) failed %s\n",
dst_key_free(&key);
++*nprobs;
return;
}
if (rval != 0) {
t_info("sig_tofile failed\n");
++*nprobs;
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");
dst_key_free(&key);
++*nprobs;
return;
}
/*
* Verify that the key signed the data.
*/
exp_res = 0;
exp_res = 1;
if (isc_result != ISC_R_SUCCESS) {
t_info("dst_context_create returned %s\n",
++*nfails;
}
if (isc_result != ISC_R_SUCCESS) {
t_info("dst_context_adddata returned %s\n",
++*nfails;
}
t_info("dst_context_verify returned %s, expected %s\n",
++*nfails;
}
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 const 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) {
t_info("isc_mem_create failed %d\n",
return(T_UNRESOLVED);
}
t_info("testing %s, %s, %s, %s, %s, %s\n",
if (nfails)
return(result);
}
static void
t2(void) {
int result;
}
testspec_t T_testlist[] = {
{ t1, "basic dst module verification" },
{ t2, "signature ineffability" },
};