X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/c55a77db55ebf46a399f136eeb3a928b1e862772..d4f09789499b5a665a0e79d6ed0086806fc7b648:/test/src/client.c diff --git a/test/src/client.c b/test/src/client.c index 0a2159472..58ab56d4c 100644 --- a/test/src/client.c +++ b/test/src/client.c @@ -1,5 +1,3 @@ -/* $Cambridge: exim/test/src/client.c,v 1.1 2006/02/06 16:24:05 ph10 Exp $ */ - /* A little hacked up program that makes a TCP/IP call and reads a script to drive it, for testing Exim server code running as a daemon. It's got a bit messy with the addition of support for either OpenSSL or GnuTLS. The code for @@ -77,11 +75,9 @@ latter needs a whole pile of tables. */ #include #define DH_BITS 768 -#define RSA_BITS 512 /* Local static variables for GNUTLS */ -static gnutls_rsa_params rsa_params = NULL; static gnutls_dh_params dh_params = NULL; static gnutls_certificate_credentials_t x509_cred = NULL; @@ -97,7 +93,6 @@ static const int kx_priority[16] = { GNUTLS_KX_RSA, GNUTLS_KX_DHE_DSS, GNUTLS_KX_DHE_RSA, - GNUTLS_KX_RSA_EXPORT, 0 }; static int default_cipher_priority[16] = { @@ -225,7 +220,7 @@ Returns: doesn't - it dies static void gnutls_error(uschar *prefix, int err) { -fprintf(stderr, "GnuTLS connection error:%s", prefix); +fprintf(stderr, "GnuTLS connection error: %s:", prefix); if (err != 0) fprintf(stderr, " %s", gnutls_strerror(err)); fprintf(stderr, "\n"); exit(1); @@ -234,14 +229,14 @@ exit(1); /************************************************* -* Setup up RSA and DH parameters * +* Setup up DH parameters * *************************************************/ /* For the test suite, the parameters should always be available in the spool directory. */ static void -init_rsa_dh(void) +init_dh(void) { int fd; int ret; @@ -251,17 +246,11 @@ struct stat statbuf; /* Initialize the data structures for holding the parameters */ -ret = gnutls_rsa_params_init(&rsa_params); -if (ret < 0) gnutls_error(US"init rsa_params", ret); - ret = gnutls_dh_params_init(&dh_params); if (ret < 0) gnutls_error(US"init dh_params", ret); /* Open the cache file for reading and if successful, read it and set up the -parameters. If we can't set up the RSA parameters, assume that we are dealing -with an old-style cache file that is in another format, and fall through to -compute new values. However, if we correctly get RSA parameters, a failure to -set up D-H parameters is treated as an error. */ +parameters. */ fd = open("aux-fixed/gnutls-params", O_RDONLY, 0); if (fd < 0) @@ -284,8 +273,6 @@ if (read(fd, m.data, m.size) != m.size) return gnutls_error(US"TLS cache read failed", 0); (void)close(fd); -ret = gnutls_rsa_params_import_pkcs1(rsa_params, &m, GNUTLS_X509_FMT_PEM); -if (ret < 0) return gnutls_error(US"RSA params import", ret); ret = gnutls_dh_params_import_pkcs3(dh_params, &m, GNUTLS_X509_FMT_PEM); if (ret < 0) return gnutls_error(US"DH params import", ret); free(m.data); @@ -312,9 +299,9 @@ int rc; rc = gnutls_global_init(); if (rc < 0) gnutls_error(US"gnutls_global_init", rc); -/* Read RSA and D-H parameters from the cache file. */ +/* Read D-H parameters from the cache file. */ -init_rsa_dh(); +init_dh(); /* Create the credentials structure */ @@ -333,7 +320,6 @@ if (certificate != NULL) /* Associate the parameters with the x509 credentials structure. */ gnutls_certificate_set_dh_params(x509_cred, dh_params); -gnutls_certificate_set_rsa_export_params(x509_cred, rsa_params); } @@ -375,13 +361,14 @@ return session; * Main Program * *************************************************/ -/* Usage: client - - - [] - [] - [] -*/ +const char * const HELP_MESSAGE = "\n\ +Usage: client\n\ + \n\ + \n\ + []\n\ + []\n\ + []\n\ +\n"; int main(int argc, char **argv) { @@ -391,12 +378,14 @@ char *interface = NULL; char *address = NULL; char *certfile = NULL; char *keyfile = NULL; +char *end = NULL; int argi = 1; int host_af, port, s_len, rc, sock, save_errno; int timeout = 1; int tls_active = 0; int sent_starttls = 0; int tls_on_connect = 0; +long tmplong; #if HAVE_IPV6 struct sockaddr_in6 s_in6; @@ -417,6 +406,13 @@ unsigned char *inptr = inbuffer; while (argc >= argi + 1 && argv[argi][0] == '-') { + if (strcmp(argv[argi], "-help") == 0 || + strcmp(argv[argi], "--help") == 0 || + strcmp(argv[argi], "-h") == 0) + { + printf(HELP_MESSAGE); + exit(0); + } if (strcmp(argv[argi], "-tls-on-connect") == 0) { tls_on_connect = 1; @@ -424,12 +420,30 @@ while (argc >= argi + 1 && argv[argi][0] == '-') } else if (argv[argi][1] == 't' && isdigit(argv[argi][2])) { - timeout = atoi(argv[argi]+1); + tmplong = strtol(argv[argi]+2, &end, 10); + if (end == argv[argi]+2 || *end) + { + fprintf(stderr, "Failed to parse seconds from option <%s>\n", + argv[argi]); + exit(1); + } + if (tmplong > 10000L) + { + fprintf(stderr, "Unreasonably long wait of %d seconds requested\n", + tmplong); + exit(1); + } + if (tmplong < 0L) + { + fprintf(stderr, "Timeout must not be negative (%d)\n", tmplong); + exit(1); + } + timeout = (int) tmplong; argi++; } else { - printf("Unrecognized option %s\n", argv[argi]); + fprintf(stderr, "Unrecognized option %s\n", argv[argi]); exit(1); } } @@ -438,7 +452,7 @@ while (argc >= argi + 1 && argv[argi][0] == '-') if (argc < argi+1) { - printf("No IP address given\n"); + fprintf(stderr, "No IP address given\n"); exit(1); } @@ -449,7 +463,7 @@ host_af = (strchr(address, ':') != NULL)? AF_INET6 : AF_INET; if (argc < argi+1) { - printf("No port number given\n"); + fprintf(stderr, "No port number given\n"); exit(1); }