@@ -237,27 +237,28 @@ + (void)downloadPackage:(NSDictionary *)updatePackage
237237 }
238238
239239 CPLog ((isDiffUpdate) ? @" Applying diff update." : @" Applying full update." );
240-
240+
241+ if (![CodePushUpdateUtils verifyFolderHash: newUpdateFolderPath
242+ expectedHash: newUpdateHash
243+ error: &error]) {
244+ CPLog (@" The update contents failed the data integrity check." );
245+ if (!error) {
246+ error = [CodePushErrorUtils errorWithMessage: @" The update contents failed the data integrity check." ];
247+ }
248+
249+ failCallback (error);
250+ return ;
251+ } else {
252+ CPLog (@" The update contents succeeded the data integrity check." );
253+ }
254+
241255 BOOL isSignatureVerificationEnabled = (publicKey != nil );
242-
256+
243257 NSString *signatureFilePath = [CodePushUpdateUtils getSignatureFilePath: newUpdateFolderPath];
244258 BOOL isSignatureAppearedInBundle = [[NSFileManager defaultManager ] fileExistsAtPath: signatureFilePath];
245-
259+
246260 if (isSignatureVerificationEnabled) {
247261 if (isSignatureAppearedInBundle) {
248- if (![CodePushUpdateUtils verifyFolderHash: newUpdateFolderPath
249- expectedHash: newUpdateHash
250- error: &error]) {
251- CPLog (@" The update contents failed the data integrity check." );
252- if (!error) {
253- error = [CodePushErrorUtils errorWithMessage: @" The update contents failed the data integrity check." ];
254- }
255-
256- failCallback (error);
257- return ;
258- } else {
259- CPLog (@" The update contents succeeded the data integrity check." );
260- }
261262 BOOL isSignatureValid = [CodePushUpdateUtils verifyUpdateSignatureFor: newUpdateFolderPath
262263 expectedHash: newUpdateHash
263264 withPublicKey: publicKey
@@ -283,29 +284,10 @@ + (void)downloadPackage:(NSDictionary *)updatePackage
283284 }
284285
285286 } else {
286- BOOL needToVerifyHash;
287287 if (isSignatureAppearedInBundle) {
288288 CPLog (@" Warning! JWT signature exists in codepush update but code integrity check couldn't be performed" \
289289 " because there is no public key configured. " \
290290 " Please ensure that public key is properly configured within your application." );
291- needToVerifyHash = true ;
292- } else {
293- needToVerifyHash = isDiffUpdate;
294- }
295- if (needToVerifyHash){
296- if (![CodePushUpdateUtils verifyFolderHash: newUpdateFolderPath
297- expectedHash: newUpdateHash
298- error: &error]) {
299- CPLog (@" The update contents failed the data integrity check." );
300- if (!error) {
301- error = [CodePushErrorUtils errorWithMessage: @" The update contents failed the data integrity check." ];
302- }
303-
304- failCallback (error);
305- return ;
306- } else {
307- CPLog (@" The update contents succeeded the data integrity check." );
308- }
309291 }
310292 }
311293 } else {
0 commit comments