Update `NEWS'.
[gnutls.git] / src / certtool-gaa.c
blob2f2266e577819ea3f8b2b6c068f5ebafdbf9d241
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "certtool.gaa"
7 /* C declarations */
9 #include <config.h>
10 #ifdef _WIN32
11 # include <io.h>
12 #endif
14 void certtool_version(void);
16 #include <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
20 #ifndef GAA_NO_WIN32
21 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
22 #define GAA_WIN32
23 #endif
24 #endif
26 static void* gaa_malloc( size_t size) {
27 void* ret;
28 ret = malloc(size);
29 if (ret==NULL) {
30 fprintf(stderr, "gaa: could not allocate memory");
31 exit(1);
33 return ret;
36 static void __gaa_helpsingle(char short_name, char *name,
37 char *arg_desc, char *opt_help)
39 int col1, col3, col4, tabsize = 3, curr;
40 int i;
42 col1 = 5; /* Default values */
43 col3 = 30;
44 col4 = 70;
46 curr = 0;
47 for(i = 0; i < col1; i++)
49 printf(" ");
50 curr++;
52 if(short_name)
54 if(name && *name)
56 printf("-%c, ", short_name);
57 curr += 4;
59 else
61 printf("-%c ", short_name);
62 curr += 3;
65 if(name && *name)
67 printf("--%s ", name);
68 curr += 3 + strlen(name);
70 if(arg_desc && *arg_desc)
72 printf("%s ", arg_desc);
73 curr += 1 + strlen(arg_desc);
75 if(curr >= col3)
77 printf("\n");
78 curr = 0;
80 if(opt_help) /* let's print the option's help body */
82 const char *str = opt_help;
83 while(*str)
85 while(curr < col3)
87 printf(" ");
88 curr++;
90 switch(*str)
92 case '\n':
93 printf("\n");
94 curr = 0;
95 break;
96 case '\t':
99 printf(" ");
100 curr++;
102 while((curr - col3) % tabsize != 0 && curr < col4);
103 case ' ':
104 if(*str == ' ')
106 curr++;
107 printf(" ");
109 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
110 && str[i] != '\t'; i++);
111 if(curr + i - 1 >= col4)
112 curr = col4;
113 break;
114 default:
115 printf("%c", *str);
116 curr++;
118 if(curr >= col4)
120 printf("\n");
121 curr = 0;
123 str++;
126 printf("\n");
129 void gaa_help(void)
131 printf("Certtool help\nUsage: certtool [options]\n");
132 __gaa_helpsingle('s', "generate-self-signed", "", "Generate a self-signed certificate.");
133 __gaa_helpsingle('c', "generate-certificate", "", "Generate a signed certificate.");
134 __gaa_helpsingle(0, "generate-proxy", "", "Generate a proxy certificate.");
135 __gaa_helpsingle(0, "generate-crl", "", "Generate a CRL.");
136 __gaa_helpsingle('u', "update-certificate", "", "Update a signed certificate.");
137 __gaa_helpsingle('p', "generate-privkey", "", "Generate a private key.");
138 __gaa_helpsingle('q', "generate-request", "", "Generate a PKCS #10 certificate request.");
139 __gaa_helpsingle('e', "verify-chain", "", "Verify a PEM encoded certificate chain. The last certificate in the chain must be a self signed one.");
140 __gaa_helpsingle(0, "verify-crl", "", "Verify a CRL.");
141 __gaa_helpsingle(0, "generate-dh-params", "", "Generate PKCS #3 encoded Diffie Hellman parameters.");
142 __gaa_helpsingle(0, "get-dh-params", "", "Get the included PKCS #3 encoded Diffie Hellman parameters.");
143 __gaa_helpsingle(0, "load-privkey", "FILE ", "Private key file to use.");
144 __gaa_helpsingle(0, "load-request", "FILE ", "Certificate request file to use.");
145 __gaa_helpsingle(0, "load-certificate", "FILE ", "Certificate file to use.");
146 __gaa_helpsingle(0, "load-ca-privkey", "FILE ", "Certificate authority's private key file to use.");
147 __gaa_helpsingle(0, "load-ca-certificate", "FILE ", "Certificate authority's certificate file to use.");
148 __gaa_helpsingle(0, "password", "PASSWORD ", "Password to use.");
149 __gaa_helpsingle('i', "certificate-info", "", "Print information on a certificate.");
150 __gaa_helpsingle('l', "crl-info", "", "Print information on a CRL.");
151 __gaa_helpsingle(0, "p12-info", "", "Print information on a PKCS #12 structure.");
152 __gaa_helpsingle(0, "p7-info", "", "Print information on a PKCS #7 structure.");
153 __gaa_helpsingle(0, "smime-to-p7", "", "Convert S/MIME to PKCS #7 structure.");
154 __gaa_helpsingle('k', "key-info", "", "Print information on a private key.");
155 __gaa_helpsingle(0, "fix-key", "", "Regenerate the parameters in a private key.");
156 __gaa_helpsingle(0, "to-p12", "", "Generate a PKCS #12 structure.");
157 __gaa_helpsingle('8', "pkcs8", "", "Use PKCS #8 format for private keys.");
158 __gaa_helpsingle(0, "dsa", "", "Use DSA keys.");
159 __gaa_helpsingle(0, "hash", "STR ", "Hash algorithm to use for signing (MD5,SHA1,RMD160,SHA256,SHA384,SHA512).");
160 __gaa_helpsingle(0, "export-ciphers", "", "Use weak encryption algorithms.");
161 __gaa_helpsingle(0, "inder", "", "Use DER format for input certificates and private keys.");
162 __gaa_helpsingle(0, "outder", "", "Use DER format for output certificates and private keys.");
163 __gaa_helpsingle(0, "bits", "BITS ", "specify the number of bits for key generation.");
164 __gaa_helpsingle(0, "quick-random", "", "Use /dev/urandom for all operation, reducing the quality of randomness used.");
165 __gaa_helpsingle(0, "outfile", "FILE ", "Output file.");
166 __gaa_helpsingle(0, "infile", "FILE ", "Input file.");
167 __gaa_helpsingle(0, "template", "FILE ", "Template file to use for non interactive operation.");
168 __gaa_helpsingle('d', "debug", "LEVEL ", "specify the debug level. Default is 1.");
169 __gaa_helpsingle('h', "help", "", "shows this help text");
170 __gaa_helpsingle('v', "version", "", "shows the program's version");
172 #line 100 "gaa.skel"
174 /* Copy of C area */
176 #line 104 "gaa.skel"
177 /* GAA HEADER */
178 #ifndef GAA_HEADER_POKY
179 #define GAA_HEADER_POKY
181 typedef struct _gaainfo gaainfo;
183 struct _gaainfo
185 #line 107 "certtool.gaa"
186 int debug;
187 #line 103 "certtool.gaa"
188 char *template;
189 #line 100 "certtool.gaa"
190 char *infile;
191 #line 97 "certtool.gaa"
192 char *outfile;
193 #line 94 "certtool.gaa"
194 int quick_random;
195 #line 91 "certtool.gaa"
196 int bits;
197 #line 88 "certtool.gaa"
198 int outcert_format;
199 #line 85 "certtool.gaa"
200 int incert_format;
201 #line 82 "certtool.gaa"
202 int export;
203 #line 79 "certtool.gaa"
204 char *hash;
205 #line 76 "certtool.gaa"
206 int dsa;
207 #line 73 "certtool.gaa"
208 int pkcs8;
209 #line 68 "certtool.gaa"
210 int fix_key;
211 #line 53 "certtool.gaa"
212 char *pass;
213 #line 50 "certtool.gaa"
214 char *ca;
215 #line 47 "certtool.gaa"
216 char *ca_privkey;
217 #line 44 "certtool.gaa"
218 char *cert;
219 #line 41 "certtool.gaa"
220 char *request;
221 #line 38 "certtool.gaa"
222 char *privkey;
223 #line 16 "certtool.gaa"
224 int action;
226 #line 114 "gaa.skel"
229 #ifdef __cplusplus
230 extern "C"
232 #endif
234 int gaa(int argc, char *argv[], gaainfo *gaaval);
236 void gaa_help(void);
238 int gaa_file(const char *name, gaainfo *gaaval);
240 #ifdef __cplusplus
242 #endif
245 #endif
247 #line 135 "gaa.skel"
249 /* C declarations */
251 #define GAAERROR(x) \
253 gaa_error = 1; \
254 return x; \
257 static char *gaa_current_option;
258 static int gaa_error = 0;
260 /* Generated by gaa */
262 #include <string.h>
263 #include <stdlib.h>
266 #define GAA_OK -1
268 #define GAA_ERROR_NOMATCH 0
269 #define GAA_ERROR_NOTENOUGH_ARGS 1
270 #define GAA_ERROR_INVALID_ARG 2
271 #define GAA_ERROR_UNKNOWN 3
273 #define GAA_NOT_AN_OPTION 0
274 #define GAA_WORD_OPTION 1
275 #define GAA_LETTER_OPTION 2
276 #define GAA_MULTIPLE_OPTION 3
278 #define GAA_REST 0
279 #define GAA_NB_OPTION 39
280 #define GAAOPTID_version 1
281 #define GAAOPTID_help 2
282 #define GAAOPTID_debug 3
283 #define GAAOPTID_template 4
284 #define GAAOPTID_infile 5
285 #define GAAOPTID_outfile 6
286 #define GAAOPTID_quick_random 7
287 #define GAAOPTID_bits 8
288 #define GAAOPTID_outder 9
289 #define GAAOPTID_inder 10
290 #define GAAOPTID_export_ciphers 11
291 #define GAAOPTID_hash 12
292 #define GAAOPTID_dsa 13
293 #define GAAOPTID_pkcs8 14
294 #define GAAOPTID_to_p12 15
295 #define GAAOPTID_fix_key 16
296 #define GAAOPTID_key_info 17
297 #define GAAOPTID_smime_to_p7 18
298 #define GAAOPTID_p7_info 19
299 #define GAAOPTID_p12_info 20
300 #define GAAOPTID_crl_info 21
301 #define GAAOPTID_certificate_info 22
302 #define GAAOPTID_password 23
303 #define GAAOPTID_load_ca_certificate 24
304 #define GAAOPTID_load_ca_privkey 25
305 #define GAAOPTID_load_certificate 26
306 #define GAAOPTID_load_request 27
307 #define GAAOPTID_load_privkey 28
308 #define GAAOPTID_get_dh_params 29
309 #define GAAOPTID_generate_dh_params 30
310 #define GAAOPTID_verify_crl 31
311 #define GAAOPTID_verify_chain 32
312 #define GAAOPTID_generate_request 33
313 #define GAAOPTID_generate_privkey 34
314 #define GAAOPTID_update_certificate 35
315 #define GAAOPTID_generate_crl 36
316 #define GAAOPTID_generate_proxy 37
317 #define GAAOPTID_generate_certificate 38
318 #define GAAOPTID_generate_self_signed 39
320 #line 168 "gaa.skel"
322 #define GAA_CHECK1STR(a,b) \
323 if(a[0] == str[0]) \
325 gaa_current_option = a; \
326 return b; \
329 #define GAA_CHECKSTR(a,b) \
330 if(strcmp(a,str) == 0) \
332 gaa_current_option = a; \
333 return b; \
336 #define GAA_TESTMOREARGS \
337 if(!OK) \
339 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
340 gaa_index++; \
341 if(gaa_last_non_option == gaa_index) \
342 return GAA_ERROR_NOTENOUGH_ARGS; \
345 #define GAA_TESTMOREOPTIONALARGS \
346 if(!OK) \
348 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
349 gaa_index++; \
350 if(gaa_last_non_option == gaa_index) \
351 OK = 1; \
354 #define GAA_FILL_2ARGS(target, func) \
355 target = func(GAAargv[gaa_index]); \
356 gaa_arg_used[gaa_index] = 1; \
357 if(gaa_error == 1) \
359 gaa_error = 0; \
360 return GAA_ERROR_INVALID_ARG; \
365 #define GAA_FILL(target, func, num) \
366 if(!OK) \
368 target = func(GAAargv[gaa_index]); \
369 gaa_arg_used[gaa_index] = 1; \
370 if(gaa_error == 1) \
372 gaa_error = 0; \
373 return GAA_ERROR_INVALID_ARG; \
375 num = 1; \
377 else \
379 num = 0; \
382 #define GAA_LIST_FILL(target, func, type ,num) \
383 if(!OK) \
385 num = 0; \
386 target = NULL; \
387 if ( gaa_last_non_option - gaa_index > 0) \
388 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
389 for(; gaa_index < gaa_last_non_option; gaa_index++) \
391 if(gaa_arg_used[gaa_index] == 0) \
393 GAA_FILL_2ARGS(target[num], func); \
394 num++; \
397 if(num == 0) \
398 return GAA_ERROR_NOTENOUGH_ARGS; \
401 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
402 if(!OK) \
404 num = 0; \
405 target = NULL; \
406 if ( gaa_last_non_option - gaa_index > 0) \
407 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
408 for(; gaa_index < gaa_last_non_option; gaa_index++) \
410 if(gaa_arg_used[gaa_index] == 0) \
412 GAA_FILL_2ARGS(target[num], func); \
413 num++; \
418 #define GAA_OBLIGAT(str) \
419 k = 0; \
420 for(i = 0; i < strlen(str); i++) \
422 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
423 if(j == GAA_ERROR_NOMATCH) \
425 printf("Error: invalid 'obligat' set\n"); \
426 exit(-1); \
428 if(opt_list[j] == 1) \
429 k = 1; \
431 if(k == 0) \
433 if(strlen(str) == 1) \
434 printf("You must give the -%s option\n", str); \
435 else \
436 printf("You must give at least one option of '%s'\n", str); \
437 return 0; \
440 #define GAA_INCOMP(str) \
441 k = 0; \
442 for(i = 0; i < strlen(str); i++) \
444 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
445 if(j == GAA_ERROR_NOMATCH) \
447 printf("Error: invalid 'obligat' set\n"); \
448 exit(-1); \
450 if(opt_list[j] == 1) \
451 k++; \
453 if(k > 1) \
455 printf("The options '%s' are incompatible\n", str); \
456 return 0; \
460 static char **GAAargv;
461 static int GAAargc;
462 static char *gaa_arg_used;
463 static int gaa_processing_file = 0;
464 static int inited = 0;
466 static int gaa_getint(char *arg)
468 int tmp;
469 char a;
470 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
472 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
473 GAAERROR(-1);
475 return tmp;
478 static char gaa_getchar(char *arg)
480 if(strlen(arg) != 1)
482 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
483 GAAERROR(-1);
485 return arg[0];
488 static char* gaa_getstr(char *arg)
490 return arg;
492 static float gaa_getfloat(char *arg)
494 float tmp;
495 char a;
496 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
498 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
499 GAAERROR(-1);
501 return tmp;
503 /* option structures */
505 struct GAAOPTION_debug
507 int arg1;
508 int size1;
511 struct GAAOPTION_template
513 char* arg1;
514 int size1;
517 struct GAAOPTION_infile
519 char* arg1;
520 int size1;
523 struct GAAOPTION_outfile
525 char* arg1;
526 int size1;
529 struct GAAOPTION_bits
531 int arg1;
532 int size1;
535 struct GAAOPTION_hash
537 char* arg1;
538 int size1;
541 struct GAAOPTION_password
543 char* arg1;
544 int size1;
547 struct GAAOPTION_load_ca_certificate
549 char* arg1;
550 int size1;
553 struct GAAOPTION_load_ca_privkey
555 char* arg1;
556 int size1;
559 struct GAAOPTION_load_certificate
561 char* arg1;
562 int size1;
565 struct GAAOPTION_load_request
567 char* arg1;
568 int size1;
571 struct GAAOPTION_load_privkey
573 char* arg1;
574 int size1;
577 #line 349 "gaa.skel"
578 static int gaa_is_an_argument(char *str)
580 #ifdef GAA_WIN32
581 if(str[0] == '/' && str[1] != 0)
582 return GAA_MULTIPLE_OPTION;
583 #endif
584 if(str[0] != '-')
585 return GAA_NOT_AN_OPTION;
586 if(str[1] == 0)
587 return GAA_NOT_AN_OPTION;
588 if(str[1] == '-')
590 if(str[2] != 0)
591 return GAA_WORD_OPTION;
592 else
593 return GAA_NOT_AN_OPTION;
595 if(str[2] == 0)
596 return GAA_LETTER_OPTION;
597 else
598 return GAA_MULTIPLE_OPTION;
601 static int gaa_get_option_num(char *str, int status)
603 switch(status)
605 case GAA_LETTER_OPTION:
606 GAA_CHECK1STR("d", GAAOPTID_debug);
607 GAA_CHECK1STR("", GAAOPTID_template);
608 GAA_CHECK1STR("", GAAOPTID_infile);
609 GAA_CHECK1STR("", GAAOPTID_outfile);
610 GAA_CHECK1STR("", GAAOPTID_bits);
611 GAA_CHECK1STR("", GAAOPTID_hash);
612 GAA_CHECK1STR("", GAAOPTID_password);
613 GAA_CHECK1STR("", GAAOPTID_load_ca_certificate);
614 GAA_CHECK1STR("", GAAOPTID_load_ca_privkey);
615 GAA_CHECK1STR("", GAAOPTID_load_certificate);
616 GAA_CHECK1STR("", GAAOPTID_load_request);
617 GAA_CHECK1STR("", GAAOPTID_load_privkey);
618 case GAA_MULTIPLE_OPTION:
619 #line 375 "gaa.skel"
620 GAA_CHECK1STR("v", GAAOPTID_version);
621 GAA_CHECK1STR("h", GAAOPTID_help);
622 GAA_CHECK1STR("", GAAOPTID_quick_random);
623 GAA_CHECK1STR("", GAAOPTID_outder);
624 GAA_CHECK1STR("", GAAOPTID_inder);
625 GAA_CHECK1STR("", GAAOPTID_export_ciphers);
626 GAA_CHECK1STR("", GAAOPTID_dsa);
627 GAA_CHECK1STR("8", GAAOPTID_pkcs8);
628 GAA_CHECK1STR("", GAAOPTID_to_p12);
629 GAA_CHECK1STR("", GAAOPTID_fix_key);
630 GAA_CHECK1STR("k", GAAOPTID_key_info);
631 GAA_CHECK1STR("", GAAOPTID_smime_to_p7);
632 GAA_CHECK1STR("", GAAOPTID_p7_info);
633 GAA_CHECK1STR("", GAAOPTID_p12_info);
634 GAA_CHECK1STR("l", GAAOPTID_crl_info);
635 GAA_CHECK1STR("i", GAAOPTID_certificate_info);
636 GAA_CHECK1STR("", GAAOPTID_get_dh_params);
637 GAA_CHECK1STR("", GAAOPTID_generate_dh_params);
638 GAA_CHECK1STR("", GAAOPTID_verify_crl);
639 GAA_CHECK1STR("e", GAAOPTID_verify_chain);
640 GAA_CHECK1STR("q", GAAOPTID_generate_request);
641 GAA_CHECK1STR("p", GAAOPTID_generate_privkey);
642 GAA_CHECK1STR("u", GAAOPTID_update_certificate);
643 GAA_CHECK1STR("", GAAOPTID_generate_crl);
644 GAA_CHECK1STR("", GAAOPTID_generate_proxy);
645 GAA_CHECK1STR("c", GAAOPTID_generate_certificate);
646 GAA_CHECK1STR("s", GAAOPTID_generate_self_signed);
648 #line 277 "gaa.skel"
649 break;
650 case GAA_WORD_OPTION:
651 GAA_CHECKSTR("version", GAAOPTID_version);
652 GAA_CHECKSTR("help", GAAOPTID_help);
653 GAA_CHECKSTR("debug", GAAOPTID_debug);
654 GAA_CHECKSTR("template", GAAOPTID_template);
655 GAA_CHECKSTR("infile", GAAOPTID_infile);
656 GAA_CHECKSTR("outfile", GAAOPTID_outfile);
657 GAA_CHECKSTR("quick-random", GAAOPTID_quick_random);
658 GAA_CHECKSTR("bits", GAAOPTID_bits);
659 GAA_CHECKSTR("outder", GAAOPTID_outder);
660 GAA_CHECKSTR("inder", GAAOPTID_inder);
661 GAA_CHECKSTR("export-ciphers", GAAOPTID_export_ciphers);
662 GAA_CHECKSTR("hash", GAAOPTID_hash);
663 GAA_CHECKSTR("dsa", GAAOPTID_dsa);
664 GAA_CHECKSTR("pkcs8", GAAOPTID_pkcs8);
665 GAA_CHECKSTR("to-p12", GAAOPTID_to_p12);
666 GAA_CHECKSTR("fix-key", GAAOPTID_fix_key);
667 GAA_CHECKSTR("key-info", GAAOPTID_key_info);
668 GAA_CHECKSTR("smime-to-p7", GAAOPTID_smime_to_p7);
669 GAA_CHECKSTR("p7-info", GAAOPTID_p7_info);
670 GAA_CHECKSTR("p12-info", GAAOPTID_p12_info);
671 GAA_CHECKSTR("crl-info", GAAOPTID_crl_info);
672 GAA_CHECKSTR("certificate-info", GAAOPTID_certificate_info);
673 GAA_CHECKSTR("password", GAAOPTID_password);
674 GAA_CHECKSTR("load-ca-certificate", GAAOPTID_load_ca_certificate);
675 GAA_CHECKSTR("load-ca-privkey", GAAOPTID_load_ca_privkey);
676 GAA_CHECKSTR("load-certificate", GAAOPTID_load_certificate);
677 GAA_CHECKSTR("load-request", GAAOPTID_load_request);
678 GAA_CHECKSTR("load-privkey", GAAOPTID_load_privkey);
679 GAA_CHECKSTR("get-dh-params", GAAOPTID_get_dh_params);
680 GAA_CHECKSTR("generate-dh-params", GAAOPTID_generate_dh_params);
681 GAA_CHECKSTR("verify-crl", GAAOPTID_verify_crl);
682 GAA_CHECKSTR("verify-chain", GAAOPTID_verify_chain);
683 GAA_CHECKSTR("generate-request", GAAOPTID_generate_request);
684 GAA_CHECKSTR("generate-privkey", GAAOPTID_generate_privkey);
685 GAA_CHECKSTR("update-certificate", GAAOPTID_update_certificate);
686 GAA_CHECKSTR("generate-crl", GAAOPTID_generate_crl);
687 GAA_CHECKSTR("generate-proxy", GAAOPTID_generate_proxy);
688 GAA_CHECKSTR("generate-certificate", GAAOPTID_generate_certificate);
689 GAA_CHECKSTR("generate-self-signed", GAAOPTID_generate_self_signed);
691 #line 281 "gaa.skel"
692 break;
693 default: break;
695 return GAA_ERROR_NOMATCH;
698 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
700 int OK = 0;
701 int gaa_last_non_option;
702 struct GAAOPTION_debug GAATMP_debug;
703 struct GAAOPTION_template GAATMP_template;
704 struct GAAOPTION_infile GAATMP_infile;
705 struct GAAOPTION_outfile GAATMP_outfile;
706 struct GAAOPTION_bits GAATMP_bits;
707 struct GAAOPTION_hash GAATMP_hash;
708 struct GAAOPTION_password GAATMP_password;
709 struct GAAOPTION_load_ca_certificate GAATMP_load_ca_certificate;
710 struct GAAOPTION_load_ca_privkey GAATMP_load_ca_privkey;
711 struct GAAOPTION_load_certificate GAATMP_load_certificate;
712 struct GAAOPTION_load_request GAATMP_load_request;
713 struct GAAOPTION_load_privkey GAATMP_load_privkey;
715 #line 393 "gaa.skel"
716 #ifdef GAA_REST_EXISTS
717 struct GAAREST GAAREST_tmp;
718 #endif
720 opt_list[gaa_num] = 1;
722 for(gaa_last_non_option = gaa_index;
723 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
724 gaa_last_non_option++);
726 if(gaa_num == GAA_REST)
728 gaa_index = 1;
729 gaa_last_non_option = GAAargc;
732 switch(gaa_num)
734 case GAAOPTID_version:
735 OK = 0;
736 #line 112 "certtool.gaa"
737 { certtool_version(); exit(0); ;};
739 return GAA_OK;
740 break;
741 case GAAOPTID_help:
742 OK = 0;
743 #line 110 "certtool.gaa"
744 { gaa_help(); exit(0); ;};
746 return GAA_OK;
747 break;
748 case GAAOPTID_debug:
749 OK = 0;
750 GAA_TESTMOREARGS;
751 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
752 gaa_index++;
753 #line 108 "certtool.gaa"
754 { gaaval->debug = GAATMP_debug.arg1 ;};
756 return GAA_OK;
757 break;
758 case GAAOPTID_template:
759 OK = 0;
760 GAA_TESTMOREARGS;
761 GAA_FILL(GAATMP_template.arg1, gaa_getstr, GAATMP_template.size1);
762 gaa_index++;
763 #line 104 "certtool.gaa"
764 { gaaval->template = GAATMP_template.arg1 ;};
766 return GAA_OK;
767 break;
768 case GAAOPTID_infile:
769 OK = 0;
770 GAA_TESTMOREARGS;
771 GAA_FILL(GAATMP_infile.arg1, gaa_getstr, GAATMP_infile.size1);
772 gaa_index++;
773 #line 101 "certtool.gaa"
774 { gaaval->infile = GAATMP_infile.arg1 ;};
776 return GAA_OK;
777 break;
778 case GAAOPTID_outfile:
779 OK = 0;
780 GAA_TESTMOREARGS;
781 GAA_FILL(GAATMP_outfile.arg1, gaa_getstr, GAATMP_outfile.size1);
782 gaa_index++;
783 #line 98 "certtool.gaa"
784 { gaaval->outfile = GAATMP_outfile.arg1 ;};
786 return GAA_OK;
787 break;
788 case GAAOPTID_quick_random:
789 OK = 0;
790 #line 95 "certtool.gaa"
791 { gaaval->quick_random = 1; ;};
793 return GAA_OK;
794 break;
795 case GAAOPTID_bits:
796 OK = 0;
797 GAA_TESTMOREARGS;
798 GAA_FILL(GAATMP_bits.arg1, gaa_getint, GAATMP_bits.size1);
799 gaa_index++;
800 #line 92 "certtool.gaa"
801 { gaaval->bits = GAATMP_bits.arg1 ;};
803 return GAA_OK;
804 break;
805 case GAAOPTID_outder:
806 OK = 0;
807 #line 89 "certtool.gaa"
808 { gaaval->outcert_format=1 ;};
810 return GAA_OK;
811 break;
812 case GAAOPTID_inder:
813 OK = 0;
814 #line 86 "certtool.gaa"
815 { gaaval->incert_format=1 ;};
817 return GAA_OK;
818 break;
819 case GAAOPTID_export_ciphers:
820 OK = 0;
821 #line 83 "certtool.gaa"
822 { gaaval->export=1 ;};
824 return GAA_OK;
825 break;
826 case GAAOPTID_hash:
827 OK = 0;
828 GAA_TESTMOREARGS;
829 GAA_FILL(GAATMP_hash.arg1, gaa_getstr, GAATMP_hash.size1);
830 gaa_index++;
831 #line 80 "certtool.gaa"
832 { gaaval->hash = GAATMP_hash.arg1 ;};
834 return GAA_OK;
835 break;
836 case GAAOPTID_dsa:
837 OK = 0;
838 #line 77 "certtool.gaa"
839 { gaaval->dsa=1 ;};
841 return GAA_OK;
842 break;
843 case GAAOPTID_pkcs8:
844 OK = 0;
845 #line 74 "certtool.gaa"
846 { gaaval->pkcs8=1 ;};
848 return GAA_OK;
849 break;
850 case GAAOPTID_to_p12:
851 OK = 0;
852 #line 71 "certtool.gaa"
853 { gaaval->action = 8; ;};
855 return GAA_OK;
856 break;
857 case GAAOPTID_fix_key:
858 OK = 0;
859 #line 69 "certtool.gaa"
860 { gaaval->fix_key = 1; ;};
862 return GAA_OK;
863 break;
864 case GAAOPTID_key_info:
865 OK = 0;
866 #line 66 "certtool.gaa"
867 { gaaval->action = 6; ;};
869 return GAA_OK;
870 break;
871 case GAAOPTID_smime_to_p7:
872 OK = 0;
873 #line 64 "certtool.gaa"
874 { gaaval->action = 15; ;};
876 return GAA_OK;
877 break;
878 case GAAOPTID_p7_info:
879 OK = 0;
880 #line 62 "certtool.gaa"
881 { gaaval->action = 12; ;};
883 return GAA_OK;
884 break;
885 case GAAOPTID_p12_info:
886 OK = 0;
887 #line 60 "certtool.gaa"
888 { gaaval->action = 9; ;};
890 return GAA_OK;
891 break;
892 case GAAOPTID_crl_info:
893 OK = 0;
894 #line 58 "certtool.gaa"
895 { gaaval->action = 11; ;};
897 return GAA_OK;
898 break;
899 case GAAOPTID_certificate_info:
900 OK = 0;
901 #line 56 "certtool.gaa"
902 { gaaval->action = 2; ;};
904 return GAA_OK;
905 break;
906 case GAAOPTID_password:
907 OK = 0;
908 GAA_TESTMOREARGS;
909 GAA_FILL(GAATMP_password.arg1, gaa_getstr, GAATMP_password.size1);
910 gaa_index++;
911 #line 54 "certtool.gaa"
912 { gaaval->pass = GAATMP_password.arg1 ;};
914 return GAA_OK;
915 break;
916 case GAAOPTID_load_ca_certificate:
917 OK = 0;
918 GAA_TESTMOREARGS;
919 GAA_FILL(GAATMP_load_ca_certificate.arg1, gaa_getstr, GAATMP_load_ca_certificate.size1);
920 gaa_index++;
921 #line 51 "certtool.gaa"
922 { gaaval->ca = GAATMP_load_ca_certificate.arg1 ;};
924 return GAA_OK;
925 break;
926 case GAAOPTID_load_ca_privkey:
927 OK = 0;
928 GAA_TESTMOREARGS;
929 GAA_FILL(GAATMP_load_ca_privkey.arg1, gaa_getstr, GAATMP_load_ca_privkey.size1);
930 gaa_index++;
931 #line 48 "certtool.gaa"
932 { gaaval->ca_privkey = GAATMP_load_ca_privkey.arg1 ;};
934 return GAA_OK;
935 break;
936 case GAAOPTID_load_certificate:
937 OK = 0;
938 GAA_TESTMOREARGS;
939 GAA_FILL(GAATMP_load_certificate.arg1, gaa_getstr, GAATMP_load_certificate.size1);
940 gaa_index++;
941 #line 45 "certtool.gaa"
942 { gaaval->cert = GAATMP_load_certificate.arg1 ;};
944 return GAA_OK;
945 break;
946 case GAAOPTID_load_request:
947 OK = 0;
948 GAA_TESTMOREARGS;
949 GAA_FILL(GAATMP_load_request.arg1, gaa_getstr, GAATMP_load_request.size1);
950 gaa_index++;
951 #line 42 "certtool.gaa"
952 { gaaval->request = GAATMP_load_request.arg1 ;};
954 return GAA_OK;
955 break;
956 case GAAOPTID_load_privkey:
957 OK = 0;
958 GAA_TESTMOREARGS;
959 GAA_FILL(GAATMP_load_privkey.arg1, gaa_getstr, GAATMP_load_privkey.size1);
960 gaa_index++;
961 #line 39 "certtool.gaa"
962 { gaaval->privkey = GAATMP_load_privkey.arg1 ;};
964 return GAA_OK;
965 break;
966 case GAAOPTID_get_dh_params:
967 OK = 0;
968 #line 36 "certtool.gaa"
969 { gaaval->action=16; ;};
971 return GAA_OK;
972 break;
973 case GAAOPTID_generate_dh_params:
974 OK = 0;
975 #line 35 "certtool.gaa"
976 { gaaval->action=10; ;};
978 return GAA_OK;
979 break;
980 case GAAOPTID_verify_crl:
981 OK = 0;
982 #line 33 "certtool.gaa"
983 { gaaval->action=14; ;};
985 return GAA_OK;
986 break;
987 case GAAOPTID_verify_chain:
988 OK = 0;
989 #line 31 "certtool.gaa"
990 { gaaval->action=5; ;};
992 return GAA_OK;
993 break;
994 case GAAOPTID_generate_request:
995 OK = 0;
996 #line 29 "certtool.gaa"
997 { gaaval->action=3; ;};
999 return GAA_OK;
1000 break;
1001 case GAAOPTID_generate_privkey:
1002 OK = 0;
1003 #line 27 "certtool.gaa"
1004 { gaaval->action=1; ;};
1006 return GAA_OK;
1007 break;
1008 case GAAOPTID_update_certificate:
1009 OK = 0;
1010 #line 25 "certtool.gaa"
1011 { gaaval->action=7; ;};
1013 return GAA_OK;
1014 break;
1015 case GAAOPTID_generate_crl:
1016 OK = 0;
1017 #line 23 "certtool.gaa"
1018 { gaaval->action=13; ;};
1020 return GAA_OK;
1021 break;
1022 case GAAOPTID_generate_proxy:
1023 OK = 0;
1024 #line 21 "certtool.gaa"
1025 { gaaval->action=17; ;};
1027 return GAA_OK;
1028 break;
1029 case GAAOPTID_generate_certificate:
1030 OK = 0;
1031 #line 19 "certtool.gaa"
1032 { gaaval->action=4; ;};
1034 return GAA_OK;
1035 break;
1036 case GAAOPTID_generate_self_signed:
1037 OK = 0;
1038 #line 17 "certtool.gaa"
1039 { gaaval->action=0; ;};
1041 return GAA_OK;
1042 break;
1044 #line 413 "gaa.skel"
1045 default: break;
1047 return GAA_ERROR_UNKNOWN;
1050 int gaa(int argc, char **argv, gaainfo *gaaval)
1052 int tmp1, tmp2;
1053 int i, j;
1054 char *opt_list;
1056 GAAargv = argv;
1057 GAAargc = argc;
1059 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1061 for(i = 0; i < GAA_NB_OPTION + 1; i++)
1062 opt_list[i] = 0;
1063 /* initialization */
1064 if(inited == 0)
1067 #line 114 "certtool.gaa"
1068 { gaaval->bits = 1024; gaaval->pkcs8 = 0; gaaval->privkey = NULL; gaaval->ca=NULL; gaaval->ca_privkey = NULL;
1069 gaaval->debug=1; gaaval->request = NULL; gaaval->infile = NULL; gaaval->outfile = NULL; gaaval->cert = NULL;
1070 gaaval->incert_format = 0; gaaval->outcert_format = 0; gaaval->action=-1; gaaval->pass = NULL;
1071 gaaval->export = 0; gaaval->template = NULL; gaaval->hash=NULL; gaaval->fix_key = 0; gaaval->quick_random=0; ;};
1074 inited = 1;
1075 #line 438 "gaa.skel"
1076 gaa_arg_used = NULL;
1078 if (argc > 0) {
1079 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1082 for(i = 1; i < argc; i++)
1083 gaa_arg_used[i] = 0;
1084 for(i = 1; i < argc; i++)
1086 if(gaa_arg_used[i] == 0)
1088 j = 0;
1089 tmp1 = gaa_is_an_argument(GAAargv[i]);
1090 switch(tmp1)
1092 case GAA_WORD_OPTION:
1093 j++;
1094 case GAA_LETTER_OPTION:
1095 j++;
1096 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1097 if(tmp2 == GAA_ERROR_NOMATCH)
1099 printf("Invalid option '%s'\n", argv[i]+j);
1100 return 0;
1102 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1104 case GAA_ERROR_NOTENOUGH_ARGS:
1105 printf("'%s': not enough arguments\n",gaa_current_option);
1106 return 0;
1107 case GAA_ERROR_INVALID_ARG:
1108 printf("Invalid arguments\n");
1109 return 0;
1110 case GAA_OK:
1111 break;
1112 default:
1113 printf("Unknown error\n");
1115 gaa_arg_used[i] = 1;
1116 break;
1117 case GAA_MULTIPLE_OPTION:
1118 for(j = 1; j < strlen(argv[i]); j++)
1120 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1121 if(tmp2 == GAA_ERROR_NOMATCH)
1123 printf("Invalid option '%c'\n", *(argv[i]+j));
1124 return 0;
1126 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1128 case GAA_ERROR_NOTENOUGH_ARGS:
1129 printf("'%s': not enough arguments\n",gaa_current_option);
1130 return 0;
1131 case GAA_ERROR_INVALID_ARG:
1132 printf("Invalid arguments\n");
1133 return 0;
1134 case GAA_OK:
1135 break;
1136 default:
1137 printf("Unknown error\n");
1140 gaa_arg_used[i] = 1;
1141 break;
1142 default: break;
1146 if(gaa_processing_file == 0)
1149 #line 507 "gaa.skel"
1150 #ifdef GAA_REST_EXISTS
1151 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1153 case GAA_ERROR_NOTENOUGH_ARGS:
1154 printf("Rest: not enough arguments\n");
1155 return 0;
1156 case GAA_ERROR_INVALID_ARG:
1157 printf("Invalid arguments\n");
1158 return 0;
1159 case GAA_OK:
1160 break;
1161 default:
1162 printf("Unknown error\n");
1164 #endif
1166 for(i = 1; i < argc; i++)
1168 if(gaa_arg_used[i] == 0)
1170 printf("Too many arguments\n");
1171 return 0;
1174 free(gaa_arg_used);
1175 free(opt_list);
1176 return -1;
1179 struct gaastrnode
1181 char *str;
1182 struct gaastrnode *next;
1185 typedef struct gaastrnode gaa_str_node;
1187 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1189 int pos_ini;
1190 int a;
1191 int i = 0, len = 0, newline = 0;
1193 if(argc == 1) {
1194 newline = 1;
1195 len = 2;
1198 a = fgetc( file);
1199 if (a == EOF) return 0;
1201 while(a == ' ' || a == 9 || a == '\n')
1203 if(a == '\n')
1205 newline=1;
1206 len = 2;
1208 a = fgetc( file);
1209 if (a == EOF) return 0;
1212 pos_ini = ftell(file) - 1;
1214 while(a != ' ' && a != 9 && a != '\n')
1217 len++;
1218 a = fgetc( file);
1219 if(a==EOF) return 0; //a = ' ';
1222 len += 1;
1223 tmp_str->str = gaa_malloc((len) * sizeof(char));
1225 if(newline == 1)
1227 tmp_str->str[0] = '-';
1228 tmp_str->str[1] = '-';
1229 i = 2;
1231 else
1233 i = 0;
1236 fseek(file,pos_ini, SEEK_SET);
1239 a = fgetc( file);
1241 if (a == EOF) {
1242 i+=2;
1243 break;
1245 tmp_str->str[i] = a;
1246 i++;
1248 while(a != ' ' && a != 9 && a != '\n' && i < len);
1250 tmp_str->str[i - 1] = 0;
1252 fseek(file,- 1, SEEK_CUR);
1253 /* printf("%d\n", ftell(file)); */
1255 return -1;
1258 int gaa_file(const char *name, gaainfo *gaaval)
1260 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1261 int rval, i;
1262 char **argv;
1263 int argc = 0;
1264 FILE *file;
1266 gaa_processing_file = 1;
1268 if((file = fopen(name, "r")) == NULL)
1270 printf("Couldn't open '%s' configuration file for reading\n", name);
1271 return 1;
1274 tmp_str = &first_str;
1277 argc++;
1278 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1280 (*tmp_str)->str = NULL;
1281 (*tmp_str)->next = NULL;
1283 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1284 tmp_str = &((*tmp_str)->next);
1286 while(rval == -1);
1288 if(rval == 1)
1289 return 0;
1291 argv = gaa_malloc((1 + argc) * sizeof(char*));
1293 tmp_str2 = first_str;
1294 argv[0] = "cfg";
1295 for(i = 1; i < argc; i++)
1297 argv[i] = tmp_str2->str;
1298 tmp_str2 = tmp_str2->next;
1301 rval = gaa(argc, argv, gaaval);
1302 gaa_processing_file = 0;
1303 return rval;