summaryrefslogtreecommitdiff
path: root/legacy/eet
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2008-11-13 16:31:13 +0000
committerCedric BAIL <cedric.bail@free.fr>2008-11-13 16:31:13 +0000
commit0f36b190f1f03a0167b67e59dc195875e62f4afd (patch)
tree92bd387681aa4218872dc891415aab0f6e33759f /legacy/eet
parentf3456d436822e6d571e56f05a7367c0291fad797 (diff)
Add crypto support to eet.
GNUTLS support by Arnaud de Turckheim <quarium@gmail.com>. SVN revision: 37603
Diffstat (limited to 'legacy/eet')
-rw-r--r--legacy/eet/AUTHORS1
-rw-r--r--legacy/eet/configure.ac62
-rw-r--r--legacy/eet/src/bin/eet_main.c52
-rw-r--r--legacy/eet/src/lib/Eet.h25
-rw-r--r--legacy/eet/src/lib/Eet_private.h20
-rw-r--r--legacy/eet/src/lib/Makefile.am7
-rw-r--r--legacy/eet/src/lib/eet_data.c197
-rw-r--r--legacy/eet/src/lib/eet_image.c186
-rw-r--r--legacy/eet/src/lib/eet_lib.c141
-rw-r--r--legacy/eet/src/tests/eet_suite.c60
10 files changed, 629 insertions, 122 deletions
diff --git a/legacy/eet/AUTHORS b/legacy/eet/AUTHORS
index c491082982..394dccea56 100644
--- a/legacy/eet/AUTHORS
+++ b/legacy/eet/AUTHORS
@@ -1,3 +1,4 @@
1The Rasterman (Carsten Haitzler) <raster@rasterman.com> 1The Rasterman (Carsten Haitzler) <raster@rasterman.com>
2David Goodlad <dgoodlad@gmail.com> 2David Goodlad <dgoodlad@gmail.com>
3Cedric Bail <cedric.bail@free.fr> 3Cedric Bail <cedric.bail@free.fr>
4Arnaud de Turckheim <quarium@gmail.com>
diff --git a/legacy/eet/configure.ac b/legacy/eet/configure.ac
index 0dbf64a84a..39e848cee9 100644
--- a/legacy/eet/configure.ac
+++ b/legacy/eet/configure.ac
@@ -29,13 +29,15 @@ AC_SUBST(version_info)
29 29
30case "$host_os" in 30case "$host_os" in
31 mingw* | cegcc*) 31 mingw* | cegcc*)
32 want_gnutls="no"
32 want_openssl="no" 33 want_openssl="no"
33 want_cypher="no" 34 want_cipher="no"
34 want_signature="no" 35 want_signature="no"
35 ;; 36 ;;
36 *) 37 *)
38 want_gnutls="auto"
37 want_openssl="auto" 39 want_openssl="auto"
38 want_cypher="yes" 40 want_cipher="yes"
39 want_signature="yes" 41 want_signature="yes"
40 ;; 42 ;;
41esac 43esac
@@ -64,6 +66,15 @@ else
64 AC_DEFINE(EET_OLD_EET_FILE_FORMAT, 0, [support old eet file format]) 66 AC_DEFINE(EET_OLD_EET_FILE_FORMAT, 0, [support old eet file format])
65fi 67fi
66 68
69# Gnutls support
70
71AC_ARG_ENABLE([gnutls],
72 [AC_HELP_STRING([--disable-gnutls], [disable gnutls eet support])],
73 [want_gnutls=$enableval]
74)
75AC_MSG_CHECKING([whether to use Gnutls])
76AC_MSG_RESULT([${want_gnutls}])
77
67# Openssl support 78# Openssl support
68 79
69AC_ARG_ENABLE([openssl], 80AC_ARG_ENABLE([openssl],
@@ -75,12 +86,12 @@ AC_MSG_RESULT([${want_openssl}])
75 86
76# Cryptography support 87# Cryptography support
77 88
78AC_ARG_ENABLE([cypher], 89AC_ARG_ENABLE([cipher],
79 [AC_HELP_STRING([--disable-cypher], [disable cypher support for eet API])], 90 [AC_HELP_STRING([--disable-cipher], [disable cipher support for eet API])],
80 [want_cypher=$enableval] 91 [want_cipher=$enableval]
81) 92)
82AC_MSG_CHECKING([whether to use cypher]) 93AC_MSG_CHECKING([whether to use cipher])
83AC_MSG_RESULT([${want_cypher}]) 94AC_MSG_RESULT([${want_cipher}])
84 95
85AC_ARG_ENABLE([signature], 96AC_ARG_ENABLE([signature],
86 [AC_HELP_STRING([--disable-signature], [disable signature file support for eet])], 97 [AC_HELP_STRING([--disable-signature], [disable signature file support for eet])],
@@ -152,6 +163,20 @@ AC_SUBST(EET_LIBS)
152PKG_CHECK_MODULES(EINA, [eina-0]) 163PKG_CHECK_MODULES(EINA, [eina-0])
153requirement_eet="eina-0 ${requirement_eet}" 164requirement_eet="eina-0 ${requirement_eet}"
154 165
166# Gnutls library
167have_gnutls="no"
168if test "x${want_gnutls}" = "xyes" -o "x${want_gnutls}" = "xauto" ; then
169 PKG_CHECK_MODULES(GNUTLS, [gnutls >= 1.7.6],
170 [
171 have_gnutls="yes"
172 AC_DEFINE(HAVE_GNUTLS, 1, [Have Gnutls support])
173 requirement_eet="gnutls ${requirement_eet}"
174 ],
175 [
176 have_gnutls="no"
177 ])
178fi
179
155# Openssl library 180# Openssl library
156have_openssl="no" 181have_openssl="no"
157if test "x${want_openssl}" = "xyes" -o "x${want_openssl}" = "xauto" ; then 182if test "x${want_openssl}" = "xyes" -o "x${want_openssl}" = "xauto" ; then
@@ -164,17 +189,23 @@ if test "x${want_openssl}" = "xyes" -o "x${want_openssl}" = "xauto" ; then
164 [have_openssl="no"]) 189 [have_openssl="no"])
165fi 190fi
166 191
167have_cypher="no" 192have_cipher="no"
168if test "x${have_openssl}" = "xyes" -a "x${want_cypher}" = "xyes" ; then 193if test "x${have_gnutls}" = "xyes" -a "x${want_cipher}" = "xyes" ; then
169 have_cypher="yes" 194 have_cipher="yes"
170 AC_DEFINE(HAVE_CYPHER, 1, [Have cypher support built in eet]) 195 AC_DEFINE(HAVE_CIPHER, 1, [Have cipher support built in eet])
196elif test "x${have_openssl}" = "xyes" -a "x${want_cipher}" = "xyes" ; then
197 have_cipher="yes"
198 AC_DEFINE(HAVE_CIPHER, 1, [Have cipher support built in eet])
171fi 199fi
172 200
173AC_MSG_CHECKING(whether to activate cypher support in eet) 201AC_MSG_CHECKING(whether to activate cipher support in eet)
174AC_MSG_RESULT(${have_cypher}) 202AC_MSG_RESULT(${have_cipher})
175 203
176have_signature="no" 204have_signature="no"
177if test "x${have_openssl}" = "xyes" -a "x${want_signature}" = "xyes" ; then 205if test "x${have_gnutls}" = "xyes" -a "x${want_signature}" = "xyes" ; then
206 have_signature="yes"
207 AC_DEFINE(HAVE_SIGNATURE, 1, [Have signature support for eet file])
208elif test "x${have_openssl}" = "xyes" -a "x${want_signature}" = "xyes" ; then
178 have_signature="yes" 209 have_signature="yes"
179 AC_DEFINE(HAVE_SIGNATURE, 1, [Have signature support for eet file]) 210 AC_DEFINE(HAVE_SIGNATURE, 1, [Have signature support for eet file])
180fi 211fi
@@ -313,8 +344,9 @@ echo "------------------------------------------------------------------------"
313echo 344echo
314echo "Configuration Options Summary:" 345echo "Configuration Options Summary:"
315echo 346echo
347echo " Gnutls...............: ${have_gnutls}"
316echo " Openssl..............: ${have_openssl}" 348echo " Openssl..............: ${have_openssl}"
317echo " Cypher support.....: ${have_cypher}" 349echo " Cipher support.....: ${have_cipher}"
318echo " Signature..........: ${have_signature}" 350echo " Signature..........: ${have_signature}"
319echo 351echo
320echo " Documentation........: ${enable_doc}" 352echo " Documentation........: ${enable_doc}"
diff --git a/legacy/eet/src/bin/eet_main.c b/legacy/eet/src/bin/eet_main.c
index 76360f9527..114fffe51a 100644
--- a/legacy/eet/src/bin/eet_main.c
+++ b/legacy/eet/src/bin/eet_main.c
@@ -41,7 +41,7 @@ do_eet_list(const char *file)
41} 41}
42 42
43static void 43static void
44do_eet_extract(const char *file, const char *key, const char *out) 44do_eet_extract(const char *file, const char *key, const char *out, const char *crypto_key)
45{ 45{
46 Eet_File *ef; 46 Eet_File *ef;
47 void *data; 47 void *data;
@@ -54,7 +54,7 @@ do_eet_extract(const char *file, const char *key, const char *out)
54 printf("cannot open for reading: %s\n", file); 54 printf("cannot open for reading: %s\n", file);
55 exit(-1); 55 exit(-1);
56 } 56 }
57 data = eet_read(ef, key, &size); 57 data = eet_read_cipher(ef, key, &size, crypto_key);
58 if (!data) 58 if (!data)
59 { 59 {
60 printf("cannot read key %s\n", key); 60 printf("cannot read key %s\n", key);
@@ -83,7 +83,7 @@ do_eet_decode_dump(void *data, const char *str)
83} 83}
84 84
85static void 85static void
86do_eet_decode(const char *file, const char *key, const char *out) 86do_eet_decode(const char *file, const char *key, const char *out, const char *crypto_key)
87{ 87{
88 Eet_File *ef; 88 Eet_File *ef;
89 FILE *f; 89 FILE *f;
@@ -100,7 +100,7 @@ do_eet_decode(const char *file, const char *key, const char *out)
100 printf("cannot open %s\n", out); 100 printf("cannot open %s\n", out);
101 exit(-1); 101 exit(-1);
102 } 102 }
103 if (!eet_data_dump(ef, key, do_eet_decode_dump, f)) 103 if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
104 { 104 {
105 printf("cannot write to %s\n", out); 105 printf("cannot write to %s\n", out);
106 exit(-1); 106 exit(-1);
@@ -110,7 +110,7 @@ do_eet_decode(const char *file, const char *key, const char *out)
110} 110}
111 111
112static void 112static void
113do_eet_insert(const char *file, const char *key, const char *out, int compress) 113do_eet_insert(const char *file, const char *key, const char *out, int compress, const char *crypto_key)
114{ 114{
115 Eet_File *ef; 115 Eet_File *ef;
116 void *data; 116 void *data;
@@ -146,13 +146,13 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress)
146 exit(-1); 146 exit(-1);
147 } 147 }
148 fclose(f); 148 fclose(f);
149 eet_write(ef, key, data, size, compress); 149 eet_write_cipher(ef, key, data, size, compress, crypto_key);
150 free(data); 150 free(data);
151 eet_close(ef); 151 eet_close(ef);
152} 152}
153 153
154static void 154static void
155do_eet_encode(const char *file, const char *key, const char *out, int compress) 155do_eet_encode(const char *file, const char *key, const char *out, int compress, const char *crypto_key)
156{ 156{
157 Eet_File *ef; 157 Eet_File *ef;
158 char *text; 158 char *text;
@@ -189,7 +189,7 @@ do_eet_encode(const char *file, const char *key, const char *out, int compress)
189 exit(-1); 189 exit(-1);
190 } 190 }
191 fclose(f); 191 fclose(f);
192 if (!eet_data_undump(ef, key, text, textlen, compress)) 192 if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
193 { 193 {
194 printf("cannot parse %s\n", out); 194 printf("cannot parse %s\n", out);
195 exit(-1); 195 exit(-1);
@@ -265,14 +265,14 @@ main(int argc, char **argv)
265 { 265 {
266 help: 266 help:
267 printf("Usage:\n" 267 printf("Usage:\n"
268 " eet -l FILE.EET list all keys in FILE.EET\n" 268 " eet -l FILE.EET list all keys in FILE.EET\n"
269 " eet -x FILE.EET KEY OUT-FILE extract data stored in KEY in FILE.EET and write to OUT-FILE\n" 269 " eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
270 " eet -d FILE.EET KEY OUT-FILE extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n" 270 " 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"
271 " eet -i FILE.EET KEY IN-FILE COMPRESS insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n" 271 " 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"
272 " eet -e FILE.EET KEY IN-FILE COMPRESS insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n" 272 " 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"
273 " eet -r FILE.EET KEY remove KEY in FILE.EET\n" 273 " eet -r FILE.EET KEY remove KEY in FILE.EET\n"
274 " eet -c FILE.EET report and check the signature information of an eet file\n" 274 " eet -c FILE.EET report and check the signature information of an eet file\n"
275 " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n" 275 " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
276 ); 276 );
277 eet_shutdown(); 277 eet_shutdown();
278 return -1; 278 return -1;
@@ -287,19 +287,31 @@ main(int argc, char **argv)
287 } 287 }
288 else if ((!strcmp(argv[1], "-x")) && (argc > 4)) 288 else if ((!strcmp(argv[1], "-x")) && (argc > 4))
289 { 289 {
290 do_eet_extract(argv[2], argv[3], argv[4]); 290 if (argc > 5)
291 do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
292 else
293 do_eet_extract(argv[2], argv[3], argv[4], NULL);
291 } 294 }
292 else if ((!strcmp(argv[1], "-d")) && (argc > 4)) 295 else if ((!strcmp(argv[1], "-d")) && (argc > 4))
293 { 296 {
294 do_eet_decode(argv[2], argv[3], argv[4]); 297 if (argc > 5)
298 do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
299 else
300 do_eet_decode(argv[2], argv[3], argv[4], NULL);
295 } 301 }
296 else if ((!strcmp(argv[1], "-i")) && (argc > 5)) 302 else if ((!strcmp(argv[1], "-i")) && (argc > 5))
297 { 303 {
298 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5])); 304 if (argc > 6)
305 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
306 else
307 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
299 } 308 }
300 else if ((!strcmp(argv[1], "-e")) && (argc > 5)) 309 else if ((!strcmp(argv[1], "-e")) && (argc > 5))
301 { 310 {
302 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5])); 311 if (argc > 6)
312 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
313 else
314 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
303 } 315 }
304 else if ((!strcmp(argv[1], "-r")) && (argc > 3)) 316 else if ((!strcmp(argv[1], "-r")) && (argc > 3))
305 { 317 {
diff --git a/legacy/eet/src/lib/Eet.h b/legacy/eet/src/lib/Eet.h
index 606c7fe733..4b34c06a9d 100644
--- a/legacy/eet/src/lib/Eet.h
+++ b/legacy/eet/src/lib/Eet.h
@@ -94,7 +94,10 @@ extern "C" {
94 EET_ERROR_SIGNATURE_FAILED, 94 EET_ERROR_SIGNATURE_FAILED,
95 EET_ERROR_INVALID_SIGNATURE, 95 EET_ERROR_INVALID_SIGNATURE,
96 EET_ERROR_NOT_SIGNED, 96 EET_ERROR_NOT_SIGNED,
97 EET_ERROR_NOT_IMPLEMENTED 97 EET_ERROR_NOT_IMPLEMENTED,
98 EET_ERROR_PRNG_NOT_SEEDED,
99 EET_ERROR_ENCRYPT_FAILED,
100 EET_ERROR_DECRYPT_FAILED
98 } Eet_Error; 101 } Eet_Error;
99 102
100 typedef struct _Eet_File Eet_File; 103 typedef struct _Eet_File Eet_File;
@@ -358,6 +361,7 @@ extern "C" {
358 * 361 *
359 * @since 1.0.0 362 * @since 1.0.0
360 */ 363 */
364 EAPI void *eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *cipher_key);
361 EAPI void *eet_read(Eet_File *ef, const char *name, int *size_ret); 365 EAPI void *eet_read(Eet_File *ef, const char *name, int *size_ret);
362 366
363 /** 367 /**
@@ -406,6 +410,7 @@ extern "C" {
406 * 410 *
407 * @since 1.0.0 411 * @since 1.0.0
408 */ 412 */
413 EAPI int eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int compress, const char *cipher_key);
409 EAPI int eet_write(Eet_File *ef, const char *name, const void *data, int size, int compress); 414 EAPI int eet_write(Eet_File *ef, const char *name, const void *data, int size, int compress);
410 415
411 /** 416 /**
@@ -503,6 +508,7 @@ extern "C" {
503 * 508 *
504 * @since 1.0.0 509 * @since 1.0.0
505 */ 510 */
511 EAPI int eet_data_image_header_read_cipher(Eet_File *ef, const char *name, const char *key, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
506 EAPI int eet_data_image_header_read(Eet_File *ef, const char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy); 512 EAPI int eet_data_image_header_read(Eet_File *ef, const char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
507 513
508 /** 514 /**
@@ -540,6 +546,7 @@ extern "C" {
540 * 546 *
541 * @since 1.0.0 547 * @since 1.0.0
542 */ 548 */
549 EAPI void *eet_data_image_read_cipher(Eet_File *ef, const char *name, const char *key, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
543 EAPI void *eet_data_image_read(Eet_File *ef, const char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy); 550 EAPI void *eet_data_image_read(Eet_File *ef, const char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
544 551
545 /** 552 /**
@@ -579,7 +586,8 @@ extern "C" {
579 * 586 *
580 * @since 1.0.2 587 * @since 1.0.2
581 */ 588 */
582 EAPI int eet_data_image_read_to_surface(Eet_File *ef, const char *name, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy); 589 EAPI int eet_data_image_read_to_surface_cipher(Eet_File *ef, const char *name, const char *key, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy);
590 EAPI int eet_data_image_read_to_surface(Eet_File *ef, const char *name, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy);
583 591
584 /** 592 /**
585 * Write image data to the named key in an eet file. 593 * Write image data to the named key in an eet file.
@@ -613,6 +621,7 @@ extern "C" {
613 * 621 *
614 * @since 1.0.0 622 * @since 1.0.0
615 */ 623 */
624 EAPI int eet_data_image_write_cipher(Eet_File *ef, const char *name, const char *key, const void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
616 EAPI int eet_data_image_write(Eet_File *ef, const char *name, const void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy); 625 EAPI int eet_data_image_write(Eet_File *ef, const char *name, const void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
617 626
618 /** 627 /**
@@ -648,6 +657,7 @@ extern "C" {
648 * 657 *
649 * @since 1.0.0 658 * @since 1.0.0
650 */ 659 */
660 EAPI int eet_data_image_header_decode_cipher(const void *data, const char *key, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
651 EAPI int eet_data_image_header_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy); 661 EAPI int eet_data_image_header_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
652 662
653 /** 663 /**
@@ -685,6 +695,7 @@ extern "C" {
685 * 695 *
686 * @since 1.0.0 696 * @since 1.0.0
687 */ 697 */
698 EAPI void *eet_data_image_decode_cipher(const void *data, const char *key, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
688 EAPI void *eet_data_image_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy); 699 EAPI void *eet_data_image_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
689 700
690 /** 701 /**
@@ -724,6 +735,7 @@ extern "C" {
724 * 735 *
725 * @since 1.0.2 736 * @since 1.0.2
726 */ 737 */
738 EAPI int eet_data_image_decode_to_surface_cipher(const void *data, const char *key, int size, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy);
727 EAPI int eet_data_image_decode_to_surface(const void *data, int size, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy); 739 EAPI int eet_data_image_decode_to_surface(const void *data, int size, unsigned int src_x, unsigned int src_y, unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, int *alpha, int *compress, int *quality, int *lossy);
728 740
729 /** 741 /**
@@ -757,6 +769,7 @@ extern "C" {
757 * 769 *
758 * @since 1.0.0 770 * @since 1.0.0
759 */ 771 */
772 EAPI void *eet_data_image_encode_cipher(const void *data, const char *key, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy, int *size_ret);
760 EAPI void *eet_data_image_encode(const void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy); 773 EAPI void *eet_data_image_encode(const void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
761 774
762/***************************************************************************/ 775/***************************************************************************/
@@ -986,6 +999,7 @@ extern "C" {
986 * 999 *
987 * @since 1.0.0 1000 * @since 1.0.0
988 */ 1001 */
1002 EAPI void *eet_data_read_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *key);
989 EAPI void *eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name); 1003 EAPI void *eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name);
990 1004
991 /** 1005 /**
@@ -1002,6 +1016,7 @@ extern "C" {
1002 * 1016 *
1003 * @since 1.0.0 1017 * @since 1.0.0
1004 */ 1018 */
1019 EAPI int eet_data_write_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *key, const void *data, int compress);
1005 EAPI int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress); 1020 EAPI int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress);
1006 1021
1007 /** 1022 /**
@@ -1047,6 +1062,7 @@ extern "C" {
1047 * 1062 *
1048 * @since 1.0.0 1063 * @since 1.0.0
1049 */ 1064 */
1065 EAPI int eet_data_text_dump_cipher(const void *data_in, const char *key, int size_in, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
1050 EAPI int eet_data_text_dump(const void *data_in, int size_in, void (*dumpfunc) (void *data, const char *str), void *dumpdata); 1066 EAPI int eet_data_text_dump(const void *data_in, int size_in, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
1051 1067
1052 /** 1068 /**
@@ -1063,6 +1079,7 @@ extern "C" {
1063 * 1079 *
1064 * @since 1.0.0 1080 * @since 1.0.0
1065 */ 1081 */
1082 EAPI void *eet_data_text_undump_cipher(const char *text, const char *key, int textlen, int *size_ret);
1066 EAPI void *eet_data_text_undump(const char *text, int textlen, int *size_ret); 1083 EAPI void *eet_data_text_undump(const char *text, int textlen, int *size_ret);
1067 1084
1068 /** 1085 /**
@@ -1082,6 +1099,7 @@ extern "C" {
1082 * 1099 *
1083 * @since 1.0.0 1100 * @since 1.0.0
1084 */ 1101 */
1102 EAPI int eet_data_dump_cipher(Eet_File *ef, const char *name, const char *key, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
1085 EAPI int eet_data_dump(Eet_File *ef, const char *name, void (*dumpfunc) (void *data, const char *str), void *dumpdata); 1103 EAPI int eet_data_dump(Eet_File *ef, const char *name, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
1086 1104
1087 /** 1105 /**
@@ -1102,6 +1120,7 @@ extern "C" {
1102 * 1120 *
1103 * @since 1.0.0 1121 * @since 1.0.0
1104 */ 1122 */
1123 EAPI int eet_data_undump_cipher(Eet_File *ef, const char *name, const char *key, const char *text, int textlen, int compress);
1105 EAPI int eet_data_undump(Eet_File *ef, const char *name, const char *text, int textlen, int compress); 1124 EAPI int eet_data_undump(Eet_File *ef, const char *name, const char *text, int textlen, int compress);
1106 1125
1107 /** 1126 /**
@@ -1128,6 +1147,7 @@ extern "C" {
1128 * 1147 *
1129 * @since 1.0.0 1148 * @since 1.0.0
1130 */ 1149 */
1150 EAPI void *eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd, const void *data_in, const char *key, int size_in);
1131 EAPI void *eet_data_descriptor_decode(Eet_Data_Descriptor *edd, const void *data_in, int size_in); 1151 EAPI void *eet_data_descriptor_decode(Eet_Data_Descriptor *edd, const void *data_in, int size_in);
1132 1152
1133 /** 1153 /**
@@ -1156,6 +1176,7 @@ extern "C" {
1156 * 1176 *
1157 * @since 1.0.0 1177 * @since 1.0.0
1158 */ 1178 */
1179 EAPI void *eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd, const void *data_in, const char *key, int *size_ret);
1159 EAPI void *eet_data_descriptor_encode(Eet_Data_Descriptor *edd, const void *data_in, int *size_ret); 1180 EAPI void *eet_data_descriptor_encode(Eet_Data_Descriptor *edd, const void *data_in, int *size_ret);
1160 1181
1161 /** 1182 /**
diff --git a/legacy/eet/src/lib/Eet_private.h b/legacy/eet/src/lib/Eet_private.h
index 617ca10d6c..acbd981279 100644
--- a/legacy/eet/src/lib/Eet_private.h
+++ b/legacy/eet/src/lib/Eet_private.h
@@ -16,10 +16,15 @@
16# include <config.h> 16# include <config.h>
17#endif 17#endif
18 18
19#ifdef HAVE_GNUTLS
20# include <gnutls/gnutls.h>
21# include <gnutls/x509.h>
22#else
19#ifdef HAVE_OPENSSL 23#ifdef HAVE_OPENSSL
20#include <openssl/evp.h> 24# include <openssl/evp.h>
21#include <openssl/x509.h> 25# include <openssl/x509.h>
22#include <openssl/pem.h> 26# include <openssl/pem.h>
27#endif
23#endif 28#endif
24 29
25typedef struct _Eet_String Eet_String; 30typedef struct _Eet_String Eet_String;
@@ -67,8 +72,13 @@ struct _Eet_Key
67{ 72{
68 int references; 73 int references;
69#ifdef HAVE_SIGNATURE 74#ifdef HAVE_SIGNATURE
75# ifdef HAVE_GNUTLS
76 gnutls_x509_crt_t certificate;
77 gnutls_x509_privkey_t private_key;
78# else
70 X509 *certificate; 79 X509 *certificate;
71 EVP_PKEY *private_key; 80 EVP_PKEY *private_key;
81# endif
72#endif 82#endif
73}; 83};
74 84
@@ -86,8 +96,8 @@ int _eet_hash_gen(const char *key, int hash_size);
86const void* eet_identity_check(const void *data_base, unsigned int data_length, 96const void* eet_identity_check(const void *data_base, unsigned int data_length,
87 const void *signature_base, unsigned int signature_length, 97 const void *signature_base, unsigned int signature_length,
88 int *x509_length); 98 int *x509_length);
89Eet_Error eet_cypher(void *data, unsigned int size, const char *key, unsigned int length); 99Eet_Error eet_cipher(const void *data, unsigned int size, const char *key, unsigned int length, void **result, unsigned int *result_length);
90Eet_Error eet_decypher(void *data, unsigned int size, const char *key, unsigned int length); 100Eet_Error eet_decipher(const void *data, unsigned int size, const char *key, unsigned int length, void **result, unsigned int *result_length);
91Eet_Error eet_identity_sign(FILE *fp, Eet_Key *key); 101Eet_Error eet_identity_sign(FILE *fp, Eet_Key *key);
92void eet_identity_unref(Eet_Key *key); 102void eet_identity_unref(Eet_Key *key);
93void eet_identity_ref(Eet_Key *key); 103void eet_identity_ref(Eet_Key *key);
diff --git a/legacy/eet/src/lib/Makefile.am b/legacy/eet/src/lib/Makefile.am
index c93b86be5a..e24d080f73 100644
--- a/legacy/eet/src/lib/Makefile.am
+++ b/legacy/eet/src/lib/Makefile.am
@@ -13,7 +13,8 @@ AM_CPPFLAGS = \
13@EET_CPPFLAGS@ \ 13@EET_CPPFLAGS@ \
14@EFL_EET_BUILD@ \ 14@EFL_EET_BUILD@ \
15@EFL_COVERAGE_CFLAGS@ \ 15@EFL_COVERAGE_CFLAGS@ \
16@OPENSSL_CFLAGS@ 16@OPENSSL_CFLAGS@ \
17@GNUTLS_CFLAGS@
17 18
18include_HEADERS = Eet.h 19include_HEADERS = Eet.h
19 20
@@ -23,12 +24,12 @@ libeet_la_SOURCES = \
23eet_lib.c \ 24eet_lib.c \
24eet_data.c \ 25eet_data.c \
25eet_image.c \ 26eet_image.c \
26eet_cypher.c \ 27eet_cipher.c \
27eet_dictionary.c \ 28eet_dictionary.c \
28eet_utils.c 29eet_utils.c
29 30
30libeet_la_CFLAGS = @EET_CFLAGS@ @DEBUG_CFLAGS@ 31libeet_la_CFLAGS = @EET_CFLAGS@ @DEBUG_CFLAGS@
31libeet_la_LIBADD = @OPENSSL_LIBS@ @EFL_COVERAGE_LIBS@ @EET_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ -lz -ljpeg -lm 32libeet_la_LIBADD = @GNUTLS_LIBS@ @OPENSSL_LIBS@ @EFL_COVERAGE_LIBS@ @EET_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ -lz -ljpeg -lm
32libeet_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ 33libeet_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@
33 34
34EXTRA_DIST = Eet_private.h 35EXTRA_DIST = Eet_private.h
diff --git a/legacy/eet/src/lib/eet_data.c b/legacy/eet/src/lib/eet_data.c
index 19b4bc384a..474f9c147f 100644
--- a/legacy/eet/src/lib/eet_data.c
+++ b/legacy/eet/src/lib/eet_data.c
@@ -1190,21 +1190,22 @@ eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
1190} 1190}
1191 1191
1192EAPI void * 1192EAPI void *
1193eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name) 1193eet_data_read_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *key)
1194{ 1194{
1195 const Eet_Dictionary *ed = NULL; 1195 const Eet_Dictionary *ed = NULL;
1196 const void *data; 1196 const void *data = NULL;
1197 void *data_dec; 1197 void *data_dec;
1198 int size;
1199 int required_free = 0; 1198 int required_free = 0;
1199 int size;
1200 1200
1201 ed = eet_dictionary_get(ef); 1201 ed = eet_dictionary_get(ef);
1202 1202
1203 data = eet_read_direct(ef, name, &size); 1203 if (!key)
1204 data = eet_read_direct(ef, name, &size);
1204 if (!data) 1205 if (!data)
1205 { 1206 {
1206 required_free = 1; 1207 required_free = 1;
1207 data = eet_read(ef, name, &size); 1208 data = eet_read_cipher(ef, name, &size, key);
1208 if (!data) return NULL; 1209 if (!data) return NULL;
1209 } 1210 }
1210 1211
@@ -1215,8 +1216,14 @@ eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name)
1215 return data_dec; 1216 return data_dec;
1216} 1217}
1217 1218
1219EAPI void *
1220eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name)
1221{
1222 return eet_data_read_cipher(ef, edd, name, NULL);
1223}
1224
1218EAPI int 1225EAPI int
1219eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress) 1226eet_data_write_cipher(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const char *key, const void *data, int compress)
1220{ 1227{
1221 Eet_Dictionary *ed; 1228 Eet_Dictionary *ed;
1222 void *data_enc; 1229 void *data_enc;
@@ -1227,11 +1234,17 @@ eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const v
1227 1234
1228 data_enc = _eet_data_descriptor_encode(ed, edd, data, &size); 1235 data_enc = _eet_data_descriptor_encode(ed, edd, data, &size);
1229 if (!data_enc) return 0; 1236 if (!data_enc) return 0;
1230 val = eet_write(ef, name, data_enc, size, compress); 1237 val = eet_write_cipher(ef, name, data_enc, size, compress, key);
1231 free(data_enc); 1238 free(data_enc);
1232 return val; 1239 return val;
1233} 1240}
1234 1241
1242EAPI int
1243eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress)
1244{
1245 return eet_data_write_cipher(ef, edd, name, NULL, data, compress);
1246}
1247
1235typedef struct _Eet_Free Eet_Free; 1248typedef struct _Eet_Free Eet_Free;
1236struct _Eet_Free 1249struct _Eet_Free
1237{ 1250{
@@ -3028,24 +3041,25 @@ eet_data_put_hash(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element
3028} 3041}
3029 3042
3030EAPI int 3043EAPI int
3031eet_data_dump(Eet_File *ef, 3044eet_data_dump_cipher(Eet_File *ef,
3032 const char *name, 3045 const char *name, const char *key,
3033 void (*dumpfunc) (void *data, const char *str), 3046 void (*dumpfunc) (void *data, const char *str),
3034 void *dumpdata) 3047 void *dumpdata)
3035{ 3048{
3036 const Eet_Dictionary *ed = NULL; 3049 const Eet_Dictionary *ed = NULL;
3037 const void *data; 3050 const void *data = NULL;
3038 int ret = 0; 3051 int ret = 0;
3039 int required_free = 0; 3052 int required_free = 0;
3040 int size; 3053 int size;
3041 3054
3042 ed = eet_dictionary_get(ef); 3055 ed = eet_dictionary_get(ef);
3043 3056
3044 data = eet_read_direct(ef, name, &size); 3057 if (!key)
3058 data = eet_read_direct(ef, name, &size);
3045 if (!data) 3059 if (!data)
3046 { 3060 {
3047 required_free = 1; 3061 required_free = 1;
3048 data = eet_read(ef, name, &size); 3062 data = eet_read_cipher(ef, name, &size, key);
3049 if (!data) return 0; 3063 if (!data) return 0;
3050 } 3064 }
3051 3065
@@ -3059,6 +3073,46 @@ eet_data_dump(Eet_File *ef,
3059 return ret; 3073 return ret;
3060} 3074}
3061 3075
3076EAPI int
3077eet_data_dump(Eet_File *ef,
3078 const char *name,
3079 void (*dumpfunc) (void *data, const char *str),
3080 void *dumpdata)
3081{
3082 return eet_data_dump_cipher(ef, name, NULL, dumpfunc, dumpdata);
3083}
3084
3085
3086EAPI int
3087eet_data_text_dump_cipher(const void *data_in,
3088 const char *key, int size_in,
3089 void (*dumpfunc) (void *data, const char *str),
3090 void *dumpdata)
3091{
3092 void *ret = NULL;
3093 unsigned int ret_len = 0;
3094
3095 if (data_in && key)
3096 {
3097 if (eet_decipher(data_in, size_in, key, strlen(key), &ret, &ret_len))
3098 {
3099 if (ret) free(ret);
3100 return 1;
3101 }
3102 if (_eet_data_descriptor_decode(NULL, NULL, ret, ret_len, 0,
3103 dumpfunc, dumpdata))
3104 {
3105 free(ret);
3106 return 1;
3107 }
3108 free(ret);
3109 return 0;
3110 }
3111 if (_eet_data_descriptor_decode(NULL, NULL, data_in, size_in, 0,
3112 dumpfunc, dumpdata))
3113 return 1;
3114 return 0;
3115}
3062 3116
3063EAPI int 3117EAPI int
3064eet_data_text_dump(const void *data_in, 3118eet_data_text_dump(const void *data_in,
@@ -3066,10 +3120,34 @@ eet_data_text_dump(const void *data_in,
3066 void (*dumpfunc) (void *data, const char *str), 3120 void (*dumpfunc) (void *data, const char *str),
3067 void *dumpdata) 3121 void *dumpdata)
3068{ 3122{
3069 if (_eet_data_descriptor_decode(NULL, NULL, data_in, size_in, 0, 3123 return eet_data_text_dump_cipher(data_in, NULL, size_in, dumpfunc, dumpdata);
3070 dumpfunc, dumpdata)) 3124}
3071 return 1; 3125
3072 return 0; 3126EAPI void *
3127eet_data_text_undump_cipher(const char *text,
3128 const char *key,
3129 int textlen,
3130 int *size_ret)
3131{
3132 void *ret = NULL;
3133 void *cyphered = NULL;
3134 unsigned int cyphered_len;
3135
3136 ret = _eet_data_dump_parse(NULL, size_ret, text, textlen);
3137 if (ret && key)
3138 {
3139 if (eet_cipher(ret, *size_ret, key, strlen(key), &cyphered, &cyphered_len))
3140 {
3141 if (cyphered) free(cyphered);
3142 size_ret = 0;
3143 free(ret);
3144 return NULL;
3145 }
3146 free(ret);
3147 *size_ret = cyphered_len;
3148 ret = cyphered;
3149 }
3150 return ret;
3073} 3151}
3074 3152
3075EAPI void * 3153EAPI void *
@@ -3077,15 +3155,16 @@ eet_data_text_undump(const char *text,
3077 int textlen, 3155 int textlen,
3078 int *size_ret) 3156 int *size_ret)
3079{ 3157{
3080 return _eet_data_dump_parse(NULL, size_ret, text, textlen); 3158 return eet_data_text_undump_cipher(text, NULL, textlen, size_ret);
3081} 3159}
3082 3160
3083EAPI int 3161EAPI int
3084eet_data_undump(Eet_File *ef, 3162eet_data_undump_cipher(Eet_File *ef,
3085 const char *name, 3163 const char *name,
3086 const char *text, 3164 const char *key,
3087 int textlen, 3165 const char *text,
3088 int compress) 3166 int textlen,
3167 int compress)
3089{ 3168{
3090 Eet_Dictionary *ed; 3169 Eet_Dictionary *ed;
3091 void *data_enc; 3170 void *data_enc;
@@ -3096,18 +3175,53 @@ eet_data_undump(Eet_File *ef,
3096 3175
3097 data_enc = _eet_data_dump_parse(ed, &size, text, textlen); 3176 data_enc = _eet_data_dump_parse(ed, &size, text, textlen);
3098 if (!data_enc) return 0; 3177 if (!data_enc) return 0;
3099 val = eet_write(ef, name, data_enc, size, compress); 3178 val = eet_write_cipher(ef, name, data_enc, size, compress, key);
3100 free(data_enc); 3179 free(data_enc);
3101 return val; 3180 return val;
3102} 3181}
3103 3182
3183EAPI int
3184eet_data_undump(Eet_File *ef,
3185 const char *name,
3186 const char *text,
3187 int textlen,
3188 int compress)
3189{
3190 return eet_data_undump_cipher(ef, name, NULL, text, textlen, compress);
3191}
3192
3193EAPI void *
3194eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
3195 const void *data_in,
3196 const char *key,
3197 int size_in)
3198{
3199 void *deciphered = NULL;
3200 unsigned int deciphered_len = 0;
3201 void *ret;
3202
3203 if (key && data_in)
3204 {
3205 if (eet_decipher(data_in, size_in, key, strlen(key), &deciphered, &deciphered_len))
3206 {
3207 if (deciphered) free(deciphered);
3208 return NULL;
3209 }
3210 ret = _eet_data_descriptor_decode(NULL, edd, deciphered, deciphered_len, 0,
3211 NULL, NULL);
3212 free(deciphered);
3213 return ret;
3214 }
3215 return _eet_data_descriptor_decode(NULL, edd, data_in, size_in, 0,
3216 NULL, NULL);
3217}
3218
3104EAPI void * 3219EAPI void *
3105eet_data_descriptor_decode(Eet_Data_Descriptor *edd, 3220eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
3106 const void *data_in, 3221 const void *data_in,
3107 int size_in) 3222 int size_in)
3108{ 3223{
3109 return _eet_data_descriptor_decode(NULL, edd, data_in, size_in, 0, 3224 return eet_data_descriptor_decode_cipher(edd, data_in, NULL, size_in);
3110 NULL, NULL);
3111} 3225}
3112 3226
3113static void * 3227static void *
@@ -3161,9 +3275,36 @@ _eet_data_descriptor_encode(Eet_Dictionary *ed,
3161} 3275}
3162 3276
3163EAPI void * 3277EAPI void *
3278eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
3279 const void *data_in,
3280 const char *key,
3281 int *size_ret)
3282{
3283 void *ret = NULL;
3284 void *ciphered = NULL;
3285 unsigned int ciphered_len = 0;
3286
3287 ret = _eet_data_descriptor_encode(NULL, edd, data_in, size_ret);
3288 if (key && ret)
3289 {
3290 if (eet_cipher(ret, *size_ret, key, strlen(key), &ciphered, &ciphered_len))
3291 {
3292 if (ciphered) free(ciphered);
3293 size_ret = 0;
3294 free(ret);
3295 return NULL;
3296 }
3297 free(ret);
3298 *size_ret = ciphered_len;
3299 ret = ciphered;
3300 }
3301 return ret;
3302}
3303
3304EAPI void *
3164eet_data_descriptor_encode(Eet_Data_Descriptor *edd, 3305eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
3165 const void *data_in, 3306 const void *data_in,
3166 int *size_ret) 3307 int *size_ret)
3167{ 3308{
3168 return _eet_data_descriptor_encode(NULL, edd, data_in, size_ret); 3309 return eet_data_descriptor_encode_cipher(edd, data_in, NULL, size_ret);
3169} 3310}
diff --git a/legacy/eet/src/lib/eet_image.c b/legacy/eet/src/lib/eet_image.c
index eb1f17120a..43b0a97f77 100644
--- a/legacy/eet/src/lib/eet_image.c
+++ b/legacy/eet/src/lib/eet_image.c
@@ -906,9 +906,9 @@ eet_data_image_jpeg_alpha_convert(int *size, const void *data, unsigned int w, u
906} 906}
907 907
908EAPI int 908EAPI int
909eet_data_image_write(Eet_File *ef, const char *name, 909eet_data_image_write_cipher(Eet_File *ef, const char *name, const char *key,
910 const void *data, unsigned int w, unsigned int h, int alpha, 910 const void *data, unsigned int w, unsigned int h, int alpha,
911 int compress, int quality, int lossy) 911 int compress, int quality, int lossy)
912{ 912{
913 void *d = NULL; 913 void *d = NULL;
914 int size = 0; 914 int size = 0;
@@ -918,32 +918,41 @@ eet_data_image_write(Eet_File *ef, const char *name,
918 { 918 {
919 int v; 919 int v;
920 920
921 v = eet_write(ef, name, d, size, 0); 921 v = eet_write_cipher(ef, name, d, size, 0, key);
922 free(d); 922 free(d);
923 return v; 923 return v;
924 } 924 }
925 return 0; 925 return 0;
926} 926}
927 927
928EAPI int
929eet_data_image_write(Eet_File *ef, const char *name,
930 const void *data, unsigned int w, unsigned int h, int alpha,
931 int compress, int quality, int lossy)
932{
933 return eet_data_image_write_cipher(ef, name, NULL, data, w, h, alpha, compress, quality, lossy);
934}
935
936
928EAPI void * 937EAPI void *
929eet_data_image_read(Eet_File *ef, const char *name, 938eet_data_image_read_cipher(Eet_File *ef, const char *name, const char *key,
930 unsigned int *w, unsigned int *h, int *alpha, 939 unsigned int *w, unsigned int *h, int *alpha,
931 int *compress, int *quality, int *lossy) 940 int *compress, int *quality, int *lossy)
932{ 941{
933 unsigned int *d = NULL; 942 unsigned int *d = NULL;
934 void *data; 943 void *data = NULL;
935 int size;
936 int free_data = 0; 944 int free_data = 0;
945 int size;
937 946
938 947 if (!key)
939 data = (void *)eet_read_direct(ef, name, &size); 948 data = (void *)eet_read_direct(ef, name, &size);
940 if (!data) 949 if (!data)
941 { 950 {
942 data = eet_read(ef, name, &size); 951 data = eet_read_cipher(ef, name, &size, key);
943 free_data = 1; 952 free_data = 1;
953 if (!data) return NULL;
944 } 954 }
945 955
946 if (!data) return NULL;
947 d = eet_data_image_decode(data, size, w, h, alpha, compress, quality, lossy); 956 d = eet_data_image_decode(data, size, w, h, alpha, compress, quality, lossy);
948 957
949 if (free_data) 958 if (free_data)
@@ -952,25 +961,33 @@ eet_data_image_read(Eet_File *ef, const char *name,
952 return d; 961 return d;
953} 962}
954 963
964EAPI void *
965eet_data_image_read(Eet_File *ef, const char *name,
966 unsigned int *w, unsigned int *h, int *alpha,
967 int *compress, int *quality, int *lossy)
968{
969 return eet_data_image_read_cipher(ef, name, NULL, w, h, alpha, compress, quality, lossy);
970}
971
955EAPI int 972EAPI int
956eet_data_image_read_to_surface(Eet_File *ef, const char *name, unsigned int src_x, unsigned int src_y, 973eet_data_image_read_to_surface_cipher(Eet_File *ef, const char *name, const char *key, unsigned int src_x, unsigned int src_y,
957 unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, 974 unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride,
958 int *alpha, int *compress, int *quality, int *lossy) 975 int *alpha, int *compress, int *quality, int *lossy)
959{ 976{
960 void *data; 977 void *data = NULL;
961 int size;
962 int free_data = 0; 978 int free_data = 0;
963 int res = 1; 979 int res = 1;
980 int size;
964 981
965 982 if (!key)
966 data = (void *)eet_read_direct(ef, name, &size); 983 data = (void *)eet_read_direct(ef, name, &size);
967 if (!data) 984 if (!data)
968 { 985 {
969 data = eet_read(ef, name, &size); 986 data = eet_read_cipher(ef, name, &size, key);
970 free_data = 1; 987 free_data = 1;
988 if (!data) return 0;
971 } 989 }
972 990
973 if (!data) return 0;
974 res = eet_data_image_decode_to_surface(data, size, src_x, src_y, d, w, h, row_stride, alpha, compress, quality, lossy); 991 res = eet_data_image_decode_to_surface(data, size, src_x, src_y, d, w, h, row_stride, alpha, compress, quality, lossy);
975 992
976 if (free_data) 993 if (free_data)
@@ -980,23 +997,32 @@ eet_data_image_read_to_surface(Eet_File *ef, const char *name, unsigned int src_
980} 997}
981 998
982EAPI int 999EAPI int
983eet_data_image_header_read(Eet_File *ef, const char *name, 1000eet_data_image_read_to_surface(Eet_File *ef, const char *name, unsigned int src_x, unsigned int src_y,
984 unsigned int *w, unsigned int *h, int *alpha, 1001 unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride,
985 int *compress, int *quality, int *lossy) 1002 int *alpha, int *compress, int *quality, int *lossy)
1003{
1004 return eet_data_image_read_to_surface_cipher(ef, name, NULL, src_x, src_y, d, w, h, row_stride, alpha, compress, quality, lossy);
1005}
1006
1007EAPI int
1008eet_data_image_header_read_cipher(Eet_File *ef, const char *name, const char *key,
1009 unsigned int *w, unsigned int *h, int *alpha,
1010 int *compress, int *quality, int *lossy)
986{ 1011{
987 void *data = NULL; 1012 void *data = NULL;
988 int size = 0; 1013 int size = 0;
989 int d;
990 int free_data = 0; 1014 int free_data = 0;
1015 int d;
991 1016
992 data = (void *)eet_read_direct(ef, name, &size); 1017 if (!key)
1018 data = (void *)eet_read_direct(ef, name, &size);
993 if (!data) 1019 if (!data)
994 { 1020 {
995 data = eet_read(ef, name, &size); 1021 data = eet_read_cipher(ef, name, &size, key);
996 free_data = 1; 1022 free_data = 1;
1023 if (!data) return 0;
997 } 1024 }
998 1025
999 if (!data) return 0;
1000 d = eet_data_image_header_decode(data, size, w, h, alpha, compress, quality, lossy); 1026 d = eet_data_image_header_decode(data, size, w, h, alpha, compress, quality, lossy);
1001 if (free_data) 1027 if (free_data)
1002 free(data); 1028 free(data);
@@ -1004,10 +1030,21 @@ eet_data_image_header_read(Eet_File *ef, const char *name,
1004 return d; 1030 return d;
1005} 1031}
1006 1032
1033EAPI int
1034eet_data_image_header_read(Eet_File *ef, const char *name,
1035 unsigned int *w, unsigned int *h, int *alpha,
1036 int *compress, int *quality, int *lossy)
1037{
1038 return eet_data_image_header_read_cipher(ef, name, NULL, w, h, alpha, compress, quality, lossy);
1039}
1040
1041
1007EAPI void * 1042EAPI void *
1008eet_data_image_encode(const void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy) 1043eet_data_image_encode_cipher(const void *data, const char *key, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy, int *size_ret)
1009{ 1044{
1010 void *d = NULL; 1045 void *d = NULL;
1046 void *ciphered_d = NULL;
1047 unsigned int ciphered_sz = 0;
1011 int size = 0; 1048 int size = 0;
1012 1049
1013 if (lossy == 0) 1050 if (lossy == 0)
@@ -1027,14 +1064,45 @@ eet_data_image_encode(const void *data, int *size_ret, unsigned int w, unsigned
1027 else 1064 else
1028 d = eet_data_image_jpeg_alpha_convert(&size, data, w, h, alpha, quality); 1065 d = eet_data_image_jpeg_alpha_convert(&size, data, w, h, alpha, quality);
1029 } 1066 }
1067 if (key)
1068 {
1069 if(!eet_cipher(d, size, key, strlen(key), &ciphered_d, &ciphered_sz))
1070 {
1071 if (d) free(d);
1072 d = ciphered_d;
1073 size = ciphered_sz;
1074 }
1075 else
1076 if (ciphered_d) free(ciphered_d);
1077 }
1078
1030 if (size_ret) *size_ret = size; 1079 if (size_ret) *size_ret = size;
1031 return d; 1080 return d;
1032} 1081}
1033 1082
1083EAPI void *
1084eet_data_image_encode(const void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy)
1085{
1086 return eet_data_image_encode_cipher(data, NULL, w, h, alpha, compress, quality, lossy, size_ret);
1087}
1088
1034EAPI int 1089EAPI int
1035eet_data_image_header_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy) 1090eet_data_image_header_decode_cipher(const void *data, const char *key, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
1036{ 1091{
1037 int header[8]; 1092 int header[8];
1093 void *deciphered_d = NULL;
1094 unsigned int deciphered_sz = 0;
1095
1096 if (key)
1097 {
1098 if (!eet_decipher(data, size, key, strlen(key), &deciphered_d, &deciphered_sz))
1099 {
1100 data = deciphered_d;
1101 size = deciphered_sz;
1102 }
1103 else
1104 if (deciphered_d) free(deciphered_d);
1105 }
1038 1106
1039 if (words_bigendian == -1) 1107 if (words_bigendian == -1)
1040 { 1108 {
@@ -1115,6 +1183,12 @@ eet_data_image_header_decode(const void *data, int size, unsigned int *w, unsign
1115 return 0; 1183 return 0;
1116} 1184}
1117 1185
1186EAPI int
1187eet_data_image_header_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
1188{
1189 return eet_data_image_header_decode_cipher(data, NULL, size, w, h, alpha, compress, quality, lossy);
1190}
1191
1118static void 1192static void
1119_eet_data_image_copy_buffer(const unsigned int *src, unsigned int src_x, unsigned int src_y, unsigned int src_w, 1193_eet_data_image_copy_buffer(const unsigned int *src, unsigned int src_x, unsigned int src_y, unsigned int src_w,
1120 unsigned int *dst, unsigned int w, unsigned int h, unsigned int row_stride) 1194 unsigned int *dst, unsigned int w, unsigned int h, unsigned int row_stride)
@@ -1229,11 +1303,24 @@ _eet_data_image_decode_inside(const void *data, int size, unsigned int src_x, un
1229} 1303}
1230 1304
1231EAPI void * 1305EAPI void *
1232eet_data_image_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy) 1306eet_data_image_decode_cipher(const void *data, const char *key, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
1233{ 1307{
1234 unsigned int *d = NULL; 1308 unsigned int *d = NULL;
1235 unsigned int iw, ih; 1309 unsigned int iw, ih;
1236 int ialpha, icompress, iquality, ilossy; 1310 int ialpha, icompress, iquality, ilossy;
1311 void *deciphered_d = NULL;
1312 unsigned int deciphered_sz = 0;
1313
1314 if (key)
1315 {
1316 if (!eet_decipher(data, size, key, strlen(key), &deciphered_d, &deciphered_sz))
1317 {
1318 data = deciphered_d;
1319 size = deciphered_sz;
1320 }
1321 else
1322 if (deciphered_d) free(deciphered_d);
1323 }
1237 1324
1238 /* All check are done during header decode, this simplify the code a lot. */ 1325 /* All check are done during header decode, this simplify the code a lot. */
1239 if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress, &iquality, &ilossy)) 1326 if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress, &iquality, &ilossy))
@@ -1258,13 +1345,32 @@ eet_data_image_decode(const void *data, int size, unsigned int *w, unsigned int
1258 return d; 1345 return d;
1259} 1346}
1260 1347
1348EAPI void *
1349eet_data_image_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
1350{
1351 return eet_data_image_decode_cipher(data, NULL, size, w, h, alpha, compress, quality, lossy);
1352}
1353
1261EAPI int 1354EAPI int
1262eet_data_image_decode_to_surface(const void *data, int size, unsigned int src_x, unsigned int src_y, 1355eet_data_image_decode_to_surface_cipher(const void *data, const char *key, int size, unsigned int src_x, unsigned int src_y,
1263 unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride, 1356 unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride,
1264 int *alpha, int *compress, int *quality, int *lossy) 1357 int *alpha, int *compress, int *quality, int *lossy)
1265{ 1358{
1266 unsigned int iw, ih; 1359 unsigned int iw, ih;
1267 int ialpha, icompress, iquality, ilossy; 1360 int ialpha, icompress, iquality, ilossy;
1361 void *deciphered_d = NULL;
1362 unsigned int deciphered_sz = 0;
1363
1364 if (key)
1365 {
1366 if (!eet_decipher(data, size, key, strlen(key), &deciphered_d, &deciphered_sz))
1367 {
1368 data = deciphered_d;
1369 size = deciphered_sz;
1370 }
1371 else
1372 if (deciphered_d) free(deciphered_d);
1373 }
1268 1374
1269 /* All check are done during header decode, this simplify the code a lot. */ 1375 /* All check are done during header decode, this simplify the code a lot. */
1270 if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress, &iquality, &ilossy)) 1376 if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress, &iquality, &ilossy))
@@ -1284,3 +1390,11 @@ eet_data_image_decode_to_surface(const void *data, int size, unsigned int src_x,
1284 1390
1285 return 1; 1391 return 1;
1286} 1392}
1393
1394EAPI int
1395eet_data_image_decode_to_surface(const void *data, int size, unsigned int src_x, unsigned int src_y,
1396 unsigned int *d, unsigned int w, unsigned int h, unsigned int row_stride,
1397 int *alpha, int *compress, int *quality, int *lossy)
1398{
1399 return eet_data_image_decode_to_surface_cipher(data, NULL, size, src_x, src_y, d, w, h, row_stride, alpha, compress, quality, lossy);
1400}
diff --git a/legacy/eet/src/lib/eet_lib.c b/legacy/eet/src/lib/eet_lib.c
index cb3c535859..bcdbf2e743 100644
--- a/legacy/eet/src/lib/eet_lib.c
+++ b/legacy/eet/src/lib/eet_lib.c
@@ -35,6 +35,10 @@ void *alloca (size_t);
35#include <unistd.h> 35#include <unistd.h>
36#include <zlib.h> 36#include <zlib.h>
37 37
38#ifdef HAVE_OPENSSL
39#include <openssl/err.h>
40#endif
41
38#ifdef HAVE_NETINET_IN_H 42#ifdef HAVE_NETINET_IN_H
39# include <netinet/in.h> 43# include <netinet/in.h>
40#endif 44#endif
@@ -47,6 +51,11 @@ void *alloca (size_t);
47# include <Evil.h> 51# include <Evil.h>
48#endif 52#endif
49 53
54#ifdef HAVE_GNUTLS
55# include <gnutls/gnutls.h>
56# include <gcrypt.h>
57#endif
58
50#ifdef HAVE_OPENSSL 59#ifdef HAVE_OPENSSL
51# include <openssl/err.h> 60# include <openssl/err.h>
52#endif 61#endif
@@ -120,6 +129,7 @@ struct _Eet_File_Node
120 129
121 unsigned char free_name : 1; 130 unsigned char free_name : 1;
122 unsigned char compression : 1; 131 unsigned char compression : 1;
132 unsigned char ciphered : 1;
123}; 133};
124 134
125#if 0 135#if 0
@@ -132,7 +142,7 @@ int bytes_directory_entries; /* bytes of directory entries to follow */
132struct 142struct
133{ 143{
134 int offset; /* bytes offset into file for data chunk */ 144 int offset; /* bytes offset into file for data chunk */
135 int flags; /* flags - for now 0 = uncompressed, 1 = compressed */ 145 int flags; /* flags - for now 0 = uncompressed and clear, 1 = compressed and clear, 2 = uncompressed and ciphered, 3 = compressed and ciphered */
136 int size; /* size of the data chunk */ 146 int size; /* size of the data chunk */
137 int data_size; /* size of the (uncompressed) data chunk */ 147 int data_size; /* size of the (uncompressed) data chunk */
138 int name_size; /* length in bytes of the name field */ 148 int name_size; /* length in bytes of the name field */
@@ -459,14 +469,17 @@ eet_flush2(Eet_File *ef)
459 { 469 {
460 for (efn = ef->header->directory->nodes[i]; efn; efn = efn->next) 470 for (efn = ef->header->directory->nodes[i]; efn; efn = efn->next)
461 { 471 {
462 int ibuf[EET_FILE2_DIRECTORY_ENTRY_COUNT]; 472 unsigned int flag;
473 int ibuf[EET_FILE2_DIRECTORY_ENTRY_COUNT];
474
475 flag = (efn->ciphered << 1) | efn->compression;
463 476
464 ibuf[0] = (int) htonl ((unsigned int) efn->offset); 477 ibuf[0] = (int) htonl ((unsigned int) efn->offset);
465 ibuf[1] = (int) htonl ((unsigned int) efn->size); 478 ibuf[1] = (int) htonl ((unsigned int) efn->size);
466 ibuf[2] = (int) htonl ((unsigned int) efn->data_size); 479 ibuf[2] = (int) htonl ((unsigned int) efn->data_size);
467 ibuf[3] = (int) htonl ((unsigned int) efn->name_offset); 480 ibuf[3] = (int) htonl ((unsigned int) efn->name_offset);
468 ibuf[4] = (int) htonl ((unsigned int) efn->name_size); 481 ibuf[4] = (int) htonl ((unsigned int) efn->name_size);
469 ibuf[5] = (int) htonl ((unsigned int) efn->compression); 482 ibuf[5] = (int) htonl ((unsigned int) flag);
470 483
471 if (fwrite(ibuf, sizeof(ibuf), 1, ef->fp) != 1) 484 if (fwrite(ibuf, sizeof(ibuf), 1, ef->fp) != 1)
472 goto write_error; 485 goto write_error;
@@ -700,6 +713,30 @@ eet_init(void)
700 713
701 if (eet_initcount > 1) return eet_initcount; 714 if (eet_initcount > 1) return eet_initcount;
702 715
716#ifdef HAVE_GNUTLS
717 if (gnutls_global_init())
718 return --eet_initcount;
719 /* Before the library can be used, it must initialize itself. */
720 gcry_check_version(NULL);
721 /* Disable warning messages about problems with the secure memory subsystem.
722 This command should be run right after gcry_check_version. */
723 if (gcry_control(GCRYCTL_DISABLE_SECMEM_WARN))
724 {
725 gnutls_global_deinit();
726 return --eet_initcount;
727 }
728 /* This command is used to allocate a pool of secure memory and thus
729 enabling the use of secure memory. It also drops all extra privileges the
730 process has (i.e. if it is run as setuid (root)). If the argument nbytes
731 is 0, secure memory will be disabled. The minimum amount of secure memory
732 allocated is currently 16384 bytes; you may thus use a value of 1 to
733 request that default size. */
734 if (gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0))
735 {
736 gnutls_global_deinit();
737 return --eet_initcount;
738 }
739#endif
703#ifdef HAVE_OPENSSL 740#ifdef HAVE_OPENSSL
704 ERR_load_crypto_strings(); 741 ERR_load_crypto_strings();
705#endif 742#endif
@@ -717,6 +754,9 @@ eet_shutdown(void)
717 if (eet_initcount > 0) return eet_initcount; 754 if (eet_initcount > 0) return eet_initcount;
718 755
719 eet_clearcache(); 756 eet_clearcache();
757#ifdef HAVE_GNUTLS
758 gnutls_global_deinit();
759#endif
720#ifdef HAVE_OPENSSL 760#ifdef HAVE_OPENSSL
721 ERR_free_strings(); 761 ERR_free_strings();
722#endif 762#endif
@@ -850,6 +890,7 @@ eet_internal_read2(Eet_File *ef)
850 int name_offset; 890 int name_offset;
851 int name_size; 891 int name_size;
852 int hash; 892 int hash;
893 int flag;
853 894
854 /* out directory block is inconsistent - we have oveerun our */ 895 /* out directory block is inconsistent - we have oveerun our */
855 /* dynamic block buffer before we finished scanning dir entries */ 896 /* dynamic block buffer before we finished scanning dir entries */
@@ -863,7 +904,10 @@ eet_internal_read2(Eet_File *ef)
863 GET_INT(efn->data_size, data, index); 904 GET_INT(efn->data_size, data, index);
864 GET_INT(name_offset, data, index); 905 GET_INT(name_offset, data, index);
865 GET_INT(name_size, data, index); 906 GET_INT(name_size, data, index);
866 GET_INT(efn->compression, data, index); 907 GET_INT(flag, data, index);
908
909 efn->compression = flag & 0x1 ? 1 : 0;
910 efn->ciphered = flag & 0x2 ? 1 : 0;
867 911
868#define EFN_TEST(Test, Ef, Efn) \ 912#define EFN_TEST(Test, Ef, Efn) \
869 if (eet_test_close(Test, Ef)) \ 913 if (eet_test_close(Test, Ef)) \
@@ -1089,6 +1133,7 @@ eet_internal_read1(Eet_File *ef)
1089 EXTRACT_INT(name_size, p, indexn); 1133 EXTRACT_INT(name_size, p, indexn);
1090 1134
1091 efn->name_size = name_size; 1135 efn->name_size = name_size;
1136 efn->ciphered = 0;
1092 1137
1093 /* invalid size */ 1138 /* invalid size */
1094 if (eet_test_close(efn->size <= 0, ef)) 1139 if (eet_test_close(efn->size <= 0, ef))
@@ -1486,7 +1531,7 @@ eet_close(Eet_File *ef)
1486} 1531}
1487 1532
1488EAPI void * 1533EAPI void *
1489eet_read(Eet_File *ef, const char *name, int *size_ret) 1534eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *cipher_key)
1490{ 1535{
1491 void *data = NULL; 1536 void *data = NULL;
1492 int size = 0; 1537 int size = 0;
@@ -1524,6 +1569,8 @@ eet_read(Eet_File *ef, const char *name, int *size_ret)
1524 /* uncompressed data */ 1569 /* uncompressed data */
1525 if (efn->compression == 0) 1570 if (efn->compression == 0)
1526 { 1571 {
1572 void *data_deciphered = NULL;
1573 unsigned int data_deciphered_sz = 0;
1527 /* if we alreayd have the data in ram... copy that */ 1574 /* if we alreayd have the data in ram... copy that */
1528 if (efn->data) 1575 if (efn->data)
1529 memcpy(data, efn->data, efn->size); 1576 memcpy(data, efn->data, efn->size);
@@ -1533,11 +1580,25 @@ eet_read(Eet_File *ef, const char *name, int *size_ret)
1533 free(data); 1580 free(data);
1534 return NULL; 1581 return NULL;
1535 } 1582 }
1583 if (efn->ciphered && cipher_key)
1584 {
1585 if (eet_decipher(data, size, cipher_key, strlen(cipher_key), &data_deciphered, &data_deciphered_sz))
1586 {
1587 free(data);
1588 if (data_deciphered) free(data_deciphered);
1589 return NULL;
1590 }
1591 free(data);
1592 data = data_deciphered;
1593 size = data_deciphered_sz;
1594 }
1536 } 1595 }
1537 /* compressed data */ 1596 /* compressed data */
1538 else 1597 else
1539 { 1598 {
1540 void *tmp_data; 1599 void *tmp_data;
1600 void *data_deciphered = NULL;
1601 unsigned int data_deciphered_sz = 0;
1541 int free_tmp = 0; 1602 int free_tmp = 0;
1542 int compr_size = efn->size; 1603 int compr_size = efn->size;
1543 uLongf dlen; 1604 uLongf dlen;
@@ -1564,6 +1625,20 @@ eet_read(Eet_File *ef, const char *name, int *size_ret)
1564 } 1625 }
1565 } 1626 }
1566 1627
1628 if (efn->ciphered && cipher_key)
1629 {
1630 if (eet_decipher(tmp_data, compr_size, cipher_key, strlen(cipher_key), &data_deciphered, &data_deciphered_sz))
1631 {
1632 free(data);
1633 if (free_tmp) free(tmp_data);
1634 if (data_deciphered) free(data_deciphered);
1635 return NULL;
1636 }
1637 free(tmp_data);
1638 tmp_data = data_deciphered;
1639 compr_size = data_deciphered_sz;
1640 }
1641
1567 /* decompress it */ 1642 /* decompress it */
1568 dlen = size; 1643 dlen = size;
1569 if (uncompress((Bytef *)data, &dlen, 1644 if (uncompress((Bytef *)data, &dlen,
@@ -1584,6 +1659,12 @@ eet_read(Eet_File *ef, const char *name, int *size_ret)
1584 return data; 1659 return data;
1585} 1660}
1586 1661
1662EAPI void *
1663eet_read(Eet_File *ef, const char *name, int *size_ret)
1664{
1665 return eet_read_cipher(ef, name, size_ret, NULL);
1666}
1667
1587EAPI const void * 1668EAPI const void *
1588eet_read_direct(Eet_File *ef, const char *name, int *size_ret) 1669eet_read_direct(Eet_File *ef, const char *name, int *size_ret)
1589{ 1670{
@@ -1619,7 +1700,8 @@ eet_read_direct(Eet_File *ef, const char *name, int *size_ret)
1619 size = efn->data_size; 1700 size = efn->data_size;
1620 1701
1621 /* uncompressed data */ 1702 /* uncompressed data */
1622 if (efn->compression == 0) 1703 if (efn->compression == 0
1704 && efn->ciphered == 0)
1623 data = efn->data ? efn->data : ef->data + efn->offset; 1705 data = efn->data ? efn->data : ef->data + efn->offset;
1624 /* compressed data */ 1706 /* compressed data */
1625 else 1707 else
@@ -1633,10 +1715,10 @@ eet_read_direct(Eet_File *ef, const char *name, int *size_ret)
1633} 1715}
1634 1716
1635EAPI int 1717EAPI int
1636eet_write(Eet_File *ef, const char *name, const void *data, int size, int compress) 1718eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int compress, const char *cipher_key)
1637{ 1719{
1638 Eet_File_Node *efn; 1720 Eet_File_Node *efn;
1639 void *data2; 1721 void *data2 = NULL;
1640 int exists_already = 0; 1722 int exists_already = 0;
1641 int data_size; 1723 int data_size;
1642 int hash; 1724 int hash;
@@ -1676,9 +1758,12 @@ eet_write(Eet_File *ef, const char *name, const void *data, int size, int compre
1676 1758
1677 data_size = compress ? 12 + ((size * 101) / 100) : size; 1759 data_size = compress ? 12 + ((size * 101) / 100) : size;
1678 1760
1679 data2 = malloc(data_size); 1761 if (compress || !cipher_key)
1680 if (!data2) 1762 {
1681 return 0; 1763 data2 = malloc(data_size);
1764 if (!data2)
1765 return 0;
1766 }
1682 1767
1683 /* if we want to compress */ 1768 /* if we want to compress */
1684 if (compress) 1769 if (compress)
@@ -1709,8 +1794,30 @@ eet_write(Eet_File *ef, const char *name, const void *data, int size, int compre
1709 data2 = data3; 1794 data2 = data3;
1710 } 1795 }
1711 } 1796 }
1712 if (!compress) 1797
1713 memcpy(data2, data, size); 1798 if (cipher_key)
1799 {
1800 void *data_ciphered = NULL;
1801 unsigned int data_ciphered_sz = 0;
1802 const void *tmp;
1803
1804 tmp = data2 ? data2 : data;
1805 if (!eet_cipher(tmp, data_size, cipher_key, strlen(cipher_key), &data_ciphered, &data_ciphered_sz))
1806 {
1807 if (data2) free(data2);
1808 data2 = data_ciphered;
1809 data_size = data_ciphered_sz;
1810 size = (data_size > size) ? data_size : size;
1811 }
1812 else
1813 {
1814 if (data_ciphered) free(data_ciphered);
1815 cipher_key = NULL;
1816 }
1817 }
1818 else
1819 if (!compress)
1820 memcpy(data2, data, size);
1714 1821
1715 /* Does this node already exist? */ 1822 /* Does this node already exist? */
1716 for (efn = ef->header->directory->nodes[hash]; efn; efn = efn->next) 1823 for (efn = ef->header->directory->nodes[hash]; efn; efn = efn->next)
@@ -1719,6 +1826,7 @@ eet_write(Eet_File *ef, const char *name, const void *data, int size, int compre
1719 if ((efn->name) && (eet_string_match(efn->name, name))) 1826 if ((efn->name) && (eet_string_match(efn->name, name)))
1720 { 1827 {
1721 free(efn->data); 1828 free(efn->data);
1829 efn->ciphered = cipher_key ? 1 : 0;
1722 efn->compression = !!compress; 1830 efn->compression = !!compress;
1723 efn->size = data_size; 1831 efn->size = data_size;
1724 efn->data_size = size; 1832 efn->data_size = size;
@@ -1743,6 +1851,7 @@ eet_write(Eet_File *ef, const char *name, const void *data, int size, int compre
1743 efn->next = ef->header->directory->nodes[hash]; 1851 efn->next = ef->header->directory->nodes[hash];
1744 ef->header->directory->nodes[hash] = efn; 1852 ef->header->directory->nodes[hash] = efn;
1745 efn->offset = -1; 1853 efn->offset = -1;
1854 efn->ciphered = cipher_key ? 1 : 0;
1746 efn->compression = !!compress; 1855 efn->compression = !!compress;
1747 efn->size = data_size; 1856 efn->size = data_size;
1748 efn->data_size = size; 1857 efn->data_size = size;
@@ -1755,6 +1864,12 @@ eet_write(Eet_File *ef, const char *name, const void *data, int size, int compre
1755} 1864}
1756 1865
1757EAPI int 1866EAPI int
1867eet_write(Eet_File *ef, const char *name, const void *data, int size, int compress)
1868{
1869 return eet_write_cipher(ef, name, data, size, compress, NULL);
1870}
1871
1872EAPI int
1758eet_delete(Eet_File *ef, const char *name) 1873eet_delete(Eet_File *ef, const char *name)
1759{ 1874{
1760 Eet_File_Node *efn; 1875 Eet_File_Node *efn;
diff --git a/legacy/eet/src/tests/eet_suite.c b/legacy/eet/src/tests/eet_suite.c
index 9a75103ff0..26ddd9e04e 100644
--- a/legacy/eet/src/tests/eet_suite.c
+++ b/legacy/eet/src/tests/eet_suite.c
@@ -1275,6 +1275,60 @@ START_TEST(eet_identity_simple)
1275} 1275}
1276END_TEST 1276END_TEST
1277 1277
1278START_TEST(eet_cipher_decipher_simple)
1279{
1280 const char *buffer = "Here is a string of data to save !";
1281 const char *key = "This is a crypto key";
1282 const char *key_bad = "This is another crypto key";
1283 Eet_File *ef;
1284 char *test;
1285 char *file = strdup("/tmp/eet_suite_testXXXXXX");
1286 int size;
1287 int fd;
1288
1289 eet_init();
1290
1291 mktemp(file);
1292 chdir("src/tests");
1293
1294 /* Crypt an eet file. */
1295 ef = eet_open(file, EET_FILE_MODE_WRITE);
1296 fail_if(!ef);
1297
1298 fail_if(!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key));
1299
1300 eet_close(ef);
1301
1302 /* Decrypt an eet file. */
1303 ef = eet_open(file, EET_FILE_MODE_READ);
1304 fail_if(!ef);
1305
1306 test = eet_read_cipher(ef, "keys/tests", &size, key);
1307 fail_if(!test);
1308 fail_if(size != (int) strlen(buffer) + 1);
1309
1310 fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
1311
1312 eet_close(ef);
1313
1314 /* Decrypt an eet file. */
1315 ef = eet_open(file, EET_FILE_MODE_READ);
1316 fail_if(!ef);
1317
1318 test = eet_read_cipher(ef, "keys/tests", &size, key_bad);
1319
1320 if (size == (int) strlen(buffer) + 1)
1321 fail_if(memcmp(test, buffer, strlen(buffer) + 1) == 0);
1322
1323 eet_close(ef);
1324
1325 fail_if(unlink(file) != 0);
1326
1327 eet_shutdown();
1328}
1329END_TEST
1330
1331
1278Suite * 1332Suite *
1279eet_suite(void) 1333eet_suite(void)
1280{ 1334{
@@ -1310,6 +1364,12 @@ eet_suite(void)
1310 suite_add_tcase(s, tc); 1364 suite_add_tcase(s, tc);
1311#endif 1365#endif
1312 1366
1367#ifdef HAVE_CIPHER
1368 tc = tcase_create("Eet Cipher");
1369 tcase_add_test(tc, eet_cipher_decipher_simple);
1370 suite_add_tcase(s, tc);
1371#endif
1372
1313 return s; 1373 return s;
1314} 1374}
1315 1375