3 #endif /* ifdef HAVE_CONFIG_H */
11 #endif /* ifdef HAVE_UNISTD_H */
15 #endif /* ifdef HAVE_EVIL */
19 static int _eet_main_log_dom = -1;
21 #ifdef EET_DEFAULT_LOG_COLOR
22 #undef EET_DEFAULT_LOG_COLOR
23 #endif /* ifdef EET_DEFAULT_LOG_COLOR */
24 #define EET_DEFAULT_LOG_COLOR EINA_COLOR_CYAN
27 #endif /* ifdef ERR */
28 #define ERR(...) EINA_LOG_DOM_ERR(_eet_main_log_dom, __VA_ARGS__)
31 #endif /* ifdef DBG */
32 #define DBG(...) EINA_LOG_DOM_DBG(_eet_main_log_dom, __VA_ARGS__)
35 #endif /* ifdef INF */
36 #define INF(...) EINA_LOG_DOM_INFO(_eet_main_log_dom, __VA_ARGS__)
39 #endif /* ifdef WRN */
40 #define WRN(...) EINA_LOG_DOM_WARN(_eet_main_log_dom, __VA_ARGS__)
43 #endif /* ifdef CRIT */
44 #define CRIT(...) EINA_LOG_DOM_CRIT(_eet_main_log_dom, __VA_ARGS__)
47 do_eet_list(const char *file)
53 ef = eet_open(file, EET_FILE_MODE_READ);
56 ERR("cannot open for reading: %s", file);
60 list = eet_list(ef, "*", &num);
63 for (i = 0; i < num; i++)
64 printf("%s\n", list[i]);
72 do_eet_extract(const char *file,
75 const char *crypto_key)
82 ef = eet_open(file, EET_FILE_MODE_READ);
85 ERR("cannot open for reading: %s", file);
89 data = eet_read_cipher(ef, key, &size, crypto_key);
92 ERR("cannot read key %s", key);
99 ERR("cannot open %s", out);
103 if (fwrite(data, size, 1, f) != 1)
105 ERR("cannot write to %s", out);
112 } /* do_eet_extract */
115 do_eet_decode_dump(void *data,
118 fputs(str, (FILE *)data);
119 } /* do_eet_decode_dump */
122 do_eet_decode(const char *file,
125 const char *crypto_key)
130 ef = eet_open(file, EET_FILE_MODE_READ);
133 ERR("cannot open for reading: %s", file);
137 f = fopen(out, "wb");
140 ERR("cannot open %s", out);
144 if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
146 ERR("cannot write to %s", out);
152 } /* do_eet_decode */
155 do_eet_insert(const char *file,
159 const char *crypto_key)
166 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
168 ef = eet_open(file, EET_FILE_MODE_WRITE);
172 ERR("cannot open for read+write: %s", file);
176 f = fopen(out, "rb");
179 ERR("cannot open %s", out);
183 fseek(f, 0, SEEK_END);
189 ERR("cannot allocate %i bytes", size);
193 if (fread(data, size, 1, f) != 1)
195 ERR("cannot read file %s", out);
200 eet_write_cipher(ef, key, data, size, compress, crypto_key);
203 } /* do_eet_insert */
206 do_eet_encode(const char *file,
210 const char *crypto_key)
218 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
220 ef = eet_open(file, EET_FILE_MODE_WRITE);
224 ERR("cannot open for read+write: %s", file);
228 f = fopen(out, "rb");
231 ERR("cannot open %s", out);
235 fseek(f, 0, SEEK_END);
238 text = malloc(textlen);
241 ERR("cannot allocate %i bytes", size);
245 if (fread(text, textlen, 1, f) != 1)
247 ERR("cannot read file %s", out);
252 if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
254 ERR("cannot parse %s", out);
260 } /* do_eet_encode */
263 do_eet_remove(const char *file,
268 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
271 ERR("cannot open for read+write: %s", file);
277 } /* do_eet_remove */
280 do_eet_check(const char *file)
287 ef = eet_open(file, EET_FILE_MODE_READ);
290 ERR("checking signature of `%s` failed", file);
294 der = eet_identity_x509(ef, &der_length);
296 fprintf(stdout, "Certificate length %i.\n", der_length);
297 eet_identity_certificate_print(der, der_length, stdout);
299 eet_identity_signature(ef, &sign_length);
300 fprintf(stdout, "Signature length %i.\n", sign_length);
306 do_eet_sign(const char *file,
307 const char *private_key,
308 const char *public_key)
313 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
316 ERR("cannot open for read+write: %s.", file);
320 key = eet_identity_open(public_key, private_key, NULL);
323 ERR("cannot open key '%s:%s'.", public_key, private_key);
327 fprintf(stdout, "Using the following key to sign `%s`.\n", file);
328 eet_identity_print(key, stdout);
330 eet_identity_set(ef, key);
342 _eet_main_log_dom = eina_log_domain_register("eet_main", EINA_COLOR_CYAN);
343 if(_eet_main_log_dom < -1)
345 EINA_LOG_ERR("Impossible to create a log domain for eet_main.");
355 " eet -l FILE.EET list all keys in FILE.EET\n"
356 " eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
357 " 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"
358 " 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"
359 " 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"
360 " eet -r FILE.EET KEY remove KEY in FILE.EET\n"
361 " eet -c FILE.EET report and check the signature information of an eet file\n"
362 " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
368 if ((!strncmp(argv[1], "-h", 2)))
370 else if ((!strcmp(argv[1], "-l")) && (argc > 2))
371 do_eet_list(argv[2]);
372 else if ((!strcmp(argv[1], "-x")) && (argc > 4))
375 do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
377 do_eet_extract(argv[2], argv[3], argv[4], NULL);
379 else if ((!strcmp(argv[1], "-d")) && (argc > 4))
382 do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
384 do_eet_decode(argv[2], argv[3], argv[4], NULL);
386 else if ((!strcmp(argv[1], "-i")) && (argc > 5))
389 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
391 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
393 else if ((!strcmp(argv[1], "-e")) && (argc > 5))
396 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
398 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
400 else if ((!strcmp(argv[1], "-r")) && (argc > 3))
401 do_eet_remove(argv[2], argv[3]);
402 else if ((!strcmp(argv[1], "-c")) && (argc > 2))
403 do_eet_check(argv[2]);
404 else if ((!strcmp(argv[1], "-s")) && (argc > 4))
405 do_eet_sign(argv[2], argv[3], argv[4]);
409 eina_log_domain_unregister(_eet_main_log_dom);