1 /* File generated by GAA 1.6.6
14 #include "certtool-common.h"
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, "crq-info", "", "Print information on a Certificate Request.");
154 __gaa_helpsingle(0, "no-crq-extensions", "", "Do not use extensions in certificate requests.");
155 __gaa_helpsingle(0, "p12-info", "", "Print information on a PKCS #12 structure.");
156 __gaa_helpsingle(0, "p7-info", "", "Print information on a PKCS #7 structure.");
157 __gaa_helpsingle(0, "smime-to-p7", "", "Convert S/MIME to PKCS #7 structure.");
158 __gaa_helpsingle('k', "key-info", "", "Print information on a private key.");
159 __gaa_helpsingle(0, "pgp-key-info", "", "Print information on a OpenPGP private key.");
160 __gaa_helpsingle(0, "fix-key", "", "Regenerate the parameters in a private key.");
161 __gaa_helpsingle(0, "v1", "", "Generate an X.509 version 1 certificate (no extensions).");
162 __gaa_helpsingle(0, "to-p12", "", "Generate a PKCS #12 structure.");
163 __gaa_helpsingle(0, "to-p8", "", "Generate a PKCS #8 key structure.");
164 __gaa_helpsingle('8', "pkcs8", "", "Use PKCS #8 format for private keys.");
165 __gaa_helpsingle(0, "dsa", "", "Use DSA keys.");
166 __gaa_helpsingle(0, "hash", "STR ", "Hash algorithm to use for signing (MD5,SHA1,RMD160,SHA256,SHA384,SHA512).");
167 __gaa_helpsingle(0, "export-ciphers", "", "Use weak encryption algorithms.");
168 __gaa_helpsingle(0, "inder", "", "Use DER format for input certificates and private keys.");
169 __gaa_helpsingle(0, "inraw", "", "Use RAW/DER format for input certificates and private keys.");
170 __gaa_helpsingle(0, "outder", "", "Use DER format for output certificates and private keys.");
171 __gaa_helpsingle(0, "outraw", "", "Use RAW/DER format for output certificates and private keys.");
172 __gaa_helpsingle(0, "bits", "BITS ", "specify the number of bits for key generation.");
173 __gaa_helpsingle(0, "disable-quick-random", "", "Use /dev/random for key generationg, thus increasing the quality of randomness used.");
174 __gaa_helpsingle(0, "outfile", "FILE ", "Output file.");
175 __gaa_helpsingle(0, "infile", "FILE ", "Input file.");
176 __gaa_helpsingle(0, "template", "FILE ", "Template file to use for non interactive operation.");
177 __gaa_helpsingle(0, "pkcs-cipher", "CIPHER ", "Cipher to use for pkcs operations (3des,aes-128,aes-192,aes-256,rc2-40).");
178 __gaa_helpsingle('d', "debug", "LEVEL ", "specify the debug level. Default is 1.");
179 __gaa_helpsingle('h', "help", "", "shows this help text");
180 __gaa_helpsingle('v', "version", "", "shows the program's version");
188 #ifndef GAA_HEADER_POKY
189 #define GAA_HEADER_POKY
191 typedef struct _gaainfo gaainfo
;
195 #line 131 "certtool.gaa"
197 #line 127 "certtool.gaa"
199 #line 124 "certtool.gaa"
201 #line 121 "certtool.gaa"
203 #line 118 "certtool.gaa"
205 #line 115 "certtool.gaa"
207 #line 112 "certtool.gaa"
209 #line 108 "certtool.gaa"
211 #line 104 "certtool.gaa"
213 #line 101 "certtool.gaa"
215 #line 98 "certtool.gaa"
217 #line 95 "certtool.gaa"
219 #line 92 "certtool.gaa"
221 #line 85 "certtool.gaa"
223 #line 82 "certtool.gaa"
225 #line 67 "certtool.gaa"
227 #line 54 "certtool.gaa"
229 #line 51 "certtool.gaa"
231 #line 48 "certtool.gaa"
233 #line 45 "certtool.gaa"
235 #line 42 "certtool.gaa"
237 #line 39 "certtool.gaa"
239 #line 17 "certtool.gaa"
241 #line 16 "certtool.gaa"
252 int gaa(int argc
, char *argv
[], gaainfo
*gaaval
);
256 int gaa_file(const char *name
, gaainfo
*gaaval
);
269 #define GAAERROR(x) \
275 static char *gaa_current_option
;
276 static int gaa_error
= 0;
278 /* Generated by gaa */
286 #define GAA_ERROR_NOMATCH 0
287 #define GAA_ERROR_NOTENOUGH_ARGS 1
288 #define GAA_ERROR_INVALID_ARG 2
289 #define GAA_ERROR_UNKNOWN 3
291 #define GAA_NOT_AN_OPTION 0
292 #define GAA_WORD_OPTION 1
293 #define GAA_LETTER_OPTION 2
294 #define GAA_MULTIPLE_OPTION 3
297 #define GAA_NB_OPTION 49
298 #define GAAOPTID_version 1
299 #define GAAOPTID_help 2
300 #define GAAOPTID_debug 3
301 #define GAAOPTID_pkcs_cipher 4
302 #define GAAOPTID_template 5
303 #define GAAOPTID_infile 6
304 #define GAAOPTID_outfile 7
305 #define GAAOPTID_disable_quick_random 8
306 #define GAAOPTID_bits 9
307 #define GAAOPTID_outraw 10
308 #define GAAOPTID_outder 11
309 #define GAAOPTID_inraw 12
310 #define GAAOPTID_inder 13
311 #define GAAOPTID_export_ciphers 14
312 #define GAAOPTID_hash 15
313 #define GAAOPTID_dsa 16
314 #define GAAOPTID_pkcs8 17
315 #define GAAOPTID_to_p8 18
316 #define GAAOPTID_to_p12 19
317 #define GAAOPTID_v1 20
318 #define GAAOPTID_fix_key 21
319 #define GAAOPTID_pgp_key_info 22
320 #define GAAOPTID_key_info 23
321 #define GAAOPTID_smime_to_p7 24
322 #define GAAOPTID_p7_info 25
323 #define GAAOPTID_p12_info 26
324 #define GAAOPTID_no_crq_extensions 27
325 #define GAAOPTID_crq_info 28
326 #define GAAOPTID_crl_info 29
327 #define GAAOPTID_pgp_ring_info 30
328 #define GAAOPTID_pgp_certificate_info 31
329 #define GAAOPTID_certificate_info 32
330 #define GAAOPTID_password 33
331 #define GAAOPTID_load_ca_certificate 34
332 #define GAAOPTID_load_ca_privkey 35
333 #define GAAOPTID_load_certificate 36
334 #define GAAOPTID_load_request 37
335 #define GAAOPTID_load_privkey 38
336 #define GAAOPTID_get_dh_params 39
337 #define GAAOPTID_generate_dh_params 40
338 #define GAAOPTID_verify_crl 41
339 #define GAAOPTID_verify_chain 42
340 #define GAAOPTID_generate_request 43
341 #define GAAOPTID_generate_privkey 44
342 #define GAAOPTID_update_certificate 45
343 #define GAAOPTID_generate_crl 46
344 #define GAAOPTID_generate_proxy 47
345 #define GAAOPTID_generate_certificate 48
346 #define GAAOPTID_generate_self_signed 49
350 #define GAA_CHECK1STR(a,b) \
353 gaa_current_option = a; \
357 #define GAA_CHECKSTR(a,b) \
358 if(strcmp(a,str) == 0) \
360 gaa_current_option = a; \
364 #define GAA_TESTMOREARGS \
367 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
369 if(gaa_last_non_option == gaa_index) \
370 return GAA_ERROR_NOTENOUGH_ARGS; \
373 #define GAA_TESTMOREOPTIONALARGS \
376 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
378 if(gaa_last_non_option == gaa_index) \
382 #define GAA_FILL_2ARGS(target, func) \
383 target = func(GAAargv[gaa_index]); \
384 gaa_arg_used[gaa_index] = 1; \
388 return GAA_ERROR_INVALID_ARG; \
393 #define GAA_FILL(target, func, num) \
396 target = func(GAAargv[gaa_index]); \
397 gaa_arg_used[gaa_index] = 1; \
401 return GAA_ERROR_INVALID_ARG; \
410 #define GAA_LIST_FILL(target, func, type ,num) \
415 if ( gaa_last_non_option - gaa_index > 0) \
416 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
417 for(; gaa_index < gaa_last_non_option; gaa_index++) \
419 if(gaa_arg_used[gaa_index] == 0) \
421 GAA_FILL_2ARGS(target[num], func); \
426 return GAA_ERROR_NOTENOUGH_ARGS; \
429 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
434 if ( gaa_last_non_option - gaa_index > 0) \
435 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
436 for(; gaa_index < gaa_last_non_option; gaa_index++) \
438 if(gaa_arg_used[gaa_index] == 0) \
440 GAA_FILL_2ARGS(target[num], func); \
446 #define GAA_OBLIGAT(str) \
448 for(i = 0; i < strlen(str); i++) \
450 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
451 if(j == GAA_ERROR_NOMATCH) \
453 printf("Error: invalid 'obligat' set\n"); \
456 if(opt_list[j] == 1) \
461 if(strlen(str) == 1) \
462 printf("You must give the -%s option\n", str); \
464 printf("You must give at least one option of '%s'\n", str); \
468 #define GAA_INCOMP(str) \
470 for(i = 0; i < strlen(str); i++) \
472 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
473 if(j == GAA_ERROR_NOMATCH) \
475 printf("Error: invalid 'obligat' set\n"); \
478 if(opt_list[j] == 1) \
483 printf("The options '%s' are incompatible\n", str); \
488 static char **GAAargv
;
490 static char *gaa_arg_used
;
491 static int gaa_processing_file
= 0;
492 static int inited
= 0;
494 static int gaa_getint(char *arg
)
498 if(sscanf(arg
, "%d%c", &tmp
, &a
) < 1)
500 printf("Option %s: '%s' isn't an integer\n", gaa_current_option
, arg
);
506 static char gaa_getchar(char *arg
)
510 printf("Option %s: '%s' isn't an character\n", gaa_current_option
, arg
);
516 static char* gaa_getstr(char *arg
)
520 static float gaa_getfloat(char *arg
)
524 if(sscanf(arg
, "%f%c", &tmp
, &a
) < 1)
526 printf("Option %s: '%s' isn't a float number\n", gaa_current_option
, arg
);
531 /* option structures */
533 struct GAAOPTION_debug
539 struct GAAOPTION_pkcs_cipher
545 struct GAAOPTION_template
551 struct GAAOPTION_infile
557 struct GAAOPTION_outfile
563 struct GAAOPTION_bits
569 struct GAAOPTION_hash
575 struct GAAOPTION_password
581 struct GAAOPTION_load_ca_certificate
587 struct GAAOPTION_load_ca_privkey
593 struct GAAOPTION_load_certificate
599 struct GAAOPTION_load_request
605 struct GAAOPTION_load_privkey
612 static int gaa_is_an_argument(char *str
)
615 if(str
[0] == '/' && str
[1] != 0)
616 return GAA_MULTIPLE_OPTION
;
619 return GAA_NOT_AN_OPTION
;
621 return GAA_NOT_AN_OPTION
;
625 return GAA_WORD_OPTION
;
627 return GAA_NOT_AN_OPTION
;
630 return GAA_LETTER_OPTION
;
632 return GAA_MULTIPLE_OPTION
;
635 static int gaa_get_option_num(char *str
, int status
)
639 case GAA_LETTER_OPTION
:
640 GAA_CHECK1STR("d", GAAOPTID_debug
);
641 GAA_CHECK1STR("", GAAOPTID_pkcs_cipher
);
642 GAA_CHECK1STR("", GAAOPTID_template
);
643 GAA_CHECK1STR("", GAAOPTID_infile
);
644 GAA_CHECK1STR("", GAAOPTID_outfile
);
645 GAA_CHECK1STR("", GAAOPTID_bits
);
646 GAA_CHECK1STR("", GAAOPTID_hash
);
647 GAA_CHECK1STR("", GAAOPTID_password
);
648 GAA_CHECK1STR("", GAAOPTID_load_ca_certificate
);
649 GAA_CHECK1STR("", GAAOPTID_load_ca_privkey
);
650 GAA_CHECK1STR("", GAAOPTID_load_certificate
);
651 GAA_CHECK1STR("", GAAOPTID_load_request
);
652 GAA_CHECK1STR("", GAAOPTID_load_privkey
);
653 case GAA_MULTIPLE_OPTION
:
655 GAA_CHECK1STR("v", GAAOPTID_version
);
656 GAA_CHECK1STR("h", GAAOPTID_help
);
657 GAA_CHECK1STR("", GAAOPTID_disable_quick_random
);
658 GAA_CHECK1STR("", GAAOPTID_outraw
);
659 GAA_CHECK1STR("", GAAOPTID_outder
);
660 GAA_CHECK1STR("", GAAOPTID_inraw
);
661 GAA_CHECK1STR("", GAAOPTID_inder
);
662 GAA_CHECK1STR("", GAAOPTID_export_ciphers
);
663 GAA_CHECK1STR("", GAAOPTID_dsa
);
664 GAA_CHECK1STR("8", GAAOPTID_pkcs8
);
665 GAA_CHECK1STR("", GAAOPTID_to_p8
);
666 GAA_CHECK1STR("", GAAOPTID_to_p12
);
667 GAA_CHECK1STR("", GAAOPTID_v1
);
668 GAA_CHECK1STR("", GAAOPTID_fix_key
);
669 GAA_CHECK1STR("", GAAOPTID_pgp_key_info
);
670 GAA_CHECK1STR("k", GAAOPTID_key_info
);
671 GAA_CHECK1STR("", GAAOPTID_smime_to_p7
);
672 GAA_CHECK1STR("", GAAOPTID_p7_info
);
673 GAA_CHECK1STR("", GAAOPTID_p12_info
);
674 GAA_CHECK1STR("", GAAOPTID_no_crq_extensions
);
675 GAA_CHECK1STR("", GAAOPTID_crq_info
);
676 GAA_CHECK1STR("l", GAAOPTID_crl_info
);
677 GAA_CHECK1STR("", GAAOPTID_pgp_ring_info
);
678 GAA_CHECK1STR("", GAAOPTID_pgp_certificate_info
);
679 GAA_CHECK1STR("i", GAAOPTID_certificate_info
);
680 GAA_CHECK1STR("", GAAOPTID_get_dh_params
);
681 GAA_CHECK1STR("", GAAOPTID_generate_dh_params
);
682 GAA_CHECK1STR("", GAAOPTID_verify_crl
);
683 GAA_CHECK1STR("e", GAAOPTID_verify_chain
);
684 GAA_CHECK1STR("q", GAAOPTID_generate_request
);
685 GAA_CHECK1STR("p", GAAOPTID_generate_privkey
);
686 GAA_CHECK1STR("u", GAAOPTID_update_certificate
);
687 GAA_CHECK1STR("", GAAOPTID_generate_crl
);
688 GAA_CHECK1STR("", GAAOPTID_generate_proxy
);
689 GAA_CHECK1STR("c", GAAOPTID_generate_certificate
);
690 GAA_CHECK1STR("s", GAAOPTID_generate_self_signed
);
694 case GAA_WORD_OPTION
:
695 GAA_CHECKSTR("version", GAAOPTID_version
);
696 GAA_CHECKSTR("help", GAAOPTID_help
);
697 GAA_CHECKSTR("debug", GAAOPTID_debug
);
698 GAA_CHECKSTR("pkcs-cipher", GAAOPTID_pkcs_cipher
);
699 GAA_CHECKSTR("template", GAAOPTID_template
);
700 GAA_CHECKSTR("infile", GAAOPTID_infile
);
701 GAA_CHECKSTR("outfile", GAAOPTID_outfile
);
702 GAA_CHECKSTR("disable-quick-random", GAAOPTID_disable_quick_random
);
703 GAA_CHECKSTR("bits", GAAOPTID_bits
);
704 GAA_CHECKSTR("outraw", GAAOPTID_outraw
);
705 GAA_CHECKSTR("outder", GAAOPTID_outder
);
706 GAA_CHECKSTR("inraw", GAAOPTID_inraw
);
707 GAA_CHECKSTR("inder", GAAOPTID_inder
);
708 GAA_CHECKSTR("export-ciphers", GAAOPTID_export_ciphers
);
709 GAA_CHECKSTR("hash", GAAOPTID_hash
);
710 GAA_CHECKSTR("dsa", GAAOPTID_dsa
);
711 GAA_CHECKSTR("pkcs8", GAAOPTID_pkcs8
);
712 GAA_CHECKSTR("to-p8", GAAOPTID_to_p8
);
713 GAA_CHECKSTR("to-p12", GAAOPTID_to_p12
);
714 GAA_CHECKSTR("v1", GAAOPTID_v1
);
715 GAA_CHECKSTR("fix-key", GAAOPTID_fix_key
);
716 GAA_CHECKSTR("pgp-key-info", GAAOPTID_pgp_key_info
);
717 GAA_CHECKSTR("key-info", GAAOPTID_key_info
);
718 GAA_CHECKSTR("smime-to-p7", GAAOPTID_smime_to_p7
);
719 GAA_CHECKSTR("p7-info", GAAOPTID_p7_info
);
720 GAA_CHECKSTR("p12-info", GAAOPTID_p12_info
);
721 GAA_CHECKSTR("no-crq-extensions", GAAOPTID_no_crq_extensions
);
722 GAA_CHECKSTR("crq-info", GAAOPTID_crq_info
);
723 GAA_CHECKSTR("crl-info", GAAOPTID_crl_info
);
724 GAA_CHECKSTR("pgp-ring-info", GAAOPTID_pgp_ring_info
);
725 GAA_CHECKSTR("pgp-certificate-info", GAAOPTID_pgp_certificate_info
);
726 GAA_CHECKSTR("certificate-info", GAAOPTID_certificate_info
);
727 GAA_CHECKSTR("password", GAAOPTID_password
);
728 GAA_CHECKSTR("load-ca-certificate", GAAOPTID_load_ca_certificate
);
729 GAA_CHECKSTR("load-ca-privkey", GAAOPTID_load_ca_privkey
);
730 GAA_CHECKSTR("load-certificate", GAAOPTID_load_certificate
);
731 GAA_CHECKSTR("load-request", GAAOPTID_load_request
);
732 GAA_CHECKSTR("load-privkey", GAAOPTID_load_privkey
);
733 GAA_CHECKSTR("get-dh-params", GAAOPTID_get_dh_params
);
734 GAA_CHECKSTR("generate-dh-params", GAAOPTID_generate_dh_params
);
735 GAA_CHECKSTR("verify-crl", GAAOPTID_verify_crl
);
736 GAA_CHECKSTR("verify-chain", GAAOPTID_verify_chain
);
737 GAA_CHECKSTR("generate-request", GAAOPTID_generate_request
);
738 GAA_CHECKSTR("generate-privkey", GAAOPTID_generate_privkey
);
739 GAA_CHECKSTR("update-certificate", GAAOPTID_update_certificate
);
740 GAA_CHECKSTR("generate-crl", GAAOPTID_generate_crl
);
741 GAA_CHECKSTR("generate-proxy", GAAOPTID_generate_proxy
);
742 GAA_CHECKSTR("generate-certificate", GAAOPTID_generate_certificate
);
743 GAA_CHECKSTR("generate-self-signed", GAAOPTID_generate_self_signed
);
749 return GAA_ERROR_NOMATCH
;
752 static int gaa_try(int gaa_num
, int gaa_index
, gaainfo
*gaaval
, char *opt_list
)
755 int gaa_last_non_option
;
756 struct GAAOPTION_debug GAATMP_debug
;
757 struct GAAOPTION_pkcs_cipher GAATMP_pkcs_cipher
;
758 struct GAAOPTION_template GAATMP_template
;
759 struct GAAOPTION_infile GAATMP_infile
;
760 struct GAAOPTION_outfile GAATMP_outfile
;
761 struct GAAOPTION_bits GAATMP_bits
;
762 struct GAAOPTION_hash GAATMP_hash
;
763 struct GAAOPTION_password GAATMP_password
;
764 struct GAAOPTION_load_ca_certificate GAATMP_load_ca_certificate
;
765 struct GAAOPTION_load_ca_privkey GAATMP_load_ca_privkey
;
766 struct GAAOPTION_load_certificate GAATMP_load_certificate
;
767 struct GAAOPTION_load_request GAATMP_load_request
;
768 struct GAAOPTION_load_privkey GAATMP_load_privkey
;
771 #ifdef GAA_REST_EXISTS
772 struct GAAREST GAAREST_tmp
;
775 opt_list
[gaa_num
] = 1;
777 for(gaa_last_non_option
= gaa_index
;
778 (gaa_last_non_option
!= GAAargc
) && (gaa_is_an_argument(GAAargv
[gaa_last_non_option
]) == GAA_NOT_AN_OPTION
);
779 gaa_last_non_option
++);
781 if(gaa_num
== GAA_REST
)
784 gaa_last_non_option
= GAAargc
;
789 case GAAOPTID_version
:
791 #line 136 "certtool.gaa"
792 { certtool_version(); exit(0); ;};
798 #line 134 "certtool.gaa"
799 { gaa_help(); exit(0); ;};
806 GAA_FILL(GAATMP_debug
.arg1
, gaa_getint
, GAATMP_debug
.size1
);
808 #line 132 "certtool.gaa"
809 { gaaval
->debug
= GAATMP_debug
.arg1
;};
813 case GAAOPTID_pkcs_cipher
:
816 GAA_FILL(GAATMP_pkcs_cipher
.arg1
, gaa_getstr
, GAATMP_pkcs_cipher
.size1
);
818 #line 128 "certtool.gaa"
819 { gaaval
->pkcs_cipher
= GAATMP_pkcs_cipher
.arg1
;};
823 case GAAOPTID_template
:
826 GAA_FILL(GAATMP_template
.arg1
, gaa_getstr
, GAATMP_template
.size1
);
828 #line 125 "certtool.gaa"
829 { gaaval
->template = GAATMP_template
.arg1
;};
833 case GAAOPTID_infile
:
836 GAA_FILL(GAATMP_infile
.arg1
, gaa_getstr
, GAATMP_infile
.size1
);
838 #line 122 "certtool.gaa"
839 { gaaval
->infile
= GAATMP_infile
.arg1
;};
843 case GAAOPTID_outfile
:
846 GAA_FILL(GAATMP_outfile
.arg1
, gaa_getstr
, GAATMP_outfile
.size1
);
848 #line 119 "certtool.gaa"
849 { gaaval
->outfile
= GAATMP_outfile
.arg1
;};
853 case GAAOPTID_disable_quick_random
:
855 #line 116 "certtool.gaa"
856 { gaaval
->quick_random
= 0; ;};
863 GAA_FILL(GAATMP_bits
.arg1
, gaa_getint
, GAATMP_bits
.size1
);
865 #line 113 "certtool.gaa"
866 { gaaval
->bits
= GAATMP_bits
.arg1
;};
870 case GAAOPTID_outraw
:
872 #line 110 "certtool.gaa"
873 { gaaval
->outcert_format
=1 ;};
877 case GAAOPTID_outder
:
879 #line 109 "certtool.gaa"
880 { gaaval
->outcert_format
=1 ;};
886 #line 106 "certtool.gaa"
887 { gaaval
->incert_format
=1 ;};
893 #line 105 "certtool.gaa"
894 { gaaval
->incert_format
=1 ;};
898 case GAAOPTID_export_ciphers
:
900 #line 102 "certtool.gaa"
901 { gaaval
->export
=1 ;};
908 GAA_FILL(GAATMP_hash
.arg1
, gaa_getstr
, GAATMP_hash
.size1
);
910 #line 99 "certtool.gaa"
911 { gaaval
->hash
= GAATMP_hash
.arg1
;};
917 #line 96 "certtool.gaa"
924 #line 93 "certtool.gaa"
925 { gaaval
->pkcs8
=1 ;};
931 #line 90 "certtool.gaa"
932 { gaaval
->action
= ACTION_GENERATE_PKCS8
; ;};
936 case GAAOPTID_to_p12
:
938 #line 88 "certtool.gaa"
939 { gaaval
->action
= ACTION_TO_PKCS12
; ;};
945 #line 86 "certtool.gaa"
946 { gaaval
->v1_cert
= 1; ;};
950 case GAAOPTID_fix_key
:
952 #line 83 "certtool.gaa"
953 { gaaval
->privkey_op
=1; gaaval
->fix_key
= 1; ;};
957 case GAAOPTID_pgp_key_info
:
959 #line 80 "certtool.gaa"
960 { gaaval
->privkey_op
=1; gaaval
->action
= ACTION_PGP_PRIVKEY_INFO
; ;};
964 case GAAOPTID_key_info
:
966 #line 78 "certtool.gaa"
967 { gaaval
->privkey_op
=1; gaaval
->action
= ACTION_PRIVKEY_INFO
; ;};
971 case GAAOPTID_smime_to_p7
:
973 #line 74 "certtool.gaa"
974 { gaaval
->action
= ACTION_SMIME_TO_P7
; ;};
978 case GAAOPTID_p7_info
:
980 #line 72 "certtool.gaa"
981 { gaaval
->action
= ACTION_P7_INFO
; ;};
985 case GAAOPTID_p12_info
:
987 #line 70 "certtool.gaa"
988 { gaaval
->action
= ACTION_PKCS12_INFO
; ;};
992 case GAAOPTID_no_crq_extensions
:
994 #line 68 "certtool.gaa"
995 { gaaval
->crq_extensions
= 0; ;};
999 case GAAOPTID_crq_info
:
1001 #line 65 "certtool.gaa"
1002 { gaaval
->action
= ACTION_REQUEST
; ;};
1006 case GAAOPTID_crl_info
:
1008 #line 63 "certtool.gaa"
1009 { gaaval
->action
= ACTION_CRL_INFO
; ;};
1013 case GAAOPTID_pgp_ring_info
:
1015 #line 61 "certtool.gaa"
1016 { gaaval
->action
= ACTION_RING_INFO
; ;};
1020 case GAAOPTID_pgp_certificate_info
:
1022 #line 59 "certtool.gaa"
1023 { gaaval
->action
= ACTION_PGP_INFO
; ;};
1027 case GAAOPTID_certificate_info
:
1029 #line 57 "certtool.gaa"
1030 { gaaval
->action
= ACTION_CERT_INFO
; ;};
1034 case GAAOPTID_password
:
1037 GAA_FILL(GAATMP_password
.arg1
, gaa_getstr
, GAATMP_password
.size1
);
1039 #line 55 "certtool.gaa"
1040 { gaaval
->pass
= GAATMP_password
.arg1
;};
1044 case GAAOPTID_load_ca_certificate
:
1047 GAA_FILL(GAATMP_load_ca_certificate
.arg1
, gaa_getstr
, GAATMP_load_ca_certificate
.size1
);
1049 #line 52 "certtool.gaa"
1050 { gaaval
->ca
= GAATMP_load_ca_certificate
.arg1
;};
1054 case GAAOPTID_load_ca_privkey
:
1057 GAA_FILL(GAATMP_load_ca_privkey
.arg1
, gaa_getstr
, GAATMP_load_ca_privkey
.size1
);
1059 #line 49 "certtool.gaa"
1060 { gaaval
->ca_privkey
= GAATMP_load_ca_privkey
.arg1
;};
1064 case GAAOPTID_load_certificate
:
1067 GAA_FILL(GAATMP_load_certificate
.arg1
, gaa_getstr
, GAATMP_load_certificate
.size1
);
1069 #line 46 "certtool.gaa"
1070 { gaaval
->cert
= GAATMP_load_certificate
.arg1
;};
1074 case GAAOPTID_load_request
:
1077 GAA_FILL(GAATMP_load_request
.arg1
, gaa_getstr
, GAATMP_load_request
.size1
);
1079 #line 43 "certtool.gaa"
1080 { gaaval
->request
= GAATMP_load_request
.arg1
;};
1084 case GAAOPTID_load_privkey
:
1087 GAA_FILL(GAATMP_load_privkey
.arg1
, gaa_getstr
, GAATMP_load_privkey
.size1
);
1089 #line 40 "certtool.gaa"
1090 { gaaval
->privkey
= GAATMP_load_privkey
.arg1
;};
1094 case GAAOPTID_get_dh_params
:
1096 #line 37 "certtool.gaa"
1097 { gaaval
->action
=ACTION_GET_DH
; ;};
1101 case GAAOPTID_generate_dh_params
:
1103 #line 36 "certtool.gaa"
1104 { gaaval
->action
=ACTION_GENERATE_DH
; ;};
1108 case GAAOPTID_verify_crl
:
1110 #line 34 "certtool.gaa"
1111 { gaaval
->action
=ACTION_VERIFY_CRL
; ;};
1115 case GAAOPTID_verify_chain
:
1117 #line 32 "certtool.gaa"
1118 { gaaval
->action
=ACTION_VERIFY_CHAIN
; ;};
1122 case GAAOPTID_generate_request
:
1124 #line 30 "certtool.gaa"
1125 { gaaval
->action
=ACTION_GENERATE_REQUEST
; ;};
1129 case GAAOPTID_generate_privkey
:
1131 #line 28 "certtool.gaa"
1132 { gaaval
->privkey_op
=1; gaaval
->action
=ACTION_GENERATE_PRIVKEY
; ;};
1136 case GAAOPTID_update_certificate
:
1138 #line 26 "certtool.gaa"
1139 { gaaval
->action
=ACTION_UPDATE_CERTIFICATE
; ;};
1143 case GAAOPTID_generate_crl
:
1145 #line 24 "certtool.gaa"
1146 { gaaval
->action
=ACTION_GENERATE_CRL
; ;};
1150 case GAAOPTID_generate_proxy
:
1152 #line 22 "certtool.gaa"
1153 { gaaval
->action
=ACTION_GENERATE_PROXY
; ;};
1157 case GAAOPTID_generate_certificate
:
1159 #line 20 "certtool.gaa"
1160 { gaaval
->action
=ACTION_GENERATE_CERTIFICATE
; ;};
1164 case GAAOPTID_generate_self_signed
:
1166 #line 18 "certtool.gaa"
1167 { gaaval
->action
=ACTION_SELF_SIGNED
; ;};
1172 #line 413 "gaa.skel"
1175 return GAA_ERROR_UNKNOWN
;
1178 int gaa(int argc
, char **argv
, gaainfo
*gaaval
)
1187 opt_list
= (char*) gaa_malloc(GAA_NB_OPTION
+ 1);
1189 for(i
= 0; i
< GAA_NB_OPTION
+ 1; i
++)
1191 /* initialization */
1195 #line 138 "certtool.gaa"
1196 { gaaval
->bits
= 2048; gaaval
->pkcs8
= 0; gaaval
->privkey
= NULL
; gaaval
->ca
=NULL
; gaaval
->ca_privkey
= NULL
;
1197 gaaval
->debug
=1; gaaval
->request
= NULL
; gaaval
->infile
= NULL
; gaaval
->outfile
= NULL
; gaaval
->cert
= NULL
;
1198 gaaval
->incert_format
= 0; gaaval
->outcert_format
= 0; gaaval
->action
=-1; gaaval
->pass
= NULL
; gaaval
->v1_cert
= 0;
1199 gaaval
->export
= 0; gaaval
->template = NULL
; gaaval
->hash
=NULL
; gaaval
->fix_key
= 0; gaaval
->quick_random
=1;
1200 gaaval
->privkey_op
= 0; gaaval
->pkcs_cipher
= "3des"; gaaval
->crq_extensions
=1; ;};
1204 #line 438 "gaa.skel"
1205 gaa_arg_used
= NULL
;
1208 gaa_arg_used
= gaa_malloc(argc
* sizeof(char));
1211 for(i
= 1; i
< argc
; i
++)
1212 gaa_arg_used
[i
] = 0;
1213 for(i
= 1; i
< argc
; i
++)
1215 if(gaa_arg_used
[i
] == 0)
1218 tmp1
= gaa_is_an_argument(GAAargv
[i
]);
1221 case GAA_WORD_OPTION
:
1223 case GAA_LETTER_OPTION
:
1225 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
1226 if(tmp2
== GAA_ERROR_NOMATCH
)
1228 printf("Invalid option '%s'\n", argv
[i
]+j
);
1231 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
1233 case GAA_ERROR_NOTENOUGH_ARGS
:
1234 printf("'%s': not enough arguments\n",gaa_current_option
);
1236 case GAA_ERROR_INVALID_ARG
:
1237 printf("Invalid arguments\n");
1242 printf("Unknown error\n");
1244 gaa_arg_used
[i
] = 1;
1246 case GAA_MULTIPLE_OPTION
:
1247 for(j
= 1; j
< strlen(argv
[i
]); j
++)
1249 tmp2
= gaa_get_option_num(argv
[i
]+j
, tmp1
);
1250 if(tmp2
== GAA_ERROR_NOMATCH
)
1252 printf("Invalid option '%c'\n", *(argv
[i
]+j
));
1255 switch(gaa_try(tmp2
, i
+1, gaaval
, opt_list
))
1257 case GAA_ERROR_NOTENOUGH_ARGS
:
1258 printf("'%s': not enough arguments\n",gaa_current_option
);
1260 case GAA_ERROR_INVALID_ARG
:
1261 printf("Invalid arguments\n");
1266 printf("Unknown error\n");
1269 gaa_arg_used
[i
] = 1;
1275 if(gaa_processing_file
== 0)
1278 #line 507 "gaa.skel"
1279 #ifdef GAA_REST_EXISTS
1280 switch(gaa_try(GAA_REST
, 1, gaaval
, opt_list
))
1282 case GAA_ERROR_NOTENOUGH_ARGS
:
1283 printf("Rest: not enough arguments\n");
1285 case GAA_ERROR_INVALID_ARG
:
1286 printf("Invalid arguments\n");
1291 printf("Unknown error\n");
1295 for(i
= 1; i
< argc
; i
++)
1297 if(gaa_arg_used
[i
] == 0)
1299 printf("Too many arguments\n");
1311 struct gaastrnode
*next
;
1314 typedef struct gaastrnode gaa_str_node
;
1316 static int gaa_internal_get_next_str(FILE *file
, gaa_str_node
*tmp_str
, int argc
)
1320 int i
= 0, len
= 0, newline
= 0;
1328 if (a
== EOF
) return 0;
1330 while(a
== ' ' || a
== 9 || a
== '\n')
1338 if (a
== EOF
) return 0;
1341 pos_ini
= ftell(file
) - 1;
1343 while(a
!= ' ' && a
!= 9 && a
!= '\n')
1348 if(a
==EOF
) return 0; //a = ' ';
1352 tmp_str
->str
= gaa_malloc((len
) * sizeof(char));
1356 tmp_str
->str
[0] = '-';
1357 tmp_str
->str
[1] = '-';
1365 fseek(file
,pos_ini
, SEEK_SET
);
1374 tmp_str
->str
[i
] = a
;
1377 while(a
!= ' ' && a
!= 9 && a
!= '\n' && i
< len
);
1379 tmp_str
->str
[i
- 1] = 0;
1381 fseek(file
,- 1, SEEK_CUR
);
1382 /* printf("%d\n", ftell(file)); */
1387 int gaa_file(const char *name
, gaainfo
*gaaval
)
1389 gaa_str_node
*first_str
, **tmp_str
, *tmp_str2
;
1395 gaa_processing_file
= 1;
1397 if((file
= fopen(name
, "r")) == NULL
)
1399 printf("Couldn't open '%s' configuration file for reading\n", name
);
1403 tmp_str
= &first_str
;
1407 *tmp_str
= gaa_malloc(sizeof(gaa_str_node
));
1409 (*tmp_str
)->str
= NULL
;
1410 (*tmp_str
)->next
= NULL
;
1412 rval
= gaa_internal_get_next_str(file
, *tmp_str
, argc
);
1413 tmp_str
= &((*tmp_str
)->next
);
1420 argv
= gaa_malloc((1 + argc
) * sizeof(char*));
1422 tmp_str2
= first_str
;
1424 for(i
= 1; i
< argc
; i
++)
1426 argv
[i
] = tmp_str2
->str
;
1427 tmp_str2
= tmp_str2
->next
;
1430 rval
= gaa(argc
, argv
, gaaval
);
1431 gaa_processing_file
= 0;