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(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");
185 #ifndef GAA_HEADER_POKY
186 #define GAA_HEADER_POKY
188 typedef struct _gaainfo gaainfo
;
192 #line 123 "certtool.gaa"
194 #line 119 "certtool.gaa"
196 #line 116 "certtool.gaa"
198 #line 113 "certtool.gaa"
200 #line 110 "certtool.gaa"
202 #line 107 "certtool.gaa"
204 #line 103 "certtool.gaa"
206 #line 99 "certtool.gaa"
208 #line 96 "certtool.gaa"
210 #line 93 "certtool.gaa"
212 #line 90 "certtool.gaa"
214 #line 87 "certtool.gaa"
216 #line 80 "certtool.gaa"
218 #line 77 "certtool.gaa"
220 #line 54 "certtool.gaa"
222 #line 51 "certtool.gaa"
224 #line 48 "certtool.gaa"
226 #line 45 "certtool.gaa"
228 #line 42 "certtool.gaa"
230 #line 39 "certtool.gaa"
232 #line 17 "certtool.gaa"
234 #line 16 "certtool.gaa"
245 int gaa(int argc
, char *argv
[], gaainfo
*gaaval
);
249 int gaa_file(const char *name
, gaainfo
*gaaval
);
262 #define GAAERROR(x) \
268 static char *gaa_current_option
;
269 static int gaa_error
= 0;
271 /* Generated by gaa */
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
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
340 #define GAA_CHECK1STR(a,b) \
343 gaa_current_option = a; \
347 #define GAA_CHECKSTR(a,b) \
348 if(strcmp(a,str) == 0) \
350 gaa_current_option = a; \
354 #define GAA_TESTMOREARGS \
357 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
359 if(gaa_last_non_option == gaa_index) \
360 return GAA_ERROR_NOTENOUGH_ARGS; \
363 #define GAA_TESTMOREOPTIONALARGS \
366 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
368 if(gaa_last_non_option == gaa_index) \
372 #define GAA_FILL_2ARGS(target, func) \
373 target = func(GAAargv[gaa_index]); \
374 gaa_arg_used[gaa_index] = 1; \
378 return GAA_ERROR_INVALID_ARG; \
383 #define GAA_FILL(target, func, num) \
386 target = func(GAAargv[gaa_index]); \
387 gaa_arg_used[gaa_index] = 1; \
391 return GAA_ERROR_INVALID_ARG; \
400 #define GAA_LIST_FILL(target, func, type ,num) \
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); \
416 return GAA_ERROR_NOTENOUGH_ARGS; \
419 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
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); \
436 #define GAA_OBLIGAT(str) \
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"); \
446 if(opt_list[j] == 1) \
451 if(strlen(str) == 1) \
452 printf("You must give the -%s option\n", str); \
454 printf("You must give at least one option of '%s'\n", str); \
458 #define GAA_INCOMP(str) \
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"); \
468 if(opt_list[j] == 1) \
473 printf("The options '%s' are incompatible\n", str); \
478 static char **GAAargv
;
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
)
488 if(sscanf(arg
, "%d%c", &tmp
, &a
) < 1)
490 printf("Option %s: '%s' isn't an integer\n", gaa_current_option
, arg
);
496 static char gaa_getchar(char *arg
)
500 printf("Option %s: '%s' isn't an character\n", gaa_current_option
, arg
);
506 static char* gaa_getstr(char *arg
)
510 static float gaa_getfloat(char *arg
)
514 if(sscanf(arg
, "%f%c", &tmp
, &a
) < 1)
516 printf("Option %s: '%s' isn't a float number\n", gaa_current_option
, arg
);
521 /* option structures */
523 struct GAAOPTION_debug
529 struct GAAOPTION_template
535 struct GAAOPTION_infile
541 struct GAAOPTION_outfile
547 struct GAAOPTION_bits
553 struct GAAOPTION_hash
559 struct GAAOPTION_password
565 struct GAAOPTION_load_ca_certificate
571 struct GAAOPTION_load_ca_privkey
577 struct GAAOPTION_load_certificate
583 struct GAAOPTION_load_request
589 struct GAAOPTION_load_privkey
596 static int gaa_is_an_argument(char *str
)
599 if(str
[0] == '/' && str
[1] != 0)
600 return GAA_MULTIPLE_OPTION
;
603 return GAA_NOT_AN_OPTION
;
605 return GAA_NOT_AN_OPTION
;
609 return GAA_WORD_OPTION
;
611 return GAA_NOT_AN_OPTION
;
614 return GAA_LETTER_OPTION
;
616 return GAA_MULTIPLE_OPTION
;
619 static int gaa_get_option_num(char *str
, int 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
:
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
);
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
);
727 return GAA_ERROR_NOMATCH
;
730 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
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
;
748 #ifdef GAA_REST_EXISTS
749 struct GAAREST GAAREST_tmp
;
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
)
761 gaa_last_non_option
= GAAargc
;
766 case GAAOPTID_version
:
768 #line 128 "certtool.gaa"
769 { certtool_version(); exit(0); ;};
775 #line 126 "certtool.gaa"
776 { gaa_help(); exit(0); ;};
783 GAA_FILL(GAATMP_debug
.arg1
, gaa_getint
, GAATMP_debug
.size1
);
785 #line 124 "certtool.gaa"
786 { gaaval
->debug
= GAATMP_debug
.arg1
;};
790 case GAAOPTID_template
:
793 GAA_FILL(GAATMP_template
.arg1
, gaa_getstr
, GAATMP_template
.size1
);
795 #line 120 "certtool.gaa"
796 { gaaval
->template = GAATMP_template
.arg1
;};
800 case GAAOPTID_infile
:
803 GAA_FILL(GAATMP_infile
.arg1
, gaa_getstr
, GAATMP_infile
.size1
);
805 #line 117 "certtool.gaa"
806 { gaaval
->infile
= GAATMP_infile
.arg1
;};
810 case GAAOPTID_outfile
:
813 GAA_FILL(GAATMP_outfile
.arg1
, gaa_getstr
, GAATMP_outfile
.size1
);
815 #line 114 "certtool.gaa"
816 { gaaval
->outfile
= GAATMP_outfile
.arg1
;};
820 case GAAOPTID_disable_quick_random
:
822 #line 111 "certtool.gaa"
823 { gaaval
->quick_random
= 0; ;};
830 GAA_FILL(GAATMP_bits
.arg1
, gaa_getint
, GAATMP_bits
.size1
);
832 #line 108 "certtool.gaa"
833 { gaaval
->bits
= GAATMP_bits
.arg1
;};
837 case GAAOPTID_outraw
:
839 #line 105 "certtool.gaa"
840 { gaaval
->outcert_format
=1 ;};
844 case GAAOPTID_outder
:
846 #line 104 "certtool.gaa"
847 { gaaval
->outcert_format
=1 ;};
853 #line 101 "certtool.gaa"
854 { gaaval
->incert_format
=1 ;};
860 #line 100 "certtool.gaa"
861 { gaaval
->incert_format
=1 ;};
865 case GAAOPTID_export_ciphers
:
867 #line 97 "certtool.gaa"
868 { gaaval
->export
=1 ;};
875 GAA_FILL(GAATMP_hash
.arg1
, gaa_getstr
, GAATMP_hash
.size1
);
877 #line 94 "certtool.gaa"
878 { gaaval
->hash
= GAATMP_hash
.arg1
;};
884 #line 91 "certtool.gaa"
891 #line 88 "certtool.gaa"
892 { gaaval
->pkcs8
=1 ;};
898 #line 85 "certtool.gaa"
899 { gaaval
->action
= 18; ;};
903 case GAAOPTID_to_p12
:
905 #line 83 "certtool.gaa"
906 { gaaval
->action
= 8; ;};
912 #line 81 "certtool.gaa"
913 { gaaval
->v1_cert
= 1; ;};
917 case GAAOPTID_fix_key
:
919 #line 78 "certtool.gaa"
920 { gaaval
->privkey_op
=1; gaaval
->fix_key
= 1; ;};
924 case GAAOPTID_pgp_key_info
:
926 #line 75 "certtool.gaa"
927 { gaaval
->privkey_op
=1; gaaval
->action
= 20; ;};
931 case GAAOPTID_key_info
:
933 #line 73 "certtool.gaa"
934 { gaaval
->privkey_op
=1; gaaval
->action
= 6; ;};
938 case GAAOPTID_smime_to_p7
:
940 #line 69 "certtool.gaa"
941 { gaaval
->action
= 15; ;};
945 case GAAOPTID_p7_info
:
947 #line 67 "certtool.gaa"
948 { gaaval
->action
= 12; ;};
952 case GAAOPTID_p12_info
:
954 #line 65 "certtool.gaa"
955 { gaaval
->action
= 9; ;};
959 case GAAOPTID_crl_info
:
961 #line 63 "certtool.gaa"
962 { gaaval
->action
= 11; ;};
966 case GAAOPTID_pgp_ring_info
:
968 #line 61 "certtool.gaa"
969 { gaaval
->action
= 21; ;};
973 case GAAOPTID_pgp_certificate_info
:
975 #line 59 "certtool.gaa"
976 { gaaval
->action
= 19; ;};
980 case GAAOPTID_certificate_info
:
982 #line 57 "certtool.gaa"
983 { gaaval
->action
= 2; ;};
987 case GAAOPTID_password
:
990 GAA_FILL(GAATMP_password
.arg1
, gaa_getstr
, GAATMP_password
.size1
);
992 #line 55 "certtool.gaa"
993 { gaaval
->pass
= GAATMP_password
.arg1
;};
997 case GAAOPTID_load_ca_certificate
:
1000 GAA_FILL(GAATMP_load_ca_certificate
.arg1
, gaa_getstr
, GAATMP_load_ca_certificate
.size1
);
1002 #line 52 "certtool.gaa"
1003 { gaaval
->ca
= GAATMP_load_ca_certificate
.arg1
;};
1007 case GAAOPTID_load_ca_privkey
:
1010 GAA_FILL(GAATMP_load_ca_privkey
.arg1
, gaa_getstr
, GAATMP_load_ca_privkey
.size1
);
1012 #line 49 "certtool.gaa"
1013 { gaaval
->ca_privkey
= GAATMP_load_ca_privkey
.arg1
;};
1017 case GAAOPTID_load_certificate
:
1020 GAA_FILL(GAATMP_load_certificate
.arg1
, gaa_getstr
, GAATMP_load_certificate
.size1
);
1022 #line 46 "certtool.gaa"
1023 { gaaval
->cert
= GAATMP_load_certificate
.arg1
;};
1027 case GAAOPTID_load_request
:
1030 GAA_FILL(GAATMP_load_request
.arg1
, gaa_getstr
, GAATMP_load_request
.size1
);
1032 #line 43 "certtool.gaa"
1033 { gaaval
->request
= GAATMP_load_request
.arg1
;};
1037 case GAAOPTID_load_privkey
:
1040 GAA_FILL(GAATMP_load_privkey
.arg1
, gaa_getstr
, GAATMP_load_privkey
.size1
);
1042 #line 40 "certtool.gaa"
1043 { gaaval
->privkey
= GAATMP_load_privkey
.arg1
;};
1047 case GAAOPTID_get_dh_params
:
1049 #line 37 "certtool.gaa"
1050 { gaaval
->action
=16; ;};
1054 case GAAOPTID_generate_dh_params
:
1056 #line 36 "certtool.gaa"
1057 { gaaval
->action
=10; ;};
1061 case GAAOPTID_verify_crl
:
1063 #line 34 "certtool.gaa"
1064 { gaaval
->action
=14; ;};
1068 case GAAOPTID_verify_chain
:
1070 #line 32 "certtool.gaa"
1071 { gaaval
->action
=5; ;};
1075 case GAAOPTID_generate_request
:
1077 #line 30 "certtool.gaa"
1078 { gaaval
->action
=3; ;};
1082 case GAAOPTID_generate_privkey
:
1084 #line 28 "certtool.gaa"
1085 { gaaval
->privkey_op
=1; gaaval
->action
=1; ;};
1089 case GAAOPTID_update_certificate
:
1091 #line 26 "certtool.gaa"
1092 { gaaval
->action
=7; ;};
1096 case GAAOPTID_generate_crl
:
1098 #line 24 "certtool.gaa"
1099 { gaaval
->action
=13; ;};
1103 case GAAOPTID_generate_proxy
:
1105 #line 22 "certtool.gaa"
1106 { gaaval
->action
=17; ;};
1110 case GAAOPTID_generate_certificate
:
1112 #line 20 "certtool.gaa"
1113 { gaaval
->action
=4; ;};
1117 case GAAOPTID_generate_self_signed
:
1119 #line 18 "certtool.gaa"
1120 { gaaval
->action
=0; ;};
1125 #line 413 "gaa.skel"
1128 return GAA_ERROR_UNKNOWN
;
1131 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
1140 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
1142 for(i
= 0; i
< GAA_NB_OPTION
+ 1; i
++)
1144 /* initialization */
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; ;};
1157 #line 438 "gaa.skel"
1158 gaa_arg_used
= NULL
;
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)
1171 tmp1
= gaa_is_an_argument(GAAargv
[i
]);
1174 case GAA_WORD_OPTION
:
1176 case GAA_LETTER_OPTION
:
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
);
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
);
1189 case GAA_ERROR_INVALID_ARG
:
1190 printf("Invalid arguments\n");
1195 printf("Unknown error\n");
1197 gaa_arg_used
[i
] = 1;
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
));
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
);
1213 case GAA_ERROR_INVALID_ARG
:
1214 printf("Invalid arguments\n");
1219 printf("Unknown error\n");
1222 gaa_arg_used
[i
] = 1;
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");
1238 case GAA_ERROR_INVALID_ARG
:
1239 printf("Invalid arguments\n");
1244 printf("Unknown error\n");
1248 for(i
= 1; i
< argc
; i
++)
1250 if(gaa_arg_used
[i
] == 0)
1252 printf("Too many arguments\n");
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
)
1273 int i
= 0, len
= 0, newline
= 0;
1281 if (a
== EOF
) return 0;
1283 while(a
== ' ' || a
== 9 || a
== '\n')
1291 if (a
== EOF
) return 0;
1294 pos_ini
= ftell(file
) - 1;
1296 while(a
!= ' ' && a
!= 9 && a
!= '\n')
1301 if(a
==EOF
) return 0; //a = ' ';
1305 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
1309 tmp_str
->str
[0] = '-';
1310 tmp_str
->str
[1] = '-';
1318 fseek(file
,pos_ini
, SEEK_SET
);
1327 tmp_str
->str
[i
] = a
;
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)); */
1340 int gaa_file(const char *name
, gaainfo
*gaaval
)
1342 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
1348 gaa_processing_file
= 1;
1350 if((file
= fopen(name
, "r")) == NULL
)
1352 printf("Couldn't open '%s' configuration file for reading\n", name
);
1356 tmp_str
= &first_str
;
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
);
1373 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
1375 tmp_str2
= first_str
;
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;