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-pubkey", "FILE ", "Public key file to use.");
145 __gaa_helpsingle(0, "load-request", "FILE ", "Certificate request file to use.");
146 __gaa_helpsingle(0, "load-certificate", "FILE ", "Certificate file to use.");
147 __gaa_helpsingle(0, "load-ca-privkey", "FILE ", "Certificate authority's private key file to use.");
148 __gaa_helpsingle(0, "load-ca-certificate", "FILE ", "Certificate authority's certificate file to use.");
149 __gaa_helpsingle(0, "password", "PASSWORD ", "Password to use.");
150 __gaa_helpsingle('i', "certificate-info", "", "Print information on a certificate.");
151 __gaa_helpsingle(0, "certificate-pubkey", "", "Print certificate public key.");
152 __gaa_helpsingle(0, "pgp-certificate-info", "", "Print information on a OpenPGP certificate.");
153 __gaa_helpsingle(0, "pgp-ring-info", "", "Print information on a keyring structure.");
154 __gaa_helpsingle('l', "crl-info", "", "Print information on a CRL.");
155 __gaa_helpsingle(0, "crq-info", "", "Print information on a Certificate Request.");
156 __gaa_helpsingle(0, "no-crq-extensions", "", "Do not use extensions in certificate requests.");
157 __gaa_helpsingle(0, "p12-info", "", "Print information on a PKCS #12 structure.");
158 __gaa_helpsingle(0, "p7-info", "", "Print information on a PKCS #7 structure.");
159 __gaa_helpsingle(0, "smime-to-p7", "", "Convert S/MIME to PKCS #7 structure.");
160 __gaa_helpsingle('k', "key-info", "", "Print information on a private key.");
161 __gaa_helpsingle(0, "pgp-key-info", "", "Print information on a OpenPGP private key.");
162 __gaa_helpsingle(0, "pubkey-info", "", "Print information on a public key.");
163 __gaa_helpsingle(0, "fix-key", "", "Regenerate the parameters in a private key.");
164 __gaa_helpsingle(0, "v1", "", "Generate an X.509 version 1 certificate (no extensions).");
165 __gaa_helpsingle(0, "to-p12", "", "Generate a PKCS #12 structure.");
166 __gaa_helpsingle(0, "to-p8", "", "Generate a PKCS #8 key structure.");
167 __gaa_helpsingle('8', "pkcs8", "", "Use PKCS #8 format for private keys.");
168 __gaa_helpsingle(0, "dsa", "", "Use DSA keys.");
169 __gaa_helpsingle(0, "hash", "STR ", "Hash algorithm to use for signing (MD5,SHA1,RMD160,SHA256,SHA384,SHA512).");
170 __gaa_helpsingle(0, "export-ciphers", "", "Use weak encryption algorithms.");
171 __gaa_helpsingle(0, "inder", "", "Use DER format for input certificates and private keys.");
172 __gaa_helpsingle(0, "inraw", "", "Use RAW/DER format for input certificates and private keys.");
173 __gaa_helpsingle(0, "outder", "", "Use DER format for output certificates and private keys.");
174 __gaa_helpsingle(0, "outraw", "", "Use RAW/DER format for output certificates and private keys.");
175 __gaa_helpsingle(0, "bits", "BITS ", "specify the number of bits for key generation.");
176 __gaa_helpsingle(0, "sec-param", "PARAM ", "specify the security level [low|normal|high|ultra].");
177 __gaa_helpsingle(0, "disable-quick-random", "", "Use /dev/random for key generationg, thus increasing the quality of randomness used.");
178 __gaa_helpsingle(0, "outfile", "FILE ", "Output file.");
179 __gaa_helpsingle(0, "infile", "FILE ", "Input file.");
180 __gaa_helpsingle(0, "template", "FILE ", "Template file to use for non interactive operation.");
181 __gaa_helpsingle(0, "pkcs-cipher", "CIPHER ", "Cipher to use for pkcs operations (3des,3des-pkcs12,aes-128,aes-192,aes-256,rc2-40,arcfour).");
182 __gaa_helpsingle('d', "debug", "LEVEL ", "specify the debug level. Default is 1.");
183 __gaa_helpsingle('h', "help", "", "shows this help text");
184 __gaa_helpsingle('v', "version", "", "shows the program's version");
192 #ifndef GAA_HEADER_POKY
193 #define GAA_HEADER_POKY
195 typedef struct _gaainfo gaainfo;
199 #line 140 "certtool.gaa"
201 #line 137 "certtool.gaa"
203 #line 134 "certtool.gaa"
205 #line 131 "certtool.gaa"
207 #line 128 "certtool.gaa"
209 #line 125 "certtool.gaa"
211 #line 122 "certtool.gaa"
213 #line 119 "certtool.gaa"
215 #line 115 "certtool.gaa"
217 #line 111 "certtool.gaa"
219 #line 108 "certtool.gaa"
221 #line 105 "certtool.gaa"
223 #line 102 "certtool.gaa"
225 #line 99 "certtool.gaa"
227 #line 92 "certtool.gaa"
229 #line 89 "certtool.gaa"
231 #line 72 "certtool.gaa"
233 #line 57 "certtool.gaa"
235 #line 54 "certtool.gaa"
237 #line 51 "certtool.gaa"
239 #line 48 "certtool.gaa"
241 #line 45 "certtool.gaa"
243 #line 42 "certtool.gaa"
245 #line 39 "certtool.gaa"
247 #line 17 "certtool.gaa"
249 #line 16 "certtool.gaa"
260 int gaa(int argc, char *argv[], gaainfo *gaaval);
264 int gaa_file(const char *name, gaainfo *gaaval);
277 #define GAAERROR(x) \
283 static char *gaa_current_option;
284 static int gaa_error = 0;
286 /* Generated by gaa */
294 #define GAA_ERROR_NOMATCH 0
295 #define GAA_ERROR_NOTENOUGH_ARGS 1
296 #define GAA_ERROR_INVALID_ARG 2
297 #define GAA_ERROR_UNKNOWN 3
299 #define GAA_NOT_AN_OPTION 0
300 #define GAA_WORD_OPTION 1
301 #define GAA_LETTER_OPTION 2
302 #define GAA_MULTIPLE_OPTION 3
305 #define GAA_NB_OPTION 53
306 #define GAAOPTID_version 1
307 #define GAAOPTID_help 2
308 #define GAAOPTID_debug 3
309 #define GAAOPTID_pkcs_cipher 4
310 #define GAAOPTID_template 5
311 #define GAAOPTID_infile 6
312 #define GAAOPTID_outfile 7
313 #define GAAOPTID_disable_quick_random 8
314 #define GAAOPTID_sec_param 9
315 #define GAAOPTID_bits 10
316 #define GAAOPTID_outraw 11
317 #define GAAOPTID_outder 12
318 #define GAAOPTID_inraw 13
319 #define GAAOPTID_inder 14
320 #define GAAOPTID_export_ciphers 15
321 #define GAAOPTID_hash 16
322 #define GAAOPTID_dsa 17
323 #define GAAOPTID_pkcs8 18
324 #define GAAOPTID_to_p8 19
325 #define GAAOPTID_to_p12 20
326 #define GAAOPTID_v1 21
327 #define GAAOPTID_fix_key 22
328 #define GAAOPTID_pubkey_info 23
329 #define GAAOPTID_pgp_key_info 24
330 #define GAAOPTID_key_info 25
331 #define GAAOPTID_smime_to_p7 26
332 #define GAAOPTID_p7_info 27
333 #define GAAOPTID_p12_info 28
334 #define GAAOPTID_no_crq_extensions 29
335 #define GAAOPTID_crq_info 30
336 #define GAAOPTID_crl_info 31
337 #define GAAOPTID_pgp_ring_info 32
338 #define GAAOPTID_pgp_certificate_info 33
339 #define GAAOPTID_certificate_pubkey 34
340 #define GAAOPTID_certificate_info 35
341 #define GAAOPTID_password 36
342 #define GAAOPTID_load_ca_certificate 37
343 #define GAAOPTID_load_ca_privkey 38
344 #define GAAOPTID_load_certificate 39
345 #define GAAOPTID_load_request 40
346 #define GAAOPTID_load_pubkey 41
347 #define GAAOPTID_load_privkey 42
348 #define GAAOPTID_get_dh_params 43
349 #define GAAOPTID_generate_dh_params 44
350 #define GAAOPTID_verify_crl 45
351 #define GAAOPTID_verify_chain 46
352 #define GAAOPTID_generate_request 47
353 #define GAAOPTID_generate_privkey 48
354 #define GAAOPTID_update_certificate 49
355 #define GAAOPTID_generate_crl 50
356 #define GAAOPTID_generate_proxy 51
357 #define GAAOPTID_generate_certificate 52
358 #define GAAOPTID_generate_self_signed 53
362 #define GAA_CHECK1STR(a,b) \
365 gaa_current_option = a; \
369 #define GAA_CHECKSTR(a,b) \
370 if(strcmp(a,str) == 0) \
372 gaa_current_option = a; \
376 #define GAA_TESTMOREARGS \
379 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
381 if(gaa_last_non_option == gaa_index) \
382 return GAA_ERROR_NOTENOUGH_ARGS; \
385 #define GAA_TESTMOREOPTIONALARGS \
388 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
390 if(gaa_last_non_option == gaa_index) \
394 #define GAA_FILL_2ARGS(target, func) \
395 target = func(GAAargv[gaa_index]); \
396 gaa_arg_used[gaa_index] = 1; \
400 return GAA_ERROR_INVALID_ARG; \
405 #define GAA_FILL(target, func, num) \
408 target = func(GAAargv[gaa_index]); \
409 gaa_arg_used[gaa_index] = 1; \
413 return GAA_ERROR_INVALID_ARG; \
422 #define GAA_LIST_FILL(target, func, type ,num) \
427 if ( gaa_last_non_option - gaa_index > 0) \
428 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
429 for(; gaa_index < gaa_last_non_option; gaa_index++) \
431 if(gaa_arg_used[gaa_index] == 0) \
433 GAA_FILL_2ARGS(target[num], func); \
438 return GAA_ERROR_NOTENOUGH_ARGS; \
441 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
446 if ( gaa_last_non_option - gaa_index > 0) \
447 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
448 for(; gaa_index < gaa_last_non_option; gaa_index++) \
450 if(gaa_arg_used[gaa_index] == 0) \
452 GAA_FILL_2ARGS(target[num], func); \
458 #define GAA_OBLIGAT(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 if(strlen(str) == 1) \
474 printf("You must give the -%s option\n", str); \
476 printf("You must give at least one option of '%s'\n", str); \
480 #define GAA_INCOMP(str) \
482 for(i = 0; i < strlen(str); i++) \
484 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
485 if(j == GAA_ERROR_NOMATCH) \
487 printf("Error: invalid 'obligat' set\n"); \
490 if(opt_list[j] == 1) \
495 printf("The options '%s' are incompatible\n", str); \
500 static char **GAAargv;
502 static char *gaa_arg_used;
503 static int gaa_processing_file = 0;
504 static int inited = 0;
506 static int gaa_getint(char *arg)
510 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
512 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
518 static char gaa_getchar(char *arg)
522 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
528 static char* gaa_getstr(char *arg)
532 static float gaa_getfloat(char *arg)
536 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
538 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
543 /* option structures */
545 struct GAAOPTION_debug
551 struct GAAOPTION_pkcs_cipher
557 struct GAAOPTION_template
563 struct GAAOPTION_infile
569 struct GAAOPTION_outfile
575 struct GAAOPTION_sec_param
581 struct GAAOPTION_bits
587 struct GAAOPTION_hash
593 struct GAAOPTION_password
599 struct GAAOPTION_load_ca_certificate
605 struct GAAOPTION_load_ca_privkey
611 struct GAAOPTION_load_certificate
617 struct GAAOPTION_load_request
623 struct GAAOPTION_load_pubkey
629 struct GAAOPTION_load_privkey
636 static int gaa_is_an_argument(char *str)
639 if(str[0] == '/' && str[1] != 0)
640 return GAA_MULTIPLE_OPTION;
643 return GAA_NOT_AN_OPTION;
645 return GAA_NOT_AN_OPTION;
649 return GAA_WORD_OPTION;
651 return GAA_NOT_AN_OPTION;
654 return GAA_LETTER_OPTION;
656 return GAA_MULTIPLE_OPTION;
659 static int gaa_get_option_num(char *str, int status)
663 case GAA_LETTER_OPTION:
664 GAA_CHECK1STR("d", GAAOPTID_debug);
665 GAA_CHECK1STR("", GAAOPTID_pkcs_cipher);
666 GAA_CHECK1STR("", GAAOPTID_template);
667 GAA_CHECK1STR("", GAAOPTID_infile);
668 GAA_CHECK1STR("", GAAOPTID_outfile);
669 GAA_CHECK1STR("", GAAOPTID_sec_param);
670 GAA_CHECK1STR("", GAAOPTID_bits);
671 GAA_CHECK1STR("", GAAOPTID_hash);
672 GAA_CHECK1STR("", GAAOPTID_password);
673 GAA_CHECK1STR("", GAAOPTID_load_ca_certificate);
674 GAA_CHECK1STR("", GAAOPTID_load_ca_privkey);
675 GAA_CHECK1STR("", GAAOPTID_load_certificate);
676 GAA_CHECK1STR("", GAAOPTID_load_request);
677 GAA_CHECK1STR("", GAAOPTID_load_pubkey);
678 GAA_CHECK1STR("", GAAOPTID_load_privkey);
679 case GAA_MULTIPLE_OPTION:
681 GAA_CHECK1STR("v", GAAOPTID_version);
682 GAA_CHECK1STR("h", GAAOPTID_help);
683 GAA_CHECK1STR("", GAAOPTID_disable_quick_random);
684 GAA_CHECK1STR("", GAAOPTID_outraw);
685 GAA_CHECK1STR("", GAAOPTID_outder);
686 GAA_CHECK1STR("", GAAOPTID_inraw);
687 GAA_CHECK1STR("", GAAOPTID_inder);
688 GAA_CHECK1STR("", GAAOPTID_export_ciphers);
689 GAA_CHECK1STR("", GAAOPTID_dsa);
690 GAA_CHECK1STR("8", GAAOPTID_pkcs8);
691 GAA_CHECK1STR("", GAAOPTID_to_p8);
692 GAA_CHECK1STR("", GAAOPTID_to_p12);
693 GAA_CHECK1STR("", GAAOPTID_v1);
694 GAA_CHECK1STR("", GAAOPTID_fix_key);
695 GAA_CHECK1STR("", GAAOPTID_pubkey_info);
696 GAA_CHECK1STR("", GAAOPTID_pgp_key_info);
697 GAA_CHECK1STR("k", GAAOPTID_key_info);
698 GAA_CHECK1STR("", GAAOPTID_smime_to_p7);
699 GAA_CHECK1STR("", GAAOPTID_p7_info);
700 GAA_CHECK1STR("", GAAOPTID_p12_info);
701 GAA_CHECK1STR("", GAAOPTID_no_crq_extensions);
702 GAA_CHECK1STR("", GAAOPTID_crq_info);
703 GAA_CHECK1STR("l", GAAOPTID_crl_info);
704 GAA_CHECK1STR("", GAAOPTID_pgp_ring_info);
705 GAA_CHECK1STR("", GAAOPTID_pgp_certificate_info);
706 GAA_CHECK1STR("", GAAOPTID_certificate_pubkey);
707 GAA_CHECK1STR("i", GAAOPTID_certificate_info);
708 GAA_CHECK1STR("", GAAOPTID_get_dh_params);
709 GAA_CHECK1STR("", GAAOPTID_generate_dh_params);
710 GAA_CHECK1STR("", GAAOPTID_verify_crl);
711 GAA_CHECK1STR("e", GAAOPTID_verify_chain);
712 GAA_CHECK1STR("q", GAAOPTID_generate_request);
713 GAA_CHECK1STR("p", GAAOPTID_generate_privkey);
714 GAA_CHECK1STR("u", GAAOPTID_update_certificate);
715 GAA_CHECK1STR("", GAAOPTID_generate_crl);
716 GAA_CHECK1STR("", GAAOPTID_generate_proxy);
717 GAA_CHECK1STR("c", GAAOPTID_generate_certificate);
718 GAA_CHECK1STR("s", GAAOPTID_generate_self_signed);
722 case GAA_WORD_OPTION:
723 GAA_CHECKSTR("version", GAAOPTID_version);
724 GAA_CHECKSTR("help", GAAOPTID_help);
725 GAA_CHECKSTR("debug", GAAOPTID_debug);
726 GAA_CHECKSTR("pkcs-cipher", GAAOPTID_pkcs_cipher);
727 GAA_CHECKSTR("template", GAAOPTID_template);
728 GAA_CHECKSTR("infile", GAAOPTID_infile);
729 GAA_CHECKSTR("outfile", GAAOPTID_outfile);
730 GAA_CHECKSTR("disable-quick-random", GAAOPTID_disable_quick_random);
731 GAA_CHECKSTR("sec-param", GAAOPTID_sec_param);
732 GAA_CHECKSTR("bits", GAAOPTID_bits);
733 GAA_CHECKSTR("outraw", GAAOPTID_outraw);
734 GAA_CHECKSTR("outder", GAAOPTID_outder);
735 GAA_CHECKSTR("inraw", GAAOPTID_inraw);
736 GAA_CHECKSTR("inder", GAAOPTID_inder);
737 GAA_CHECKSTR("export-ciphers", GAAOPTID_export_ciphers);
738 GAA_CHECKSTR("hash", GAAOPTID_hash);
739 GAA_CHECKSTR("dsa", GAAOPTID_dsa);
740 GAA_CHECKSTR("pkcs8", GAAOPTID_pkcs8);
741 GAA_CHECKSTR("to-p8", GAAOPTID_to_p8);
742 GAA_CHECKSTR("to-p12", GAAOPTID_to_p12);
743 GAA_CHECKSTR("v1", GAAOPTID_v1);
744 GAA_CHECKSTR("fix-key", GAAOPTID_fix_key);
745 GAA_CHECKSTR("pubkey-info", GAAOPTID_pubkey_info);
746 GAA_CHECKSTR("pgp-key-info", GAAOPTID_pgp_key_info);
747 GAA_CHECKSTR("key-info", GAAOPTID_key_info);
748 GAA_CHECKSTR("smime-to-p7", GAAOPTID_smime_to_p7);
749 GAA_CHECKSTR("p7-info", GAAOPTID_p7_info);
750 GAA_CHECKSTR("p12-info", GAAOPTID_p12_info);
751 GAA_CHECKSTR("no-crq-extensions", GAAOPTID_no_crq_extensions);
752 GAA_CHECKSTR("crq-info", GAAOPTID_crq_info);
753 GAA_CHECKSTR("crl-info", GAAOPTID_crl_info);
754 GAA_CHECKSTR("pgp-ring-info", GAAOPTID_pgp_ring_info);
755 GAA_CHECKSTR("pgp-certificate-info", GAAOPTID_pgp_certificate_info);
756 GAA_CHECKSTR("certificate-pubkey", GAAOPTID_certificate_pubkey);
757 GAA_CHECKSTR("certificate-info", GAAOPTID_certificate_info);
758 GAA_CHECKSTR("password", GAAOPTID_password);
759 GAA_CHECKSTR("load-ca-certificate", GAAOPTID_load_ca_certificate);
760 GAA_CHECKSTR("load-ca-privkey", GAAOPTID_load_ca_privkey);
761 GAA_CHECKSTR("load-certificate", GAAOPTID_load_certificate);
762 GAA_CHECKSTR("load-request", GAAOPTID_load_request);
763 GAA_CHECKSTR("load-pubkey", GAAOPTID_load_pubkey);
764 GAA_CHECKSTR("load-privkey", GAAOPTID_load_privkey);
765 GAA_CHECKSTR("get-dh-params", GAAOPTID_get_dh_params);
766 GAA_CHECKSTR("generate-dh-params", GAAOPTID_generate_dh_params);
767 GAA_CHECKSTR("verify-crl", GAAOPTID_verify_crl);
768 GAA_CHECKSTR("verify-chain", GAAOPTID_verify_chain);
769 GAA_CHECKSTR("generate-request", GAAOPTID_generate_request);
770 GAA_CHECKSTR("generate-privkey", GAAOPTID_generate_privkey);
771 GAA_CHECKSTR("update-certificate", GAAOPTID_update_certificate);
772 GAA_CHECKSTR("generate-crl", GAAOPTID_generate_crl);
773 GAA_CHECKSTR("generate-proxy", GAAOPTID_generate_proxy);
774 GAA_CHECKSTR("generate-certificate", GAAOPTID_generate_certificate);
775 GAA_CHECKSTR("generate-self-signed", GAAOPTID_generate_self_signed);
781 return GAA_ERROR_NOMATCH;
784 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
787 int gaa_last_non_option;
788 struct GAAOPTION_debug GAATMP_debug;
789 struct GAAOPTION_pkcs_cipher GAATMP_pkcs_cipher;
790 struct GAAOPTION_template GAATMP_template;
791 struct GAAOPTION_infile GAATMP_infile;
792 struct GAAOPTION_outfile GAATMP_outfile;
793 struct GAAOPTION_sec_param GAATMP_sec_param;
794 struct GAAOPTION_bits GAATMP_bits;
795 struct GAAOPTION_hash GAATMP_hash;
796 struct GAAOPTION_password GAATMP_password;
797 struct GAAOPTION_load_ca_certificate GAATMP_load_ca_certificate;
798 struct GAAOPTION_load_ca_privkey GAATMP_load_ca_privkey;
799 struct GAAOPTION_load_certificate GAATMP_load_certificate;
800 struct GAAOPTION_load_request GAATMP_load_request;
801 struct GAAOPTION_load_pubkey GAATMP_load_pubkey;
802 struct GAAOPTION_load_privkey GAATMP_load_privkey;
805 #ifdef GAA_REST_EXISTS
806 struct GAAREST GAAREST_tmp;
809 opt_list[gaa_num] = 1;
811 for(gaa_last_non_option = gaa_index;
812 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
813 gaa_last_non_option++);
815 if(gaa_num == GAA_REST)
818 gaa_last_non_option = GAAargc;
823 case GAAOPTID_version:
825 #line 145 "certtool.gaa"
826 { certtool_version(); exit(0); ;};
832 #line 143 "certtool.gaa"
833 { gaa_help(); exit(0); ;};
840 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
842 #line 141 "certtool.gaa"
843 { gaaval->debug = GAATMP_debug.arg1 ;};
847 case GAAOPTID_pkcs_cipher:
850 GAA_FILL(GAATMP_pkcs_cipher.arg1, gaa_getstr, GAATMP_pkcs_cipher.size1);
852 #line 138 "certtool.gaa"
853 { gaaval->pkcs_cipher = GAATMP_pkcs_cipher.arg1 ;};
857 case GAAOPTID_template:
860 GAA_FILL(GAATMP_template.arg1, gaa_getstr, GAATMP_template.size1);
862 #line 135 "certtool.gaa"
863 { gaaval->template = GAATMP_template.arg1 ;};
867 case GAAOPTID_infile:
870 GAA_FILL(GAATMP_infile.arg1, gaa_getstr, GAATMP_infile.size1);
872 #line 132 "certtool.gaa"
873 { gaaval->infile = GAATMP_infile.arg1 ;};
877 case GAAOPTID_outfile:
880 GAA_FILL(GAATMP_outfile.arg1, gaa_getstr, GAATMP_outfile.size1);
882 #line 129 "certtool.gaa"
883 { gaaval->outfile = GAATMP_outfile.arg1 ;};
887 case GAAOPTID_disable_quick_random:
889 #line 126 "certtool.gaa"
890 { gaaval->quick_random = 0; ;};
894 case GAAOPTID_sec_param:
897 GAA_FILL(GAATMP_sec_param.arg1, gaa_getstr, GAATMP_sec_param.size1);
899 #line 123 "certtool.gaa"
900 { gaaval->sec_param = GAATMP_sec_param.arg1 ;};
907 GAA_FILL(GAATMP_bits.arg1, gaa_getint, GAATMP_bits.size1);
909 #line 120 "certtool.gaa"
910 { gaaval->bits = GAATMP_bits.arg1 ;};
914 case GAAOPTID_outraw:
916 #line 117 "certtool.gaa"
917 { gaaval->outcert_format=1 ;};
921 case GAAOPTID_outder:
923 #line 116 "certtool.gaa"
924 { gaaval->outcert_format=1 ;};
930 #line 113 "certtool.gaa"
931 { gaaval->incert_format=1 ;};
937 #line 112 "certtool.gaa"
938 { gaaval->incert_format=1 ;};
942 case GAAOPTID_export_ciphers:
944 #line 109 "certtool.gaa"
945 { gaaval->export=1 ;};
952 GAA_FILL(GAATMP_hash.arg1, gaa_getstr, GAATMP_hash.size1);
954 #line 106 "certtool.gaa"
955 { gaaval->hash = GAATMP_hash.arg1 ;};
961 #line 103 "certtool.gaa"
968 #line 100 "certtool.gaa"
969 { gaaval->pkcs8=1 ;};
975 #line 97 "certtool.gaa"
976 { gaaval->action = ACTION_GENERATE_PKCS8; ;};
980 case GAAOPTID_to_p12:
982 #line 95 "certtool.gaa"
983 { gaaval->action = ACTION_TO_PKCS12; ;};
989 #line 93 "certtool.gaa"
990 { gaaval->v1_cert = 1; ;};
994 case GAAOPTID_fix_key:
996 #line 90 "certtool.gaa"
997 { gaaval->privkey_op=1; gaaval->fix_key = 1; ;};
1001 case GAAOPTID_pubkey_info:
1003 #line 87 "certtool.gaa"
1004 { gaaval->action = ACTION_PUBKEY_INFO; ;};
1008 case GAAOPTID_pgp_key_info:
1010 #line 85 "certtool.gaa"
1011 { gaaval->privkey_op=1; gaaval->action = ACTION_PGP_PRIVKEY_INFO; ;};
1015 case GAAOPTID_key_info:
1017 #line 83 "certtool.gaa"
1018 { gaaval->privkey_op=1; gaaval->action = ACTION_PRIVKEY_INFO; ;};
1022 case GAAOPTID_smime_to_p7:
1024 #line 79 "certtool.gaa"
1025 { gaaval->action = ACTION_SMIME_TO_P7; ;};
1029 case GAAOPTID_p7_info:
1031 #line 77 "certtool.gaa"
1032 { gaaval->action = ACTION_P7_INFO; ;};
1036 case GAAOPTID_p12_info:
1038 #line 75 "certtool.gaa"
1039 { gaaval->action = ACTION_PKCS12_INFO; ;};
1043 case GAAOPTID_no_crq_extensions:
1045 #line 73 "certtool.gaa"
1046 { gaaval->crq_extensions = 0; ;};
1050 case GAAOPTID_crq_info:
1052 #line 70 "certtool.gaa"
1053 { gaaval->action = ACTION_REQUEST; ;};
1057 case GAAOPTID_crl_info:
1059 #line 68 "certtool.gaa"
1060 { gaaval->action = ACTION_CRL_INFO; ;};
1064 case GAAOPTID_pgp_ring_info:
1066 #line 66 "certtool.gaa"
1067 { gaaval->action = ACTION_RING_INFO; ;};
1071 case GAAOPTID_pgp_certificate_info:
1073 #line 64 "certtool.gaa"
1074 { gaaval->action = ACTION_PGP_INFO; ;};
1078 case GAAOPTID_certificate_pubkey:
1080 #line 62 "certtool.gaa"
1081 { gaaval->action = ACTION_CERT_PUBKEY; ;};
1085 case GAAOPTID_certificate_info:
1087 #line 60 "certtool.gaa"
1088 { gaaval->action = ACTION_CERT_INFO; ;};
1092 case GAAOPTID_password:
1095 GAA_FILL(GAATMP_password.arg1, gaa_getstr, GAATMP_password.size1);
1097 #line 58 "certtool.gaa"
1098 { gaaval->pass = GAATMP_password.arg1 ;};
1102 case GAAOPTID_load_ca_certificate:
1105 GAA_FILL(GAATMP_load_ca_certificate.arg1, gaa_getstr, GAATMP_load_ca_certificate.size1);
1107 #line 55 "certtool.gaa"
1108 { gaaval->ca = GAATMP_load_ca_certificate.arg1 ;};
1112 case GAAOPTID_load_ca_privkey:
1115 GAA_FILL(GAATMP_load_ca_privkey.arg1, gaa_getstr, GAATMP_load_ca_privkey.size1);
1117 #line 52 "certtool.gaa"
1118 { gaaval->ca_privkey = GAATMP_load_ca_privkey.arg1 ;};
1122 case GAAOPTID_load_certificate:
1125 GAA_FILL(GAATMP_load_certificate.arg1, gaa_getstr, GAATMP_load_certificate.size1);
1127 #line 49 "certtool.gaa"
1128 { gaaval->cert = GAATMP_load_certificate.arg1 ;};
1132 case GAAOPTID_load_request:
1135 GAA_FILL(GAATMP_load_request.arg1, gaa_getstr, GAATMP_load_request.size1);
1137 #line 46 "certtool.gaa"
1138 { gaaval->request = GAATMP_load_request.arg1 ;};
1142 case GAAOPTID_load_pubkey:
1145 GAA_FILL(GAATMP_load_pubkey.arg1, gaa_getstr, GAATMP_load_pubkey.size1);
1147 #line 43 "certtool.gaa"
1148 { gaaval->pubkey = GAATMP_load_pubkey.arg1 ;};
1152 case GAAOPTID_load_privkey:
1155 GAA_FILL(GAATMP_load_privkey.arg1, gaa_getstr, GAATMP_load_privkey.size1);
1157 #line 40 "certtool.gaa"
1158 { gaaval->privkey = GAATMP_load_privkey.arg1 ;};
1162 case GAAOPTID_get_dh_params:
1164 #line 37 "certtool.gaa"
1165 { gaaval->action=ACTION_GET_DH; ;};
1169 case GAAOPTID_generate_dh_params:
1171 #line 36 "certtool.gaa"
1172 { gaaval->action=ACTION_GENERATE_DH; ;};
1176 case GAAOPTID_verify_crl:
1178 #line 34 "certtool.gaa"
1179 { gaaval->action=ACTION_VERIFY_CRL; ;};
1183 case GAAOPTID_verify_chain:
1185 #line 32 "certtool.gaa"
1186 { gaaval->action=ACTION_VERIFY_CHAIN; ;};
1190 case GAAOPTID_generate_request:
1192 #line 30 "certtool.gaa"
1193 { gaaval->privkey_op=1; gaaval->action=ACTION_GENERATE_REQUEST; ;};
1197 case GAAOPTID_generate_privkey:
1199 #line 28 "certtool.gaa"
1200 { gaaval->privkey_op=1; gaaval->action=ACTION_GENERATE_PRIVKEY; ;};
1204 case GAAOPTID_update_certificate:
1206 #line 26 "certtool.gaa"
1207 { gaaval->action=ACTION_UPDATE_CERTIFICATE; ;};
1211 case GAAOPTID_generate_crl:
1213 #line 24 "certtool.gaa"
1214 { gaaval->action=ACTION_GENERATE_CRL; ;};
1218 case GAAOPTID_generate_proxy:
1220 #line 22 "certtool.gaa"
1221 { gaaval->action=ACTION_GENERATE_PROXY; ;};
1225 case GAAOPTID_generate_certificate:
1227 #line 20 "certtool.gaa"
1228 { gaaval->action=ACTION_GENERATE_CERTIFICATE; ;};
1232 case GAAOPTID_generate_self_signed:
1234 #line 18 "certtool.gaa"
1235 { gaaval->action=ACTION_SELF_SIGNED; ;};
1240 #line 413 "gaa.skel"
1243 return GAA_ERROR_UNKNOWN;
1246 int gaa(int argc, char **argv, gaainfo *gaaval)
1255 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1257 for(i = 0; i < GAA_NB_OPTION + 1; i++)
1259 /* initialization */
1263 #line 147 "certtool.gaa"
1264 { gaaval->bits = 0; gaaval->pkcs8 = 0; gaaval->privkey = NULL; gaaval->ca=NULL; gaaval->ca_privkey = NULL;
1265 gaaval->debug=1; gaaval->request = NULL; gaaval->infile = NULL; gaaval->outfile = NULL; gaaval->cert = NULL;
1266 gaaval->incert_format = 0; gaaval->outcert_format = 0; gaaval->action=-1; gaaval->pass = NULL; gaaval->v1_cert = 0;
1267 gaaval->export = 0; gaaval->template = NULL; gaaval->hash=NULL; gaaval->fix_key = 0; gaaval->quick_random=1;
1268 gaaval->privkey_op = 0; gaaval->pkcs_cipher = "aes-128"; gaaval->crq_extensions=1; ;};
1272 #line 438 "gaa.skel"
1273 gaa_arg_used = NULL;
1276 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1279 for(i = 1; i < argc; i++)
1280 gaa_arg_used[i] = 0;
1281 for(i = 1; i < argc; i++)
1283 if(gaa_arg_used[i] == 0)
1286 tmp1 = gaa_is_an_argument(GAAargv[i]);
1289 case GAA_WORD_OPTION:
1291 case GAA_LETTER_OPTION:
1293 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1294 if(tmp2 == GAA_ERROR_NOMATCH)
1296 printf("Invalid option '%s'\n", argv[i]+j);
1299 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1301 case GAA_ERROR_NOTENOUGH_ARGS:
1302 printf("'%s': not enough arguments\n",gaa_current_option);
1304 case GAA_ERROR_INVALID_ARG:
1305 printf("Invalid arguments\n");
1310 printf("Unknown error\n");
1312 gaa_arg_used[i] = 1;
1314 case GAA_MULTIPLE_OPTION:
1315 for(j = 1; j < strlen(argv[i]); j++)
1317 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1318 if(tmp2 == GAA_ERROR_NOMATCH)
1320 printf("Invalid option '%c'\n", *(argv[i]+j));
1323 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1325 case GAA_ERROR_NOTENOUGH_ARGS:
1326 printf("'%s': not enough arguments\n",gaa_current_option);
1328 case GAA_ERROR_INVALID_ARG:
1329 printf("Invalid arguments\n");
1334 printf("Unknown error\n");
1337 gaa_arg_used[i] = 1;
1343 if(gaa_processing_file == 0)
1346 #line 507 "gaa.skel"
1347 #ifdef GAA_REST_EXISTS
1348 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1350 case GAA_ERROR_NOTENOUGH_ARGS:
1351 printf("Rest: not enough arguments\n");
1353 case GAA_ERROR_INVALID_ARG:
1354 printf("Invalid arguments\n");
1359 printf("Unknown error\n");
1363 for(i = 1; i < argc; i++)
1365 if(gaa_arg_used[i] == 0)
1367 printf("Too many arguments\n");
1379 struct gaastrnode *next;
1382 typedef struct gaastrnode gaa_str_node;
1384 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1388 int i = 0, len = 0, newline = 0;
1396 if (a == EOF) return 0;
1398 while(a == ' ' || a == 9 || a == '\n')
1406 if (a == EOF) return 0;
1409 pos_ini = ftell(file) - 1;
1411 while(a != ' ' && a != 9 && a != '\n')
1416 if(a==EOF) return 0;
1420 tmp_str->str = gaa_malloc((len) * sizeof(char));
1424 tmp_str->str[0] = '-';
1425 tmp_str->str[1] = '-';
1433 fseek(file,pos_ini, SEEK_SET);
1442 tmp_str->str[i] = a;
1445 while(a != ' ' && a != 9 && a != '\n' && i < len);
1447 tmp_str->str[i - 1] = 0;
1449 fseek(file,- 1, SEEK_CUR);
1450 /* printf("%d\n", ftell(file)); */
1455 int gaa_file(const char *name, gaainfo *gaaval)
1457 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1463 gaa_processing_file = 1;
1465 if((file = fopen(name, "r")) == NULL)
1467 printf("Couldn't open '%s' configuration file for reading\n", name);
1471 tmp_str = &first_str;
1475 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1477 (*tmp_str)->str = NULL;
1478 (*tmp_str)->next = NULL;
1480 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1481 tmp_str = &((*tmp_str)->next);
1488 argv = gaa_malloc((1 + argc) * sizeof(char*));
1490 tmp_str2 = first_str;
1492 for(i = 1; i < argc; i++)
1494 argv[i] = tmp_str2->str;
1495 tmp_str2 = tmp_str2->next;
1498 rval = gaa(argc, argv, gaaval);
1499 gaa_processing_file = 0;