From 7496ed36073b2734cc54f0437dddb0a311953264 Mon Sep 17 00:00:00 2001 From: tihmstar Date: Tue, 25 Apr 2017 17:19:27 +0200 Subject: [PATCH] checking SEP to match sepmanifest --- futurerestore/futurerestore.cpp | 27 ++++++++++++++++++++++++--- futurerestore/futurerestore.hpp | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/futurerestore/futurerestore.cpp b/futurerestore/futurerestore.cpp index 1e5d5448..6725f237 100644 --- a/futurerestore/futurerestore.cpp +++ b/futurerestore/futurerestore.cpp @@ -56,6 +56,14 @@ extern "C"{ #define SEP_TMP_PATH FUTURERESTORE_TMP_PATH"/sep.im4p" #define SEP_MANIFEST_TMP_PATH FUTURERESTORE_TMP_PATH"/sepManifest.plist" +#ifdef __APPLE__ +# include +# define SHA1(d, n, md) CC_SHA1(d, n, md) +# define SHA384(d, n, md) CC_SHA384(d, n, md) +#else +# include +#endif // __APPLE__ + #define reterror(code,msg ...) error(msg),throw int(code) #define safeFree(buf) if (buf) free(buf), buf = NULL @@ -524,11 +532,24 @@ int futurerestore::doRestore(const char *ipsw){ plist_t sep_manifest = plist_dict_get_item(sep_build_identity, "Manifest"); plist_t sep_sep = plist_copy(plist_dict_get_item(sep_manifest, "SEP")); plist_dict_set_item(manifest, "SEP", sep_sep); + //check SEP + unsigned char genHash[48]; //SHA384 digest length + ptr_smartsephash = NULL; + uint64_t sephashlen = 0; + plist_t digest = plist_dict_get_item(sep_sep, "Digest"); + if (!digest || plist_get_node_type(digest) != PLIST_DATA) + reterror(-66, "ERROR: can't find sep digest\n"); + + plist_get_data_val(digest, &sephash, &sephashlen); + + if (sephashlen == 20) + SHA1(_client->sepfwdata, (unsigned int)_client->sepfwdatasize, genHash); + else + SHA384(_client->sepfwdata, (unsigned int)_client->sepfwdatasize, genHash); + if (memcmp(genHash, static_cast(sephash), sephashlen)) + reterror(-67, "ERROR: SEP does not match sepmanifest\n"); } - - - /* print information about current build identity */ build_identity_print_information(build_identity); diff --git a/futurerestore/futurerestore.hpp b/futurerestore/futurerestore.hpp index d74bf1d9..c70676dd 100644 --- a/futurerestore/futurerestore.hpp +++ b/futurerestore/futurerestore.hpp @@ -29,6 +29,7 @@ public: ptr_smart(){_p = NULL;} T operator=(T p){return _p = p;} T *operator&(){return &_p;} + explicit operator const char*() const {return _p;} ~ptr_smart(){if (_p) (_ptr_free) ? _ptr_free(_p) : free((void*)_p);} };