@capgo/capacitor-updater 6.14.12 → 6.14.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ import java.io.FileInputStream;
16
16
  import java.net.HttpURLConnection;
17
17
  import java.net.URL;
18
18
  import java.nio.channels.FileChannel;
19
+ import java.nio.file.Files;
19
20
  import java.security.MessageDigest;
20
21
  import java.util.ArrayList;
21
22
  import java.util.Arrays;
@@ -35,7 +36,6 @@ import okhttp3.ResponseBody;
35
36
  import org.brotli.dec.BrotliInputStream;
36
37
  import org.json.JSONArray;
37
38
  import org.json.JSONObject;
38
- import java.nio.file.Files;
39
39
 
40
40
  public class DownloadService extends Worker {
41
41
 
@@ -163,25 +163,38 @@ public class DownloadService extends Worker {
163
163
  String fileHash = entry.getString("file_hash");
164
164
  String downloadUrl = entry.getString("download_url");
165
165
 
166
+ if (!publicKey.isEmpty() && sessionKey != null && !sessionKey.isEmpty()) {
167
+ try {
168
+ fileHash = CryptoCipherV2.decryptChecksum(fileHash, publicKey);
169
+ } catch (Exception e) {
170
+ Log.e(TAG, "Error decrypting checksum for " + fileName, e);
171
+ hasError.set(true);
172
+ continue;
173
+ }
174
+ }
175
+
176
+ final String finalFileHash = fileHash;
166
177
  File targetFile = new File(destFolder, fileName);
167
- File cacheFile = new File(cacheFolder, fileHash + "_" + new File(fileName).getName());
178
+ File cacheFile = new File(cacheFolder, finalFileHash + "_" + new File(fileName).getName());
168
179
  File builtinFile = new File(builtinFolder, fileName);
169
180
 
170
181
  // Ensure parent directories of the target file exist
171
182
  if (!Objects.requireNonNull(targetFile.getParentFile()).exists() && !targetFile.getParentFile().mkdirs()) {
172
- throw new IOException("Failed to create parent directory for: " + targetFile.getAbsolutePath());
183
+ Log.e(TAG, "Failed to create parent directory for: " + targetFile.getAbsolutePath());
184
+ hasError.set(true);
185
+ continue;
173
186
  }
174
187
 
175
188
  Future<?> future = executor.submit(() -> {
176
189
  try {
177
- if (builtinFile.exists() && verifyChecksum(builtinFile, fileHash)) {
190
+ if (builtinFile.exists() && verifyChecksum(builtinFile, finalFileHash)) {
178
191
  copyFile(builtinFile, targetFile);
179
192
  Log.d(TAG, "using builtin file " + fileName);
180
- } else if (cacheFile.exists() && verifyChecksum(cacheFile, fileHash)) {
193
+ } else if (cacheFile.exists() && verifyChecksum(cacheFile, finalFileHash)) {
181
194
  copyFile(cacheFile, targetFile);
182
195
  Log.d(TAG, "already cached " + fileName);
183
196
  } else {
184
- downloadAndVerify(downloadUrl, targetFile, cacheFile, fileHash, sessionKey, publicKey);
197
+ downloadAndVerify(downloadUrl, targetFile, cacheFile, finalFileHash, sessionKey, publicKey);
185
198
  }
186
199
 
187
200
  long completed = completedFiles.incrementAndGet();
@@ -479,7 +492,7 @@ public class DownloadService extends Worker {
479
492
  }
480
493
 
481
494
  // Handle brotli.compress minimal wrapper (quality 0)
482
- if (data[0] == 0x0b && data[1] == 0x02 && data[2] == (byte)0x80 && data[data.length - 1] == 0x03) {
495
+ if (data[0] == 0x0b && data[1] == 0x02 && data[2] == (byte) 0x80 && data[data.length - 1] == 0x03) {
483
496
  return Arrays.copyOfRange(data, 3, data.length - 1);
484
497
  }
485
498
  } catch (ArrayIndexOutOfBoundsException e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "6.14.12",
3
+ "version": "6.14.13",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",