2008-10-24 01:06:08 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef HAVE_CONFIG_H */
|
2008-10-24 01:06:08 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-01-10 12:25:26 -08:00
|
|
|
#include <unistd.h>
|
2008-10-24 01:06:08 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
#include <Eet.h>
|
|
|
|
|
2009-10-01 20:59:17 -07:00
|
|
|
static int _eet_main_log_dom = -1;
|
|
|
|
|
|
|
|
#ifdef EET_DEFAULT_LOG_COLOR
|
|
|
|
#undef EET_DEFAULT_LOG_COLOR
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef EET_DEFAULT_LOG_COLOR */
|
2009-10-01 20:59:17 -07:00
|
|
|
#define EET_DEFAULT_LOG_COLOR EINA_COLOR_CYAN
|
|
|
|
#ifdef ERR
|
|
|
|
#undef ERR
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef ERR */
|
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(_eet_main_log_dom, __VA_ARGS__)
|
2009-10-01 20:59:17 -07:00
|
|
|
#ifdef DBG
|
|
|
|
#undef DBG
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef DBG */
|
|
|
|
#define DBG(...) EINA_LOG_DOM_DBG(_eet_main_log_dom, __VA_ARGS__)
|
2009-10-01 20:59:17 -07:00
|
|
|
#ifdef INF
|
|
|
|
#undef INF
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef INF */
|
|
|
|
#define INF(...) EINA_LOG_DOM_INFO(_eet_main_log_dom, __VA_ARGS__)
|
2009-10-01 20:59:17 -07:00
|
|
|
#ifdef WRN
|
|
|
|
#undef WRN
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef WRN */
|
|
|
|
#define WRN(...) EINA_LOG_DOM_WARN(_eet_main_log_dom, __VA_ARGS__)
|
2013-12-25 19:22:05 -08:00
|
|
|
#ifdef CRI
|
|
|
|
#undef CRI
|
|
|
|
#endif /* ifdef CRI */
|
|
|
|
#define CRI(...) EINA_LOG_DOM_CRIT(_eet_main_log_dom, __VA_ARGS__)
|
2009-10-01 20:59:17 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
static void
|
2012-10-30 22:58:50 -07:00
|
|
|
do_eet_list(const char *file, Eina_Bool verbose)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2012-10-30 22:58:50 -07:00
|
|
|
Eina_Iterator *it;
|
|
|
|
Eet_Entry *entry;
|
2011-10-20 22:40:01 -07:00
|
|
|
Eet_File *ef;
|
2012-10-30 22:58:50 -07:00
|
|
|
unsigned long long total = 0;
|
2008-03-29 00:28:18 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ);
|
|
|
|
if (!ef)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot open for reading: %s", file);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-10-30 22:58:50 -07:00
|
|
|
it = eet_list_entries(ef);
|
|
|
|
EINA_ITERATOR_FOREACH(it, entry)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2012-10-30 22:58:50 -07:00
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (entry->alias)
|
|
|
|
{
|
|
|
|
printf("%s is an alias for %s\n",
|
|
|
|
entry->name, eet_alias_get(ef, entry->name));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (entry->compression)
|
|
|
|
printf("%s start at %i with a size of %i Bytes with an uncompressed size of %i Bytes.\n",
|
|
|
|
entry->name, entry->offset, entry->size, entry->data_size);
|
|
|
|
else
|
|
|
|
printf("%s start at %i with a size of %i Bytes.\n",
|
|
|
|
entry->name, entry->offset, entry->size);
|
|
|
|
total += entry->size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s\n", entry->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eina_iterator_free(it);
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
printf("*** ***\n");
|
2015-11-23 00:35:07 -08:00
|
|
|
printf("Total payload size : %llu.\n", total);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
eet_close(ef);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_list */
|
2007-09-08 02:35:41 -07:00
|
|
|
|
2012-02-10 07:30:33 -08:00
|
|
|
static void
|
|
|
|
do_eet_stats(const char *file)
|
|
|
|
{
|
|
|
|
int i, num;
|
|
|
|
int count[2] = { 0, 0 };
|
|
|
|
int size[2] = { 0, 0 };
|
|
|
|
char **list;
|
|
|
|
Eet_File *ef;
|
|
|
|
Eet_Dictionary *ed;
|
|
|
|
|
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ);
|
|
|
|
if (!ef)
|
|
|
|
{
|
|
|
|
ERR("cannot open for reading: %s", file);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("*** sections stats ***\n");
|
|
|
|
list = eet_list(ef, "*", &num);
|
|
|
|
if (list)
|
|
|
|
{
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
const void *ro = NULL;
|
|
|
|
void *rw = NULL;
|
|
|
|
int tsize;
|
|
|
|
|
|
|
|
ro = eet_read_direct(ef, list[i], &tsize);
|
|
|
|
if (!ro) rw = eet_read(ef, list[i], &tsize);
|
|
|
|
printf(rw ? "%s of size %i is compressed.\n" : "%s of size %i is not compressed.\n", list[i], tsize);
|
|
|
|
count[rw ? 0 : 1]++;
|
|
|
|
size[rw ? 0 : 1] += tsize;
|
|
|
|
free(rw);
|
|
|
|
}
|
|
|
|
free(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("*** dictionary ***\n");
|
|
|
|
ed = eet_dictionary_get(ef);
|
|
|
|
if (ed)
|
|
|
|
{
|
|
|
|
printf("%i strings inside the dictionary.\n", eet_dictionary_count(ed));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("no dictionary in this file.\n");
|
|
|
|
}
|
|
|
|
printf("*** global ***\n");
|
|
|
|
printf("%i sections\n", num);
|
|
|
|
printf("- %i of them are compressed (%02.2f%%) expanding in %i bytes.\n",
|
|
|
|
count[0], (float) count[0] * 100 / (float) num, size[0]);
|
|
|
|
printf("- %i of them are directly mappable in memory (%02.2f%%) representing %i bytes.\n",
|
|
|
|
count[1], (float) count[1] * 100 / (float) num, size[1]);
|
|
|
|
|
|
|
|
eet_close(ef);
|
|
|
|
}
|
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
static void
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_extract(const char *file,
|
|
|
|
const char *key,
|
|
|
|
const char *out,
|
|
|
|
const char *crypto_key)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2011-10-20 22:40:01 -07:00
|
|
|
Eet_File *ef;
|
|
|
|
void *data;
|
2007-09-08 02:35:41 -07:00
|
|
|
int size = 0;
|
2012-01-07 05:33:15 -08:00
|
|
|
FILE *f = stdout;
|
2008-03-29 00:28:18 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ);
|
|
|
|
if (!ef)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot open for reading: %s", file);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
data = eet_read_cipher(ef, key, &size, crypto_key);
|
2007-09-08 02:35:41 -07:00
|
|
|
if (!data)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot read key %s", key);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-01-07 05:33:15 -08:00
|
|
|
if (out)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2012-01-07 05:33:15 -08:00
|
|
|
f = fopen(out, "wb");
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
ERR("cannot open %s", out);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
if (fwrite(data, size, 1, f) != 1)
|
|
|
|
{
|
2012-01-07 05:33:15 -08:00
|
|
|
ERR("cannot write to %s", out ? out : "standard output");
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-01-07 05:33:15 -08:00
|
|
|
if (out) fclose(f);
|
2007-09-08 02:35:41 -07:00
|
|
|
free(data);
|
|
|
|
eet_close(ef);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_extract */
|
2007-09-08 02:35:41 -07:00
|
|
|
|
|
|
|
static void
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_decode_dump(void *data,
|
|
|
|
const char *str)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
|
|
|
fputs(str, (FILE *)data);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_decode_dump */
|
2007-09-08 02:35:41 -07:00
|
|
|
|
|
|
|
static void
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_decode(const char *file,
|
|
|
|
const char *key,
|
|
|
|
const char *out,
|
|
|
|
const char *crypto_key)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2011-10-20 22:40:01 -07:00
|
|
|
Eet_File *ef;
|
2012-01-07 05:33:15 -08:00
|
|
|
FILE *f = stdout;
|
2008-03-29 00:28:18 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ);
|
|
|
|
if (!ef)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot open for reading: %s", file);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-01-07 05:33:15 -08:00
|
|
|
if (out)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2012-01-07 05:33:15 -08:00
|
|
|
f = fopen(out, "wb");
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
ERR("cannot open %s", out);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2008-11-13 08:31:13 -08:00
|
|
|
if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2012-01-07 05:33:15 -08:00
|
|
|
ERR("cannot write to %s", out ? out : "standard output");
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-01-07 05:33:15 -08:00
|
|
|
if (out) fclose(f);
|
2007-09-08 02:35:41 -07:00
|
|
|
eet_close(ef);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_decode */
|
2007-09-08 02:35:41 -07:00
|
|
|
|
|
|
|
static void
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_insert(const char *file,
|
|
|
|
const char *key,
|
2015-03-25 10:55:40 -07:00
|
|
|
const char *in,
|
2011-10-20 22:40:01 -07:00
|
|
|
int compress,
|
|
|
|
const char *crypto_key)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2011-10-20 22:40:01 -07:00
|
|
|
Eet_File *ef;
|
|
|
|
void *data;
|
2007-09-08 02:35:41 -07:00
|
|
|
int size = 0;
|
2011-10-20 22:40:01 -07:00
|
|
|
FILE *f;
|
2008-03-29 00:28:18 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
|
|
|
|
if (!ef)
|
2011-10-20 22:40:01 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_WRITE);
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
if (!ef)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot open for read+write: %s", file);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2015-03-25 10:55:40 -07:00
|
|
|
f = fopen(in, "rb");
|
2007-09-08 02:35:41 -07:00
|
|
|
if (!f)
|
|
|
|
{
|
2015-03-25 10:55:40 -07:00
|
|
|
ERR("cannot open %s", in);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
size = ftell(f);
|
2013-11-18 03:58:39 -08:00
|
|
|
if (size < 0)
|
|
|
|
{
|
2015-03-25 10:55:40 -07:00
|
|
|
ERR("cannot obtain current file position %s", in);
|
2013-11-18 03:58:39 -08:00
|
|
|
fclose(f);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
rewind(f);
|
|
|
|
data = malloc(size);
|
|
|
|
if (!data)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot allocate %i bytes", size);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
if (fread(data, size, 1, f) != 1)
|
|
|
|
{
|
2015-03-25 10:55:40 -07:00
|
|
|
ERR("cannot read file %s", in);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
fclose(f);
|
2008-11-13 08:31:13 -08:00
|
|
|
eet_write_cipher(ef, key, data, size, compress, crypto_key);
|
2007-09-08 02:35:41 -07:00
|
|
|
free(data);
|
|
|
|
eet_close(ef);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_insert */
|
2007-09-08 02:35:41 -07:00
|
|
|
|
|
|
|
static void
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_encode(const char *file,
|
|
|
|
const char *key,
|
2015-03-25 10:55:40 -07:00
|
|
|
const char *in,
|
2011-10-20 22:40:01 -07:00
|
|
|
int compress,
|
|
|
|
const char *crypto_key)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2011-10-20 22:40:01 -07:00
|
|
|
Eet_File *ef;
|
|
|
|
char *text;
|
2007-09-08 02:35:41 -07:00
|
|
|
int textlen = 0;
|
|
|
|
int size = 0;
|
2011-10-20 22:40:01 -07:00
|
|
|
FILE *f;
|
2008-03-29 00:28:18 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
|
|
|
|
if (!ef)
|
2011-10-20 22:40:01 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_WRITE);
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
if (!ef)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot open for read+write: %s", file);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2015-03-25 10:55:40 -07:00
|
|
|
f = fopen(in, "rb");
|
2007-09-08 02:35:41 -07:00
|
|
|
if (!f)
|
|
|
|
{
|
2015-03-25 10:55:40 -07:00
|
|
|
ERR("cannot open %s", in);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
textlen = ftell(f);
|
2013-11-18 04:37:38 -08:00
|
|
|
if (textlen < 0)
|
|
|
|
{
|
2015-03-25 10:55:40 -07:00
|
|
|
ERR("cannot obtain current file position %s", in);
|
2013-11-18 04:37:38 -08:00
|
|
|
fclose(f);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
rewind(f);
|
|
|
|
text = malloc(textlen);
|
|
|
|
if (!text)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot allocate %i bytes", size);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
if (fread(text, textlen, 1, f) != 1)
|
|
|
|
{
|
2015-03-25 10:55:40 -07:00
|
|
|
ERR("cannot read file %s", in);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
fclose(f);
|
2008-11-13 08:31:13 -08:00
|
|
|
if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2015-03-25 10:55:40 -07:00
|
|
|
ERR("cannot parse %s", in);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
free(text);
|
|
|
|
eet_close(ef);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_encode */
|
2007-09-08 02:35:41 -07:00
|
|
|
|
|
|
|
static void
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_remove(const char *file,
|
|
|
|
const char *key)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2011-10-20 22:40:01 -07:00
|
|
|
Eet_File *ef;
|
2008-03-29 00:28:18 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
|
|
|
|
if (!ef)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot open for read+write: %s", file);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
eet_delete(ef, key);
|
|
|
|
eet_close(ef);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_remove */
|
2007-09-08 02:35:41 -07:00
|
|
|
|
2008-09-08 02:19:57 -07:00
|
|
|
static void
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_check(const char *file)
|
2008-09-08 02:19:57 -07:00
|
|
|
{
|
2011-10-20 22:40:01 -07:00
|
|
|
Eet_File *ef;
|
|
|
|
const void *der;
|
2008-09-08 02:19:57 -07:00
|
|
|
int der_length;
|
2009-01-27 05:12:59 -08:00
|
|
|
int sign_length;
|
2008-09-08 02:19:57 -07:00
|
|
|
|
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ);
|
|
|
|
if (!ef)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("checking signature of `%s` failed", file);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2008-09-08 02:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
der = eet_identity_x509(ef, &der_length);
|
|
|
|
|
2017-03-23 22:03:20 -07:00
|
|
|
if (!der)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "No Certificate.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stdout, "Certificate length %i.\n", der_length);
|
|
|
|
eet_identity_certificate_print(der, der_length, stdout);
|
2008-09-08 02:19:57 -07:00
|
|
|
|
2017-03-23 22:03:20 -07:00
|
|
|
eet_identity_signature(ef, &sign_length);
|
|
|
|
fprintf(stdout, "Signature length %i.\n", sign_length);
|
|
|
|
}
|
2009-01-27 05:12:59 -08:00
|
|
|
|
2008-09-08 02:19:57 -07:00
|
|
|
eet_close(ef);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_check */
|
2008-09-08 02:19:57 -07:00
|
|
|
|
|
|
|
static void
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_sign(const char *file,
|
|
|
|
const char *private_key,
|
|
|
|
const char *public_key)
|
2008-09-08 02:19:57 -07:00
|
|
|
{
|
2011-10-20 22:40:01 -07:00
|
|
|
Eet_File *ef;
|
|
|
|
Eet_Key *key;
|
2008-09-08 02:19:57 -07:00
|
|
|
|
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
|
|
|
|
if (!ef)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot open for read+write: %s.", file);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2008-09-08 02:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
key = eet_identity_open(public_key, private_key, NULL);
|
2008-12-05 01:42:06 -08:00
|
|
|
if (!key)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
ERR("cannot open key '%s:%s'.", public_key, private_key);
|
2010-07-27 18:45:57 -07:00
|
|
|
exit(-1);
|
2008-12-05 01:42:06 -08:00
|
|
|
}
|
2008-09-08 02:19:57 -07:00
|
|
|
|
2009-10-06 05:07:29 -07:00
|
|
|
fprintf(stdout, "Using the following key to sign `%s`.\n", file);
|
2008-09-08 02:19:57 -07:00
|
|
|
eet_identity_print(key, stdout);
|
|
|
|
|
|
|
|
eet_identity_set(ef, key);
|
|
|
|
|
|
|
|
eet_close(ef);
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* do_eet_sign */
|
2008-09-08 02:19:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
int
|
2011-10-20 22:40:01 -07:00
|
|
|
main(int argc,
|
|
|
|
char **argv)
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2009-10-01 21:06:58 -07:00
|
|
|
if (!eet_init())
|
2011-10-20 22:40:01 -07:00
|
|
|
return -1;
|
2009-10-01 21:06:58 -07:00
|
|
|
|
2010-10-07 16:51:20 -07:00
|
|
|
_eet_main_log_dom = eina_log_domain_register("eet_main", EINA_COLOR_CYAN);
|
2009-10-01 20:59:17 -07:00
|
|
|
if(_eet_main_log_dom < -1)
|
|
|
|
{
|
2010-10-07 16:53:16 -07:00
|
|
|
EINA_LOG_ERR("Impossible to create a log domain for eet_main.");
|
2010-07-27 18:45:57 -07:00
|
|
|
eet_shutdown();
|
2011-10-20 22:40:01 -07:00
|
|
|
return -1;
|
2009-10-01 20:59:17 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2007-09-08 02:35:41 -07:00
|
|
|
if (argc < 2)
|
|
|
|
{
|
2010-07-27 18:45:57 -07:00
|
|
|
help:
|
|
|
|
printf(
|
2011-10-20 22:40:01 -07:00
|
|
|
"Usage:\n"
|
2012-10-30 22:58:50 -07:00
|
|
|
" eet -l [-v] FILE.EET list all keys in FILE.EET\n"
|
2012-01-07 05:33:15 -08:00
|
|
|
" eet -x FILE.EET KEY [OUT-FILE] [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE or standard output\n"
|
|
|
|
" eet -d FILE.EET KEY [OUT-FILE] [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE or standard output\n"
|
2011-10-20 22:40:01 -07:00
|
|
|
" 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"
|
|
|
|
" 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"
|
|
|
|
" eet -r FILE.EET KEY remove KEY in FILE.EET\n"
|
|
|
|
" eet -c FILE.EET report and check the signature information of an eet file\n"
|
|
|
|
" eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
|
2012-02-10 07:30:33 -08:00
|
|
|
" eet -t FILE.EET give some statistic about a file\n"
|
2015-04-02 06:32:06 -07:00
|
|
|
" eet -h print out this help message\n"
|
2015-04-02 06:40:05 -07:00
|
|
|
" eet -V [--version] show program version\n"
|
2011-10-20 22:40:01 -07:00
|
|
|
);
|
2010-07-27 18:45:57 -07:00
|
|
|
eet_shutdown();
|
|
|
|
return -1;
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2008-03-28 07:37:29 -07:00
|
|
|
if ((!strncmp(argv[1], "-h", 2)))
|
2011-10-20 22:40:01 -07:00
|
|
|
goto help;
|
2015-04-02 06:40:05 -07:00
|
|
|
else if ((!strncmp(argv[1], "-V", 2)) || (!strncmp(argv[1], "--version",9 )))
|
|
|
|
printf("Version: %s\n", PACKAGE_VERSION);
|
2012-10-30 22:58:50 -07:00
|
|
|
else if (((!strcmp(argv[1], "-l")) || (!strcmp(argv[1], "-v"))) && (argc > 2))
|
|
|
|
{
|
|
|
|
if (argc == 3)
|
|
|
|
do_eet_list(argv[2], EINA_FALSE);
|
|
|
|
else if ((!strcmp(argv[2], "-l")) || (!strcmp(argv[2], "-v")))
|
|
|
|
do_eet_list(argv[3], EINA_TRUE);
|
|
|
|
else
|
|
|
|
goto help;
|
|
|
|
}
|
2012-01-07 05:33:15 -08:00
|
|
|
else if ((!strcmp(argv[1], "-x")) && (argc > 3))
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2012-01-07 05:33:15 -08:00
|
|
|
switch (argc)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
do_eet_extract(argv[2], argv[3], NULL, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
do_eet_extract(argv[2], argv[3], argv[4], NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
2012-01-07 05:33:15 -08:00
|
|
|
else if ((!strcmp(argv[1], "-d")) && (argc > 3))
|
2007-09-08 02:35:41 -07:00
|
|
|
{
|
2012-01-07 05:33:15 -08:00
|
|
|
switch (argc)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
do_eet_decode(argv[2], argv[3], NULL, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
do_eet_decode(argv[2], argv[3], argv[4], NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
|
|
|
else if ((!strcmp(argv[1], "-i")) && (argc > 5))
|
|
|
|
{
|
2008-11-13 08:31:13 -08:00
|
|
|
if (argc > 6)
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
|
2010-07-27 18:45:57 -07:00
|
|
|
else
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
|
|
|
else if ((!strcmp(argv[1], "-e")) && (argc > 5))
|
|
|
|
{
|
2008-11-13 08:31:13 -08:00
|
|
|
if (argc > 6)
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
|
2010-07-27 18:45:57 -07:00
|
|
|
else
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
|
2007-09-08 02:35:41 -07:00
|
|
|
}
|
|
|
|
else if ((!strcmp(argv[1], "-r")) && (argc > 3))
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_remove(argv[2], argv[3]);
|
2008-09-08 02:19:57 -07:00
|
|
|
else if ((!strcmp(argv[1], "-c")) && (argc > 2))
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_check(argv[2]);
|
2008-09-08 02:19:57 -07:00
|
|
|
else if ((!strcmp(argv[1], "-s")) && (argc > 4))
|
2011-10-20 22:40:01 -07:00
|
|
|
do_eet_sign(argv[2], argv[3], argv[4]);
|
2012-02-10 07:30:33 -08:00
|
|
|
else if ((!strcmp(argv[1], "-t")) && (argc > 2))
|
|
|
|
do_eet_stats(argv[2]);
|
2008-09-08 02:19:57 -07:00
|
|
|
else
|
2011-10-20 22:40:01 -07:00
|
|
|
goto help;
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2009-10-01 20:59:17 -07:00
|
|
|
eina_log_domain_unregister(_eet_main_log_dom);
|
2007-09-08 02:35:41 -07:00
|
|
|
eet_shutdown();
|
|
|
|
return 0;
|
2010-07-30 18:54:48 -07:00
|
|
|
} /* main */
|
|
|
|
|