The test now works.
[gnutls.git] / src / certtool-gaa.c
blobbc0cdf0f3495525c0250ac17c24b34b7c3edbd18
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(0, "pgp-certificate-info", "", "Print information on a OpenPGP certificate.");
151 __gaa_helpsingle(0, "pgp-ring-info", "", "Print information on a keyring structure.");
152 __gaa_helpsingle('l', "crl-info", "", "Print information on a CRL.");
153 __gaa_helpsingle(0, "p12-info", "", "Print information on a PKCS #12 structure.");
154 __gaa_helpsingle(0, "p7-info", "", "Print information on a PKCS #7 structure.");
155 __gaa_helpsingle(0, "smime-to-p7", "", "Convert S/MIME to PKCS #7 structure.");
156 __gaa_helpsingle('k', "key-info", "", "Print information on a private key.");
157 __gaa_helpsingle(0, "pgp-key-info", "", "Print information on a OpenPGP private key.");
158 __gaa_helpsingle(0, "fix-key", "", "Regenerate the parameters in a private key.");
159 __gaa_helpsingle(0, "v1", "", "Generate an X.509 version 1 certificate (no extensions).");
160 __gaa_helpsingle(0, "to-p12", "", "Generate a PKCS #12 structure.");
161 __gaa_helpsingle(0, "to-p8", "", "Generate a PKCS #8 key structure.");
162 __gaa_helpsingle('8', "pkcs8", "", "Use PKCS #8 format for private keys.");
163 __gaa_helpsingle(0, "dsa", "", "Use DSA keys.");
164 __gaa_helpsingle(0, "hash", "STR ", "Hash algorithm to use for signing (MD5,SHA1,RMD160,SHA256,SHA384,SHA512).");
165 __gaa_helpsingle(0, "export-ciphers", "", "Use weak encryption algorithms.");
166 __gaa_helpsingle(0, "inder", "", "Use DER format for input certificates and private keys.");
167 __gaa_helpsingle(0, "inraw", "", "Use RAW/DER format for input certificates and private keys.");
168 __gaa_helpsingle(0, "outder", "", "Use DER format for output certificates and private keys.");
169 __gaa_helpsingle(0, "outraw", "", "Use RAW/DER format for output certificates and private keys.");
170 __gaa_helpsingle(0, "bits", "BITS ", "specify the number of bits for key generation.");
171 __gaa_helpsingle(0, "disable-quick-random", "", "Use /dev/random for key generationg, thus increasing the quality of randomness used.");
172 __gaa_helpsingle(0, "outfile", "FILE ", "Output file.");
173 __gaa_helpsingle(0, "infile", "FILE ", "Input file.");
174 __gaa_helpsingle(0, "template", "FILE ", "Template file to use for non interactive operation.");
175 __gaa_helpsingle('d', "debug", "LEVEL ", "specify the debug level. Default is 1.");
176 __gaa_helpsingle('h', "help", "", "shows this help text");
177 __gaa_helpsingle('v', "version", "", "shows the program's version");
179 #line 100 "gaa.skel"
181 /* Copy of C area */
183 #line 104 "gaa.skel"
184 /* GAA HEADER */
185 #ifndef GAA_HEADER_POKY
186 #define GAA_HEADER_POKY
188 typedef struct _gaainfo gaainfo;
190 struct _gaainfo
192 #line 123 "certtool.gaa"
193 int debug;
194 #line 119 "certtool.gaa"
195 char *template;
196 #line 116 "certtool.gaa"
197 char *infile;
198 #line 113 "certtool.gaa"
199 char *outfile;
200 #line 110 "certtool.gaa"
201 int quick_random;
202 #line 107 "certtool.gaa"
203 int bits;
204 #line 103 "certtool.gaa"
205 int outcert_format;
206 #line 99 "certtool.gaa"
207 int incert_format;
208 #line 96 "certtool.gaa"
209 int export;
210 #line 93 "certtool.gaa"
211 char *hash;
212 #line 90 "certtool.gaa"
213 int dsa;
214 #line 87 "certtool.gaa"
215 int pkcs8;
216 #line 80 "certtool.gaa"
217 int v1_cert;
218 #line 77 "certtool.gaa"
219 int fix_key;
220 #line 54 "certtool.gaa"
221 char *pass;
222 #line 51 "certtool.gaa"
223 char *ca;
224 #line 48 "certtool.gaa"
225 char *ca_privkey;
226 #line 45 "certtool.gaa"
227 char *cert;
228 #line 42 "certtool.gaa"
229 char *request;
230 #line 39 "certtool.gaa"
231 char *privkey;
232 #line 17 "certtool.gaa"
233 int action;
234 #line 16 "certtool.gaa"
235 int privkey_op;
237 #line 114 "gaa.skel"
240 #ifdef __cplusplus
241 extern "C"
243 #endif
245 int gaa(int argc, char *argv[], gaainfo *gaaval);
247 void gaa_help(void);
249 int gaa_file(const char *name, gaainfo *gaaval);
251 #ifdef __cplusplus
253 #endif
256 #endif
258 #line 135 "gaa.skel"
260 /* C declarations */
262 #define GAAERROR(x) \
264 gaa_error = 1; \
265 return x; \
268 static char *gaa_current_option;
269 static int gaa_error = 0;
271 /* Generated by gaa */
273 #include <string.h>
274 #include <stdlib.h>
277 #define GAA_OK -1
279 #define GAA_ERROR_NOMATCH 0
280 #define GAA_ERROR_NOTENOUGH_ARGS 1
281 #define GAA_ERROR_INVALID_ARG 2
282 #define GAA_ERROR_UNKNOWN 3
284 #define GAA_NOT_AN_OPTION 0
285 #define GAA_WORD_OPTION 1
286 #define GAA_LETTER_OPTION 2
287 #define GAA_MULTIPLE_OPTION 3
289 #define GAA_REST 0
290 #define GAA_NB_OPTION 46
291 #define GAAOPTID_version 1
292 #define GAAOPTID_help 2
293 #define GAAOPTID_debug 3
294 #define GAAOPTID_template 4
295 #define GAAOPTID_infile 5
296 #define GAAOPTID_outfile 6
297 #define GAAOPTID_disable_quick_random 7
298 #define GAAOPTID_bits 8
299 #define GAAOPTID_outraw 9
300 #define GAAOPTID_outder 10
301 #define GAAOPTID_inraw 11
302 #define GAAOPTID_inder 12
303 #define GAAOPTID_export_ciphers 13
304 #define GAAOPTID_hash 14
305 #define GAAOPTID_dsa 15
306 #define GAAOPTID_pkcs8 16
307 #define GAAOPTID_to_p8 17
308 #define GAAOPTID_to_p12 18
309 #define GAAOPTID_v1 19
310 #define GAAOPTID_fix_key 20
311 #define GAAOPTID_pgp_key_info 21
312 #define GAAOPTID_key_info 22
313 #define GAAOPTID_smime_to_p7 23
314 #define GAAOPTID_p7_info 24
315 #define GAAOPTID_p12_info 25
316 #define GAAOPTID_crl_info 26
317 #define GAAOPTID_pgp_ring_info 27
318 #define GAAOPTID_pgp_certificate_info 28
319 #define GAAOPTID_certificate_info 29
320 #define GAAOPTID_password 30
321 #define GAAOPTID_load_ca_certificate 31
322 #define GAAOPTID_load_ca_privkey 32
323 #define GAAOPTID_load_certificate 33
324 #define GAAOPTID_load_request 34
325 #define GAAOPTID_load_privkey 35
326 #define GAAOPTID_get_dh_params 36
327 #define GAAOPTID_generate_dh_params 37
328 #define GAAOPTID_verify_crl 38
329 #define GAAOPTID_verify_chain 39
330 #define GAAOPTID_generate_request 40
331 #define GAAOPTID_generate_privkey 41
332 #define GAAOPTID_update_certificate 42
333 #define GAAOPTID_generate_crl 43
334 #define GAAOPTID_generate_proxy 44
335 #define GAAOPTID_generate_certificate 45
336 #define GAAOPTID_generate_self_signed 46
338 #line 168 "gaa.skel"
340 #define GAA_CHECK1STR(a,b) \
341 if(a[0] == str[0]) \
343 gaa_current_option = a; \
344 return b; \
347 #define GAA_CHECKSTR(a,b) \
348 if(strcmp(a,str) == 0) \
350 gaa_current_option = a; \
351 return b; \
354 #define GAA_TESTMOREARGS \
355 if(!OK) \
357 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
358 gaa_index++; \
359 if(gaa_last_non_option == gaa_index) \
360 return GAA_ERROR_NOTENOUGH_ARGS; \
363 #define GAA_TESTMOREOPTIONALARGS \
364 if(!OK) \
366 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
367 gaa_index++; \
368 if(gaa_last_non_option == gaa_index) \
369 OK = 1; \
372 #define GAA_FILL_2ARGS(target, func) \
373 target = func(GAAargv[gaa_index]); \
374 gaa_arg_used[gaa_index] = 1; \
375 if(gaa_error == 1) \
377 gaa_error = 0; \
378 return GAA_ERROR_INVALID_ARG; \
383 #define GAA_FILL(target, func, num) \
384 if(!OK) \
386 target = func(GAAargv[gaa_index]); \
387 gaa_arg_used[gaa_index] = 1; \
388 if(gaa_error == 1) \
390 gaa_error = 0; \
391 return GAA_ERROR_INVALID_ARG; \
393 num = 1; \
395 else \
397 num = 0; \
400 #define GAA_LIST_FILL(target, func, type ,num) \
401 if(!OK) \
403 num = 0; \
404 target = NULL; \
405 if ( gaa_last_non_option - gaa_index > 0) \
406 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
407 for(; gaa_index < gaa_last_non_option; gaa_index++) \
409 if(gaa_arg_used[gaa_index] == 0) \
411 GAA_FILL_2ARGS(target[num], func); \
412 num++; \
415 if(num == 0) \
416 return GAA_ERROR_NOTENOUGH_ARGS; \
419 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
420 if(!OK) \
422 num = 0; \
423 target = NULL; \
424 if ( gaa_last_non_option - gaa_index > 0) \
425 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
426 for(; gaa_index < gaa_last_non_option; gaa_index++) \
428 if(gaa_arg_used[gaa_index] == 0) \
430 GAA_FILL_2ARGS(target[num], func); \
431 num++; \
436 #define GAA_OBLIGAT(str) \
437 k = 0; \
438 for(i = 0; i < strlen(str); i++) \
440 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
441 if(j == GAA_ERROR_NOMATCH) \
443 printf("Error: invalid 'obligat' set\n"); \
444 exit(-1); \
446 if(opt_list[j] == 1) \
447 k = 1; \
449 if(k == 0) \
451 if(strlen(str) == 1) \
452 printf("You must give the -%s option\n", str); \
453 else \
454 printf("You must give at least one option of '%s'\n", str); \
455 return 0; \
458 #define GAA_INCOMP(str) \
459 k = 0; \
460 for(i = 0; i < strlen(str); i++) \
462 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
463 if(j == GAA_ERROR_NOMATCH) \
465 printf("Error: invalid 'obligat' set\n"); \
466 exit(-1); \
468 if(opt_list[j] == 1) \
469 k++; \
471 if(k > 1) \
473 printf("The options '%s' are incompatible\n", str); \
474 return 0; \
478 static char **GAAargv;
479 static int GAAargc;
480 static char *gaa_arg_used;
481 static int gaa_processing_file = 0;
482 static int inited = 0;
484 static int gaa_getint(char *arg)
486 int tmp;
487 char a;
488 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
490 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
491 GAAERROR(-1);
493 return tmp;
496 static char gaa_getchar(char *arg)
498 if(strlen(arg) != 1)
500 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
501 GAAERROR(-1);
503 return arg[0];
506 static char* gaa_getstr(char *arg)
508 return arg;
510 static float gaa_getfloat(char *arg)
512 float tmp;
513 char a;
514 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
516 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
517 GAAERROR(-1);
519 return tmp;
521 /* option structures */
523 struct GAAOPTION_debug
525 int arg1;
526 int size1;
529 struct GAAOPTION_template
531 char* arg1;
532 int size1;
535 struct GAAOPTION_infile
537 char* arg1;
538 int size1;
541 struct GAAOPTION_outfile
543 char* arg1;
544 int size1;
547 struct GAAOPTION_bits
549 int arg1;
550 int size1;
553 struct GAAOPTION_hash
555 char* arg1;
556 int size1;
559 struct GAAOPTION_password
561 char* arg1;
562 int size1;
565 struct GAAOPTION_load_ca_certificate
567 char* arg1;
568 int size1;
571 struct GAAOPTION_load_ca_privkey
573 char* arg1;
574 int size1;
577 struct GAAOPTION_load_certificate
579 char* arg1;
580 int size1;
583 struct GAAOPTION_load_request
585 char* arg1;
586 int size1;
589 struct GAAOPTION_load_privkey
591 char* arg1;
592 int size1;
595 #line 349 "gaa.skel"
596 static int gaa_is_an_argument(char *str)
598 #ifdef GAA_WIN32
599 if(str[0] == '/' && str[1] != 0)
600 return GAA_MULTIPLE_OPTION;
601 #endif
602 if(str[0] != '-')
603 return GAA_NOT_AN_OPTION;
604 if(str[1] == 0)
605 return GAA_NOT_AN_OPTION;
606 if(str[1] == '-')
608 if(str[2] != 0)
609 return GAA_WORD_OPTION;
610 else
611 return GAA_NOT_AN_OPTION;
613 if(str[2] == 0)
614 return GAA_LETTER_OPTION;
615 else
616 return GAA_MULTIPLE_OPTION;
619 static int gaa_get_option_num(char *str, int status)
621 switch(status)
623 case GAA_LETTER_OPTION:
624 GAA_CHECK1STR("d", GAAOPTID_debug);
625 GAA_CHECK1STR("", GAAOPTID_template);
626 GAA_CHECK1STR("", GAAOPTID_infile);
627 GAA_CHECK1STR("", GAAOPTID_outfile);
628 GAA_CHECK1STR("", GAAOPTID_bits);
629 GAA_CHECK1STR("", GAAOPTID_hash);
630 GAA_CHECK1STR("", GAAOPTID_password);
631 GAA_CHECK1STR("", GAAOPTID_load_ca_certificate);
632 GAA_CHECK1STR("", GAAOPTID_load_ca_privkey);
633 GAA_CHECK1STR("", GAAOPTID_load_certificate);
634 GAA_CHECK1STR("", GAAOPTID_load_request);
635 GAA_CHECK1STR("", GAAOPTID_load_privkey);
636 case GAA_MULTIPLE_OPTION:
637 #line 375 "gaa.skel"
638 GAA_CHECK1STR("v", GAAOPTID_version);
639 GAA_CHECK1STR("h", GAAOPTID_help);
640 GAA_CHECK1STR("", GAAOPTID_disable_quick_random);
641 GAA_CHECK1STR("", GAAOPTID_outraw);
642 GAA_CHECK1STR("", GAAOPTID_outder);
643 GAA_CHECK1STR("", GAAOPTID_inraw);
644 GAA_CHECK1STR("", GAAOPTID_inder);
645 GAA_CHECK1STR("", GAAOPTID_export_ciphers);
646 GAA_CHECK1STR("", GAAOPTID_dsa);
647 GAA_CHECK1STR("8", GAAOPTID_pkcs8);
648 GAA_CHECK1STR("", GAAOPTID_to_p8);
649 GAA_CHECK1STR("", GAAOPTID_to_p12);
650 GAA_CHECK1STR("", GAAOPTID_v1);
651 GAA_CHECK1STR("", GAAOPTID_fix_key);
652 GAA_CHECK1STR("", GAAOPTID_pgp_key_info);
653 GAA_CHECK1STR("k", GAAOPTID_key_info);
654 GAA_CHECK1STR("", GAAOPTID_smime_to_p7);
655 GAA_CHECK1STR("", GAAOPTID_p7_info);
656 GAA_CHECK1STR("", GAAOPTID_p12_info);
657 GAA_CHECK1STR("l", GAAOPTID_crl_info);
658 GAA_CHECK1STR("", GAAOPTID_pgp_ring_info);
659 GAA_CHECK1STR("", GAAOPTID_pgp_certificate_info);
660 GAA_CHECK1STR("i", GAAOPTID_certificate_info);
661 GAA_CHECK1STR("", GAAOPTID_get_dh_params);
662 GAA_CHECK1STR("", GAAOPTID_generate_dh_params);
663 GAA_CHECK1STR("", GAAOPTID_verify_crl);
664 GAA_CHECK1STR("e", GAAOPTID_verify_chain);
665 GAA_CHECK1STR("q", GAAOPTID_generate_request);
666 GAA_CHECK1STR("p", GAAOPTID_generate_privkey);
667 GAA_CHECK1STR("u", GAAOPTID_update_certificate);
668 GAA_CHECK1STR("", GAAOPTID_generate_crl);
669 GAA_CHECK1STR("", GAAOPTID_generate_proxy);
670 GAA_CHECK1STR("c", GAAOPTID_generate_certificate);
671 GAA_CHECK1STR("s", GAAOPTID_generate_self_signed);
673 #line 277 "gaa.skel"
674 break;
675 case GAA_WORD_OPTION:
676 GAA_CHECKSTR("version", GAAOPTID_version);
677 GAA_CHECKSTR("help", GAAOPTID_help);
678 GAA_CHECKSTR("debug", GAAOPTID_debug);
679 GAA_CHECKSTR("template", GAAOPTID_template);
680 GAA_CHECKSTR("infile", GAAOPTID_infile);
681 GAA_CHECKSTR("outfile", GAAOPTID_outfile);
682 GAA_CHECKSTR("disable-quick-random", GAAOPTID_disable_quick_random);
683 GAA_CHECKSTR("bits", GAAOPTID_bits);
684 GAA_CHECKSTR("outraw", GAAOPTID_outraw);
685 GAA_CHECKSTR("outder", GAAOPTID_outder);
686 GAA_CHECKSTR("inraw", GAAOPTID_inraw);
687 GAA_CHECKSTR("inder", GAAOPTID_inder);
688 GAA_CHECKSTR("export-ciphers", GAAOPTID_export_ciphers);
689 GAA_CHECKSTR("hash", GAAOPTID_hash);
690 GAA_CHECKSTR("dsa", GAAOPTID_dsa);
691 GAA_CHECKSTR("pkcs8", GAAOPTID_pkcs8);
692 GAA_CHECKSTR("to-p8", GAAOPTID_to_p8);
693 GAA_CHECKSTR("to-p12", GAAOPTID_to_p12);
694 GAA_CHECKSTR("v1", GAAOPTID_v1);
695 GAA_CHECKSTR("fix-key", GAAOPTID_fix_key);
696 GAA_CHECKSTR("pgp-key-info", GAAOPTID_pgp_key_info);
697 GAA_CHECKSTR("key-info", GAAOPTID_key_info);
698 GAA_CHECKSTR("smime-to-p7", GAAOPTID_smime_to_p7);
699 GAA_CHECKSTR("p7-info", GAAOPTID_p7_info);
700 GAA_CHECKSTR("p12-info", GAAOPTID_p12_info);
701 GAA_CHECKSTR("crl-info", GAAOPTID_crl_info);
702 GAA_CHECKSTR("pgp-ring-info", GAAOPTID_pgp_ring_info);
703 GAA_CHECKSTR("pgp-certificate-info", GAAOPTID_pgp_certificate_info);
704 GAA_CHECKSTR("certificate-info", GAAOPTID_certificate_info);
705 GAA_CHECKSTR("password", GAAOPTID_password);
706 GAA_CHECKSTR("load-ca-certificate", GAAOPTID_load_ca_certificate);
707 GAA_CHECKSTR("load-ca-privkey", GAAOPTID_load_ca_privkey);
708 GAA_CHECKSTR("load-certificate", GAAOPTID_load_certificate);
709 GAA_CHECKSTR("load-request", GAAOPTID_load_request);
710 GAA_CHECKSTR("load-privkey", GAAOPTID_load_privkey);
711 GAA_CHECKSTR("get-dh-params", GAAOPTID_get_dh_params);
712 GAA_CHECKSTR("generate-dh-params", GAAOPTID_generate_dh_params);
713 GAA_CHECKSTR("verify-crl", GAAOPTID_verify_crl);
714 GAA_CHECKSTR("verify-chain", GAAOPTID_verify_chain);
715 GAA_CHECKSTR("generate-request", GAAOPTID_generate_request);
716 GAA_CHECKSTR("generate-privkey", GAAOPTID_generate_privkey);
717 GAA_CHECKSTR("update-certificate", GAAOPTID_update_certificate);
718 GAA_CHECKSTR("generate-crl", GAAOPTID_generate_crl);
719 GAA_CHECKSTR("generate-proxy", GAAOPTID_generate_proxy);
720 GAA_CHECKSTR("generate-certificate", GAAOPTID_generate_certificate);
721 GAA_CHECKSTR("generate-self-signed", GAAOPTID_generate_self_signed);
723 #line 281 "gaa.skel"
724 break;
725 default: break;
727 return GAA_ERROR_NOMATCH;
730 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
732 int OK = 0;
733 int gaa_last_non_option;
734 struct GAAOPTION_debug GAATMP_debug;
735 struct GAAOPTION_template GAATMP_template;
736 struct GAAOPTION_infile GAATMP_infile;
737 struct GAAOPTION_outfile GAATMP_outfile;
738 struct GAAOPTION_bits GAATMP_bits;
739 struct GAAOPTION_hash GAATMP_hash;
740 struct GAAOPTION_password GAATMP_password;
741 struct GAAOPTION_load_ca_certificate GAATMP_load_ca_certificate;
742 struct GAAOPTION_load_ca_privkey GAATMP_load_ca_privkey;
743 struct GAAOPTION_load_certificate GAATMP_load_certificate;
744 struct GAAOPTION_load_request GAATMP_load_request;
745 struct GAAOPTION_load_privkey GAATMP_load_privkey;
747 #line 393 "gaa.skel"
748 #ifdef GAA_REST_EXISTS
749 struct GAAREST GAAREST_tmp;
750 #endif
752 opt_list[gaa_num] = 1;
754 for(gaa_last_non_option = gaa_index;
755 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
756 gaa_last_non_option++);
758 if(gaa_num == GAA_REST)
760 gaa_index = 1;
761 gaa_last_non_option = GAAargc;
764 switch(gaa_num)
766 case GAAOPTID_version:
767 OK = 0;
768 #line 128 "certtool.gaa"
769 { certtool_version(); exit(0); ;};
771 return GAA_OK;
772 break;
773 case GAAOPTID_help:
774 OK = 0;
775 #line 126 "certtool.gaa"
776 { gaa_help(); exit(0); ;};
778 return GAA_OK;
779 break;
780 case GAAOPTID_debug:
781 OK = 0;
782 GAA_TESTMOREARGS;
783 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
784 gaa_index++;
785 #line 124 "certtool.gaa"
786 { gaaval->debug = GAATMP_debug.arg1 ;};
788 return GAA_OK;
789 break;
790 case GAAOPTID_template:
791 OK = 0;
792 GAA_TESTMOREARGS;
793 GAA_FILL(GAATMP_template.arg1, gaa_getstr, GAATMP_template.size1);
794 gaa_index++;
795 #line 120 "certtool.gaa"
796 { gaaval->template = GAATMP_template.arg1 ;};
798 return GAA_OK;
799 break;
800 case GAAOPTID_infile:
801 OK = 0;
802 GAA_TESTMOREARGS;
803 GAA_FILL(GAATMP_infile.arg1, gaa_getstr, GAATMP_infile.size1);
804 gaa_index++;
805 #line 117 "certtool.gaa"
806 { gaaval->infile = GAATMP_infile.arg1 ;};
808 return GAA_OK;
809 break;
810 case GAAOPTID_outfile:
811 OK = 0;
812 GAA_TESTMOREARGS;
813 GAA_FILL(GAATMP_outfile.arg1, gaa_getstr, GAATMP_outfile.size1);
814 gaa_index++;
815 #line 114 "certtool.gaa"
816 { gaaval->outfile = GAATMP_outfile.arg1 ;};
818 return GAA_OK;
819 break;
820 case GAAOPTID_disable_quick_random:
821 OK = 0;
822 #line 111 "certtool.gaa"
823 { gaaval->quick_random = 0; ;};
825 return GAA_OK;
826 break;
827 case GAAOPTID_bits:
828 OK = 0;
829 GAA_TESTMOREARGS;
830 GAA_FILL(GAATMP_bits.arg1, gaa_getint, GAATMP_bits.size1);
831 gaa_index++;
832 #line 108 "certtool.gaa"
833 { gaaval->bits = GAATMP_bits.arg1 ;};
835 return GAA_OK;
836 break;
837 case GAAOPTID_outraw:
838 OK = 0;
839 #line 105 "certtool.gaa"
840 { gaaval->outcert_format=1 ;};
842 return GAA_OK;
843 break;
844 case GAAOPTID_outder:
845 OK = 0;
846 #line 104 "certtool.gaa"
847 { gaaval->outcert_format=1 ;};
849 return GAA_OK;
850 break;
851 case GAAOPTID_inraw:
852 OK = 0;
853 #line 101 "certtool.gaa"
854 { gaaval->incert_format=1 ;};
856 return GAA_OK;
857 break;
858 case GAAOPTID_inder:
859 OK = 0;
860 #line 100 "certtool.gaa"
861 { gaaval->incert_format=1 ;};
863 return GAA_OK;
864 break;
865 case GAAOPTID_export_ciphers:
866 OK = 0;
867 #line 97 "certtool.gaa"
868 { gaaval->export=1 ;};
870 return GAA_OK;
871 break;
872 case GAAOPTID_hash:
873 OK = 0;
874 GAA_TESTMOREARGS;
875 GAA_FILL(GAATMP_hash.arg1, gaa_getstr, GAATMP_hash.size1);
876 gaa_index++;
877 #line 94 "certtool.gaa"
878 { gaaval->hash = GAATMP_hash.arg1 ;};
880 return GAA_OK;
881 break;
882 case GAAOPTID_dsa:
883 OK = 0;
884 #line 91 "certtool.gaa"
885 { gaaval->dsa=1 ;};
887 return GAA_OK;
888 break;
889 case GAAOPTID_pkcs8:
890 OK = 0;
891 #line 88 "certtool.gaa"
892 { gaaval->pkcs8=1 ;};
894 return GAA_OK;
895 break;
896 case GAAOPTID_to_p8:
897 OK = 0;
898 #line 85 "certtool.gaa"
899 { gaaval->action = 18; ;};
901 return GAA_OK;
902 break;
903 case GAAOPTID_to_p12:
904 OK = 0;
905 #line 83 "certtool.gaa"
906 { gaaval->action = 8; ;};
908 return GAA_OK;
909 break;
910 case GAAOPTID_v1:
911 OK = 0;
912 #line 81 "certtool.gaa"
913 { gaaval->v1_cert = 1; ;};
915 return GAA_OK;
916 break;
917 case GAAOPTID_fix_key:
918 OK = 0;
919 #line 78 "certtool.gaa"
920 { gaaval->privkey_op=1; gaaval->fix_key = 1; ;};
922 return GAA_OK;
923 break;
924 case GAAOPTID_pgp_key_info:
925 OK = 0;
926 #line 75 "certtool.gaa"
927 { gaaval->privkey_op=1; gaaval->action = 20; ;};
929 return GAA_OK;
930 break;
931 case GAAOPTID_key_info:
932 OK = 0;
933 #line 73 "certtool.gaa"
934 { gaaval->privkey_op=1; gaaval->action = 6; ;};
936 return GAA_OK;
937 break;
938 case GAAOPTID_smime_to_p7:
939 OK = 0;
940 #line 69 "certtool.gaa"
941 { gaaval->action = 15; ;};
943 return GAA_OK;
944 break;
945 case GAAOPTID_p7_info:
946 OK = 0;
947 #line 67 "certtool.gaa"
948 { gaaval->action = 12; ;};
950 return GAA_OK;
951 break;
952 case GAAOPTID_p12_info:
953 OK = 0;
954 #line 65 "certtool.gaa"
955 { gaaval->action = 9; ;};
957 return GAA_OK;
958 break;
959 case GAAOPTID_crl_info:
960 OK = 0;
961 #line 63 "certtool.gaa"
962 { gaaval->action = 11; ;};
964 return GAA_OK;
965 break;
966 case GAAOPTID_pgp_ring_info:
967 OK = 0;
968 #line 61 "certtool.gaa"
969 { gaaval->action = 21; ;};
971 return GAA_OK;
972 break;
973 case GAAOPTID_pgp_certificate_info:
974 OK = 0;
975 #line 59 "certtool.gaa"
976 { gaaval->action = 19; ;};
978 return GAA_OK;
979 break;
980 case GAAOPTID_certificate_info:
981 OK = 0;
982 #line 57 "certtool.gaa"
983 { gaaval->action = 2; ;};
985 return GAA_OK;
986 break;
987 case GAAOPTID_password:
988 OK = 0;
989 GAA_TESTMOREARGS;
990 GAA_FILL(GAATMP_password.arg1, gaa_getstr, GAATMP_password.size1);
991 gaa_index++;
992 #line 55 "certtool.gaa"
993 { gaaval->pass = GAATMP_password.arg1 ;};
995 return GAA_OK;
996 break;
997 case GAAOPTID_load_ca_certificate:
998 OK = 0;
999 GAA_TESTMOREARGS;
1000 GAA_FILL(GAATMP_load_ca_certificate.arg1, gaa_getstr, GAATMP_load_ca_certificate.size1);
1001 gaa_index++;
1002 #line 52 "certtool.gaa"
1003 { gaaval->ca = GAATMP_load_ca_certificate.arg1 ;};
1005 return GAA_OK;
1006 break;
1007 case GAAOPTID_load_ca_privkey:
1008 OK = 0;
1009 GAA_TESTMOREARGS;
1010 GAA_FILL(GAATMP_load_ca_privkey.arg1, gaa_getstr, GAATMP_load_ca_privkey.size1);
1011 gaa_index++;
1012 #line 49 "certtool.gaa"
1013 { gaaval->ca_privkey = GAATMP_load_ca_privkey.arg1 ;};
1015 return GAA_OK;
1016 break;
1017 case GAAOPTID_load_certificate:
1018 OK = 0;
1019 GAA_TESTMOREARGS;
1020 GAA_FILL(GAATMP_load_certificate.arg1, gaa_getstr, GAATMP_load_certificate.size1);
1021 gaa_index++;
1022 #line 46 "certtool.gaa"
1023 { gaaval->cert = GAATMP_load_certificate.arg1 ;};
1025 return GAA_OK;
1026 break;
1027 case GAAOPTID_load_request:
1028 OK = 0;
1029 GAA_TESTMOREARGS;
1030 GAA_FILL(GAATMP_load_request.arg1, gaa_getstr, GAATMP_load_request.size1);
1031 gaa_index++;
1032 #line 43 "certtool.gaa"
1033 { gaaval->request = GAATMP_load_request.arg1 ;};
1035 return GAA_OK;
1036 break;
1037 case GAAOPTID_load_privkey:
1038 OK = 0;
1039 GAA_TESTMOREARGS;
1040 GAA_FILL(GAATMP_load_privkey.arg1, gaa_getstr, GAATMP_load_privkey.size1);
1041 gaa_index++;
1042 #line 40 "certtool.gaa"
1043 { gaaval->privkey = GAATMP_load_privkey.arg1 ;};
1045 return GAA_OK;
1046 break;
1047 case GAAOPTID_get_dh_params:
1048 OK = 0;
1049 #line 37 "certtool.gaa"
1050 { gaaval->action=16; ;};
1052 return GAA_OK;
1053 break;
1054 case GAAOPTID_generate_dh_params:
1055 OK = 0;
1056 #line 36 "certtool.gaa"
1057 { gaaval->action=10; ;};
1059 return GAA_OK;
1060 break;
1061 case GAAOPTID_verify_crl:
1062 OK = 0;
1063 #line 34 "certtool.gaa"
1064 { gaaval->action=14; ;};
1066 return GAA_OK;
1067 break;
1068 case GAAOPTID_verify_chain:
1069 OK = 0;
1070 #line 32 "certtool.gaa"
1071 { gaaval->action=5; ;};
1073 return GAA_OK;
1074 break;
1075 case GAAOPTID_generate_request:
1076 OK = 0;
1077 #line 30 "certtool.gaa"
1078 { gaaval->action=3; ;};
1080 return GAA_OK;
1081 break;
1082 case GAAOPTID_generate_privkey:
1083 OK = 0;
1084 #line 28 "certtool.gaa"
1085 { gaaval->privkey_op=1; gaaval->action=1; ;};
1087 return GAA_OK;
1088 break;
1089 case GAAOPTID_update_certificate:
1090 OK = 0;
1091 #line 26 "certtool.gaa"
1092 { gaaval->action=7; ;};
1094 return GAA_OK;
1095 break;
1096 case GAAOPTID_generate_crl:
1097 OK = 0;
1098 #line 24 "certtool.gaa"
1099 { gaaval->action=13; ;};
1101 return GAA_OK;
1102 break;
1103 case GAAOPTID_generate_proxy:
1104 OK = 0;
1105 #line 22 "certtool.gaa"
1106 { gaaval->action=17; ;};
1108 return GAA_OK;
1109 break;
1110 case GAAOPTID_generate_certificate:
1111 OK = 0;
1112 #line 20 "certtool.gaa"
1113 { gaaval->action=4; ;};
1115 return GAA_OK;
1116 break;
1117 case GAAOPTID_generate_self_signed:
1118 OK = 0;
1119 #line 18 "certtool.gaa"
1120 { gaaval->action=0; ;};
1122 return GAA_OK;
1123 break;
1125 #line 413 "gaa.skel"
1126 default: break;
1128 return GAA_ERROR_UNKNOWN;
1131 int gaa(int argc, char **argv, gaainfo *gaaval)
1133 int tmp1, tmp2;
1134 int i, j;
1135 char *opt_list;
1137 GAAargv = argv;
1138 GAAargc = argc;
1140 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1142 for(i = 0; i < GAA_NB_OPTION + 1; i++)
1143 opt_list[i] = 0;
1144 /* initialization */
1145 if(inited == 0)
1148 #line 130 "certtool.gaa"
1149 { gaaval->bits = 2048; gaaval->pkcs8 = 0; gaaval->privkey = NULL; gaaval->ca=NULL; gaaval->ca_privkey = NULL;
1150 gaaval->debug=1; gaaval->request = NULL; gaaval->infile = NULL; gaaval->outfile = NULL; gaaval->cert = NULL;
1151 gaaval->incert_format = 0; gaaval->outcert_format = 0; gaaval->action=-1; gaaval->pass = NULL; gaaval->v1_cert = 0;
1152 gaaval->export = 0; gaaval->template = NULL; gaaval->hash=NULL; gaaval->fix_key = 0; gaaval->quick_random=1;
1153 gaaval->privkey_op = 0; ;};
1156 inited = 1;
1157 #line 438 "gaa.skel"
1158 gaa_arg_used = NULL;
1160 if (argc > 0) {
1161 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1164 for(i = 1; i < argc; i++)
1165 gaa_arg_used[i] = 0;
1166 for(i = 1; i < argc; i++)
1168 if(gaa_arg_used[i] == 0)
1170 j = 0;
1171 tmp1 = gaa_is_an_argument(GAAargv[i]);
1172 switch(tmp1)
1174 case GAA_WORD_OPTION:
1175 j++;
1176 case GAA_LETTER_OPTION:
1177 j++;
1178 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1179 if(tmp2 == GAA_ERROR_NOMATCH)
1181 printf("Invalid option '%s'\n", argv[i]+j);
1182 return 0;
1184 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1186 case GAA_ERROR_NOTENOUGH_ARGS:
1187 printf("'%s': not enough arguments\n",gaa_current_option);
1188 return 0;
1189 case GAA_ERROR_INVALID_ARG:
1190 printf("Invalid arguments\n");
1191 return 0;
1192 case GAA_OK:
1193 break;
1194 default:
1195 printf("Unknown error\n");
1197 gaa_arg_used[i] = 1;
1198 break;
1199 case GAA_MULTIPLE_OPTION:
1200 for(j = 1; j < strlen(argv[i]); j++)
1202 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1203 if(tmp2 == GAA_ERROR_NOMATCH)
1205 printf("Invalid option '%c'\n", *(argv[i]+j));
1206 return 0;
1208 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1210 case GAA_ERROR_NOTENOUGH_ARGS:
1211 printf("'%s': not enough arguments\n",gaa_current_option);
1212 return 0;
1213 case GAA_ERROR_INVALID_ARG:
1214 printf("Invalid arguments\n");
1215 return 0;
1216 case GAA_OK:
1217 break;
1218 default:
1219 printf("Unknown error\n");
1222 gaa_arg_used[i] = 1;
1223 break;
1224 default: break;
1228 if(gaa_processing_file == 0)
1231 #line 507 "gaa.skel"
1232 #ifdef GAA_REST_EXISTS
1233 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1235 case GAA_ERROR_NOTENOUGH_ARGS:
1236 printf("Rest: not enough arguments\n");
1237 return 0;
1238 case GAA_ERROR_INVALID_ARG:
1239 printf("Invalid arguments\n");
1240 return 0;
1241 case GAA_OK:
1242 break;
1243 default:
1244 printf("Unknown error\n");
1246 #endif
1248 for(i = 1; i < argc; i++)
1250 if(gaa_arg_used[i] == 0)
1252 printf("Too many arguments\n");
1253 return 0;
1256 free(gaa_arg_used);
1257 free(opt_list);
1258 return -1;
1261 struct gaastrnode
1263 char *str;
1264 struct gaastrnode *next;
1267 typedef struct gaastrnode gaa_str_node;
1269 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1271 int pos_ini;
1272 int a;
1273 int i = 0, len = 0, newline = 0;
1275 if(argc == 1) {
1276 newline = 1;
1277 len = 2;
1280 a = fgetc( file);
1281 if (a == EOF) return 0;
1283 while(a == ' ' || a == 9 || a == '\n')
1285 if(a == '\n')
1287 newline=1;
1288 len = 2;
1290 a = fgetc( file);
1291 if (a == EOF) return 0;
1294 pos_ini = ftell(file) - 1;
1296 while(a != ' ' && a != 9 && a != '\n')
1299 len++;
1300 a = fgetc( file);
1301 if(a==EOF) return 0; //a = ' ';
1304 len += 1;
1305 tmp_str->str = gaa_malloc((len) * sizeof(char));
1307 if(newline == 1)
1309 tmp_str->str[0] = '-';
1310 tmp_str->str[1] = '-';
1311 i = 2;
1313 else
1315 i = 0;
1318 fseek(file,pos_ini, SEEK_SET);
1321 a = fgetc( file);
1323 if (a == EOF) {
1324 i+=2;
1325 break;
1327 tmp_str->str[i] = a;
1328 i++;
1330 while(a != ' ' && a != 9 && a != '\n' && i < len);
1332 tmp_str->str[i - 1] = 0;
1334 fseek(file,- 1, SEEK_CUR);
1335 /* printf("%d\n", ftell(file)); */
1337 return -1;
1340 int gaa_file(const char *name, gaainfo *gaaval)
1342 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1343 int rval, i;
1344 char **argv;
1345 int argc = 0;
1346 FILE *file;
1348 gaa_processing_file = 1;
1350 if((file = fopen(name, "r")) == NULL)
1352 printf("Couldn't open '%s' configuration file for reading\n", name);
1353 return 1;
1356 tmp_str = &first_str;
1359 argc++;
1360 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1362 (*tmp_str)->str = NULL;
1363 (*tmp_str)->next = NULL;
1365 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1366 tmp_str = &((*tmp_str)->next);
1368 while(rval == -1);
1370 if(rval == 1)
1371 return 0;
1373 argv = gaa_malloc((1 + argc) * sizeof(char*));
1375 tmp_str2 = first_str;
1376 argv[0] = "cfg";
1377 for(i = 1; i < argc; i++)
1379 argv[i] = tmp_str2->str;
1380 tmp_str2 = tmp_str2->next;
1383 rval = gaa(argc, argv, gaaval);
1384 gaa_processing_file = 0;
1385 return rval;