File: | src/p11tool-gaa.c |
Location: | line 762, column 2 |
Description: | Value stored to 'OK' is never read |
1 | /* File generated by GAA 1.6.6 |
2 | */ |
3 | #define GAA_NO_WIN32 |
4 | #line 1 "p11tool.gaa" |
5 | |
6 | |
7 | /* C declarations */ |
8 | |
9 | #include <config.h> |
10 | #ifdef _WIN32 |
11 | # include <io.h> |
12 | #endif |
13 | |
14 | #include "certtool-common.h" |
15 | #include "p11tool.h" |
16 | #include <gnutls/pkcs11.h> |
17 | |
18 | #include <stdio.h> |
19 | #include <string.h> |
20 | #include <stdlib.h> |
21 | |
22 | #ifndef GAA_NO_WIN32 |
23 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS) |
24 | #define GAA_WIN32 |
25 | #endif |
26 | #endif |
27 | |
28 | static void* gaa_malloc( size_t size) { |
29 | void* ret; |
30 | ret = malloc(size); |
31 | if (ret==NULL((void*)0)) { |
32 | fprintf(stderrstderr, "gaa: could not allocate memory"); |
33 | exit(1); |
34 | } |
35 | return ret; |
36 | } |
37 | |
38 | static void __gaa_helpsingle(char short_name, char *name, |
39 | char *arg_desc, char *opt_help) |
40 | { |
41 | int col1, col3, col4, tabsize = 3, curr; |
42 | int i; |
43 | |
44 | col1 = 5; /* Default values */ |
45 | col3 = 30; |
46 | col4 = 70; |
47 | |
48 | curr = 0; |
49 | for(i = 0; i < col1; i++) |
50 | { |
51 | printf(" "); |
52 | curr++; |
53 | } |
54 | if(short_name) |
55 | { |
56 | if(name && *name) |
57 | { |
58 | printf("-%c, ", short_name); |
59 | curr += 4; |
60 | } |
61 | else |
62 | { |
63 | printf("-%c ", short_name); |
64 | curr += 3; |
65 | } |
66 | } |
67 | if(name && *name) |
68 | { |
69 | printf("--%s ", name); |
70 | curr += 3 + strlen(name); |
71 | } |
72 | if(arg_desc && *arg_desc) |
73 | { |
74 | printf("%s ", arg_desc); |
75 | curr += 1 + strlen(arg_desc); |
76 | } |
77 | if(curr >= col3) |
78 | { |
79 | printf("\n"); |
80 | curr = 0; |
81 | } |
82 | if(opt_help) /* let's print the option's help body */ |
83 | { |
84 | const char *str = opt_help; |
85 | while(*str) |
86 | { |
87 | while(curr < col3) |
88 | { |
89 | printf(" "); |
90 | curr++; |
91 | } |
92 | switch(*str) |
93 | { |
94 | case '\n': |
95 | printf("\n"); |
96 | curr = 0; |
97 | break; |
98 | case '\t': |
99 | do |
100 | { |
101 | printf(" "); |
102 | curr++; |
103 | } |
104 | while((curr - col3) % tabsize != 0 && curr < col4); |
105 | case ' ': |
106 | if(*str == ' ') |
107 | { |
108 | curr++; |
109 | printf(" "); |
110 | } |
111 | for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n' |
112 | && str[i] != '\t'; i++); |
113 | if(curr + i - 1 >= col4) |
114 | curr = col4; |
115 | break; |
116 | default: |
117 | printf("%c", *str); |
118 | curr++; |
119 | } |
120 | if(curr >= col4) |
121 | { |
122 | printf("\n"); |
123 | curr = 0; |
124 | } |
125 | str++; |
126 | } |
127 | } |
128 | printf("\n"); |
129 | } |
130 | |
131 | void gaa_help(void) |
132 | { |
133 | printf("p11tool help\nUsage: p11tool [options]\n"); |
134 | printf("Usage: p11tool --list-tokens\n"); |
135 | printf("Usage: p11tool --list-all\n"); |
136 | printf("Usage: p11tool --export 'pkcs11:...'\n\n"); |
137 | __gaa_helpsingle(0, "export", "URL ", "Export an object specified by a pkcs11 URL"); |
138 | __gaa_helpsingle(0, "list-tokens", "", "List all available tokens"); |
139 | __gaa_helpsingle(0, "list-mechanisms", "URL ", "List all available mechanisms in token."); |
140 | __gaa_helpsingle(0, "list-all", "", "List all objects specified by a PKCS#11 URL"); |
141 | __gaa_helpsingle(0, "list-all-certs", "", "List all certificates specified by a PKCS#11 URL"); |
142 | __gaa_helpsingle(0, "list-certs", "", "List certificates that have a private key specified by a PKCS#11 URL"); |
143 | __gaa_helpsingle(0, "list-privkeys", "", "List private keys specified by a PKCS#11 URL"); |
144 | __gaa_helpsingle(0, "list-trusted", "", "List certificates marked as trusted, specified by a PKCS#11 URL"); |
145 | __gaa_helpsingle(0, "initialize", "URL ", "Initializes a PKCS11 token."); |
146 | __gaa_helpsingle(0, "write", "URL ", "Writes loaded certificates, private or secret keys to a PKCS11 token."); |
147 | __gaa_helpsingle(0, "delete", "URL ", "Deletes objects matching the URL."); |
148 | __gaa_helpsingle(0, "generate-rsa", "URL ", "Generates an RSA private key on the specified token."); |
149 | __gaa_helpsingle(0, "generate-dsa", "URL ", "Generates a DSA private key on the specified token."); |
150 | __gaa_helpsingle(0, "generate-ecc", "URL ", "Generates an ECDSA private key on the specified token."); |
151 | __gaa_helpsingle(0, "label", "label ", "Sets a label for the write operation."); |
152 | __gaa_helpsingle(0, "trusted", "", "Marks the certificate to be written as trusted."); |
153 | __gaa_helpsingle(0, "private", "", "Marks the object to be written as private (requires PIN)."); |
154 | __gaa_helpsingle(0, "no-private", "", "Marks the object to be written as not private."); |
155 | __gaa_helpsingle(0, "login", "", "Force login to token"); |
156 | __gaa_helpsingle(0, "detailed-url", "", "Export detailed URLs."); |
157 | __gaa_helpsingle(0, "no-detailed-url", "", "Export less detailed URLs."); |
158 | __gaa_helpsingle(0, "secret-key", "HEX_KEY ", "Provide a hex encoded secret key."); |
159 | __gaa_helpsingle(0, "load-privkey", "FILE ", "Private key file to use."); |
160 | __gaa_helpsingle(0, "load-pubkey", "FILE ", "Private key file to use."); |
161 | __gaa_helpsingle(0, "load-certificate", "FILE ", "Certificate file to use."); |
162 | __gaa_helpsingle('8', "pkcs8", "", "Use PKCS #8 format for private keys."); |
163 | __gaa_helpsingle(0, "bits", "BITS ", "specify the number of bits for key generation."); |
164 | __gaa_helpsingle(0, "sec-param", "PARAM ", "specify the security level [low|normal|high|ultra]."); |
165 | __gaa_helpsingle(0, "inder", "", "Use DER format for input certificates and private keys."); |
166 | __gaa_helpsingle(0, "inraw", "", "Use RAW/DER format for input certificates and private keys."); |
167 | __gaa_helpsingle(0, "provider", "Library ", "Specify the pkcs11 provider library"); |
168 | __gaa_helpsingle(0, "outfile", "FILE ", "Output file."); |
169 | __gaa_helpsingle('d', "debug", "LEVEL ", "specify the debug level. Default is 1."); |
170 | __gaa_helpsingle('h', "help", "", "shows this help text"); |
171 | |
172 | #line 100 "gaa.skel" |
173 | } |
174 | /* Copy of C area */ |
175 | |
176 | #line 104 "gaa.skel" |
177 | /* GAA HEADER */ |
178 | #ifndef GAA_HEADER_POKY |
179 | #define GAA_HEADER_POKY |
180 | |
181 | typedef struct _gaainfo gaainfo; |
182 | |
183 | struct _gaainfo |
184 | { |
185 | #line 94 "p11tool.gaa" |
186 | int debug; |
187 | #line 89 "p11tool.gaa" |
188 | char *outfile; |
189 | #line 86 "p11tool.gaa" |
190 | int action; |
191 | #line 85 "p11tool.gaa" |
192 | char* pkcs11_provider; |
193 | #line 81 "p11tool.gaa" |
194 | int incert_format; |
195 | #line 78 "p11tool.gaa" |
196 | char* sec_param; |
197 | #line 75 "p11tool.gaa" |
198 | int bits; |
199 | #line 72 "p11tool.gaa" |
200 | int pkcs8; |
201 | #line 69 "p11tool.gaa" |
202 | char *cert; |
203 | #line 66 "p11tool.gaa" |
204 | char *pubkey; |
205 | #line 63 "p11tool.gaa" |
206 | char *privkey; |
207 | #line 60 "p11tool.gaa" |
208 | char* secret_key; |
209 | #line 56 "p11tool.gaa" |
210 | int pkcs11_detailed_url; |
211 | #line 53 "p11tool.gaa" |
212 | int pkcs11_login; |
213 | #line 49 "p11tool.gaa" |
214 | int pkcs11_private; |
215 | #line 46 "p11tool.gaa" |
216 | int pkcs11_trusted; |
217 | #line 40 "p11tool.gaa" |
218 | int key_type; |
219 | #line 35 "p11tool.gaa" |
220 | char* pkcs11_label; |
221 | #line 24 "p11tool.gaa" |
222 | int pkcs11_type; |
223 | #line 21 "p11tool.gaa" |
224 | char* pkcs11_url; |
225 | |
226 | #line 114 "gaa.skel" |
227 | }; |
228 | |
229 | #ifdef __cplusplus |
230 | extern "C" |
231 | { |
232 | #endif |
233 | |
234 | int gaa(int argc, char *argv[], gaainfo *gaaval); |
235 | |
236 | void gaa_help(void); |
237 | |
238 | int gaa_file(const char *name, gaainfo *gaaval); |
239 | |
240 | #ifdef __cplusplus |
241 | } |
242 | #endif |
243 | |
244 | |
245 | #endif |
246 | |
247 | #line 135 "gaa.skel" |
248 | |
249 | /* C declarations */ |
250 | |
251 | #define GAAERROR(x){ gaa_error = 1; return x; } \ |
252 | { \ |
253 | gaa_error = 1; \ |
254 | return x; \ |
255 | } |
256 | |
257 | static char *gaa_current_option; |
258 | static int gaa_error = 0; |
259 | |
260 | /* Generated by gaa */ |
261 | |
262 | #include <string.h> |
263 | #include <stdlib.h> |
264 | |
265 | |
266 | #define GAA_OK-1 -1 |
267 | |
268 | #define GAA_ERROR_NOMATCH0 0 |
269 | #define GAA_ERROR_NOTENOUGH_ARGS1 1 |
270 | #define GAA_ERROR_INVALID_ARG2 2 |
271 | #define GAA_ERROR_UNKNOWN3 3 |
272 | |
273 | #define GAA_NOT_AN_OPTION0 0 |
274 | #define GAA_WORD_OPTION1 1 |
275 | #define GAA_LETTER_OPTION2 2 |
276 | #define GAA_MULTIPLE_OPTION3 3 |
277 | |
278 | #define GAA_REST0 0 |
279 | #define GAA_NB_OPTION34 34 |
280 | #define GAAOPTID_help1 1 |
281 | #define GAAOPTID_debug2 2 |
282 | #define GAAOPTID_outfile3 3 |
283 | #define GAAOPTID_provider4 4 |
284 | #define GAAOPTID_inraw5 5 |
285 | #define GAAOPTID_inder6 6 |
286 | #define GAAOPTID_sec_param7 7 |
287 | #define GAAOPTID_bits8 8 |
288 | #define GAAOPTID_pkcs89 9 |
289 | #define GAAOPTID_load_certificate10 10 |
290 | #define GAAOPTID_load_pubkey11 11 |
291 | #define GAAOPTID_load_privkey12 12 |
292 | #define GAAOPTID_secret_key13 13 |
293 | #define GAAOPTID_no_detailed_url14 14 |
294 | #define GAAOPTID_detailed_url15 15 |
295 | #define GAAOPTID_login16 16 |
296 | #define GAAOPTID_no_private17 17 |
297 | #define GAAOPTID_private18 18 |
298 | #define GAAOPTID_trusted19 19 |
299 | #define GAAOPTID_label20 20 |
300 | #define GAAOPTID_generate_ecc21 21 |
301 | #define GAAOPTID_generate_dsa22 22 |
302 | #define GAAOPTID_generate_rsa23 23 |
303 | #define GAAOPTID_delete24 24 |
304 | #define GAAOPTID_write25 25 |
305 | #define GAAOPTID_initialize26 26 |
306 | #define GAAOPTID_list_trusted27 27 |
307 | #define GAAOPTID_list_privkeys28 28 |
308 | #define GAAOPTID_list_certs29 29 |
309 | #define GAAOPTID_list_all_certs30 30 |
310 | #define GAAOPTID_list_all31 31 |
311 | #define GAAOPTID_list_mechanisms32 32 |
312 | #define GAAOPTID_list_tokens33 33 |
313 | #define GAAOPTID_export34 34 |
314 | |
315 | #line 168 "gaa.skel" |
316 | |
317 | #define GAA_CHECK1STR(a,b)if(a[0] == str[0]) { gaa_current_option = a; return b; } \ |
318 | if(a[0] == str[0]) \ |
319 | { \ |
320 | gaa_current_option = a; \ |
321 | return b; \ |
322 | } |
323 | |
324 | #define GAA_CHECKSTR(a,b)if(strcmp(a,str) == 0) { gaa_current_option = a; return b; } \ |
325 | if(strcmp(a,str) == 0) \ |
326 | { \ |
327 | gaa_current_option = a; \ |
328 | return b; \ |
329 | } |
330 | |
331 | #define GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; } \ |
332 | if(!OK) \ |
333 | { \ |
334 | while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \ |
335 | gaa_index++; \ |
336 | if(gaa_last_non_option == gaa_index) \ |
337 | return GAA_ERROR_NOTENOUGH_ARGS1; \ |
338 | } |
339 | |
340 | #define GAA_TESTMOREOPTIONALARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) OK = 1; } \ |
341 | if(!OK) \ |
342 | { \ |
343 | while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \ |
344 | gaa_index++; \ |
345 | if(gaa_last_non_option == gaa_index) \ |
346 | OK = 1; \ |
347 | } |
348 | |
349 | #define GAA_FILL_2ARGS(target, func)target = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1 ; if(gaa_error == 1) { gaa_error = 0; return 2; } \ |
350 | target = func(GAAargv[gaa_index]); \ |
351 | gaa_arg_used[gaa_index] = 1; \ |
352 | if(gaa_error == 1) \ |
353 | { \ |
354 | gaa_error = 0; \ |
355 | return GAA_ERROR_INVALID_ARG2; \ |
356 | } |
357 | |
358 | |
359 | |
360 | #define GAA_FILL(target, func, num)if(!OK) { target = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index ] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } num = 1 ; } else { num = 0; } \ |
361 | if(!OK) \ |
362 | { \ |
363 | target = func(GAAargv[gaa_index]); \ |
364 | gaa_arg_used[gaa_index] = 1; \ |
365 | if(gaa_error == 1) \ |
366 | { \ |
367 | gaa_error = 0; \ |
368 | return GAA_ERROR_INVALID_ARG2; \ |
369 | } \ |
370 | num = 1; \ |
371 | } \ |
372 | else \ |
373 | { \ |
374 | num = 0; \ |
375 | } |
376 | |
377 | #define GAA_LIST_FILL(target, func, type ,num)if(!OK) { num = 0; target = ((void*)0); if ( gaa_last_non_option - gaa_index > 0) target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));for(; gaa_index < gaa_last_non_option ; gaa_index++) { if(gaa_arg_used[gaa_index] == 0) { target[num ] = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1; if (gaa_error == 1) { gaa_error = 0; return 2; }; num++; } } if( num == 0) return 1; } \ |
378 | if(!OK) \ |
379 | { \ |
380 | num = 0; \ |
381 | target = NULL((void*)0); \ |
382 | if ( gaa_last_non_option - gaa_index > 0) \ |
383 | target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\ |
384 | for(; gaa_index < gaa_last_non_option; gaa_index++) \ |
385 | { \ |
386 | if(gaa_arg_used[gaa_index] == 0) \ |
387 | { \ |
388 | GAA_FILL_2ARGS(target[num], func)target[num] = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index ] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; }; \ |
389 | num++; \ |
390 | } \ |
391 | } \ |
392 | if(num == 0) \ |
393 | return GAA_ERROR_NOTENOUGH_ARGS1; \ |
394 | } |
395 | |
396 | #define GAA_OPTIONALLIST_FILL(target, func, type ,num)if(!OK) { num = 0; target = ((void*)0); if ( gaa_last_non_option - gaa_index > 0) target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));for(; gaa_index < gaa_last_non_option ; gaa_index++) { if(gaa_arg_used[gaa_index] == 0) { target[num ] = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1; if (gaa_error == 1) { gaa_error = 0; return 2; }; num++; } } } \ |
397 | if(!OK) \ |
398 | { \ |
399 | num = 0; \ |
400 | target = NULL((void*)0); \ |
401 | if ( gaa_last_non_option - gaa_index > 0) \ |
402 | target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\ |
403 | for(; gaa_index < gaa_last_non_option; gaa_index++) \ |
404 | { \ |
405 | if(gaa_arg_used[gaa_index] == 0) \ |
406 | { \ |
407 | GAA_FILL_2ARGS(target[num], func)target[num] = func(GAAargv[gaa_index]); gaa_arg_used[gaa_index ] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; }; \ |
408 | num++; \ |
409 | } \ |
410 | } \ |
411 | } |
412 | |
413 | #define GAA_OBLIGAT(str)k = 0; for(i = 0; i < strlen(str); i++) { j = gaa_get_option_num (str + i, 2); if(j == 0) { printf("Error: invalid 'obligat' set\n" ); exit(-1); } if(opt_list[j] == 1) k = 1; } if(k == 0) { if( strlen(str) == 1) printf("You must give the -%s option\n", str ); else printf("You must give at least one option of '%s'\n", str); return 0; } \ |
414 | k = 0; \ |
415 | for(i = 0; i < strlen(str); i++) \ |
416 | { \ |
417 | j = gaa_get_option_num(str + i, GAA_LETTER_OPTION2); \ |
418 | if(j == GAA_ERROR_NOMATCH0) \ |
419 | { \ |
420 | printf("Error: invalid 'obligat' set\n"); \ |
421 | exit(-1); \ |
422 | } \ |
423 | if(opt_list[j] == 1) \ |
424 | k = 1; \ |
425 | } \ |
426 | if(k == 0) \ |
427 | { \ |
428 | if(strlen(str) == 1) \ |
429 | printf("You must give the -%s option\n", str); \ |
430 | else \ |
431 | printf("You must give at least one option of '%s'\n", str); \ |
432 | return 0; \ |
433 | } |
434 | |
435 | #define GAA_INCOMP(str)k = 0; for(i = 0; i < strlen(str); i++) { j = gaa_get_option_num (str + i, 2); if(j == 0) { printf("Error: invalid 'obligat' set\n" ); exit(-1); } if(opt_list[j] == 1) k++; } if(k > 1) { printf ("The options '%s' are incompatible\n", str); return 0; } \ |
436 | k = 0; \ |
437 | for(i = 0; i < strlen(str); i++) \ |
438 | { \ |
439 | j = gaa_get_option_num(str + i, GAA_LETTER_OPTION2); \ |
440 | if(j == GAA_ERROR_NOMATCH0) \ |
441 | { \ |
442 | printf("Error: invalid 'obligat' set\n"); \ |
443 | exit(-1); \ |
444 | } \ |
445 | if(opt_list[j] == 1) \ |
446 | k++; \ |
447 | } \ |
448 | if(k > 1) \ |
449 | { \ |
450 | printf("The options '%s' are incompatible\n", str); \ |
451 | return 0; \ |
452 | } |
453 | |
454 | |
455 | static char **GAAargv; |
456 | static int GAAargc; |
457 | static char *gaa_arg_used; |
458 | static int gaa_processing_file = 0; |
459 | static int inited = 0; |
460 | |
461 | static int gaa_getint(char *arg) |
462 | { |
463 | int tmp; |
464 | char a; |
465 | if(sscanf(arg, "%d%c", &tmp, &a) < 1) |
466 | { |
467 | printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg); |
468 | GAAERROR(-1){ gaa_error = 1; return -1; }; |
469 | } |
470 | return tmp; |
471 | } |
472 | |
473 | static char gaa_getchar(char *arg) |
474 | { |
475 | if(strlen(arg) != 1) |
476 | { |
477 | printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg); |
478 | GAAERROR(-1){ gaa_error = 1; return -1; }; |
479 | } |
480 | return arg[0]; |
481 | } |
482 | |
483 | static char* gaa_getstr(char *arg) |
484 | { |
485 | return arg; |
486 | } |
487 | static float gaa_getfloat(char *arg) |
488 | { |
489 | float tmp; |
490 | char a; |
491 | if(sscanf(arg, "%f%c", &tmp, &a) < 1) |
492 | { |
493 | printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg); |
494 | GAAERROR(-1){ gaa_error = 1; return -1; }; |
495 | } |
496 | return tmp; |
497 | } |
498 | /* option structures */ |
499 | |
500 | struct GAAOPTION_debug |
501 | { |
502 | int arg1; |
503 | int size1; |
504 | }; |
505 | |
506 | struct GAAOPTION_outfile |
507 | { |
508 | char* arg1; |
509 | int size1; |
510 | }; |
511 | |
512 | struct GAAOPTION_provider |
513 | { |
514 | char* arg1; |
515 | int size1; |
516 | }; |
517 | |
518 | struct GAAOPTION_sec_param |
519 | { |
520 | char* arg1; |
521 | int size1; |
522 | }; |
523 | |
524 | struct GAAOPTION_bits |
525 | { |
526 | int arg1; |
527 | int size1; |
528 | }; |
529 | |
530 | struct GAAOPTION_load_certificate |
531 | { |
532 | char* arg1; |
533 | int size1; |
534 | }; |
535 | |
536 | struct GAAOPTION_load_pubkey |
537 | { |
538 | char* arg1; |
539 | int size1; |
540 | }; |
541 | |
542 | struct GAAOPTION_load_privkey |
543 | { |
544 | char* arg1; |
545 | int size1; |
546 | }; |
547 | |
548 | struct GAAOPTION_secret_key |
549 | { |
550 | char* arg1; |
551 | int size1; |
552 | }; |
553 | |
554 | struct GAAOPTION_label |
555 | { |
556 | char* arg1; |
557 | int size1; |
558 | }; |
559 | |
560 | struct GAAOPTION_generate_ecc |
561 | { |
562 | char* arg1; |
563 | int size1; |
564 | }; |
565 | |
566 | struct GAAOPTION_generate_dsa |
567 | { |
568 | char* arg1; |
569 | int size1; |
570 | }; |
571 | |
572 | struct GAAOPTION_generate_rsa |
573 | { |
574 | char* arg1; |
575 | int size1; |
576 | }; |
577 | |
578 | struct GAAOPTION_delete |
579 | { |
580 | char* arg1; |
581 | int size1; |
582 | }; |
583 | |
584 | struct GAAOPTION_write |
585 | { |
586 | char* arg1; |
587 | int size1; |
588 | }; |
589 | |
590 | struct GAAOPTION_initialize |
591 | { |
592 | char* arg1; |
593 | int size1; |
594 | }; |
595 | |
596 | struct GAAOPTION_list_mechanisms |
597 | { |
598 | char* arg1; |
599 | int size1; |
600 | }; |
601 | |
602 | struct GAAOPTION_export |
603 | { |
604 | char* arg1; |
605 | int size1; |
606 | }; |
607 | |
608 | #line 349 "gaa.skel" |
609 | static int gaa_is_an_argument(char *str) |
610 | { |
611 | #ifdef GAA_WIN32 |
612 | if(str[0] == '/' && str[1] != 0) |
613 | return GAA_MULTIPLE_OPTION3; |
614 | #endif |
615 | if(str[0] != '-') |
616 | return GAA_NOT_AN_OPTION0; |
617 | if(str[1] == 0) |
618 | return GAA_NOT_AN_OPTION0; |
619 | if(str[1] == '-') |
620 | { |
621 | if(str[2] != 0) |
622 | return GAA_WORD_OPTION1; |
623 | else |
624 | return GAA_NOT_AN_OPTION0; |
625 | } |
626 | if(str[2] == 0) |
627 | return GAA_LETTER_OPTION2; |
628 | else |
629 | return GAA_MULTIPLE_OPTION3; |
630 | } |
631 | |
632 | static int gaa_get_option_num(char *str, int status) |
633 | { |
634 | switch(status) |
635 | { |
636 | case GAA_LETTER_OPTION2: |
637 | GAA_CHECK1STR("d", GAAOPTID_debug)if("d"[0] == str[0]) { gaa_current_option = "d"; return 2; }; |
638 | GAA_CHECK1STR("", GAAOPTID_outfile)if(""[0] == str[0]) { gaa_current_option = ""; return 3; }; |
639 | GAA_CHECK1STR("", GAAOPTID_provider)if(""[0] == str[0]) { gaa_current_option = ""; return 4; }; |
640 | GAA_CHECK1STR("", GAAOPTID_sec_param)if(""[0] == str[0]) { gaa_current_option = ""; return 7; }; |
641 | GAA_CHECK1STR("", GAAOPTID_bits)if(""[0] == str[0]) { gaa_current_option = ""; return 8; }; |
642 | GAA_CHECK1STR("", GAAOPTID_load_certificate)if(""[0] == str[0]) { gaa_current_option = ""; return 10; }; |
643 | GAA_CHECK1STR("", GAAOPTID_load_pubkey)if(""[0] == str[0]) { gaa_current_option = ""; return 11; }; |
644 | GAA_CHECK1STR("", GAAOPTID_load_privkey)if(""[0] == str[0]) { gaa_current_option = ""; return 12; }; |
645 | GAA_CHECK1STR("", GAAOPTID_secret_key)if(""[0] == str[0]) { gaa_current_option = ""; return 13; }; |
646 | GAA_CHECK1STR("", GAAOPTID_label)if(""[0] == str[0]) { gaa_current_option = ""; return 20; }; |
647 | GAA_CHECK1STR("", GAAOPTID_generate_ecc)if(""[0] == str[0]) { gaa_current_option = ""; return 21; }; |
648 | GAA_CHECK1STR("", GAAOPTID_generate_dsa)if(""[0] == str[0]) { gaa_current_option = ""; return 22; }; |
649 | GAA_CHECK1STR("", GAAOPTID_generate_rsa)if(""[0] == str[0]) { gaa_current_option = ""; return 23; }; |
650 | GAA_CHECK1STR("", GAAOPTID_delete)if(""[0] == str[0]) { gaa_current_option = ""; return 24; }; |
651 | GAA_CHECK1STR("", GAAOPTID_write)if(""[0] == str[0]) { gaa_current_option = ""; return 25; }; |
652 | GAA_CHECK1STR("", GAAOPTID_initialize)if(""[0] == str[0]) { gaa_current_option = ""; return 26; }; |
653 | GAA_CHECK1STR("", GAAOPTID_list_mechanisms)if(""[0] == str[0]) { gaa_current_option = ""; return 32; }; |
654 | GAA_CHECK1STR("", GAAOPTID_export)if(""[0] == str[0]) { gaa_current_option = ""; return 34; }; |
655 | case GAA_MULTIPLE_OPTION3: |
656 | #line 375 "gaa.skel" |
657 | GAA_CHECK1STR("h", GAAOPTID_help)if("h"[0] == str[0]) { gaa_current_option = "h"; return 1; }; |
658 | GAA_CHECK1STR("", GAAOPTID_inraw)if(""[0] == str[0]) { gaa_current_option = ""; return 5; }; |
659 | GAA_CHECK1STR("", GAAOPTID_inder)if(""[0] == str[0]) { gaa_current_option = ""; return 6; }; |
660 | GAA_CHECK1STR("8", GAAOPTID_pkcs8)if("8"[0] == str[0]) { gaa_current_option = "8"; return 9; }; |
661 | GAA_CHECK1STR("", GAAOPTID_no_detailed_url)if(""[0] == str[0]) { gaa_current_option = ""; return 14; }; |
662 | GAA_CHECK1STR("", GAAOPTID_detailed_url)if(""[0] == str[0]) { gaa_current_option = ""; return 15; }; |
663 | GAA_CHECK1STR("", GAAOPTID_login)if(""[0] == str[0]) { gaa_current_option = ""; return 16; }; |
664 | GAA_CHECK1STR("", GAAOPTID_no_private)if(""[0] == str[0]) { gaa_current_option = ""; return 17; }; |
665 | GAA_CHECK1STR("", GAAOPTID_private)if(""[0] == str[0]) { gaa_current_option = ""; return 18; }; |
666 | GAA_CHECK1STR("", GAAOPTID_trusted)if(""[0] == str[0]) { gaa_current_option = ""; return 19; }; |
667 | GAA_CHECK1STR("", GAAOPTID_list_trusted)if(""[0] == str[0]) { gaa_current_option = ""; return 27; }; |
668 | GAA_CHECK1STR("", GAAOPTID_list_privkeys)if(""[0] == str[0]) { gaa_current_option = ""; return 28; }; |
669 | GAA_CHECK1STR("", GAAOPTID_list_certs)if(""[0] == str[0]) { gaa_current_option = ""; return 29; }; |
670 | GAA_CHECK1STR("", GAAOPTID_list_all_certs)if(""[0] == str[0]) { gaa_current_option = ""; return 30; }; |
671 | GAA_CHECK1STR("", GAAOPTID_list_all)if(""[0] == str[0]) { gaa_current_option = ""; return 31; }; |
672 | GAA_CHECK1STR("", GAAOPTID_list_tokens)if(""[0] == str[0]) { gaa_current_option = ""; return 33; }; |
673 | |
674 | #line 277 "gaa.skel" |
675 | break; |
676 | case GAA_WORD_OPTION1: |
677 | GAA_CHECKSTR("help", GAAOPTID_help)if(strcmp("help",str) == 0) { gaa_current_option = "help"; return 1; }; |
678 | GAA_CHECKSTR("debug", GAAOPTID_debug)if(strcmp("debug",str) == 0) { gaa_current_option = "debug"; return 2; }; |
679 | GAA_CHECKSTR("outfile", GAAOPTID_outfile)if(strcmp("outfile",str) == 0) { gaa_current_option = "outfile" ; return 3; }; |
680 | GAA_CHECKSTR("provider", GAAOPTID_provider)if(strcmp("provider",str) == 0) { gaa_current_option = "provider" ; return 4; }; |
681 | GAA_CHECKSTR("inraw", GAAOPTID_inraw)if(strcmp("inraw",str) == 0) { gaa_current_option = "inraw"; return 5; }; |
682 | GAA_CHECKSTR("inder", GAAOPTID_inder)if(strcmp("inder",str) == 0) { gaa_current_option = "inder"; return 6; }; |
683 | GAA_CHECKSTR("sec-param", GAAOPTID_sec_param)if(strcmp("sec-param",str) == 0) { gaa_current_option = "sec-param" ; return 7; }; |
684 | GAA_CHECKSTR("bits", GAAOPTID_bits)if(strcmp("bits",str) == 0) { gaa_current_option = "bits"; return 8; }; |
685 | GAA_CHECKSTR("pkcs8", GAAOPTID_pkcs8)if(strcmp("pkcs8",str) == 0) { gaa_current_option = "pkcs8"; return 9; }; |
686 | GAA_CHECKSTR("load-certificate", GAAOPTID_load_certificate)if(strcmp("load-certificate",str) == 0) { gaa_current_option = "load-certificate"; return 10; }; |
687 | GAA_CHECKSTR("load-pubkey", GAAOPTID_load_pubkey)if(strcmp("load-pubkey",str) == 0) { gaa_current_option = "load-pubkey" ; return 11; }; |
688 | GAA_CHECKSTR("load-privkey", GAAOPTID_load_privkey)if(strcmp("load-privkey",str) == 0) { gaa_current_option = "load-privkey" ; return 12; }; |
689 | GAA_CHECKSTR("secret-key", GAAOPTID_secret_key)if(strcmp("secret-key",str) == 0) { gaa_current_option = "secret-key" ; return 13; }; |
690 | GAA_CHECKSTR("no-detailed-url", GAAOPTID_no_detailed_url)if(strcmp("no-detailed-url",str) == 0) { gaa_current_option = "no-detailed-url"; return 14; }; |
691 | GAA_CHECKSTR("detailed-url", GAAOPTID_detailed_url)if(strcmp("detailed-url",str) == 0) { gaa_current_option = "detailed-url" ; return 15; }; |
692 | GAA_CHECKSTR("login", GAAOPTID_login)if(strcmp("login",str) == 0) { gaa_current_option = "login"; return 16; }; |
693 | GAA_CHECKSTR("no-private", GAAOPTID_no_private)if(strcmp("no-private",str) == 0) { gaa_current_option = "no-private" ; return 17; }; |
694 | GAA_CHECKSTR("private", GAAOPTID_private)if(strcmp("private",str) == 0) { gaa_current_option = "private" ; return 18; }; |
695 | GAA_CHECKSTR("trusted", GAAOPTID_trusted)if(strcmp("trusted",str) == 0) { gaa_current_option = "trusted" ; return 19; }; |
696 | GAA_CHECKSTR("label", GAAOPTID_label)if(strcmp("label",str) == 0) { gaa_current_option = "label"; return 20; }; |
697 | GAA_CHECKSTR("generate-ecc", GAAOPTID_generate_ecc)if(strcmp("generate-ecc",str) == 0) { gaa_current_option = "generate-ecc" ; return 21; }; |
698 | GAA_CHECKSTR("generate-dsa", GAAOPTID_generate_dsa)if(strcmp("generate-dsa",str) == 0) { gaa_current_option = "generate-dsa" ; return 22; }; |
699 | GAA_CHECKSTR("generate-rsa", GAAOPTID_generate_rsa)if(strcmp("generate-rsa",str) == 0) { gaa_current_option = "generate-rsa" ; return 23; }; |
700 | GAA_CHECKSTR("delete", GAAOPTID_delete)if(strcmp("delete",str) == 0) { gaa_current_option = "delete" ; return 24; }; |
701 | GAA_CHECKSTR("write", GAAOPTID_write)if(strcmp("write",str) == 0) { gaa_current_option = "write"; return 25; }; |
702 | GAA_CHECKSTR("initialize", GAAOPTID_initialize)if(strcmp("initialize",str) == 0) { gaa_current_option = "initialize" ; return 26; }; |
703 | GAA_CHECKSTR("list-trusted", GAAOPTID_list_trusted)if(strcmp("list-trusted",str) == 0) { gaa_current_option = "list-trusted" ; return 27; }; |
704 | GAA_CHECKSTR("list-privkeys", GAAOPTID_list_privkeys)if(strcmp("list-privkeys",str) == 0) { gaa_current_option = "list-privkeys" ; return 28; }; |
705 | GAA_CHECKSTR("list-certs", GAAOPTID_list_certs)if(strcmp("list-certs",str) == 0) { gaa_current_option = "list-certs" ; return 29; }; |
706 | GAA_CHECKSTR("list-all-certs", GAAOPTID_list_all_certs)if(strcmp("list-all-certs",str) == 0) { gaa_current_option = "list-all-certs" ; return 30; }; |
707 | GAA_CHECKSTR("list-all", GAAOPTID_list_all)if(strcmp("list-all",str) == 0) { gaa_current_option = "list-all" ; return 31; }; |
708 | GAA_CHECKSTR("list-mechanisms", GAAOPTID_list_mechanisms)if(strcmp("list-mechanisms",str) == 0) { gaa_current_option = "list-mechanisms"; return 32; }; |
709 | GAA_CHECKSTR("list-tokens", GAAOPTID_list_tokens)if(strcmp("list-tokens",str) == 0) { gaa_current_option = "list-tokens" ; return 33; }; |
710 | GAA_CHECKSTR("export", GAAOPTID_export)if(strcmp("export",str) == 0) { gaa_current_option = "export" ; return 34; }; |
711 | |
712 | #line 281 "gaa.skel" |
713 | break; |
714 | default: break; |
715 | } |
716 | return GAA_ERROR_NOMATCH0; |
717 | } |
718 | |
719 | static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list) |
720 | { |
721 | int OK = 0; |
722 | int gaa_last_non_option; |
723 | struct GAAOPTION_debug GAATMP_debug; |
724 | struct GAAOPTION_outfile GAATMP_outfile; |
725 | struct GAAOPTION_provider GAATMP_provider; |
726 | struct GAAOPTION_sec_param GAATMP_sec_param; |
727 | struct GAAOPTION_bits GAATMP_bits; |
728 | struct GAAOPTION_load_certificate GAATMP_load_certificate; |
729 | struct GAAOPTION_load_pubkey GAATMP_load_pubkey; |
730 | struct GAAOPTION_load_privkey GAATMP_load_privkey; |
731 | struct GAAOPTION_secret_key GAATMP_secret_key; |
732 | struct GAAOPTION_label GAATMP_label; |
733 | struct GAAOPTION_generate_ecc GAATMP_generate_ecc; |
734 | struct GAAOPTION_generate_dsa GAATMP_generate_dsa; |
735 | struct GAAOPTION_generate_rsa GAATMP_generate_rsa; |
736 | struct GAAOPTION_delete GAATMP_delete; |
737 | struct GAAOPTION_write GAATMP_write; |
738 | struct GAAOPTION_initialize GAATMP_initialize; |
739 | struct GAAOPTION_list_mechanisms GAATMP_list_mechanisms; |
740 | struct GAAOPTION_export GAATMP_export; |
741 | |
742 | #line 393 "gaa.skel" |
743 | #ifdef GAA_REST_EXISTS |
744 | struct GAAREST GAAREST_tmp; |
745 | #endif |
746 | |
747 | opt_list[gaa_num] = 1; |
748 | |
749 | for(gaa_last_non_option = gaa_index; |
750 | (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION0); |
751 | gaa_last_non_option++); |
752 | |
753 | if(gaa_num == GAA_REST0) |
754 | { |
755 | gaa_index = 1; |
756 | gaa_last_non_option = GAAargc; |
757 | } |
758 | |
759 | switch(gaa_num) |
760 | { |
761 | case GAAOPTID_help1: |
762 | OK = 0; |
Value stored to 'OK' is never read | |
763 | #line 97 "p11tool.gaa" |
764 | { gaa_help(); exit(0); ;}; |
765 | |
766 | return GAA_OK-1; |
767 | break; |
768 | case GAAOPTID_debug2: |
769 | OK = 0; |
770 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
771 | GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1)if(!OK) { GAATMP_debug.arg1 = gaa_getint(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_debug.size1 = 1; } else { GAATMP_debug .size1 = 0; }; |
772 | gaa_index++; |
773 | #line 95 "p11tool.gaa" |
774 | { gaaval->debug = GAATMP_debug.arg1 ;}; |
775 | |
776 | return GAA_OK-1; |
777 | break; |
778 | case GAAOPTID_outfile3: |
779 | OK = 0; |
780 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
781 | GAA_FILL(GAATMP_outfile.arg1, gaa_getstr, GAATMP_outfile.size1)if(!OK) { GAATMP_outfile.arg1 = gaa_getstr(GAAargv[gaa_index] ); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_outfile.size1 = 1; } else { GAATMP_outfile .size1 = 0; }; |
782 | gaa_index++; |
783 | #line 90 "p11tool.gaa" |
784 | { gaaval->outfile = GAATMP_outfile.arg1 ;}; |
785 | |
786 | return GAA_OK-1; |
787 | break; |
788 | case GAAOPTID_provider4: |
789 | OK = 0; |
790 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
791 | GAA_FILL(GAATMP_provider.arg1, gaa_getstr, GAATMP_provider.size1)if(!OK) { GAATMP_provider.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_provider.size1 = 1; } else { GAATMP_provider .size1 = 0; }; |
792 | gaa_index++; |
793 | #line 87 "p11tool.gaa" |
794 | { gaaval->pkcs11_provider = GAATMP_provider.arg1 ;}; |
795 | |
796 | return GAA_OK-1; |
797 | break; |
798 | case GAAOPTID_inraw5: |
799 | OK = 0; |
800 | #line 83 "p11tool.gaa" |
801 | { gaaval->incert_format=GNUTLS_X509_FMT_DER ;}; |
802 | |
803 | return GAA_OK-1; |
804 | break; |
805 | case GAAOPTID_inder6: |
806 | OK = 0; |
807 | #line 82 "p11tool.gaa" |
808 | { gaaval->incert_format=GNUTLS_X509_FMT_DER ;}; |
809 | |
810 | return GAA_OK-1; |
811 | break; |
812 | case GAAOPTID_sec_param7: |
813 | OK = 0; |
814 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
815 | GAA_FILL(GAATMP_sec_param.arg1, gaa_getstr, GAATMP_sec_param.size1)if(!OK) { GAATMP_sec_param.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_sec_param.size1 = 1; } else { GAATMP_sec_param .size1 = 0; }; |
816 | gaa_index++; |
817 | #line 79 "p11tool.gaa" |
818 | { gaaval->sec_param = GAATMP_sec_param.arg1 ;}; |
819 | |
820 | return GAA_OK-1; |
821 | break; |
822 | case GAAOPTID_bits8: |
823 | OK = 0; |
824 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
825 | GAA_FILL(GAATMP_bits.arg1, gaa_getint, GAATMP_bits.size1)if(!OK) { GAATMP_bits.arg1 = gaa_getint(GAAargv[gaa_index]); gaa_arg_used [gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2 ; } GAATMP_bits.size1 = 1; } else { GAATMP_bits.size1 = 0; }; |
826 | gaa_index++; |
827 | #line 76 "p11tool.gaa" |
828 | { gaaval->bits = GAATMP_bits.arg1 ;}; |
829 | |
830 | return GAA_OK-1; |
831 | break; |
832 | case GAAOPTID_pkcs89: |
833 | OK = 0; |
834 | #line 73 "p11tool.gaa" |
835 | { gaaval->pkcs8=1 ;}; |
836 | |
837 | return GAA_OK-1; |
838 | break; |
839 | case GAAOPTID_load_certificate10: |
840 | OK = 0; |
841 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
842 | GAA_FILL(GAATMP_load_certificate.arg1, gaa_getstr, GAATMP_load_certificate.size1)if(!OK) { GAATMP_load_certificate.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_load_certificate.size1 = 1; } else { GAATMP_load_certificate.size1 = 0; }; |
843 | gaa_index++; |
844 | #line 70 "p11tool.gaa" |
845 | { gaaval->cert = GAATMP_load_certificate.arg1 ;}; |
846 | |
847 | return GAA_OK-1; |
848 | break; |
849 | case GAAOPTID_load_pubkey11: |
850 | OK = 0; |
851 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
852 | GAA_FILL(GAATMP_load_pubkey.arg1, gaa_getstr, GAATMP_load_pubkey.size1)if(!OK) { GAATMP_load_pubkey.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_load_pubkey.size1 = 1; } else { GAATMP_load_pubkey .size1 = 0; }; |
853 | gaa_index++; |
854 | #line 67 "p11tool.gaa" |
855 | { gaaval->pubkey = GAATMP_load_pubkey.arg1 ;}; |
856 | |
857 | return GAA_OK-1; |
858 | break; |
859 | case GAAOPTID_load_privkey12: |
860 | OK = 0; |
861 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
862 | GAA_FILL(GAATMP_load_privkey.arg1, gaa_getstr, GAATMP_load_privkey.size1)if(!OK) { GAATMP_load_privkey.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_load_privkey.size1 = 1; } else { GAATMP_load_privkey .size1 = 0; }; |
863 | gaa_index++; |
864 | #line 64 "p11tool.gaa" |
865 | { gaaval->privkey = GAATMP_load_privkey.arg1 ;}; |
866 | |
867 | return GAA_OK-1; |
868 | break; |
869 | case GAAOPTID_secret_key13: |
870 | OK = 0; |
871 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
872 | GAA_FILL(GAATMP_secret_key.arg1, gaa_getstr, GAATMP_secret_key.size1)if(!OK) { GAATMP_secret_key.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_secret_key.size1 = 1; } else { GAATMP_secret_key .size1 = 0; }; |
873 | gaa_index++; |
874 | #line 61 "p11tool.gaa" |
875 | { gaaval->secret_key = GAATMP_secret_key.arg1; ;}; |
876 | |
877 | return GAA_OK-1; |
878 | break; |
879 | case GAAOPTID_no_detailed_url14: |
880 | OK = 0; |
881 | #line 58 "p11tool.gaa" |
882 | { gaaval->pkcs11_detailed_url = 0; ;}; |
883 | |
884 | return GAA_OK-1; |
885 | break; |
886 | case GAAOPTID_detailed_url15: |
887 | OK = 0; |
888 | #line 57 "p11tool.gaa" |
889 | { gaaval->pkcs11_detailed_url = GNUTLS_PKCS11_URL_LIB; ;}; |
890 | |
891 | return GAA_OK-1; |
892 | break; |
893 | case GAAOPTID_login16: |
894 | OK = 0; |
895 | #line 54 "p11tool.gaa" |
896 | { gaaval->pkcs11_login = 1; ;}; |
897 | |
898 | return GAA_OK-1; |
899 | break; |
900 | case GAAOPTID_no_private17: |
901 | OK = 0; |
902 | #line 51 "p11tool.gaa" |
903 | { gaaval->pkcs11_private = 0; ;}; |
904 | |
905 | return GAA_OK-1; |
906 | break; |
907 | case GAAOPTID_private18: |
908 | OK = 0; |
909 | #line 50 "p11tool.gaa" |
910 | { gaaval->pkcs11_private = 1; ;}; |
911 | |
912 | return GAA_OK-1; |
913 | break; |
914 | case GAAOPTID_trusted19: |
915 | OK = 0; |
916 | #line 47 "p11tool.gaa" |
917 | { gaaval->pkcs11_trusted = 1; ;}; |
918 | |
919 | return GAA_OK-1; |
920 | break; |
921 | case GAAOPTID_label20: |
922 | OK = 0; |
923 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
924 | GAA_FILL(GAATMP_label.arg1, gaa_getstr, GAATMP_label.size1)if(!OK) { GAATMP_label.arg1 = gaa_getstr(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_label.size1 = 1; } else { GAATMP_label .size1 = 0; }; |
925 | gaa_index++; |
926 | #line 45 "p11tool.gaa" |
927 | { gaaval->pkcs11_label = GAATMP_label.arg1; ;}; |
928 | |
929 | return GAA_OK-1; |
930 | break; |
931 | case GAAOPTID_generate_ecc21: |
932 | OK = 0; |
933 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
934 | GAA_FILL(GAATMP_generate_ecc.arg1, gaa_getstr, GAATMP_generate_ecc.size1)if(!OK) { GAATMP_generate_ecc.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_generate_ecc.size1 = 1; } else { GAATMP_generate_ecc .size1 = 0; }; |
935 | gaa_index++; |
936 | #line 43 "p11tool.gaa" |
937 | { gaaval->action = ACTION_PKCS11_GENERATE; gaaval->key_type = GNUTLS_PK_EC; gaaval->pkcs11_url = GAATMP_generate_ecc.arg1; ;}; |
938 | |
939 | return GAA_OK-1; |
940 | break; |
941 | case GAAOPTID_generate_dsa22: |
942 | OK = 0; |
943 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
944 | GAA_FILL(GAATMP_generate_dsa.arg1, gaa_getstr, GAATMP_generate_dsa.size1)if(!OK) { GAATMP_generate_dsa.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_generate_dsa.size1 = 1; } else { GAATMP_generate_dsa .size1 = 0; }; |
945 | gaa_index++; |
946 | #line 42 "p11tool.gaa" |
947 | { gaaval->action = ACTION_PKCS11_GENERATE; gaaval->key_type = GNUTLS_PK_DSA; gaaval->pkcs11_url = GAATMP_generate_dsa.arg1; ;}; |
948 | |
949 | return GAA_OK-1; |
950 | break; |
951 | case GAAOPTID_generate_rsa23: |
952 | OK = 0; |
953 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
954 | GAA_FILL(GAATMP_generate_rsa.arg1, gaa_getstr, GAATMP_generate_rsa.size1)if(!OK) { GAATMP_generate_rsa.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_generate_rsa.size1 = 1; } else { GAATMP_generate_rsa .size1 = 0; }; |
955 | gaa_index++; |
956 | #line 41 "p11tool.gaa" |
957 | { gaaval->action = ACTION_PKCS11_GENERATE; gaaval->key_type = GNUTLS_PK_RSA; gaaval->pkcs11_url = GAATMP_generate_rsa.arg1; ;}; |
958 | |
959 | return GAA_OK-1; |
960 | break; |
961 | case GAAOPTID_delete24: |
962 | OK = 0; |
963 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
964 | GAA_FILL(GAATMP_delete.arg1, gaa_getstr, GAATMP_delete.size1)if(!OK) { GAATMP_delete.arg1 = gaa_getstr(GAAargv[gaa_index]) ; gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_delete.size1 = 1; } else { GAATMP_delete .size1 = 0; }; |
965 | gaa_index++; |
966 | #line 38 "p11tool.gaa" |
967 | { gaaval->action = ACTION_PKCS11_DELETE_URL; gaaval->pkcs11_url = GAATMP_delete.arg1; ;}; |
968 | |
969 | return GAA_OK-1; |
970 | break; |
971 | case GAAOPTID_write25: |
972 | OK = 0; |
973 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
974 | GAA_FILL(GAATMP_write.arg1, gaa_getstr, GAATMP_write.size1)if(!OK) { GAATMP_write.arg1 = gaa_getstr(GAAargv[gaa_index]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_write.size1 = 1; } else { GAATMP_write .size1 = 0; }; |
975 | gaa_index++; |
976 | #line 37 "p11tool.gaa" |
977 | { gaaval->action = ACTION_PKCS11_WRITE_URL; gaaval->pkcs11_url = GAATMP_write.arg1; ;}; |
978 | |
979 | return GAA_OK-1; |
980 | break; |
981 | case GAAOPTID_initialize26: |
982 | OK = 0; |
983 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
984 | GAA_FILL(GAATMP_initialize.arg1, gaa_getstr, GAATMP_initialize.size1)if(!OK) { GAATMP_initialize.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_initialize.size1 = 1; } else { GAATMP_initialize .size1 = 0; }; |
985 | gaa_index++; |
986 | #line 36 "p11tool.gaa" |
987 | { gaaval->action = ACTION_PKCS11_TOKEN_INIT; gaaval->pkcs11_url = GAATMP_initialize.arg1; ;}; |
988 | |
989 | return GAA_OK-1; |
990 | break; |
991 | case GAAOPTID_list_trusted27: |
992 | OK = 0; |
993 | #line 33 "p11tool.gaa" |
994 | { gaaval->action = ACTION_PKCS11_LIST; gaaval->pkcs11_type=PKCS11_TYPE_TRUSTED2; ;}; |
995 | |
996 | return GAA_OK-1; |
997 | break; |
998 | case GAAOPTID_list_privkeys28: |
999 | OK = 0; |
1000 | #line 32 "p11tool.gaa" |
1001 | { gaaval->action = ACTION_PKCS11_LIST; gaaval->pkcs11_type=PKCS11_TYPE_PRIVKEY5; ;}; |
1002 | |
1003 | return GAA_OK-1; |
1004 | break; |
1005 | case GAAOPTID_list_certs29: |
1006 | OK = 0; |
1007 | #line 31 "p11tool.gaa" |
1008 | { gaaval->action = ACTION_PKCS11_LIST; gaaval->pkcs11_type=PKCS11_TYPE_PK3; ;}; |
1009 | |
1010 | return GAA_OK-1; |
1011 | break; |
1012 | case GAAOPTID_list_all_certs30: |
1013 | OK = 0; |
1014 | #line 30 "p11tool.gaa" |
1015 | { gaaval->action = ACTION_PKCS11_LIST; gaaval->pkcs11_type=PKCS11_TYPE_CRT_ALL1; ;}; |
1016 | |
1017 | return GAA_OK-1; |
1018 | break; |
1019 | case GAAOPTID_list_all31: |
1020 | OK = 0; |
1021 | #line 29 "p11tool.gaa" |
1022 | { gaaval->action = ACTION_PKCS11_LIST; gaaval->pkcs11_type=PKCS11_TYPE_ALL4; ;}; |
1023 | |
1024 | return GAA_OK-1; |
1025 | break; |
1026 | case GAAOPTID_list_mechanisms32: |
1027 | OK = 0; |
1028 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
1029 | GAA_FILL(GAATMP_list_mechanisms.arg1, gaa_getstr, GAATMP_list_mechanisms.size1)if(!OK) { GAATMP_list_mechanisms.arg1 = gaa_getstr(GAAargv[gaa_index ]); gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_list_mechanisms.size1 = 1; } else { GAATMP_list_mechanisms .size1 = 0; }; |
1030 | gaa_index++; |
1031 | #line 27 "p11tool.gaa" |
1032 | { gaaval->pkcs11_url = GAATMP_list_mechanisms.arg1; gaaval->action = ACTION_PKCS11_MECHANISMS; ;}; |
1033 | |
1034 | return GAA_OK-1; |
1035 | break; |
1036 | case GAAOPTID_list_tokens33: |
1037 | OK = 0; |
1038 | #line 25 "p11tool.gaa" |
1039 | { gaaval->action = ACTION_PKCS11_TOKENS; ;}; |
1040 | |
1041 | return GAA_OK-1; |
1042 | break; |
1043 | case GAAOPTID_export34: |
1044 | OK = 0; |
1045 | GAA_TESTMOREARGSif(!OK) { while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) gaa_index++; if(gaa_last_non_option == gaa_index) return 1; }; |
1046 | GAA_FILL(GAATMP_export.arg1, gaa_getstr, GAATMP_export.size1)if(!OK) { GAATMP_export.arg1 = gaa_getstr(GAAargv[gaa_index]) ; gaa_arg_used[gaa_index] = 1; if(gaa_error == 1) { gaa_error = 0; return 2; } GAATMP_export.size1 = 1; } else { GAATMP_export .size1 = 0; }; |
1047 | gaa_index++; |
1048 | #line 22 "p11tool.gaa" |
1049 | { gaaval->action = ACTION_PKCS11_EXPORT_URL; gaaval->pkcs11_url = GAATMP_export.arg1; ;}; |
1050 | |
1051 | return GAA_OK-1; |
1052 | break; |
1053 | |
1054 | #line 413 "gaa.skel" |
1055 | default: break; |
1056 | } |
1057 | return GAA_ERROR_UNKNOWN3; |
1058 | } |
1059 | |
1060 | int gaa(int argc, char **argv, gaainfo *gaaval) |
1061 | { |
1062 | int tmp1, tmp2; |
1063 | int i, j; |
1064 | char *opt_list; |
1065 | |
1066 | GAAargv = argv; |
1067 | GAAargc = argc; |
1068 | |
1069 | opt_list = (char*) gaa_malloc(GAA_NB_OPTION34 + 1); |
1070 | |
1071 | for(i = 0; i < GAA_NB_OPTION34 + 1; i++) |
1072 | opt_list[i] = 0; |
1073 | /* initialization */ |
1074 | if(inited == 0) |
1075 | { |
1076 | |
1077 | #line 99 "p11tool.gaa" |
1078 | { |
1079 | gaaval->action = -1; gaaval->pkcs11_provider= NULL((void*)0); gaaval->outfile = NULL((void*)0); gaaval->pubkey = NULL((void*)0); gaaval->privkey = NULL((void*)0); |
1080 | gaaval->pkcs11_url = NULL((void*)0); gaaval->pkcs11_type = PKCS11_TYPE_PK3; gaaval->pubkey=NULL((void*)0); gaaval->pkcs11_label = NULL((void*)0); |
1081 | gaaval->pkcs11_trusted=0; gaaval->pkcs11_login = 0; gaaval->pkcs11_detailed_url = 0; |
1082 | gaaval->secret_key = NULL((void*)0); gaaval->cert = NULL((void*)0); gaaval->incert_format = GNUTLS_X509_FMT_PEM; gaaval->pkcs11_private = -1; |
1083 | gaaval->key_type = 0; gaaval->bits = 0; gaaval->sec_param = NULL((void*)0); ;}; |
1084 | |
1085 | } |
1086 | inited = 1; |
1087 | #line 438 "gaa.skel" |
1088 | gaa_arg_used = NULL((void*)0); |
1089 | |
1090 | if (argc > 0) { |
1091 | gaa_arg_used = gaa_malloc(argc * sizeof(char)); |
1092 | } |
1093 | |
1094 | for(i = 1; i < argc; i++) |
1095 | gaa_arg_used[i] = 0; |
1096 | for(i = 1; i < argc; i++) |
1097 | { |
1098 | if(gaa_arg_used[i] == 0) |
1099 | { |
1100 | j = 0; |
1101 | tmp1 = gaa_is_an_argument(GAAargv[i]); |
1102 | switch(tmp1) |
1103 | { |
1104 | case GAA_WORD_OPTION1: |
1105 | j++; |
1106 | case GAA_LETTER_OPTION2: |
1107 | j++; |
1108 | tmp2 = gaa_get_option_num(argv[i]+j, tmp1); |
1109 | if(tmp2 == GAA_ERROR_NOMATCH0) |
1110 | { |
1111 | printf("Invalid option '%s'\n", argv[i]+j); |
1112 | return 0; |
1113 | } |
1114 | switch(gaa_try(tmp2, i+1, gaaval, opt_list)) |
1115 | { |
1116 | case GAA_ERROR_NOTENOUGH_ARGS1: |
1117 | printf("'%s': not enough arguments\n",gaa_current_option); |
1118 | return 0; |
1119 | case GAA_ERROR_INVALID_ARG2: |
1120 | printf("Invalid arguments\n"); |
1121 | return 0; |
1122 | case GAA_OK-1: |
1123 | break; |
1124 | default: |
1125 | printf("Unknown error\n"); |
1126 | } |
1127 | gaa_arg_used[i] = 1; |
1128 | break; |
1129 | case GAA_MULTIPLE_OPTION3: |
1130 | for(j = 1; j < strlen(argv[i]); j++) |
1131 | { |
1132 | tmp2 = gaa_get_option_num(argv[i]+j, tmp1); |
1133 | if(tmp2 == GAA_ERROR_NOMATCH0) |
1134 | { |
1135 | printf("Invalid option '%c'\n", *(argv[i]+j)); |
1136 | return 0; |
1137 | } |
1138 | switch(gaa_try(tmp2, i+1, gaaval, opt_list)) |
1139 | { |
1140 | case GAA_ERROR_NOTENOUGH_ARGS1: |
1141 | printf("'%s': not enough arguments\n",gaa_current_option); |
1142 | return 0; |
1143 | case GAA_ERROR_INVALID_ARG2: |
1144 | printf("Invalid arguments\n"); |
1145 | return 0; |
1146 | case GAA_OK-1: |
1147 | break; |
1148 | default: |
1149 | printf("Unknown error\n"); |
1150 | } |
1151 | } |
1152 | gaa_arg_used[i] = 1; |
1153 | break; |
1154 | default: break; |
1155 | } |
1156 | } |
1157 | } |
1158 | if(gaa_processing_file == 0) |
1159 | { |
1160 | |
1161 | #line 507 "gaa.skel" |
1162 | #ifdef GAA_REST_EXISTS |
1163 | switch(gaa_try(GAA_REST0, 1, gaaval, opt_list)) |
1164 | { |
1165 | case GAA_ERROR_NOTENOUGH_ARGS1: |
1166 | printf("Rest: not enough arguments\n"); |
1167 | return 0; |
1168 | case GAA_ERROR_INVALID_ARG2: |
1169 | printf("Invalid arguments\n"); |
1170 | return 0; |
1171 | case GAA_OK-1: |
1172 | break; |
1173 | default: |
1174 | printf("Unknown error\n"); |
1175 | } |
1176 | #endif |
1177 | } |
1178 | for(i = 1; i < argc; i++) |
1179 | { |
1180 | if(gaa_arg_used[i] == 0) |
1181 | { |
1182 | printf("Too many arguments\n"); |
1183 | return 0; |
1184 | } |
1185 | } |
1186 | free(gaa_arg_used); |
1187 | free(opt_list); |
1188 | return -1; |
1189 | } |
1190 | |
1191 | struct gaastrnode |
1192 | { |
1193 | char *str; |
1194 | struct gaastrnode *next; |
1195 | }; |
1196 | |
1197 | typedef struct gaastrnode gaa_str_node; |
1198 | |
1199 | static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc) |
1200 | { |
1201 | int pos_ini; |
1202 | int a; |
1203 | int i = 0, len = 0, newline = 0; |
1204 | |
1205 | if(argc == 1) { |
1206 | newline = 1; |
1207 | len = 2; |
1208 | } |
1209 | |
1210 | a = fgetc( file); |
1211 | if (a == EOF(-1)) return 0; |
1212 | |
1213 | while(a == ' ' || a == 9 || a == '\n') |
1214 | { |
1215 | if(a == '\n') |
1216 | { |
1217 | newline=1; |
1218 | len = 2; |
1219 | } |
1220 | a = fgetc( file); |
1221 | if (a == EOF(-1)) return 0; |
1222 | } |
1223 | |
1224 | pos_ini = ftell(file) - 1; |
1225 | |
1226 | while(a != ' ' && a != 9 && a != '\n') |
1227 | { |
1228 | |
1229 | len++; |
1230 | a = fgetc( file); |
1231 | if(a==EOF(-1)) return 0; |
1232 | } |
1233 | |
1234 | len += 1; |
1235 | tmp_str->str = gaa_malloc((len) * sizeof(char)); |
1236 | |
1237 | if(newline == 1) |
1238 | { |
1239 | tmp_str->str[0] = '-'; |
1240 | tmp_str->str[1] = '-'; |
1241 | i = 2; |
1242 | } |
1243 | else |
1244 | { |
1245 | i = 0; |
1246 | } |
1247 | |
1248 | fseek(file,pos_ini, SEEK_SET0); |
1249 | do |
1250 | { |
1251 | a = fgetc( file); |
1252 | |
1253 | if (a == EOF(-1)) { |
1254 | i+=2; |
1255 | break; |
1256 | } |
1257 | tmp_str->str[i] = a; |
1258 | i++; |
1259 | } |
1260 | while(a != ' ' && a != 9 && a != '\n' && i < len); |
1261 | |
1262 | tmp_str->str[i - 1] = 0; |
1263 | |
1264 | fseek(file,- 1, SEEK_CUR1); |
1265 | /* printf("%d\n", ftell(file)); */ |
1266 | |
1267 | return -1; |
1268 | } |
1269 | |
1270 | int gaa_file(const char *name, gaainfo *gaaval) |
1271 | { |
1272 | gaa_str_node *first_str, **tmp_str, *tmp_str2; |
1273 | int rval, i; |
1274 | char **argv; |
1275 | int argc = 0; |
1276 | FILE *file; |
1277 | |
1278 | gaa_processing_file = 1; |
1279 | |
1280 | if((file = fopen(name, "r")) == NULL((void*)0)) |
1281 | { |
1282 | printf("Couldn't open '%s' configuration file for reading\n", name); |
1283 | return 1; |
1284 | } |
1285 | |
1286 | tmp_str = &first_str; |
1287 | do |
1288 | { |
1289 | argc++; |
1290 | *tmp_str = gaa_malloc(sizeof(gaa_str_node)); |
1291 | |
1292 | (*tmp_str)->str = NULL((void*)0); |
1293 | (*tmp_str)->next = NULL((void*)0); |
1294 | |
1295 | rval = gaa_internal_get_next_str(file, *tmp_str, argc); |
1296 | tmp_str = &((*tmp_str)->next); |
1297 | } |
1298 | while(rval == -1); |
1299 | |
1300 | if(rval == 1) |
1301 | return 0; |
1302 | |
1303 | argv = gaa_malloc((1 + argc) * sizeof(char*)); |
1304 | |
1305 | tmp_str2 = first_str; |
1306 | argv[0] = "cfg"; |
1307 | for(i = 1; i < argc; i++) |
1308 | { |
1309 | argv[i] = tmp_str2->str; |
1310 | tmp_str2 = tmp_str2->next; |
1311 | } |
1312 | |
1313 | rval = gaa(argc, argv, gaaval); |
1314 | gaa_processing_file = 0; |
1315 | return rval; |
1316 | } |