summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2002-02-13 10:03:22 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2002-02-13 10:03:22 +0000
commit285a03d0bcf84512c51b18fbb9e923ffde838197 (patch)
treeb1b11cfa52d45e231f6fe8d6fa41daeaf2a55e60 /src
parent96f0511ea7ec0c84410ac69137419a3d683191ed (diff)
downloadgnutls-285a03d0bcf84512c51b18fbb9e923ffde838197.tar.gz
Made most ifdefs in client program, configurable via command line.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/cli-gaa.c886
-rw-r--r--src/cli-gaa.h61
-rw-r--r--src/cli.c160
-rw-r--r--src/cli.gaa43
5 files changed, 1137 insertions, 19 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index abf39ca3a8..b25d1f5710 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
EXTRA_DIST = common.h prime.gaa crypt.gaa crypt-gaa.h README.srpcrypt prime-gaa.h \
- README
+ README cli.gaa cli-gaa.h
SUBDIRS = srp x509 openpgp
INCLUDES = -I../lib
@@ -11,7 +11,7 @@ srpcrypt_SOURCES = crypt-gaa.c crypt.c
srpcrypt_LDADD = ../lib/libgnutls.la $(LIBGCRYPT_LIBS)
prime_SOURCES = prime-gaa.c prime.c
prime_LDADD = ../lib/libgnutls.la $(LIBGCRYPT_LIBS)
-cli_SOURCES = cli.c common.c
+cli_SOURCES = cli.c common.c cli-gaa.c
cli_LDADD = ../lib/libgnutls.la $(LIBGCRYPT_LIBS)
CertificateExample_SOURCES = CertificateExample.c
@@ -26,4 +26,6 @@ crypt-gaa.c: crypt.gaa
gaa crypt.gaa -o crypt-gaa.c -i crypt-gaa.h
prime-gaa.c: prime.gaa
gaa prime.gaa -o prime-gaa.c -i prime-gaa.h
+cli-gaa.c: cli.gaa
+ gaa cli.gaa -o cli-gaa.c -i cli-gaa.h
diff --git a/src/cli-gaa.c b/src/cli-gaa.c
new file mode 100644
index 0000000000..f7bcabed09
--- /dev/null
+++ b/src/cli-gaa.c
@@ -0,0 +1,886 @@
+#include <stdio.h>
+#include <string.h>
+
+#ifndef GAA_NO_WIN32
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
+#define GAA_WIN32
+#endif
+#endif
+
+void __gaa_helpsingle(char short_name, char *name,
+ char *arg_desc, char *opt_help)
+{
+ int col1, col3, col4, tabsize = 3, curr;
+ int i;
+
+ col1 = 5; /* Default values */
+ col3 = 30;
+ col4 = 70;
+
+ curr = 0;
+ for(i = 0; i < col1; i++)
+ {
+ printf(" ");
+ curr++;
+ }
+ if(short_name)
+ {
+ if(name && *name)
+ {
+ printf("-%c, ", short_name);
+ curr += 4;
+ }
+ else
+ {
+ printf("-%c ", short_name);
+ curr += 3;
+ }
+ }
+ if(name && *name)
+ {
+ printf("--%s ", name);
+ curr += 3 + strlen(name);
+ }
+ if(arg_desc && *arg_desc)
+ {
+ printf("%s ", arg_desc);
+ curr += 1 + strlen(arg_desc);
+ }
+ if(curr >= col3)
+ {
+ printf("\n");
+ curr = 0;
+ }
+ if(opt_help) /* let's print the option's help body */
+ {
+ const char *str = opt_help;
+ while(*str)
+ {
+ while(curr < col3)
+ {
+ printf(" ");
+ curr++;
+ }
+ switch(*str)
+ {
+ case '\n':
+ printf("\n");
+ curr = 0;
+ break;
+ case '\t':
+ do
+ {
+ printf(" ");
+ curr++;
+ }
+ while((curr - col3) % tabsize != 0 && curr < col4);
+ case ' ':
+ if(*str == ' ')
+ {
+ curr++;
+ printf(" ");
+ }
+ for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
+ && str[i] != '\t'; i++);
+ if(curr + i - 1 >= col4)
+ curr = col4;
+ break;
+ default:
+ printf("%c", *str);
+ curr++;
+ }
+ if(curr >= col4)
+ {
+ printf("\n");
+ curr = 0;
+ }
+ str++;
+ }
+ }
+ printf("\n");
+}
+
+void gaa_help()
+{
+ printf("cli help\nUsage: cli [options]""\n");
+ __gaa_helpsingle('r', "resume", "", "Connect, establish a session. Connect again and resume this session.");
+ __gaa_helpsingle('p', "port", """integer"" ", "The port to connect to.");
+ __gaa_helpsingle(0, "host", """hostname"" ", "The host to connect to.");
+ __gaa_helpsingle(0, "ciphers", """cipher1 cipher2..."" ", "Ciphers to enable.");
+ __gaa_helpsingle(0, "protocols", """protocol1 protocol2..."" ", "Protocols to enable.");
+ __gaa_helpsingle(0, "comp", """comp1 comp2..."" ", "Compression methods to enable.");
+ __gaa_helpsingle(0, "macs", """mac1 mac2..."" ", "MACs to enable.");
+ __gaa_helpsingle(0, "kx", """kx1 kx2..."" ", "Key exchange methods to enable.");
+ __gaa_helpsingle(0, "certtype", """certtype1 certtype2..."" ", "Certificate types to enable.");
+ __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
+ __gaa_helpsingle('h', "help", "", "prints this help");
+
+#line 100 "gaa.skel"
+}
+/* Copy of C area */
+
+#line 104 "gaa.skel"
+/* GAA HEADER */
+#ifndef GAA_HEADER_POKY
+#define GAA_HEADER_POKY
+
+typedef struct _gaainfo gaainfo;
+
+struct _gaainfo
+{
+#line 33 "cli.gaa"
+ char **ctype;
+#line 32 "cli.gaa"
+ int nctype;
+#line 29 "cli.gaa"
+ char **kx;
+#line 28 "cli.gaa"
+ int nkx;
+#line 25 "cli.gaa"
+ char **macs;
+#line 24 "cli.gaa"
+ int nmacs;
+#line 21 "cli.gaa"
+ char **comp;
+#line 20 "cli.gaa"
+ int ncomp;
+#line 17 "cli.gaa"
+ char **proto;
+#line 16 "cli.gaa"
+ int nproto;
+#line 13 "cli.gaa"
+ char **ciphers;
+#line 12 "cli.gaa"
+ int nciphers;
+#line 9 "cli.gaa"
+ char *hostname;
+#line 6 "cli.gaa"
+ int port;
+#line 3 "cli.gaa"
+ int resume;
+
+#line 114 "gaa.skel"
+};
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int gaa(int argc, char *argv[], gaainfo *gaaval);
+
+ void gaa_help();
+
+ int gaa_file(char *name, gaainfo *gaaval);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
+#line 135 "gaa.skel"
+
+/* C declarations */
+
+#define GAAERROR \
+{ \
+gaa_error = 1; \
+return; \
+}
+
+char *gaa_current_option;
+int gaa_error = 0;
+
+/* Generated by gaa */
+
+#include <string.h>
+#include <stdlib.h>
+
+
+#define GAA_OK -1
+
+#define GAA_ERROR_NOMATCH 0
+#define GAA_ERROR_NOTENOUGH_ARGS 1
+#define GAA_ERROR_INVALID_ARG 2
+#define GAA_ERROR_UNKNOWN 3
+
+#define GAA_NOT_AN_OPTION 0
+#define GAA_WORD_OPTION 1
+#define GAA_LETTER_OPTION 2
+#define GAA_MULTIPLE_OPTION 3
+
+#define GAA_REST 0
+#define GAA_NB_OPTION 11
+#define GAAOPTID_help 1
+#define GAAOPTID_list 2
+#define GAAOPTID_certtype 3
+#define GAAOPTID_kx 4
+#define GAAOPTID_macs 5
+#define GAAOPTID_comp 6
+#define GAAOPTID_protocols 7
+#define GAAOPTID_ciphers 8
+#define GAAOPTID_host 9
+#define GAAOPTID_port 10
+#define GAAOPTID_resume 11
+
+#line 168 "gaa.skel"
+
+#define GAA_CHECK1STR(a,b) \
+if(a[0] == str[0]) \
+{ \
+ gaa_current_option = a; \
+ return b; \
+}
+
+#define GAA_CHECKSTR(a,b) \
+if(strcmp(a,str) == 0) \
+{ \
+ gaa_current_option = a; \
+ return b; \
+}
+
+#define GAA_TESTMOREARGS \
+if(!OK) \
+{ \
+while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
+ gaa_index++; \
+if(gaa_last_non_option == gaa_index) \
+ return GAA_ERROR_NOTENOUGH_ARGS; \
+}
+
+#define GAA_TESTMOREOPTIONALARGS \
+if(!OK) \
+{ \
+while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
+ gaa_index++; \
+if(gaa_last_non_option == gaa_index) \
+ OK = 1; \
+}
+
+#define GAA_FILL_2ARGS(target, func) \
+target = func(GAAargv[gaa_index]); \
+gaa_arg_used[gaa_index] = 1; \
+if(gaa_error == 1) \
+{ \
+ gaa_error = 0; \
+ return GAA_ERROR_INVALID_ARG; \
+}
+
+
+
+#define GAA_FILL(target, func, num) \
+if(!OK) \
+{ \
+target = func(GAAargv[gaa_index]); \
+gaa_arg_used[gaa_index] = 1; \
+if(gaa_error == 1) \
+{ \
+ gaa_error = 0; \
+ return GAA_ERROR_INVALID_ARG; \
+} \
+num = 1; \
+} \
+else \
+{ \
+num = 0; \
+}
+
+#define GAA_LIST_FILL(target, func, type ,num) \
+if(!OK) \
+{ \
+num = 0; \
+target = malloc((gaa_last_non_option - gaa_index) * sizeof(type)); \
+for(; gaa_index < gaa_last_non_option; gaa_index++) \
+{ \
+ if(gaa_arg_used[gaa_index] == 0) \
+ { \
+ GAA_FILL_2ARGS(target[num], func); \
+ num++; \
+ } \
+} \
+if(num == 0) \
+ return GAA_ERROR_NOTENOUGH_ARGS; \
+}
+
+#define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
+if(!OK) \
+{ \
+num = 0; \
+target = malloc((gaa_last_non_option - gaa_index) * sizeof(type)); \
+for(; gaa_index < gaa_last_non_option; gaa_index++) \
+{ \
+ if(gaa_arg_used[gaa_index] == 0) \
+ { \
+ GAA_FILL_2ARGS(target[num], func); \
+ num++; \
+ } \
+} \
+}
+
+#define GAA_OBLIGAT(str) \
+k = 0; \
+for(i = 0; i < strlen(str); i++) \
+{ \
+ j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
+ if(j == GAA_ERROR_NOMATCH) \
+ { \
+ printf("Error : invalid 'obligat' set\n"); \
+ exit(-1); \
+ } \
+ if(opt_list[j] == 1) \
+ k = 1; \
+} \
+if(k == 0) \
+{ \
+ if(strlen(str) == 1) \
+ printf("You must give the -%s option\n", str); \
+ else \
+ printf("You must give at least one option of '%s'\n", str); \
+ return 0; \
+}
+
+#define GAA_INCOMP(str) \
+k = 0; \
+for(i = 0; i < strlen(str); i++) \
+{ \
+ j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
+ if(j == GAA_ERROR_NOMATCH) \
+ { \
+ printf("Error : invalid 'obligat' set\n"); \
+ exit(-1); \
+ } \
+ if(opt_list[j] == 1) \
+ k++; \
+} \
+if(k > 1) \
+{ \
+ printf("The options '%s' are incompatible\n", str); \
+ return 0; \
+}
+
+
+char **GAAargv;
+int GAAargc;
+char *gaa_arg_used;
+int gaa_processing_file = 0;
+int inited = 0;
+
+int gaa_getint(char *arg)
+{
+ int tmp;
+ char a;
+ if(sscanf(arg, "%d%c", &tmp, &a) != 1)
+ {
+ printf("Option %s : '%s' isn't an integer\n", gaa_current_option, arg);
+ GAAERROR;
+ }
+ return tmp;
+}
+
+char gaa_getchar(char *arg)
+{
+ if(strlen(arg) != 1)
+ {
+ printf("Option %s : '%s' isn't an character\n", gaa_current_option, arg);
+ GAAERROR;
+ }
+ return arg[0];
+}
+
+char* gaa_getstr(char *arg)
+{
+ return arg;
+}
+float gaa_getfloat(char *arg)
+{
+ float tmp;
+ char a;
+ if(sscanf(arg, "%f%c", &tmp, &a) != 1)
+ {
+ printf("Option %s : '%s' isn't a float number\n", gaa_current_option, arg);
+ GAAERROR;
+ }
+ return tmp;
+}
+/* option structures */
+
+struct GAAOPTION_certtype
+{
+ char** arg1;
+ int size1;
+};
+
+struct GAAOPTION_kx
+{
+ char** arg1;
+ int size1;
+};
+
+struct GAAOPTION_macs
+{
+ char** arg1;
+ int size1;
+};
+
+struct GAAOPTION_comp
+{
+ char** arg1;
+ int size1;
+};
+
+struct GAAOPTION_protocols
+{
+ char** arg1;
+ int size1;
+};
+
+struct GAAOPTION_ciphers
+{
+ char** arg1;
+ int size1;
+};
+
+struct GAAOPTION_host
+{
+ char* arg1;
+ int size1;
+};
+
+struct GAAOPTION_port
+{
+ int arg1;
+ int size1;
+};
+
+#line 349 "gaa.skel"
+int gaa_is_an_argument(char *str)
+{
+#ifdef GAA_WIN32
+ if(str[0] == '/' && str[1] != 0)
+ return GAA_MULTIPLE_OPTION;
+#endif
+ if(str[0] != '-')
+ return GAA_NOT_AN_OPTION;
+ if(str[1] == 0)
+ return GAA_NOT_AN_OPTION;
+ if(str[1] == '-')
+ {
+ if(str[2] != 0)
+ return GAA_WORD_OPTION;
+ else
+ return GAA_NOT_AN_OPTION;
+ }
+ if(str[2] == 0)
+ return GAA_LETTER_OPTION;
+ else
+ return GAA_MULTIPLE_OPTION;
+}
+
+int gaa_get_option_num(char *str, int status)
+{
+ switch(status)
+ {
+ case GAA_LETTER_OPTION:
+ GAA_CHECK1STR("", GAAOPTID_certtype);
+ GAA_CHECK1STR("", GAAOPTID_kx);
+ GAA_CHECK1STR("", GAAOPTID_macs);
+ GAA_CHECK1STR("", GAAOPTID_comp);
+ GAA_CHECK1STR("", GAAOPTID_protocols);
+ GAA_CHECK1STR("", GAAOPTID_ciphers);
+ GAA_CHECK1STR("", GAAOPTID_host);
+ GAA_CHECK1STR("p", GAAOPTID_port);
+ case GAA_MULTIPLE_OPTION:
+#line 375 "gaa.skel"
+ GAA_CHECK1STR("h", GAAOPTID_help);
+ GAA_CHECK1STR("l", GAAOPTID_list);
+ GAA_CHECK1STR("r", GAAOPTID_resume);
+
+#line 277 "gaa.skel"
+ break;
+ case GAA_WORD_OPTION:
+ GAA_CHECKSTR("help", GAAOPTID_help);
+ GAA_CHECKSTR("list", GAAOPTID_list);
+ GAA_CHECKSTR("certtype", GAAOPTID_certtype);
+ GAA_CHECKSTR("kx", GAAOPTID_kx);
+ GAA_CHECKSTR("macs", GAAOPTID_macs);
+ GAA_CHECKSTR("comp", GAAOPTID_comp);
+ GAA_CHECKSTR("protocols", GAAOPTID_protocols);
+ GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
+ GAA_CHECKSTR("host", GAAOPTID_host);
+ GAA_CHECKSTR("port", GAAOPTID_port);
+ GAA_CHECKSTR("resume", GAAOPTID_resume);
+
+#line 281 "gaa.skel"
+ break;
+ default: break;
+ }
+ return GAA_ERROR_NOMATCH;
+}
+
+int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
+{
+ int OK = 0;
+ int gaa_last_non_option;
+ struct GAAOPTION_certtype GAATMP_certtype;
+ struct GAAOPTION_kx GAATMP_kx;
+ struct GAAOPTION_macs GAATMP_macs;
+ struct GAAOPTION_comp GAATMP_comp;
+ struct GAAOPTION_protocols GAATMP_protocols;
+ struct GAAOPTION_ciphers GAATMP_ciphers;
+ struct GAAOPTION_host GAATMP_host;
+ struct GAAOPTION_port GAATMP_port;
+
+#line 393 "gaa.skel"
+#ifdef GAA_REST_EXISTS
+ struct GAAREST GAAREST_tmp;
+#endif
+
+ opt_list[gaa_num] = 1;
+
+ for(gaa_last_non_option = gaa_index;
+ (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
+ gaa_last_non_option++);
+
+ if(gaa_num == GAA_REST)
+ {
+ gaa_index = 1;
+ gaa_last_non_option = GAAargc;
+ }
+
+ switch(gaa_num)
+ {
+ case GAAOPTID_help:
+ OK = 0;
+#line 38 "cli.gaa"
+{ gaa_help(); exit(0); ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_list:
+ OK = 0;
+#line 37 "cli.gaa"
+{ print_list(); exit(0); ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_certtype:
+ OK = 0;
+ GAA_LIST_FILL(GAATMP_certtype.arg1, gaa_getstr, char*, GAATMP_certtype.size1);
+#line 34 "cli.gaa"
+{ gaaval->ctype = GAATMP_certtype.arg1; gaaval->nctype = GAATMP_certtype.size1 ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_kx:
+ OK = 0;
+ GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
+#line 30 "cli.gaa"
+{ gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_macs:
+ OK = 0;
+ GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
+#line 26 "cli.gaa"
+{ gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_comp:
+ OK = 0;
+ GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
+#line 22 "cli.gaa"
+{ gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_protocols:
+ OK = 0;
+ GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
+#line 18 "cli.gaa"
+{ gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_ciphers:
+ OK = 0;
+ GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
+#line 14 "cli.gaa"
+{ gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_host:
+ OK = 0;
+ GAA_TESTMOREARGS;
+ GAA_FILL(GAATMP_host.arg1, gaa_getstr, GAATMP_host.size1);
+ gaa_index++;
+#line 10 "cli.gaa"
+{ gaaval->hostname = GAATMP_host.arg1 ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_port:
+ OK = 0;
+ GAA_TESTMOREARGS;
+ GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
+ gaa_index++;
+#line 7 "cli.gaa"
+{ gaaval->port = GAATMP_port.arg1 ;};
+
+ return GAA_OK;
+ break;
+ case GAAOPTID_resume:
+ OK = 0;
+#line 4 "cli.gaa"
+{ gaaval->resume = 1 ;};
+
+ return GAA_OK;
+ break;
+
+#line 413 "gaa.skel"
+ default: break;
+ }
+ return GAA_ERROR_UNKNOWN;
+}
+
+int gaa(int argc, char **argv, gaainfo *gaaval)
+{
+ int tmp1, tmp2;
+ int i, j;
+ char *opt_list;
+
+ GAAargv = argv;
+ GAAargc = argc;
+
+ opt_list = (char*) malloc(GAA_NB_OPTION + 1);
+ for(i = 0; i < GAA_NB_OPTION + 1; i++)
+ opt_list[i] = 0;
+ /* initialization */
+ if(inited == 0)
+ {
+
+#line 40 "cli.gaa"
+{ gaaval->resume=0; gaaval->port=5556; gaaval->hostname="localhost"; gaaval->ciphers=NULL;
+ gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
+ gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; ;};
+
+ }
+ inited = 1;
+#line 438 "gaa.skel"
+ gaa_arg_used = malloc(argc * sizeof(char));
+ for(i = 1; i < argc; i++)
+ gaa_arg_used[i] = 0;
+ for(i = 1; i < argc; i++)
+ {
+ if(gaa_arg_used[i] == 0)
+ {
+ j = 0;
+ tmp1 = gaa_is_an_argument(GAAargv[i]);
+ switch(tmp1)
+ {
+ case GAA_WORD_OPTION:
+ j++;
+ case GAA_LETTER_OPTION:
+ j++;
+ tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
+ if(tmp2 == GAA_ERROR_NOMATCH)
+ {
+ printf("Invalid option '%s'\n", argv[i]+j);
+ return 0;
+ }
+ switch(gaa_try(tmp2, i+1, gaaval, opt_list))
+ {
+ case GAA_ERROR_NOTENOUGH_ARGS:
+ printf("'%s' : not enough arguments\n",gaa_current_option);
+ return 0;
+ case GAA_ERROR_INVALID_ARG:
+ printf("Invalid arguments\n");
+ return 0;
+ case GAA_OK:
+ break;
+ default:
+ printf("Unknown error\n");
+ }
+ gaa_arg_used[i] = 1;
+ break;
+ case GAA_MULTIPLE_OPTION:
+ for(j = 1; j < strlen(argv[i]); j++)
+ {
+ tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
+ if(tmp2 == GAA_ERROR_NOMATCH)
+ {
+ printf("Invalid option '%c'\n", *(argv[i]+j));
+ return 0;
+ }
+ switch(gaa_try(tmp2, i+1, gaaval, opt_list))
+ {
+ case GAA_ERROR_NOTENOUGH_ARGS:
+ printf("'%s' : not enough arguments\n",gaa_current_option);
+ return 0;
+ case GAA_ERROR_INVALID_ARG:
+ printf("Invalid arguments\n");
+ return 0;
+ case GAA_OK:
+ break;
+ default:
+ printf("Unknown error\n");
+ }
+ }
+ gaa_arg_used[i] = 1;
+ break;
+ default: break;
+ }
+ }
+ }
+if(gaa_processing_file == 0)
+{
+
+#line 507 "gaa.skel"
+#ifdef GAA_REST_EXISTS
+ switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
+ {
+ case GAA_ERROR_NOTENOUGH_ARGS:
+ printf("Rest : not enough arguments\n");
+ return 0;
+ case GAA_ERROR_INVALID_ARG:
+ printf("Invalid arguments\n");
+ return 0;
+ case GAA_OK:
+ break;
+ default:
+ printf("Unknown error\n");
+ }
+#endif
+}
+ for(i = 1; i < argc; i++)
+ {
+ if(gaa_arg_used[i] == 0)
+ {
+ printf("Too many arguments\n");
+ return 0;
+ }
+ }
+ free(gaa_arg_used);
+ free(opt_list);
+ return -1;
+}
+
+struct gaastrnode
+{
+ char *str;
+ struct gaastrnode *next;
+};
+
+typedef struct gaastrnode gaa_str_node;
+
+int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
+{
+ int pos_ini;
+ char a;
+ int i = 0, len = 0, newline = 0;
+
+ if(argc == 1)
+ newline = 1;
+
+ if(fscanf(file,"%c", &a) != 1) return 0;
+
+ while(a == ' ' || a == 9 || a == '\n')
+ {
+ if(a == '\n')
+ {
+ newline=1;
+ len = 2;
+ }
+ if(fscanf(file,"%c", &a) != 1) return 0;
+ }
+
+ pos_ini = ftell(file) - 1;
+
+ while(a != ' ' && a != 9 && a != '\n')
+ {
+
+ len++;
+ if(fscanf(file,"%c", &a) != 1) a = ' ';
+ }
+
+ tmp_str->str = malloc((len + 1) * sizeof(char));
+ if(newline == 1)
+ {
+ tmp_str->str[0] = '-';
+ tmp_str->str[1] = '-';
+ i = 2;
+ }
+ else
+ {
+ i = 0;
+ }
+
+ fseek(file,pos_ini, SEEK_SET);
+ do
+ {
+ if(fscanf(file, "%c", &a) != 1)
+ {
+ i+=2;
+ break;
+ }
+ tmp_str->str[i] = a;
+ i++;
+ }
+ while(a != ' ' && a != 9 && a != '\n');
+
+ tmp_str->str[i - 1] = 0;
+
+ fseek(file,- 1, SEEK_CUR);
+
+ return -1;
+}
+
+int gaa_file(char *name, gaainfo *gaaval)
+{
+ gaa_str_node *first_str, **tmp_str, *tmp_str2;
+ int rval, i;
+ char **argv;
+ int argc = 0;
+ FILE *file;
+
+ gaa_processing_file = 1;
+
+ if((file = fopen(name, "r")) == NULL)
+ {
+ printf("Couldn't open '%s' configuration file for reading\n", name);
+ return 0;
+ }
+
+ tmp_str = &first_str;
+ do
+ {
+ argc++;
+ *tmp_str = malloc(sizeof(gaa_str_node));
+ (*tmp_str)->str = NULL;
+ (*tmp_str)->next = NULL;
+
+ rval = gaa_internal_get_next_str(file, *tmp_str, argc);
+ tmp_str = &((*tmp_str)->next);
+ }
+ while(rval == -1);
+
+ if(rval == 1)
+ return 0;
+
+ argv = malloc((1 + argc) * sizeof(char*));
+ tmp_str2 = first_str;
+ argv[0] = "cfg";
+ for(i = 1; i < argc; i++)
+ {
+ argv[i] = tmp_str2->str;
+ tmp_str2 = tmp_str2->next;
+ }
+
+ rval = gaa(argc, argv, gaaval);
+ gaa_processing_file = 0;
+ return rval;
+}
diff --git a/src/cli-gaa.h b/src/cli-gaa.h
new file mode 100644
index 0000000000..139666c1f7
--- /dev/null
+++ b/src/cli-gaa.h
@@ -0,0 +1,61 @@
+
+#line 104 "gaa.skel"
+/* GAA HEADER */
+#ifndef GAA_HEADER_POKY
+#define GAA_HEADER_POKY
+
+typedef struct _gaainfo gaainfo;
+
+struct _gaainfo
+{
+#line 33 "cli.gaa"
+ char **ctype;
+#line 32 "cli.gaa"
+ int nctype;
+#line 29 "cli.gaa"
+ char **kx;
+#line 28 "cli.gaa"
+ int nkx;
+#line 25 "cli.gaa"
+ char **macs;
+#line 24 "cli.gaa"
+ int nmacs;
+#line 21 "cli.gaa"
+ char **comp;
+#line 20 "cli.gaa"
+ int ncomp;
+#line 17 "cli.gaa"
+ char **proto;
+#line 16 "cli.gaa"
+ int nproto;
+#line 13 "cli.gaa"
+ char **ciphers;
+#line 12 "cli.gaa"
+ int nciphers;
+#line 9 "cli.gaa"
+ char *hostname;
+#line 6 "cli.gaa"
+ int port;
+#line 3 "cli.gaa"
+ int resume;
+
+#line 114 "gaa.skel"
+};
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int gaa(int argc, char *argv[], gaainfo *gaaval);
+
+ void gaa_help();
+
+ int gaa_file(char *name, gaainfo *gaaval);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
diff --git a/src/cli.c b/src/cli.c
index 82734b012e..1563a03a52 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -32,6 +32,7 @@
#include <signal.h>
#include <netdb.h>
#include <common.h>
+#include <cli-gaa.h>
#ifndef SHUT_WR
# define SHUT_WR 1
@@ -45,7 +46,19 @@
#define ERR(err,s) if (err==-1) {perror(s);return(1);}
#define MAX_BUF 4096
-/* #define RESUME */
+/* global stuff here */
+int resume;
+char* hostname;
+int port;
+
+int protocol_priority[16] = { GNUTLS_TLS1, GNUTLS_SSL3, 0 };
+int kx_priority[16] = { GNUTLS_KX_RSA, GNUTLS_KX_DHE_DSS, GNUTLS_KX_DHE_RSA, GNUTLS_KX_SRP, GNUTLS_KX_ANON_DH, 0 };
+int cipher_priority[16] = { GNUTLS_CIPHER_RIJNDAEL_128_CBC, GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0};
+int comp_priority[16] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 };
+int mac_priority[16] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 };
+int cert_type_priority[16] = { GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0 };
+
+/* end of global stuff */
#define MAX(X,Y) (X >= Y ? X : Y);
#define CAFILE "x509/ca.pem"
@@ -88,12 +101,8 @@ static int cert_callback( GNUTLS_STATE state, const gnutls_datum *client_certs,
return -1; /* send no certificate to the peer */
}
-const int protocol_priority[] = { GNUTLS_TLS1, GNUTLS_SSL3, 0 };
-const int kx_priority[] = { GNUTLS_KX_RSA, GNUTLS_KX_DHE_DSS, GNUTLS_KX_DHE_RSA, GNUTLS_KX_SRP, GNUTLS_KX_ANON_DH, 0 };
-const int cipher_priority[] = { GNUTLS_CIPHER_RIJNDAEL_128_CBC, GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0};
-const int comp_priority[] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 };
-const int mac_priority[] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 };
-const int cert_type_priority[] = { GNUTLS_CRT_OPENPGP, GNUTLS_CRT_X509, 0 };
+
+static void gaa_parser( int argc, char** argv);
int main(int argc, char** argv)
{
@@ -117,12 +126,9 @@ int main(int argc, char** argv)
GNUTLS_CERTIFICATE_CLIENT_CREDENTIALS xcred;
struct hostent* server_host;
- signal( SIGPIPE, SIG_IGN);
+ gaa_parser(argc, argv);
- if (argc!=3) {
- fprintf(stderr, "Usage: cli [HOST] [PORT]\n");
- exit(1);
- }
+ signal( SIGPIPE, SIG_IGN);
if (gnutls_global_init() < 0) {
fprintf(stderr, "global state initialization error\n");
@@ -130,9 +136,9 @@ int main(int argc, char** argv)
}
/* get server name */
- server_host = gethostbyname( argv[1]);
+ server_host = gethostbyname( hostname);
if (server_host==NULL) {
- fprintf(stderr, "Cannot resolve %s\n", argv[1]);
+ fprintf(stderr, "Cannot resolve %s\n", hostname);
exit(1);
}
@@ -190,7 +196,7 @@ int main(int argc, char** argv)
memset(&sa, '\0', sizeof(sa));
sa.sin_family = AF_INET;
- sa.sin_port = htons(atoi(argv[2]));
+ sa.sin_port = htons(port);
sa.sin_addr.s_addr = *((unsigned int*)server_host->h_addr);
@@ -200,7 +206,7 @@ int main(int argc, char** argv)
err = connect(sd, (SA *) & sa, sizeof(sa));
ERR(err, "connect");
-#ifdef RESUME
+ if (resume!=0) {
gnutls_init(&state, GNUTLS_CLIENT);
gnutls_cipher_set_priority(state, cipher_priority);
@@ -264,7 +270,7 @@ int main(int argc, char** argv)
err = connect(sd, (SA *) & sa, sizeof(sa));
ERR(err, "connect");
-#endif
+ } /* resume */
/* Begin handshake again */
gnutls_init(&state, GNUTLS_CLIENT);
@@ -408,3 +414,123 @@ int main(int argc, char** argv)
return 0;
}
+
+///int protocol_priority[16] = { GNUTLS_TLS1, GNUTLS_SSL3, 0 };
+//int kx_priority[16] = { GNUTLS_KX_RSA, GNUTLS_KX_DHE_DSS, GNUTLS_KX_DHE_RSA, GNUTLS_KX_SRP, GNUTLS_KX_ANON_DH, 0 };
+//int cipher_priority[16] = { GNUTLS_CIPHER_RIJNDAEL_128_CBC, GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0};
+//int comp_priority[16] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 };
+//int mac_priority[16] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 };
+//int cert_type_priority[16] = { GNUTLS_CRT_OPENPGP, GNUTLS_CRT_X509, 0 };
+
+static gaainfo info;
+void gaa_parser( int argc, char** argv) {
+int i,j;
+
+ if (gaa(argc, argv, &info) != -1) {
+ fprintf(stderr, "Error in the arguments.\n");
+ exit(1);
+ }
+
+ resume = info.resume;
+ port = info.port;
+ hostname = info.hostname;
+
+ if (info.proto!=NULL && info.nproto > 0) {
+ for (j=i=0;i<info.nproto;i++) {
+ if (strncasecmp( info.proto[i], "SSL", 3)==0)
+ protocol_priority[j++] = GNUTLS_SSL3;
+ if (strncasecmp( info.proto[i], "TLS", 3)==0)
+ protocol_priority[j++] = GNUTLS_TLS1;
+ }
+ protocol_priority[j] = 0;
+ }
+
+ if (info.ciphers!=NULL && info.nciphers > 0) {
+ for (j=i=0;i<info.nciphers;i++) {
+ if (strncasecmp( info.ciphers[i], "RIJ", 3)==0)
+ cipher_priority[j++] = GNUTLS_CIPHER_RIJNDAEL_128_CBC;
+ if (strncasecmp( info.ciphers[i], "TWO", 3)==0)
+ cipher_priority[j++] = GNUTLS_CIPHER_TWOFISH_128_CBC;
+ if (strncasecmp( info.ciphers[i], "3DE", 3)==0)
+ cipher_priority[j++] = GNUTLS_CIPHER_3DES_CBC;
+ if (strncasecmp( info.ciphers[i], "ARC", 3)==0)
+ cipher_priority[j++] = GNUTLS_CIPHER_ARCFOUR;
+ }
+ cipher_priority[j] = 0;
+ }
+
+ if (info.macs!=NULL && info.nmacs > 0) {
+ for (j=i=0;i<info.nmacs;i++) {
+ if (strncasecmp( info.macs[i], "MD5", 3)==0)
+ mac_priority[j++] = GNUTLS_MAC_MD5;
+ if (strncasecmp( info.macs[i], "SHA", 3)==0)
+ mac_priority[j++] = GNUTLS_MAC_SHA;
+ }
+ mac_priority[j] = 0;
+ }
+
+ if (info.ctype!=NULL && info.nctype > 0) {
+ for (j=i=0;i<info.nctype;i++) {
+ if (strncasecmp( info.ctype[i], "OPE", 3)==0)
+ cert_type_priority[j++] = GNUTLS_CRT_OPENPGP;
+ if (strncasecmp( info.ctype[i], "X", 1)==0)
+ cert_type_priority[j++] = GNUTLS_CRT_X509;
+ }
+ cert_type_priority[j] = 0;
+ }
+
+ if (info.kx!=NULL && info.nkx > 0) {
+ for (j=i=0;i<info.nkx;i++) {
+ if (strncasecmp( info.kx[i], "SRP", 3)==0)
+ kx_priority[j++] = GNUTLS_KX_SRP;
+ if (strncasecmp( info.kx[i], "RSA", 3)==0)
+ kx_priority[j++] = GNUTLS_KX_RSA;
+ if (strncasecmp( info.kx[i], "DHE_RSA", 7)==0)
+ kx_priority[j++] = GNUTLS_KX_DHE_RSA;
+ if (strncasecmp( info.kx[i], "DHE_DSS", 7)==0)
+ kx_priority[j++] = GNUTLS_KX_DHE_DSS;
+ if (strncasecmp( info.kx[i], "ANON_DH", 7)==0)
+ kx_priority[j++] = GNUTLS_KX_ANON_DH;
+ }
+ kx_priority[j] = 0;
+ }
+
+ if (info.comp!=NULL && info.ncomp > 0) {
+ for (j=i=0;i<info.ncomp;i++) {
+ if (strncasecmp( info.comp[i], "NUL", 3)==0)
+ comp_priority[j++] = GNUTLS_COMP_NULL;
+ if (strncasecmp( info.comp[i], "ZLI", 1)==0)
+ comp_priority[j++] = GNUTLS_COMP_ZLIB;
+ }
+ comp_priority[j] = 0;
+ }
+
+}
+
+void print_list(void) {
+
+ printf("\n");
+ printf("Certificate types:");
+ printf(" X.509");
+ printf(", OPENPGP\n");
+
+ printf("Protocols:");
+ printf(" TLS 1.0");
+ printf(", SSL 3.0\n");
+
+ printf("Ciphers:");
+ printf(" RIJNDAEL_128_CBC");
+ printf(", TWOFISH_128_CBC");
+ printf(", 3DES_CBC");
+ printf(", ARCFOUR\n");
+
+ printf("MACs:");
+ printf(" MD5");
+ printf(", SHA-1\n");
+
+ printf("Compression Methods:");
+ printf(" ZLIB");
+ printf(", NULL\n");
+
+ return;
+}
diff --git a/src/cli.gaa b/src/cli.gaa
new file mode 100644
index 0000000000..84ce49c76a
--- /dev/null
+++ b/src/cli.gaa
@@ -0,0 +1,43 @@
+helpnode "cli help\nUsage: cli [options]"
+
+#int resume;
+option (r, resume) { $resume = 1 } "Connect, establish a session. Connect again and resume this session."
+
+#int port;
+option (p, port) INT "integer" { $port = $1 } "The port to connect to."
+
+#char *hostname;
+option (host) STR "hostname" { $hostname = $1 } "The host to connect to."
+
+#int nciphers;
+#char **ciphers;
+option (ciphers) *STR "cipher1 cipher2..." { $ciphers = $1; $nciphers = @1 } "Ciphers to enable."
+
+#int nproto;
+#char **proto;
+option (protocols) *STR "protocol1 protocol2..." { $proto = $1; $nproto = @1 } "Protocols to enable."
+
+#int ncomp;
+#char **comp;
+option (comp) *STR "comp1 comp2..." { $comp = $1; $ncomp = @1 } "Compression methods to enable."
+
+#int nmacs;
+#char **macs;
+option (macs) *STR "mac1 mac2..." { $macs = $1; $nmacs = @1 } "MACs to enable."
+
+#int nkx;
+#char **kx;
+option (kx) *STR "kx1 kx2..." { $kx = $1; $nkx = @1 } "Key exchange methods to enable."
+
+#int nctype;
+#char **ctype;
+option (certtype) *STR "certtype1 certtype2..." { $ctype = $1; $nctype = @1 } "Certificate types to enable."
+
+
+option (l, list) { print_list(); exit(0); } "Print a list of the supported algorithms and modes."
+option (h, help) { gaa_help(); exit(0); } "prints this help"
+
+init { $resume=0; $port=5556; $hostname="localhost"; $ciphers=NULL;
+ $kx=NULL; $comp=NULL; $macs=NULL; $ctype=NULL; $nciphers=0;
+ $nkx=0; $ncomp=0; $nmacs=0; $nctype = 0; }
+