From 8b1af4cf80eff619d3465925dce7fe572fc09224 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 14 Sep 2011 18:55:59 +0200 Subject: Add OpenSSL support --- tools/Makefile.am | 4 +-- tools/idevicebackup.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++- tools/idevicebackup2.c | 1 - 3 files changed, 78 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/Makefile.am b/tools/Makefile.am index f23b0b1..19b2f92 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,7 +1,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(LFS_CFLAGS) -AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) +AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(openssl_CFLAGS) $(LFS_CFLAGS) +AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(openssl_LIBS) bin_PROGRAMS = idevice_id ideviceinfo idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index 867eaad..f744e70 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c @@ -20,13 +20,21 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include #include #include #include +#ifdef HAVE_OPENSSL +#include +#else #include +#endif #include #include @@ -66,7 +74,11 @@ enum device_link_file_status_t { static void sha1_of_data(const char *input, uint32_t size, unsigned char *hash_out) { +#ifdef HAVE_OPENSSL + SHA1((const unsigned char*)input, size, hash_out); +#else gcry_md_hash_buffer(GCRY_MD_SHA1, hash_out, input, size); +#endif } static int compare_hash(const unsigned char *hash1, const unsigned char *hash2, int hash_len) @@ -82,6 +94,10 @@ static int compare_hash(const unsigned char *hash1, const unsigned char *hash2, static void compute_datahash(const char *path, const char *destpath, uint8_t greylist, const char *domain, const char *appid, const char *version, unsigned char *hash_out) { +#ifdef HAVE_OPENSSL + SHA_CTX sha1; + SHA1_Init(&sha1); +#else gcry_md_hd_t hd = NULL; gcry_md_open(&hd, GCRY_MD_SHA1, 0); if (!hd) { @@ -89,44 +105,103 @@ static void compute_datahash(const char *path, const char *destpath, uint8_t gre return; } gcry_md_reset(hd); - +#endif FILE *f = fopen(path, "rb"); if (f) { unsigned char buf[16384]; size_t len; while ((len = fread(buf, 1, 16384, f)) > 0) { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, buf, len); +#else gcry_md_write(hd, buf, len); +#endif } fclose(f); +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, destpath, strlen(destpath)); + SHA1_Update(&sha1, ";", 1); +#else gcry_md_write(hd, destpath, strlen(destpath)); gcry_md_write(hd, ";", 1); +#endif if (greylist == 1) { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, "true", 4); +#else gcry_md_write(hd, "true", 4); +#endif } else { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, "false", 5); +#else gcry_md_write(hd, "false", 5); +#endif } +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, ";", 1); +#else gcry_md_write(hd, ";", 1); +#endif if (domain) { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, domain, strlen(domain)); +#else gcry_md_write(hd, domain, strlen(domain)); +#endif } else { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, "(null)", 6); +#else gcry_md_write(hd, "(null)", 6); +#endif } +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, ";", 1); +#else gcry_md_write(hd, ";", 1); +#endif if (appid) { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, appid, strlen(appid)); +#else gcry_md_write(hd, appid, strlen(appid)); +#endif } else { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, "(null)", 6); +#else gcry_md_write(hd, "(null)", 6); +#endif } +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, ";", 1); +#else gcry_md_write(hd, ";", 1); +#endif if (version) { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, version, strlen(version)); +#else gcry_md_write(hd, version, strlen(version)); +#endif } else { +#ifdef HAVE_OPENSSL + SHA1_Update(&sha1, "(null)", 6); +#else gcry_md_write(hd, "(null)", 6); +#endif } +#ifdef HAVE_OPENSSL + SHA1_Final(hash_out, &sha1); +#else unsigned char *newhash = gcry_md_read(hd, GCRY_MD_SHA1); memcpy(hash_out, newhash, 20); +#endif } +#ifndef HAVE_OPENSSL gcry_md_close(hd); +#endif } static void print_hash(const unsigned char *hash, int len) diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index 30ec272..5d067bf 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #if !GLIB_CHECK_VERSION(2,25,0) -- cgit v1.1-32-gdbae