@capgo/capacitor-updater 7.2.19 → 7.2.21
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.
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +22 -8
- package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +2 -2
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +185 -188
- package/android/src/main/java/ee/forgr/capacitor_updater/{CapacitorUpdater.java → CapgoUpdater.java} +50 -49
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipherV2.java +7 -7
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +21 -24
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +1 -1
- package/ios/Plugin/AES.swift +2 -2
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +93 -93
- package/ios/Plugin/{CapacitorUpdater.swift → CapgoUpdater.swift} +67 -67
- package/ios/Plugin/CryptoCipherV2.swift +25 -25
- package/ios/Plugin/DelayUpdateUtils.swift +23 -23
- package/package.json +1 -1
package/android/src/main/java/ee/forgr/capacitor_updater/{CapacitorUpdater.java → CapgoUpdater.java}
RENAMED
|
@@ -16,8 +16,6 @@ import androidx.lifecycle.LifecycleOwner;
|
|
|
16
16
|
import androidx.work.Data;
|
|
17
17
|
import androidx.work.WorkInfo;
|
|
18
18
|
import androidx.work.WorkManager;
|
|
19
|
-
import com.getcapacitor.JSObject;
|
|
20
|
-
import com.getcapacitor.plugin.WebView;
|
|
21
19
|
import com.google.common.util.concurrent.Futures;
|
|
22
20
|
import com.google.common.util.concurrent.ListenableFuture;
|
|
23
21
|
import java.io.BufferedInputStream;
|
|
@@ -30,8 +28,10 @@ import java.io.IOException;
|
|
|
30
28
|
import java.security.SecureRandom;
|
|
31
29
|
import java.util.ArrayList;
|
|
32
30
|
import java.util.Date;
|
|
31
|
+
import java.util.HashMap;
|
|
33
32
|
import java.util.Iterator;
|
|
34
33
|
import java.util.List;
|
|
34
|
+
import java.util.Map;
|
|
35
35
|
import java.util.Objects;
|
|
36
36
|
import java.util.zip.ZipEntry;
|
|
37
37
|
import java.util.zip.ZipInputStream;
|
|
@@ -40,7 +40,7 @@ import org.json.JSONArray;
|
|
|
40
40
|
import org.json.JSONException;
|
|
41
41
|
import org.json.JSONObject;
|
|
42
42
|
|
|
43
|
-
public class
|
|
43
|
+
public class CapgoUpdater {
|
|
44
44
|
|
|
45
45
|
private static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
46
46
|
private static final SecureRandom rnd = new SecureRandom();
|
|
@@ -64,6 +64,7 @@ public class CapacitorUpdater {
|
|
|
64
64
|
public String versionBuild = "";
|
|
65
65
|
public String versionCode = "";
|
|
66
66
|
public String versionOs = "";
|
|
67
|
+
public String CAP_SERVER_PATH = "";
|
|
67
68
|
|
|
68
69
|
public String customId = "";
|
|
69
70
|
public String statsUrl = "";
|
|
@@ -117,7 +118,7 @@ public class CapacitorUpdater {
|
|
|
117
118
|
|
|
118
119
|
void directUpdateFinish(final BundleInfo latest) {}
|
|
119
120
|
|
|
120
|
-
void notifyListeners(final String id, final
|
|
121
|
+
void notifyListeners(final String id, final Map<String, Object> res) {}
|
|
121
122
|
|
|
122
123
|
private String randomString() {
|
|
123
124
|
final StringBuilder sb = new StringBuilder(10);
|
|
@@ -240,7 +241,7 @@ public class CapacitorUpdater {
|
|
|
240
241
|
id,
|
|
241
242
|
new BundleInfo(id, version, BundleStatus.ERROR, new Date(System.currentTimeMillis()), "")
|
|
242
243
|
);
|
|
243
|
-
|
|
244
|
+
Map<String, Object> ret = new HashMap<>();
|
|
244
245
|
ret.put("version", getCurrentBundle().getVersionName());
|
|
245
246
|
ret.put("error", "finish_download_fail");
|
|
246
247
|
sendStats("finish_download_fail", version);
|
|
@@ -256,7 +257,7 @@ public class CapacitorUpdater {
|
|
|
256
257
|
id,
|
|
257
258
|
new BundleInfo(id, failedVersion, BundleStatus.ERROR, new Date(System.currentTimeMillis()), "")
|
|
258
259
|
);
|
|
259
|
-
|
|
260
|
+
Map<String, Object> ret = new HashMap<>();
|
|
260
261
|
ret.put("version", getCurrentBundle().getVersionName());
|
|
261
262
|
if ("low_mem_fail".equals(error)) {
|
|
262
263
|
sendStats("low_mem_fail", failedVersion);
|
|
@@ -325,7 +326,7 @@ public class CapacitorUpdater {
|
|
|
325
326
|
|
|
326
327
|
// If public key is present but no checksum provided, refuse installation
|
|
327
328
|
if (!this.publicKey.isEmpty() && checksumDecrypted.isEmpty()) {
|
|
328
|
-
Log.e(
|
|
329
|
+
Log.e(CapgoUpdater.TAG, "Public key present but no checksum provided");
|
|
329
330
|
this.sendStats("checksum_required");
|
|
330
331
|
throw new IOException("Checksum required when public key is present: " + id);
|
|
331
332
|
}
|
|
@@ -338,7 +339,7 @@ public class CapacitorUpdater {
|
|
|
338
339
|
checksum = CryptoCipherV2.calcChecksum(downloaded);
|
|
339
340
|
}
|
|
340
341
|
if ((!checksumDecrypted.isEmpty() || !this.publicKey.isEmpty()) && !checksumDecrypted.equals(checksum)) {
|
|
341
|
-
Log.e(
|
|
342
|
+
Log.e(CapgoUpdater.TAG, "Error checksum '" + checksumDecrypted + "' '" + checksum + "' '");
|
|
342
343
|
this.sendStats("checksum_fail");
|
|
343
344
|
throw new IOException("Checksum failed: " + id);
|
|
344
345
|
}
|
|
@@ -347,14 +348,14 @@ public class CapacitorUpdater {
|
|
|
347
348
|
} catch (Exception e) {
|
|
348
349
|
final Boolean res = this.delete(id);
|
|
349
350
|
if (!res) {
|
|
350
|
-
Log.i(
|
|
351
|
+
Log.i(CapgoUpdater.TAG, "Double error, cannot cleanup: " + version);
|
|
351
352
|
}
|
|
352
353
|
|
|
353
|
-
final
|
|
354
|
-
ret.put("version",
|
|
354
|
+
final Map<String, Object> ret = new HashMap<>();
|
|
355
|
+
ret.put("version", CapgoUpdater.this.getCurrentBundle().getVersionName());
|
|
355
356
|
|
|
356
|
-
|
|
357
|
-
|
|
357
|
+
CapgoUpdater.this.notifyListeners("downloadFailed", ret);
|
|
358
|
+
CapgoUpdater.this.sendStats("download_fail");
|
|
358
359
|
return false;
|
|
359
360
|
}
|
|
360
361
|
|
|
@@ -375,12 +376,12 @@ public class CapacitorUpdater {
|
|
|
375
376
|
BundleInfo next = new BundleInfo(id, version, BundleStatus.PENDING, new Date(System.currentTimeMillis()), checksum);
|
|
376
377
|
this.saveBundleInfo(id, next);
|
|
377
378
|
|
|
378
|
-
final
|
|
379
|
-
ret.put("bundle", next.
|
|
380
|
-
|
|
379
|
+
final Map<String, Object> ret = new HashMap<>();
|
|
380
|
+
ret.put("bundle", next.toJSONMap());
|
|
381
|
+
CapgoUpdater.this.notifyListeners("updateAvailable", ret);
|
|
381
382
|
if (setNext) {
|
|
382
383
|
if (this.directUpdate) {
|
|
383
|
-
|
|
384
|
+
CapgoUpdater.this.directUpdateFinish(next);
|
|
384
385
|
this.directUpdate = false;
|
|
385
386
|
} else {
|
|
386
387
|
this.setNextBundle(next.getId());
|
|
@@ -388,10 +389,10 @@ public class CapacitorUpdater {
|
|
|
388
389
|
}
|
|
389
390
|
} catch (IOException e) {
|
|
390
391
|
e.printStackTrace();
|
|
391
|
-
final
|
|
392
|
-
ret.put("version",
|
|
393
|
-
|
|
394
|
-
|
|
392
|
+
final Map<String, Object> ret = new HashMap<>();
|
|
393
|
+
ret.put("version", CapgoUpdater.this.getCurrentBundle().getVersionName());
|
|
394
|
+
CapgoUpdater.this.notifyListeners("downloadFailed", ret);
|
|
395
|
+
CapgoUpdater.this.sendStats("download_fail");
|
|
395
396
|
return false;
|
|
396
397
|
}
|
|
397
398
|
return true;
|
|
@@ -412,7 +413,7 @@ public class CapacitorUpdater {
|
|
|
412
413
|
}
|
|
413
414
|
|
|
414
415
|
private void setCurrentBundle(final File bundle) {
|
|
415
|
-
this.editor.putString(
|
|
416
|
+
this.editor.putString(this.CAP_SERVER_PATH, bundle.getPath());
|
|
416
417
|
Log.i(TAG, "Current bundle set to: " + bundle);
|
|
417
418
|
this.editor.commit();
|
|
418
419
|
}
|
|
@@ -545,7 +546,7 @@ public class CapacitorUpdater {
|
|
|
545
546
|
return this.delete(id, true);
|
|
546
547
|
} catch (IOException e) {
|
|
547
548
|
e.printStackTrace();
|
|
548
|
-
Log.i(
|
|
549
|
+
Log.i(CapgoUpdater.TAG, "Failed to delete bundle (" + id + ")" + "\nError:\n" + e.toString());
|
|
549
550
|
return false;
|
|
550
551
|
}
|
|
551
552
|
}
|
|
@@ -599,12 +600,12 @@ public class CapacitorUpdater {
|
|
|
599
600
|
public void setSuccess(final BundleInfo bundle, Boolean autoDeletePrevious) {
|
|
600
601
|
this.setBundleStatus(bundle.getId(), BundleStatus.SUCCESS);
|
|
601
602
|
final BundleInfo fallback = this.getFallbackBundle();
|
|
602
|
-
Log.d(
|
|
603
|
-
Log.i(
|
|
603
|
+
Log.d(CapgoUpdater.TAG, "Fallback bundle is: " + fallback);
|
|
604
|
+
Log.i(CapgoUpdater.TAG, "Version successfully loaded: " + bundle.getVersionName());
|
|
604
605
|
if (autoDeletePrevious && !fallback.isBuiltin()) {
|
|
605
606
|
final Boolean res = this.delete(fallback.getId());
|
|
606
607
|
if (res) {
|
|
607
|
-
Log.i(
|
|
608
|
+
Log.i(CapgoUpdater.TAG, "Deleted previous bundle: " + fallback.getVersionName());
|
|
608
609
|
}
|
|
609
610
|
}
|
|
610
611
|
this.setFallbackBundle(bundle);
|
|
@@ -615,7 +616,7 @@ public class CapacitorUpdater {
|
|
|
615
616
|
}
|
|
616
617
|
|
|
617
618
|
public void reset(final boolean internal) {
|
|
618
|
-
Log.d(
|
|
619
|
+
Log.d(CapgoUpdater.TAG, "reset: " + internal);
|
|
619
620
|
var currentBundleName = this.getCurrentBundle().getVersionName();
|
|
620
621
|
this.setCurrentBundle(new File("public"));
|
|
621
622
|
this.setFallbackBundle(null);
|
|
@@ -658,7 +659,7 @@ public class CapacitorUpdater {
|
|
|
658
659
|
new okhttp3.Callback() {
|
|
659
660
|
@Override
|
|
660
661
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
661
|
-
|
|
662
|
+
Map<String, Object> retError = new HashMap<>();
|
|
662
663
|
retError.put("message", "Request failed: " + e.getMessage());
|
|
663
664
|
retError.put("error", "network_error");
|
|
664
665
|
callback.callback(retError);
|
|
@@ -668,7 +669,7 @@ public class CapacitorUpdater {
|
|
|
668
669
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
669
670
|
try (ResponseBody responseBody = response.body()) {
|
|
670
671
|
if (!response.isSuccessful()) {
|
|
671
|
-
|
|
672
|
+
Map<String, Object> retError = new HashMap<>();
|
|
672
673
|
retError.put("message", "Server error: " + response.code());
|
|
673
674
|
retError.put("error", "response_error");
|
|
674
675
|
callback.callback(retError);
|
|
@@ -678,7 +679,7 @@ public class CapacitorUpdater {
|
|
|
678
679
|
assert responseBody != null;
|
|
679
680
|
String responseData = responseBody.string();
|
|
680
681
|
JSONObject jsonResponse = new JSONObject(responseData);
|
|
681
|
-
|
|
682
|
+
Map<String, Object> ret = new HashMap<>();
|
|
682
683
|
|
|
683
684
|
Iterator<String> keys = jsonResponse.keys();
|
|
684
685
|
while (keys.hasNext()) {
|
|
@@ -693,7 +694,7 @@ public class CapacitorUpdater {
|
|
|
693
694
|
}
|
|
694
695
|
callback.callback(ret);
|
|
695
696
|
} catch (JSONException e) {
|
|
696
|
-
|
|
697
|
+
Map<String, Object> retError = new HashMap<>();
|
|
697
698
|
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
698
699
|
retError.put("error", "parse_error");
|
|
699
700
|
callback.callback(retError);
|
|
@@ -712,14 +713,14 @@ public class CapacitorUpdater {
|
|
|
712
713
|
}
|
|
713
714
|
} catch (JSONException e) {
|
|
714
715
|
Log.e(TAG, "Error getLatest JSONException", e);
|
|
715
|
-
final
|
|
716
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
716
717
|
retError.put("message", "Cannot get info: " + e);
|
|
717
718
|
retError.put("error", "json_error");
|
|
718
719
|
callback.callback(retError);
|
|
719
720
|
return;
|
|
720
721
|
}
|
|
721
722
|
|
|
722
|
-
Log.i(
|
|
723
|
+
Log.i(CapgoUpdater.TAG, "Auto-update parameters: " + json);
|
|
723
724
|
|
|
724
725
|
makeJsonRequest(updateUrl, json, callback);
|
|
725
726
|
}
|
|
@@ -728,7 +729,7 @@ public class CapacitorUpdater {
|
|
|
728
729
|
String channelUrl = this.channelUrl;
|
|
729
730
|
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
730
731
|
Log.e(TAG, "Channel URL is not set");
|
|
731
|
-
final
|
|
732
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
732
733
|
retError.put("message", "channelUrl missing");
|
|
733
734
|
retError.put("error", "missing_config");
|
|
734
735
|
callback.callback(retError);
|
|
@@ -739,7 +740,7 @@ public class CapacitorUpdater {
|
|
|
739
740
|
json = this.createInfoObject();
|
|
740
741
|
} catch (JSONException e) {
|
|
741
742
|
Log.e(TAG, "Error unsetChannel JSONException", e);
|
|
742
|
-
final
|
|
743
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
743
744
|
retError.put("message", "Cannot get info: " + e);
|
|
744
745
|
retError.put("error", "json_error");
|
|
745
746
|
callback.callback(retError);
|
|
@@ -757,7 +758,7 @@ public class CapacitorUpdater {
|
|
|
757
758
|
new okhttp3.Callback() {
|
|
758
759
|
@Override
|
|
759
760
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
760
|
-
|
|
761
|
+
Map<String, Object> retError = new HashMap<>();
|
|
761
762
|
retError.put("message", "Request failed: " + e.getMessage());
|
|
762
763
|
retError.put("error", "network_error");
|
|
763
764
|
callback.callback(retError);
|
|
@@ -767,7 +768,7 @@ public class CapacitorUpdater {
|
|
|
767
768
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
768
769
|
try (ResponseBody responseBody = response.body()) {
|
|
769
770
|
if (!response.isSuccessful()) {
|
|
770
|
-
|
|
771
|
+
Map<String, Object> retError = new HashMap<>();
|
|
771
772
|
retError.put("message", "Server error: " + response.code());
|
|
772
773
|
retError.put("error", "response_error");
|
|
773
774
|
callback.callback(retError);
|
|
@@ -777,7 +778,7 @@ public class CapacitorUpdater {
|
|
|
777
778
|
assert responseBody != null;
|
|
778
779
|
String responseData = responseBody.string();
|
|
779
780
|
JSONObject jsonResponse = new JSONObject(responseData);
|
|
780
|
-
|
|
781
|
+
Map<String, Object> ret = new HashMap<>();
|
|
781
782
|
|
|
782
783
|
Iterator<String> keys = jsonResponse.keys();
|
|
783
784
|
while (keys.hasNext()) {
|
|
@@ -789,7 +790,7 @@ public class CapacitorUpdater {
|
|
|
789
790
|
Log.i(TAG, "Channel unset");
|
|
790
791
|
callback.callback(ret);
|
|
791
792
|
} catch (JSONException e) {
|
|
792
|
-
|
|
793
|
+
Map<String, Object> retError = new HashMap<>();
|
|
793
794
|
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
794
795
|
retError.put("error", "parse_error");
|
|
795
796
|
callback.callback(retError);
|
|
@@ -803,7 +804,7 @@ public class CapacitorUpdater {
|
|
|
803
804
|
String channelUrl = this.channelUrl;
|
|
804
805
|
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
805
806
|
Log.e(TAG, "Channel URL is not set");
|
|
806
|
-
final
|
|
807
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
807
808
|
retError.put("message", "channelUrl missing");
|
|
808
809
|
retError.put("error", "missing_config");
|
|
809
810
|
callback.callback(retError);
|
|
@@ -815,7 +816,7 @@ public class CapacitorUpdater {
|
|
|
815
816
|
json.put("channel", channel);
|
|
816
817
|
} catch (JSONException e) {
|
|
817
818
|
Log.e(TAG, "Error setChannel JSONException", e);
|
|
818
|
-
final
|
|
819
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
819
820
|
retError.put("message", "Cannot get info: " + e);
|
|
820
821
|
retError.put("error", "json_error");
|
|
821
822
|
callback.callback(retError);
|
|
@@ -829,7 +830,7 @@ public class CapacitorUpdater {
|
|
|
829
830
|
String channelUrl = this.channelUrl;
|
|
830
831
|
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
831
832
|
Log.e(TAG, "Channel URL is not set");
|
|
832
|
-
final
|
|
833
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
833
834
|
retError.put("message", "Channel URL is not set");
|
|
834
835
|
retError.put("error", "missing_config");
|
|
835
836
|
callback.callback(retError);
|
|
@@ -840,7 +841,7 @@ public class CapacitorUpdater {
|
|
|
840
841
|
json = this.createInfoObject();
|
|
841
842
|
} catch (JSONException e) {
|
|
842
843
|
Log.e(TAG, "Error getChannel JSONException", e);
|
|
843
|
-
final
|
|
844
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
844
845
|
retError.put("message", "Cannot get info: " + e);
|
|
845
846
|
retError.put("error", "json_error");
|
|
846
847
|
callback.callback(retError);
|
|
@@ -858,7 +859,7 @@ public class CapacitorUpdater {
|
|
|
858
859
|
new okhttp3.Callback() {
|
|
859
860
|
@Override
|
|
860
861
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
861
|
-
|
|
862
|
+
Map<String, Object> retError = new HashMap<>();
|
|
862
863
|
retError.put("message", "Request failed: " + e.getMessage());
|
|
863
864
|
retError.put("error", "network_error");
|
|
864
865
|
callback.callback(retError);
|
|
@@ -871,7 +872,7 @@ public class CapacitorUpdater {
|
|
|
871
872
|
assert responseBody != null;
|
|
872
873
|
String data = responseBody.string();
|
|
873
874
|
if (data.contains("channel_not_found") && !defaultChannel.isEmpty()) {
|
|
874
|
-
|
|
875
|
+
Map<String, Object> ret = new HashMap<>();
|
|
875
876
|
ret.put("channel", defaultChannel);
|
|
876
877
|
ret.put("status", "default");
|
|
877
878
|
Log.i(TAG, "Channel get to \"" + ret);
|
|
@@ -881,7 +882,7 @@ public class CapacitorUpdater {
|
|
|
881
882
|
}
|
|
882
883
|
|
|
883
884
|
if (!response.isSuccessful()) {
|
|
884
|
-
|
|
885
|
+
Map<String, Object> retError = new HashMap<>();
|
|
885
886
|
retError.put("message", "Server error: " + response.code());
|
|
886
887
|
retError.put("error", "response_error");
|
|
887
888
|
callback.callback(retError);
|
|
@@ -891,7 +892,7 @@ public class CapacitorUpdater {
|
|
|
891
892
|
assert responseBody != null;
|
|
892
893
|
String responseData = responseBody.string();
|
|
893
894
|
JSONObject jsonResponse = new JSONObject(responseData);
|
|
894
|
-
|
|
895
|
+
Map<String, Object> ret = new HashMap<>();
|
|
895
896
|
|
|
896
897
|
Iterator<String> keys = jsonResponse.keys();
|
|
897
898
|
while (keys.hasNext()) {
|
|
@@ -903,7 +904,7 @@ public class CapacitorUpdater {
|
|
|
903
904
|
Log.i(TAG, "Channel get to \"" + ret);
|
|
904
905
|
callback.callback(ret);
|
|
905
906
|
} catch (JSONException e) {
|
|
906
|
-
|
|
907
|
+
Map<String, Object> retError = new HashMap<>();
|
|
907
908
|
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
908
909
|
retError.put("error", "parse_error");
|
|
909
910
|
callback.callback(retError);
|
|
@@ -1039,7 +1040,7 @@ public class CapacitorUpdater {
|
|
|
1039
1040
|
}
|
|
1040
1041
|
|
|
1041
1042
|
public String getCurrentBundlePath() {
|
|
1042
|
-
String path = this.prefs.getString(
|
|
1043
|
+
String path = this.prefs.getString(this.CAP_SERVER_PATH, "public");
|
|
1043
1044
|
if (path.trim().isEmpty()) {
|
|
1044
1045
|
return "public";
|
|
1045
1046
|
}
|
|
@@ -135,11 +135,11 @@ public class CryptoCipherV2 {
|
|
|
135
135
|
|
|
136
136
|
public static void decryptFile(final File file, final String publicKey, final String ivSessionKey) throws IOException {
|
|
137
137
|
if (publicKey.isEmpty() || ivSessionKey == null || ivSessionKey.isEmpty() || ivSessionKey.split(":").length != 2) {
|
|
138
|
-
Log.i(
|
|
138
|
+
Log.i(CapgoUpdater.TAG, "Encryption not set, no public key or seesion, ignored");
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
141
|
if (!publicKey.startsWith("-----BEGIN RSA PUBLIC KEY-----")) {
|
|
142
|
-
Log.e(
|
|
142
|
+
Log.e(CapgoUpdater.TAG, "The public key is not a valid RSA Public key");
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -168,7 +168,7 @@ public class CryptoCipherV2 {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
} catch (GeneralSecurityException e) {
|
|
171
|
-
Log.i(
|
|
171
|
+
Log.i(CapgoUpdater.TAG, "decryptFile fail");
|
|
172
172
|
e.printStackTrace();
|
|
173
173
|
throw new IOException("GeneralSecurityException");
|
|
174
174
|
}
|
|
@@ -176,7 +176,7 @@ public class CryptoCipherV2 {
|
|
|
176
176
|
|
|
177
177
|
public static String decryptChecksum(String checksum, String publicKey) throws IOException {
|
|
178
178
|
if (publicKey.isEmpty()) {
|
|
179
|
-
Log.e(
|
|
179
|
+
Log.e(CapgoUpdater.TAG, "No encryption set (public key) ignored");
|
|
180
180
|
return checksum;
|
|
181
181
|
}
|
|
182
182
|
try {
|
|
@@ -187,7 +187,7 @@ public class CryptoCipherV2 {
|
|
|
187
187
|
String result = Base64.encodeToString(decryptedChecksum, Base64.DEFAULT);
|
|
188
188
|
return result.replaceAll("\\s", ""); // Remove all whitespace, including newlines
|
|
189
189
|
} catch (GeneralSecurityException e) {
|
|
190
|
-
Log.e(
|
|
190
|
+
Log.e(CapgoUpdater.TAG, "decryptChecksum fail: " + e.getMessage());
|
|
191
191
|
throw new IOException("Decryption failed: " + e.getMessage());
|
|
192
192
|
}
|
|
193
193
|
}
|
|
@@ -198,7 +198,7 @@ public class CryptoCipherV2 {
|
|
|
198
198
|
try {
|
|
199
199
|
digest = MessageDigest.getInstance("SHA-256");
|
|
200
200
|
} catch (java.security.NoSuchAlgorithmException e) {
|
|
201
|
-
System.err.println(
|
|
201
|
+
System.err.println(CapgoUpdater.TAG + " SHA-256 algorithm not available");
|
|
202
202
|
return "";
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -217,7 +217,7 @@ public class CryptoCipherV2 {
|
|
|
217
217
|
}
|
|
218
218
|
return hexString.toString();
|
|
219
219
|
} catch (IOException e) {
|
|
220
|
-
System.err.println(
|
|
220
|
+
System.err.println(CapgoUpdater.TAG + " Cannot calc checksum v2: " + file.getPath() + " " + e.getMessage());
|
|
221
221
|
return "";
|
|
222
222
|
}
|
|
223
223
|
}
|
|
@@ -55,7 +55,7 @@ public class DelayUpdateUtils {
|
|
|
55
55
|
longValue = Long.parseLong(value);
|
|
56
56
|
} catch (NumberFormatException e) {
|
|
57
57
|
Log.e(
|
|
58
|
-
|
|
58
|
+
CapgoUpdater.TAG,
|
|
59
59
|
"Background condition (value: " +
|
|
60
60
|
value +
|
|
61
61
|
") had an invalid value at index " +
|
|
@@ -66,7 +66,7 @@ public class DelayUpdateUtils {
|
|
|
66
66
|
|
|
67
67
|
if (delta > longValue) {
|
|
68
68
|
Log.i(
|
|
69
|
-
|
|
69
|
+
CapgoUpdater.TAG,
|
|
70
70
|
"Background condition (value: " +
|
|
71
71
|
value +
|
|
72
72
|
") deleted at index " +
|
|
@@ -80,7 +80,7 @@ public class DelayUpdateUtils {
|
|
|
80
80
|
} else {
|
|
81
81
|
delayConditionListToKeep.add(condition);
|
|
82
82
|
Log.i(
|
|
83
|
-
|
|
83
|
+
CapgoUpdater.TAG,
|
|
84
84
|
"Background delay (value: " +
|
|
85
85
|
value +
|
|
86
86
|
") condition kept at index " +
|
|
@@ -97,7 +97,7 @@ public class DelayUpdateUtils {
|
|
|
97
97
|
} else {
|
|
98
98
|
delayConditionListToKeep.add(condition);
|
|
99
99
|
Log.i(
|
|
100
|
-
|
|
100
|
+
CapgoUpdater.TAG,
|
|
101
101
|
"Kill delay (value: " + value + ") condition kept at index " + index + " (source: " + source.toString() + ")"
|
|
102
102
|
);
|
|
103
103
|
}
|
|
@@ -110,25 +110,22 @@ public class DelayUpdateUtils {
|
|
|
110
110
|
assert date != null;
|
|
111
111
|
if (new Date().compareTo(date) > 0) {
|
|
112
112
|
Log.i(
|
|
113
|
-
|
|
113
|
+
CapgoUpdater.TAG,
|
|
114
114
|
"Date delay (value: " + value + ") condition removed due to expired date at index " + index
|
|
115
115
|
);
|
|
116
116
|
} else {
|
|
117
117
|
delayConditionListToKeep.add(condition);
|
|
118
|
-
Log.i(
|
|
118
|
+
Log.i(CapgoUpdater.TAG, "Date delay (value: " + value + ") condition kept at index " + index);
|
|
119
119
|
}
|
|
120
120
|
} catch (final Exception e) {
|
|
121
121
|
Log.e(
|
|
122
|
-
|
|
122
|
+
CapgoUpdater.TAG,
|
|
123
123
|
"Date delay (value: " + value + ") condition removed due to parsing issue at index " + index,
|
|
124
124
|
e
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
} else {
|
|
128
|
-
Log.d(
|
|
129
|
-
CapacitorUpdater.TAG,
|
|
130
|
-
"Date delay (value: " + value + ") condition removed due to empty value at index " + index
|
|
131
|
-
);
|
|
128
|
+
Log.d(CapgoUpdater.TAG, "Date delay (value: " + value + ") condition removed due to empty value at index " + index);
|
|
132
129
|
}
|
|
133
130
|
break;
|
|
134
131
|
case DelayUntilNext.nativeVersion:
|
|
@@ -137,23 +134,23 @@ public class DelayUpdateUtils {
|
|
|
137
134
|
final Version versionLimit = new Version(value);
|
|
138
135
|
if (this.currentVersionNative.isAtLeast(versionLimit)) {
|
|
139
136
|
Log.i(
|
|
140
|
-
|
|
137
|
+
CapgoUpdater.TAG,
|
|
141
138
|
"Native version delay (value: " + value + ") condition removed due to above limit at index " + index
|
|
142
139
|
);
|
|
143
140
|
} else {
|
|
144
141
|
delayConditionListToKeep.add(condition);
|
|
145
|
-
Log.i(
|
|
142
|
+
Log.i(CapgoUpdater.TAG, "Native version delay (value: " + value + ") condition kept at index " + index);
|
|
146
143
|
}
|
|
147
144
|
} catch (final Exception e) {
|
|
148
145
|
Log.e(
|
|
149
|
-
|
|
146
|
+
CapgoUpdater.TAG,
|
|
150
147
|
"Native version delay (value: " + value + ") condition removed due to parsing issue at index " + index,
|
|
151
148
|
e
|
|
152
149
|
);
|
|
153
150
|
}
|
|
154
151
|
} else {
|
|
155
152
|
Log.d(
|
|
156
|
-
|
|
153
|
+
CapgoUpdater.TAG,
|
|
157
154
|
"Native version delay (value: " + value + ") condition removed due to empty value at index " + index
|
|
158
155
|
);
|
|
159
156
|
}
|
|
@@ -171,10 +168,10 @@ public class DelayUpdateUtils {
|
|
|
171
168
|
try {
|
|
172
169
|
this.editor.putString(DELAY_CONDITION_PREFERENCES, delayConditions);
|
|
173
170
|
this.editor.commit();
|
|
174
|
-
Log.i(
|
|
171
|
+
Log.i(CapgoUpdater.TAG, "Delay update saved");
|
|
175
172
|
return true;
|
|
176
173
|
} catch (final Exception e) {
|
|
177
|
-
Log.e(
|
|
174
|
+
Log.e(CapgoUpdater.TAG, "Failed to delay update, [Error calling '_setMultiDelay()']", e);
|
|
178
175
|
return false;
|
|
179
176
|
}
|
|
180
177
|
}
|
|
@@ -183,9 +180,9 @@ public class DelayUpdateUtils {
|
|
|
183
180
|
try {
|
|
184
181
|
this.editor.putLong(BACKGROUND_TIMESTAMP_KEY, backgroundTimestamp);
|
|
185
182
|
this.editor.commit();
|
|
186
|
-
Log.i(
|
|
183
|
+
Log.i(CapgoUpdater.TAG, "Delay update saved");
|
|
187
184
|
} catch (final Exception e) {
|
|
188
|
-
Log.e(
|
|
185
|
+
Log.e(CapgoUpdater.TAG, "Failed to delay update, [Error calling '_setBackgroundTimestamp()']", e);
|
|
189
186
|
}
|
|
190
187
|
}
|
|
191
188
|
|
|
@@ -193,9 +190,9 @@ public class DelayUpdateUtils {
|
|
|
193
190
|
try {
|
|
194
191
|
this.editor.remove(BACKGROUND_TIMESTAMP_KEY);
|
|
195
192
|
this.editor.commit();
|
|
196
|
-
Log.i(
|
|
193
|
+
Log.i(CapgoUpdater.TAG, "Delay update saved");
|
|
197
194
|
} catch (final Exception e) {
|
|
198
|
-
Log.e(
|
|
195
|
+
Log.e(CapgoUpdater.TAG, "Failed to delay update, [Error calling '_unsetBackgroundTimestamp()']", e);
|
|
199
196
|
}
|
|
200
197
|
}
|
|
201
198
|
|
|
@@ -203,7 +200,7 @@ public class DelayUpdateUtils {
|
|
|
203
200
|
try {
|
|
204
201
|
return this.prefs.getLong(BACKGROUND_TIMESTAMP_KEY, 0);
|
|
205
202
|
} catch (final Exception e) {
|
|
206
|
-
Log.e(
|
|
203
|
+
Log.e(CapgoUpdater.TAG, "Failed to delay update, [Error calling '_getBackgroundTimestamp()']", e);
|
|
207
204
|
return 0;
|
|
208
205
|
}
|
|
209
206
|
}
|
|
@@ -212,10 +209,10 @@ public class DelayUpdateUtils {
|
|
|
212
209
|
try {
|
|
213
210
|
this.editor.remove(DELAY_CONDITION_PREFERENCES);
|
|
214
211
|
this.editor.commit();
|
|
215
|
-
Log.i(
|
|
212
|
+
Log.i(CapgoUpdater.TAG, "All delays canceled from " + source);
|
|
216
213
|
return true;
|
|
217
214
|
} catch (final Exception e) {
|
|
218
|
-
Log.e(
|
|
215
|
+
Log.e(CapgoUpdater.TAG, "Failed to cancel update delay", e);
|
|
219
216
|
return false;
|
|
220
217
|
}
|
|
221
218
|
}
|
|
@@ -409,7 +409,7 @@ public class DownloadService extends Worker {
|
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
if (!publicKey.isEmpty() && sessionKey != null && !sessionKey.isEmpty()) {
|
|
412
|
-
Log.d(
|
|
412
|
+
Log.d(CapgoUpdater.TAG + " DLSrv", "Decrypting file " + targetFile.getName());
|
|
413
413
|
CryptoCipherV2.decryptFile(compressedFile, publicKey, sessionKey);
|
|
414
414
|
}
|
|
415
415
|
|
package/ios/Plugin/AES.swift
CHANGED
|
@@ -56,11 +56,11 @@ public struct AES128Key {
|
|
|
56
56
|
result.length = Int(decryptedLength)
|
|
57
57
|
return result as Data
|
|
58
58
|
} else {
|
|
59
|
-
print("\(
|
|
59
|
+
print("\(CapgoUpdater.TAG) AES decryption failed with status: \(status)")
|
|
60
60
|
return nil
|
|
61
61
|
}
|
|
62
62
|
} else {
|
|
63
|
-
print("\(
|
|
63
|
+
print("\(CapgoUpdater.TAG) Failed to allocate memory for AES decryption")
|
|
64
64
|
return nil
|
|
65
65
|
}
|
|
66
66
|
}
|