@@ -243,69 +243,50 @@ + (void)downloadPackage:(NSDictionary *)updatePackage
243243 NSString *signatureFilePath = [CodePushUpdateUtils getSignatureFilePath: newUpdateFolderPath];
244244 BOOL isSignatureAppearedInBundle = [[NSFileManager defaultManager ] fileExistsAtPath: signatureFilePath];
245245
246+ if (isSignatureVerificationEnabled && !isSignatureAppearedInBundle) {
247+ error = [CodePushErrorUtils errorWithMessage:
248+ @" Error! Public key was provided but there is no JWT signature within app bundle to verify " \
249+ " Possible reasons, why that might happen: \n " \
250+ " 1. You've been released CodePush bundle update using version of CodePush CLI that is not support code signing.\n " \
251+ " 2. You've been released CodePush bundle update without providing --privateKeyPath option." ];
252+ failCallback (error);
253+ return ;
254+ }
255+
256+ if (!isSignatureVerificationEnabled && isSignatureAppearedInBundle) {
257+ CPLog (@" Warning! JWT signature exists in codepush update but code integrity check couldn't be performed" \
258+ " because there is no public key configured. " \
259+ " Please ensure that public key is properly configured within your application." );
260+ }
261+
262+ if (![CodePushUpdateUtils verifyFolderHash: newUpdateFolderPath
263+ expectedHash: newUpdateHash
264+ error: &error]) {
265+ CPLog (@" The update contents failed the data integrity check." );
266+ if (!error) {
267+ error = [CodePushErrorUtils errorWithMessage: @" The update contents failed the data integrity check." ];
268+ }
269+
270+ failCallback (error);
271+ return ;
272+ } else {
273+ CPLog (@" The update contents succeeded the data integrity check." );
274+ }
275+
246276 if (isSignatureVerificationEnabled) {
247- 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." );
277+ BOOL isSignatureValid = [CodePushUpdateUtils verifyUpdateSignatureFor: newUpdateFolderPath
278+ expectedHash: newUpdateHash
279+ withPublicKey: publicKey
280+ error: &error];
281+ if (!isSignatureValid) {
282+ CPLog (@" The update contents failed code signing check." );
283+ if (!error) {
284+ error = [CodePushErrorUtils errorWithMessage: @" The update contents failed code signing check." ];
260285 }
261- BOOL isSignatureValid = [CodePushUpdateUtils verifyUpdateSignatureFor: newUpdateFolderPath
262- expectedHash: newUpdateHash
263- withPublicKey: publicKey
264- error: &error];
265- if (!isSignatureValid) {
266- CPLog (@" The update contents failed code signing check." );
267- if (!error) {
268- error = [CodePushErrorUtils errorWithMessage: @" The update contents failed code signing check." ];
269- }
270- failCallback (error);
271- return ;
272- } else {
273- CPLog (@" The update contents succeeded the code signing check." );
274- }
275- } else {
276- error = [CodePushErrorUtils errorWithMessage:
277- @" Error! Public key was provided but there is no JWT signature within app bundle to verify " \
278- " Possible reasons, why that might happen: \n " \
279- " 1. You've been released CodePush bundle update using version of CodePush CLI that is not support code signing.\n " \
280- " 2. You've been released CodePush bundle update without providing --privateKeyPath option." ];
281286 failCallback (error);
282287 return ;
283- }
284-
285- } else {
286- BOOL needToVerifyHash;
287- if (isSignatureAppearedInBundle) {
288- CPLog (@" Warning! JWT signature exists in codepush update but code integrity check couldn't be performed" \
289- " because there is no public key configured. " \
290- " Please ensure that public key is properly configured within your application." );
291- needToVerifyHash = true ;
292288 } 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- }
289+ CPLog (@" The update contents succeeded the code signing check." );
309290 }
310291 }
311292 } else {
0 commit comments