2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
21 do_eet_list(const char *file)
27 ef = eet_open(file, EET_FILE_MODE_READ);
30 printf("cannot open for reading: %s\n", file);
33 list = eet_list(ef, "*", &num);
36 for (i = 0; i < num; i++)
37 printf("%s\n",list[i]);
44 do_eet_extract(const char *file, const char *key, const char *out, const char *crypto_key)
51 ef = eet_open(file, EET_FILE_MODE_READ);
54 printf("cannot open for reading: %s\n", file);
57 data = eet_read_cipher(ef, key, &size, crypto_key);
60 printf("cannot read key %s\n", key);
66 printf("cannot open %s\n", out);
69 if (fwrite(data, size, 1, f) != 1)
71 printf("cannot write to %s\n", out);
80 do_eet_decode_dump(void *data, const char *str)
82 fputs(str, (FILE *)data);
86 do_eet_decode(const char *file, const char *key, const char *out, const char *crypto_key)
91 ef = eet_open(file, EET_FILE_MODE_READ);
94 printf("cannot open for reading: %s\n", file);
100 printf("cannot open %s\n", out);
103 if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
105 printf("cannot write to %s\n", out);
113 do_eet_insert(const char *file, const char *key, const char *out, int compress, const char *crypto_key)
120 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
122 ef = eet_open(file, EET_FILE_MODE_WRITE);
125 printf("cannot open for read+write: %s\n", file);
131 printf("cannot open %s\n", out);
134 fseek(f, 0, SEEK_END);
140 printf("cannot allocate %i bytes\n", size);
143 if (fread(data, size, 1, f) != 1)
145 printf("cannot read file %s\n", out);
149 eet_write_cipher(ef, key, data, size, compress, crypto_key);
155 do_eet_encode(const char *file, const char *key, const char *out, int compress, const char *crypto_key)
163 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
165 ef = eet_open(file, EET_FILE_MODE_WRITE);
168 printf("cannot open for read+write: %s\n", file);
174 printf("cannot open %s\n", out);
177 fseek(f, 0, SEEK_END);
180 text = malloc(textlen);
183 printf("cannot allocate %i bytes\n", size);
186 if (fread(text, textlen, 1, f) != 1)
188 printf("cannot read file %s\n", out);
192 if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
194 printf("cannot parse %s\n", out);
202 do_eet_remove(const char *file, const char *key)
206 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
209 printf("cannot open for read+write: %s\n", file);
217 do_eet_check(const char *file)
224 ef = eet_open(file, EET_FILE_MODE_READ);
227 fprintf(stdout, "checking signature of `%s` failed\n", file);
231 der = eet_identity_x509(ef, &der_length);
233 fprintf(stderr, "Certificate length %i.\n", der_length);
234 eet_identity_certificate_print(der, der_length, stdout);
236 eet_identity_signature(ef, &sign_length);
237 fprintf(stderr, "Signature length %i.\n", sign_length);
243 do_eet_sign(const char *file, const char *private_key, const char *public_key)
248 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
251 fprintf(stdout, "cannot open for read+write: %s.\n", file);
255 key = eet_identity_open(public_key, private_key, NULL);
258 fprintf(stdout, "cannot open key '%s:%s'.\n", public_key, private_key);
262 fprintf(stdout, "Using the following key to sign `%s`.\n", file);
263 eet_identity_print(key, stdout);
265 eet_identity_set(ef, key);
271 main(int argc, char **argv)
278 " eet -l FILE.EET list all keys in FILE.EET\n"
279 " eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
280 " eet -d FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n"
281 " eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
282 " eet -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
283 " eet -r FILE.EET KEY remove KEY in FILE.EET\n"
284 " eet -c FILE.EET report and check the signature information of an eet file\n"
285 " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
290 if ((!strncmp(argv[1], "-h", 2)))
294 else if ((!strcmp(argv[1], "-l")) && (argc > 2))
296 do_eet_list(argv[2]);
298 else if ((!strcmp(argv[1], "-x")) && (argc > 4))
301 do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
303 do_eet_extract(argv[2], argv[3], argv[4], NULL);
305 else if ((!strcmp(argv[1], "-d")) && (argc > 4))
308 do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
310 do_eet_decode(argv[2], argv[3], argv[4], NULL);
312 else if ((!strcmp(argv[1], "-i")) && (argc > 5))
315 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
317 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
319 else if ((!strcmp(argv[1], "-e")) && (argc > 5))
322 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
324 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
326 else if ((!strcmp(argv[1], "-r")) && (argc > 3))
328 do_eet_remove(argv[2], argv[3]);
330 else if ((!strcmp(argv[1], "-c")) && (argc > 2))
332 do_eet_check(argv[2]);
334 else if ((!strcmp(argv[1], "-s")) && (argc > 4))
336 do_eet_sign(argv[2], argv[3], argv[4]);