1 /* File generated by GAA 1.6.6
14 void certtool_version(void);
21 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
26 static void* gaa_malloc( size_t size
) {
30 fprintf(stderr
, "gaa: could not allocate memory");
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
;
42 col1
= 5; /* Default values */
47 for(i
= 0; i
< col1
; i
++)
56 printf("-%c, ", short_name
);
61 printf("-%c ", short_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
);
80 if(opt_help
) /* let's print the option's help body */
82 const char *str
= opt_help
;
102 while((curr
- col3
) % tabsize
!= 0 && curr
< col4
);
109 for(i
= 1; str
[i
] && str
[i
] != ' ' && str
[i
] != '\n'
110 && str
[i
] != '\t'; i
++);
111 if(curr
+ i
- 1 >= col4
)
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");
178 #ifndef GAA_HEADER_POKY
179 #define GAA_HEADER_POKY
181 typedef struct _gaainfo gaainfo
;
185 #line 107 "certtool.gaa"
187 #line 103 "certtool.gaa"
189 #line 100 "certtool.gaa"
191 #line 97 "certtool.gaa"
193 #line 94 "certtool.gaa"
195 #line 91 "certtool.gaa"
197 #line 88 "certtool.gaa"
199 #line 85 "certtool.gaa"
201 #line 82 "certtool.gaa"
203 #line 79 "certtool.gaa"
205 #line 76 "certtool.gaa"
207 #line 73 "certtool.gaa"
209 #line 68 "certtool.gaa"
211 #line 53 "certtool.gaa"
213 #line 50 "certtool.gaa"
215 #line 47 "certtool.gaa"
217 #line 44 "certtool.gaa"
219 #line 41 "certtool.gaa"
221 #line 38 "certtool.gaa"
223 #line 16 "certtool.gaa"
234 int gaa(int argc
, char *argv
[], gaainfo
*gaaval
);
238 int gaa_file(const char *name
, gaainfo
*gaaval
);
251 #define GAAERROR(x) \
257 static char *gaa_current_option
;
258 static int gaa_error
= 0;
260 /* Generated by gaa */
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
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
322 #define GAA_CHECK1STR(a,b) \
325 gaa_current_option = a; \
329 #define GAA_CHECKSTR(a,b) \
330 if(strcmp(a,str) == 0) \
332 gaa_current_option = a; \
336 #define GAA_TESTMOREARGS \
339 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
341 if(gaa_last_non_option == gaa_index) \
342 return GAA_ERROR_NOTENOUGH_ARGS; \
345 #define GAA_TESTMOREOPTIONALARGS \
348 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
350 if(gaa_last_non_option == gaa_index) \
354 #define GAA_FILL_2ARGS(target, func) \
355 target = func(GAAargv[gaa_index]); \
356 gaa_arg_used[gaa_index] = 1; \
360 return GAA_ERROR_INVALID_ARG; \
365 #define GAA_FILL(target, func, num) \
368 target = func(GAAargv[gaa_index]); \
369 gaa_arg_used[gaa_index] = 1; \
373 return GAA_ERROR_INVALID_ARG; \
382 #define GAA_LIST_FILL(target, func, type ,num) \
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); \
398 return GAA_ERROR_NOTENOUGH_ARGS; \
401 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
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); \
418 #define GAA_OBLIGAT(str) \
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"); \
428 if(opt_list[j] == 1) \
433 if(strlen(str) == 1) \
434 printf("You must give the -%s option\n", str); \
436 printf("You must give at least one option of '%s'\n", str); \
440 #define GAA_INCOMP(str) \
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"); \
450 if(opt_list[j] == 1) \
455 printf("The options '%s' are incompatible\n", str); \
460 static char **GAAargv
;
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
)
470 if(sscanf(arg
, "%d%c", &tmp
, &a
) < 1)
472 printf("Option %s: '%s' isn't an integer\n", gaa_current_option
, arg
);
478 static char gaa_getchar(char *arg
)
482 printf("Option %s: '%s' isn't an character\n", gaa_current_option
, arg
);
488 static char* gaa_getstr(char *arg
)
492 static float gaa_getfloat(char *arg
)
496 if(sscanf(arg
, "%f%c", &tmp
, &a
) < 1)
498 printf("Option %s: '%s' isn't a float number\n", gaa_current_option
, arg
);
503 /* option structures */
505 struct GAAOPTION_debug
511 struct GAAOPTION_template
517 struct GAAOPTION_infile
523 struct GAAOPTION_outfile
529 struct GAAOPTION_bits
535 struct GAAOPTION_hash
541 struct GAAOPTION_password
547 struct GAAOPTION_load_ca_certificate
553 struct GAAOPTION_load_ca_privkey
559 struct GAAOPTION_load_certificate
565 struct GAAOPTION_load_request
571 struct GAAOPTION_load_privkey
578 static int gaa_is_an_argument(char *str
)
581 if(str
[0] == '/' && str
[1] != 0)
582 return GAA_MULTIPLE_OPTION
;
585 return GAA_NOT_AN_OPTION
;
587 return GAA_NOT_AN_OPTION
;
591 return GAA_WORD_OPTION
;
593 return GAA_NOT_AN_OPTION
;
596 return GAA_LETTER_OPTION
;
598 return GAA_MULTIPLE_OPTION
;
601 static int gaa_get_option_num(char *str
, int 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
:
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
);
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
);
695 return GAA_ERROR_NOMATCH
;
698 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
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
;
716 #ifdef GAA_REST_EXISTS
717 struct GAAREST GAAREST_tmp
;
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
)
729 gaa_last_non_option
= GAAargc
;
734 case GAAOPTID_version
:
736 #line 112 "certtool.gaa"
737 { certtool_version(); exit(0); ;};
743 #line 110 "certtool.gaa"
744 { gaa_help(); exit(0); ;};
751 GAA_FILL(GAATMP_debug
.arg1
, gaa_getint
, GAATMP_debug
.size1
);
753 #line 108 "certtool.gaa"
754 { gaaval
->debug
= GAATMP_debug
.arg1
;};
758 case GAAOPTID_template
:
761 GAA_FILL(GAATMP_template
.arg1
, gaa_getstr
, GAATMP_template
.size1
);
763 #line 104 "certtool.gaa"
764 { gaaval
->template = GAATMP_template
.arg1
;};
768 case GAAOPTID_infile
:
771 GAA_FILL(GAATMP_infile
.arg1
, gaa_getstr
, GAATMP_infile
.size1
);
773 #line 101 "certtool.gaa"
774 { gaaval
->infile
= GAATMP_infile
.arg1
;};
778 case GAAOPTID_outfile
:
781 GAA_FILL(GAATMP_outfile
.arg1
, gaa_getstr
, GAATMP_outfile
.size1
);
783 #line 98 "certtool.gaa"
784 { gaaval
->outfile
= GAATMP_outfile
.arg1
;};
788 case GAAOPTID_quick_random
:
790 #line 95 "certtool.gaa"
791 { gaaval
->quick_random
= 1; ;};
798 GAA_FILL(GAATMP_bits
.arg1
, gaa_getint
, GAATMP_bits
.size1
);
800 #line 92 "certtool.gaa"
801 { gaaval
->bits
= GAATMP_bits
.arg1
;};
805 case GAAOPTID_outder
:
807 #line 89 "certtool.gaa"
808 { gaaval
->outcert_format
=1 ;};
814 #line 86 "certtool.gaa"
815 { gaaval
->incert_format
=1 ;};
819 case GAAOPTID_export_ciphers
:
821 #line 83 "certtool.gaa"
822 { gaaval
->export
=1 ;};
829 GAA_FILL(GAATMP_hash
.arg1
, gaa_getstr
, GAATMP_hash
.size1
);
831 #line 80 "certtool.gaa"
832 { gaaval
->hash
= GAATMP_hash
.arg1
;};
838 #line 77 "certtool.gaa"
845 #line 74 "certtool.gaa"
846 { gaaval
->pkcs8
=1 ;};
850 case GAAOPTID_to_p12
:
852 #line 71 "certtool.gaa"
853 { gaaval
->action
= 8; ;};
857 case GAAOPTID_fix_key
:
859 #line 69 "certtool.gaa"
860 { gaaval
->fix_key
= 1; ;};
864 case GAAOPTID_key_info
:
866 #line 66 "certtool.gaa"
867 { gaaval
->action
= 6; ;};
871 case GAAOPTID_smime_to_p7
:
873 #line 64 "certtool.gaa"
874 { gaaval
->action
= 15; ;};
878 case GAAOPTID_p7_info
:
880 #line 62 "certtool.gaa"
881 { gaaval
->action
= 12; ;};
885 case GAAOPTID_p12_info
:
887 #line 60 "certtool.gaa"
888 { gaaval
->action
= 9; ;};
892 case GAAOPTID_crl_info
:
894 #line 58 "certtool.gaa"
895 { gaaval
->action
= 11; ;};
899 case GAAOPTID_certificate_info
:
901 #line 56 "certtool.gaa"
902 { gaaval
->action
= 2; ;};
906 case GAAOPTID_password
:
909 GAA_FILL(GAATMP_password
.arg1
, gaa_getstr
, GAATMP_password
.size1
);
911 #line 54 "certtool.gaa"
912 { gaaval
->pass
= GAATMP_password
.arg1
;};
916 case GAAOPTID_load_ca_certificate
:
919 GAA_FILL(GAATMP_load_ca_certificate
.arg1
, gaa_getstr
, GAATMP_load_ca_certificate
.size1
);
921 #line 51 "certtool.gaa"
922 { gaaval
->ca
= GAATMP_load_ca_certificate
.arg1
;};
926 case GAAOPTID_load_ca_privkey
:
929 GAA_FILL(GAATMP_load_ca_privkey
.arg1
, gaa_getstr
, GAATMP_load_ca_privkey
.size1
);
931 #line 48 "certtool.gaa"
932 { gaaval
->ca_privkey
= GAATMP_load_ca_privkey
.arg1
;};
936 case GAAOPTID_load_certificate
:
939 GAA_FILL(GAATMP_load_certificate
.arg1
, gaa_getstr
, GAATMP_load_certificate
.size1
);
941 #line 45 "certtool.gaa"
942 { gaaval
->cert
= GAATMP_load_certificate
.arg1
;};
946 case GAAOPTID_load_request
:
949 GAA_FILL(GAATMP_load_request
.arg1
, gaa_getstr
, GAATMP_load_request
.size1
);
951 #line 42 "certtool.gaa"
952 { gaaval
->request
= GAATMP_load_request
.arg1
;};
956 case GAAOPTID_load_privkey
:
959 GAA_FILL(GAATMP_load_privkey
.arg1
, gaa_getstr
, GAATMP_load_privkey
.size1
);
961 #line 39 "certtool.gaa"
962 { gaaval
->privkey
= GAATMP_load_privkey
.arg1
;};
966 case GAAOPTID_get_dh_params
:
968 #line 36 "certtool.gaa"
969 { gaaval
->action
=16; ;};
973 case GAAOPTID_generate_dh_params
:
975 #line 35 "certtool.gaa"
976 { gaaval
->action
=10; ;};
980 case GAAOPTID_verify_crl
:
982 #line 33 "certtool.gaa"
983 { gaaval
->action
=14; ;};
987 case GAAOPTID_verify_chain
:
989 #line 31 "certtool.gaa"
990 { gaaval
->action
=5; ;};
994 case GAAOPTID_generate_request
:
996 #line 29 "certtool.gaa"
997 { gaaval
->action
=3; ;};
1001 case GAAOPTID_generate_privkey
:
1003 #line 27 "certtool.gaa"
1004 { gaaval
->action
=1; ;};
1008 case GAAOPTID_update_certificate
:
1010 #line 25 "certtool.gaa"
1011 { gaaval
->action
=7; ;};
1015 case GAAOPTID_generate_crl
:
1017 #line 23 "certtool.gaa"
1018 { gaaval
->action
=13; ;};
1022 case GAAOPTID_generate_proxy
:
1024 #line 21 "certtool.gaa"
1025 { gaaval
->action
=17; ;};
1029 case GAAOPTID_generate_certificate
:
1031 #line 19 "certtool.gaa"
1032 { gaaval
->action
=4; ;};
1036 case GAAOPTID_generate_self_signed
:
1038 #line 17 "certtool.gaa"
1039 { gaaval
->action
=0; ;};
1044 #line 413 "gaa.skel"
1047 return GAA_ERROR_UNKNOWN
;
1050 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
1059 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
1061 for(i
= 0; i
< GAA_NB_OPTION
+ 1; i
++)
1063 /* initialization */
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; ;};
1075 #line 438 "gaa.skel"
1076 gaa_arg_used
= NULL
;
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)
1089 tmp1
= gaa_is_an_argument(GAAargv
[i
]);
1092 case GAA_WORD_OPTION
:
1094 case GAA_LETTER_OPTION
:
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
);
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
);
1107 case GAA_ERROR_INVALID_ARG
:
1108 printf("Invalid arguments\n");
1113 printf("Unknown error\n");
1115 gaa_arg_used
[i
] = 1;
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
));
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
);
1131 case GAA_ERROR_INVALID_ARG
:
1132 printf("Invalid arguments\n");
1137 printf("Unknown error\n");
1140 gaa_arg_used
[i
] = 1;
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");
1156 case GAA_ERROR_INVALID_ARG
:
1157 printf("Invalid arguments\n");
1162 printf("Unknown error\n");
1166 for(i
= 1; i
< argc
; i
++)
1168 if(gaa_arg_used
[i
] == 0)
1170 printf("Too many arguments\n");
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
)
1191 int i
= 0, len
= 0, newline
= 0;
1199 if (a
== EOF
) return 0;
1201 while(a
== ' ' || a
== 9 || a
== '\n')
1209 if (a
== EOF
) return 0;
1212 pos_ini
= ftell(file
) - 1;
1214 while(a
!= ' ' && a
!= 9 && a
!= '\n')
1219 if(a
==EOF
) return 0; //a = ' ';
1223 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
1227 tmp_str
->str
[0] = '-';
1228 tmp_str
->str
[1] = '-';
1236 fseek(file
,pos_ini
, SEEK_SET
);
1245 tmp_str
->str
[i
] = a
;
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)); */
1258 int gaa_file(const char *name
, gaainfo
*gaaval
)
1260 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
1266 gaa_processing_file
= 1;
1268 if((file
= fopen(name
, "r")) == NULL
)
1270 printf("Couldn't open '%s' configuration file for reading\n", name
);
1274 tmp_str
= &first_str
;
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
);
1291 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
1293 tmp_str2
= first_str
;
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;