Skip to content

Commit

Permalink
perf(live-update): verify checksum only if signature is not verified
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed Jul 14, 2024
1 parent a4b1a06 commit a1c55d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,6 @@ public void error(Exception exception) {
@Override
public void success(@NonNull File result) {
try {
// Verify the checksum
if (expectedChecksum != null) {
// Calculate the checksum
String receivedChecksum = getChecksumForFileAsString(result);
if (!expectedChecksum.equals(receivedChecksum)) {
throw new Exception(LiveUpdatePlugin.ERROR_CHECKSUM_MISMATCH);
}
}
// Verify the signature
String publicKey = config.getPublicKey();
if (publicKey != null) {
Expand All @@ -408,6 +400,14 @@ public void success(@NonNull File result) {
throw new Exception(LiveUpdatePlugin.ERROR_SIGNATURE_VERIFICATION_FAILED);
}
}
// Verify the checksum
else if (expectedChecksum != null) {
// Calculate the checksum
String receivedChecksum = getChecksumForFileAsString(result);
if (!expectedChecksum.equals(receivedChecksum)) {
throw new Exception(LiveUpdatePlugin.ERROR_CHECKSUM_MISMATCH);
}
}

// Add the bundle
addBundle(bundleId, result);
Expand Down
28 changes: 14 additions & 14 deletions packages/live-update/ios/Plugin/LiveUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,6 @@ import CommonCrypto
return
}
if let url = url {
// Verify the checksum
if let expectedChecksum = checksum {
// Calculate the checksum
do {
let receivedChecksum = try self.getChecksumForFile(url: url)
if receivedChecksum != expectedChecksum {
completion(CustomError.checksumMismatch)
return
}
} catch {
completion(CustomError.checksumCalculationFailed)
return
}
}
// Verify the signature
if let publicKey = self.config.publicKey {
guard let signature = signature else {
Expand All @@ -331,6 +317,20 @@ import CommonCrypto
return
}
}
// Verify the checksum
else if let expectedChecksum = checksum {
// Calculate the checksum
do {
let receivedChecksum = try self.getChecksumForFile(url: url)
if receivedChecksum != expectedChecksum {
completion(CustomError.checksumMismatch)
return
}
} catch {
completion(CustomError.checksumCalculationFailed)
return
}
}

// Add the bundle
self.addBundle(bundleId: bundleId, zipFile: url, completion: { error in
Expand Down

0 comments on commit a1c55d8

Please sign in to comment.