@capgo/capacitor-updater 4.13.2 → 4.13.4
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/CapacitorUpdater.java +181 -126
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +17 -7
- package/ios/Plugin/CapacitorUpdater.swift +34 -10
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +15 -9
- package/ios/Plugin/CryptoCipher.swift +33 -36
- package/package.json +1 -1
|
@@ -38,10 +38,6 @@ import org.json.JSONException;
|
|
|
38
38
|
import org.json.JSONObject;
|
|
39
39
|
|
|
40
40
|
interface Callback {
|
|
41
|
-
void callback(JSONObject jsonObject);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface CallbackChannel {
|
|
45
41
|
void callback(JSObject jsoObject);
|
|
46
42
|
}
|
|
47
43
|
|
|
@@ -58,7 +54,7 @@ public class CapacitorUpdater {
|
|
|
58
54
|
private static final String bundleDirectory = "versions";
|
|
59
55
|
|
|
60
56
|
public static final String TAG = "Capacitor-updater";
|
|
61
|
-
public static final String pluginVersion = "4.13.
|
|
57
|
+
public static final String pluginVersion = "4.13.4";
|
|
62
58
|
|
|
63
59
|
public SharedPreferences.Editor editor;
|
|
64
60
|
public SharedPreferences prefs;
|
|
@@ -508,130 +504,188 @@ public class CapacitorUpdater {
|
|
|
508
504
|
}
|
|
509
505
|
|
|
510
506
|
public void getLatest(final String updateUrl, final Callback callback) {
|
|
507
|
+
JSONObject json = null;
|
|
511
508
|
try {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
Log.
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
509
|
+
json = this.createInfoObject();
|
|
510
|
+
} catch (JSONException e) {
|
|
511
|
+
Log.e(TAG, "Error getLatest JSONException", e);
|
|
512
|
+
e.printStackTrace();
|
|
513
|
+
final JSObject retError = new JSObject();
|
|
514
|
+
retError.put("message", "Cannot get info: " + e.toString());
|
|
515
|
+
retError.put("error", "json_error");
|
|
516
|
+
callback.callback(retError);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
Log.i(CapacitorUpdater.TAG, "Auto-update parameters: " + json);
|
|
521
|
+
// Building a request
|
|
522
|
+
JsonObjectRequest request = new JsonObjectRequest(
|
|
523
|
+
Request.Method.POST,
|
|
524
|
+
updateUrl,
|
|
525
|
+
json,
|
|
526
|
+
new Response.Listener<JSONObject>() {
|
|
527
|
+
@Override
|
|
528
|
+
public void onResponse(JSONObject res) {
|
|
529
|
+
final JSObject ret = new JSObject();
|
|
530
|
+
Iterator<String> keys = res.keys();
|
|
531
|
+
while (keys.hasNext()) {
|
|
532
|
+
String key = keys.next();
|
|
533
|
+
if (res.has(key)) {
|
|
534
|
+
try {
|
|
535
|
+
ret.put(key, res.get(key));
|
|
536
|
+
} catch (JSONException e) {
|
|
537
|
+
e.printStackTrace();
|
|
538
|
+
final JSObject retError = new JSObject();
|
|
539
|
+
retError.put("message", "Cannot set info: " + e.toString());
|
|
540
|
+
retError.put("error", "response_error");
|
|
541
|
+
callback.callback(retError);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
530
544
|
}
|
|
545
|
+
callback.callback(ret);
|
|
531
546
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
547
|
+
},
|
|
548
|
+
new Response.ErrorListener() {
|
|
549
|
+
@Override
|
|
550
|
+
public void onErrorResponse(VolleyError error) {
|
|
551
|
+
Log.e(TAG, "Error getting Latest" + error.toString());
|
|
552
|
+
final JSObject retError = new JSObject();
|
|
553
|
+
retError.put("message", "Cannot set info: " + error.toString());
|
|
554
|
+
retError.put("error", "response_error");
|
|
555
|
+
callback.callback(retError);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
);
|
|
559
|
+
this.requestQueue.add(request);
|
|
538
560
|
}
|
|
539
561
|
|
|
540
|
-
public void setChannel(final String channel, final
|
|
562
|
+
public void setChannel(final String channel, final Callback callback) {
|
|
541
563
|
String channelUrl = this.channelUrl;
|
|
542
564
|
if (
|
|
543
565
|
channelUrl == null || "".equals(channelUrl) || channelUrl.length() == 0
|
|
544
566
|
) {
|
|
567
|
+
Log.e(TAG, "Channel URL is not set");
|
|
568
|
+
final JSObject retError = new JSObject();
|
|
569
|
+
retError.put("message", "channelUrl missing");
|
|
570
|
+
retError.put("error", "missing_config");
|
|
571
|
+
callback.callback(retError);
|
|
545
572
|
return;
|
|
546
573
|
}
|
|
574
|
+
JSONObject json = null;
|
|
547
575
|
try {
|
|
548
|
-
|
|
576
|
+
json = this.createInfoObject();
|
|
549
577
|
json.put("channel", channel);
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
578
|
+
} catch (JSONException e) {
|
|
579
|
+
Log.e(TAG, "Error setChannel JSONException", e);
|
|
580
|
+
e.printStackTrace();
|
|
581
|
+
final JSObject retError = new JSObject();
|
|
582
|
+
retError.put("message", "Cannot get info: " + e.toString());
|
|
583
|
+
retError.put("error", "json_error");
|
|
584
|
+
callback.callback(retError);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
// Building a request
|
|
588
|
+
JsonObjectRequest request = new JsonObjectRequest(
|
|
589
|
+
Request.Method.POST,
|
|
590
|
+
channelUrl,
|
|
591
|
+
json,
|
|
592
|
+
new Response.Listener<JSONObject>() {
|
|
593
|
+
@Override
|
|
594
|
+
public void onResponse(JSONObject res) {
|
|
595
|
+
final JSObject ret = new JSObject();
|
|
596
|
+
Iterator<String> keys = res.keys();
|
|
597
|
+
while (keys.hasNext()) {
|
|
598
|
+
String key = keys.next();
|
|
599
|
+
if (res.has(key)) {
|
|
600
|
+
try {
|
|
601
|
+
ret.put(key, res.get(key));
|
|
602
|
+
} catch (JSONException e) {
|
|
603
|
+
e.printStackTrace();
|
|
604
|
+
final JSObject retError = new JSObject();
|
|
605
|
+
retError.put("message", "Cannot set channel: " + e.toString());
|
|
606
|
+
retError.put("error", "response_error");
|
|
607
|
+
callback.callback(ret);
|
|
569
608
|
}
|
|
570
609
|
}
|
|
571
|
-
Log.i(TAG, "Channel set to \"" + channel);
|
|
572
|
-
callback.callback(ret);
|
|
573
|
-
}
|
|
574
|
-
},
|
|
575
|
-
new Response.ErrorListener() {
|
|
576
|
-
@Override
|
|
577
|
-
public void onErrorResponse(VolleyError error) {
|
|
578
|
-
Log.e(TAG, "Error set channel: " + error.toString());
|
|
579
610
|
}
|
|
611
|
+
Log.i(TAG, "Channel set to \"" + channel);
|
|
612
|
+
callback.callback(ret);
|
|
580
613
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
614
|
+
},
|
|
615
|
+
new Response.ErrorListener() {
|
|
616
|
+
@Override
|
|
617
|
+
public void onErrorResponse(VolleyError error) {
|
|
618
|
+
Log.e(TAG, "Error set channel: " + error.toString());
|
|
619
|
+
final JSObject retError = new JSObject();
|
|
620
|
+
retError.put("message", "Cannot set channel: " + error.toString());
|
|
621
|
+
retError.put("error", "response_error");
|
|
622
|
+
callback.callback(retError);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
);
|
|
626
|
+
this.requestQueue.add(request);
|
|
587
627
|
}
|
|
588
628
|
|
|
589
|
-
public void getChannel(final
|
|
629
|
+
public void getChannel(final Callback callback) {
|
|
590
630
|
String channelUrl = this.channelUrl;
|
|
591
631
|
if (
|
|
592
632
|
channelUrl == null || "".equals(channelUrl) || channelUrl.length() == 0
|
|
593
633
|
) {
|
|
634
|
+
Log.e(TAG, "Channel URL is not set");
|
|
635
|
+
final JSObject retError = new JSObject();
|
|
636
|
+
retError.put("message", "Channel URL is not set");
|
|
637
|
+
retError.put("error", "missing_config");
|
|
638
|
+
callback.callback(retError);
|
|
594
639
|
return;
|
|
595
640
|
}
|
|
641
|
+
JSONObject json = null;
|
|
596
642
|
try {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
643
|
+
json = this.createInfoObject();
|
|
644
|
+
} catch (JSONException e) {
|
|
645
|
+
Log.e(TAG, "Error getChannel JSONException", e);
|
|
646
|
+
e.printStackTrace();
|
|
647
|
+
final JSObject retError = new JSObject();
|
|
648
|
+
retError.put("message", "Cannot get info: " + e.toString());
|
|
649
|
+
retError.put("error", "json_error");
|
|
650
|
+
callback.callback(retError);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
// Building a request
|
|
654
|
+
JsonObjectRequest request = new JsonObjectRequest(
|
|
655
|
+
Request.Method.PUT,
|
|
656
|
+
channelUrl,
|
|
657
|
+
json,
|
|
658
|
+
new Response.Listener<JSONObject>() {
|
|
659
|
+
@Override
|
|
660
|
+
public void onResponse(JSONObject res) {
|
|
661
|
+
final JSObject ret = new JSObject();
|
|
662
|
+
Iterator<String> keys = res.keys();
|
|
663
|
+
while (keys.hasNext()) {
|
|
664
|
+
String key = keys.next();
|
|
665
|
+
if (res.has(key)) {
|
|
666
|
+
try {
|
|
667
|
+
ret.put(key, res.get(key));
|
|
668
|
+
} catch (JSONException e) {
|
|
669
|
+
e.printStackTrace();
|
|
617
670
|
}
|
|
618
671
|
}
|
|
619
|
-
Log.i(TAG, "Channel get to \"" + ret);
|
|
620
|
-
callback.callback(ret);
|
|
621
|
-
}
|
|
622
|
-
},
|
|
623
|
-
new Response.ErrorListener() {
|
|
624
|
-
@Override
|
|
625
|
-
public void onErrorResponse(VolleyError error) {
|
|
626
|
-
Log.e(TAG, "Error get channel: " + error.toString());
|
|
627
672
|
}
|
|
673
|
+
Log.i(TAG, "Channel get to \"" + ret);
|
|
674
|
+
callback.callback(ret);
|
|
628
675
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
676
|
+
},
|
|
677
|
+
new Response.ErrorListener() {
|
|
678
|
+
@Override
|
|
679
|
+
public void onErrorResponse(VolleyError error) {
|
|
680
|
+
Log.e(TAG, "Error get channel: " + error.toString());
|
|
681
|
+
final JSObject retError = new JSObject();
|
|
682
|
+
retError.put("message", "Error get channel: " + error.toString());
|
|
683
|
+
retError.put("error", "response_error");
|
|
684
|
+
callback.callback(retError);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
);
|
|
688
|
+
this.requestQueue.add(request);
|
|
635
689
|
}
|
|
636
690
|
|
|
637
691
|
public void sendStats(final String action, final String versionName) {
|
|
@@ -639,36 +693,37 @@ public class CapacitorUpdater {
|
|
|
639
693
|
if (statsUrl == null || "".equals(statsUrl) || statsUrl.length() == 0) {
|
|
640
694
|
return;
|
|
641
695
|
}
|
|
696
|
+
JSONObject json = null;
|
|
642
697
|
try {
|
|
643
|
-
|
|
698
|
+
json = this.createInfoObject();
|
|
644
699
|
json.put("action", action);
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
statsUrl,
|
|
650
|
-
json,
|
|
651
|
-
new Response.Listener<JSONObject>() {
|
|
652
|
-
@Override
|
|
653
|
-
public void onResponse(JSONObject response) {
|
|
654
|
-
Log.i(
|
|
655
|
-
TAG,
|
|
656
|
-
"Stats send for \"" + action + "\", version " + versionName
|
|
657
|
-
);
|
|
658
|
-
}
|
|
659
|
-
},
|
|
660
|
-
new Response.ErrorListener() {
|
|
661
|
-
@Override
|
|
662
|
-
public void onErrorResponse(VolleyError error) {
|
|
663
|
-
Log.e(TAG, "Error sending stats: " + error.toString());
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
);
|
|
667
|
-
this.requestQueue.add(request);
|
|
668
|
-
} catch (JSONException ex) {
|
|
669
|
-
// Catch if something went wrong with the params
|
|
670
|
-
Log.e(TAG, "Error sendStats JSONException", ex);
|
|
700
|
+
} catch (JSONException e) {
|
|
701
|
+
Log.e(TAG, "Error sendStats JSONException", e);
|
|
702
|
+
e.printStackTrace();
|
|
703
|
+
return;
|
|
671
704
|
}
|
|
705
|
+
// Building a request
|
|
706
|
+
JsonObjectRequest request = new JsonObjectRequest(
|
|
707
|
+
Request.Method.POST,
|
|
708
|
+
statsUrl,
|
|
709
|
+
json,
|
|
710
|
+
new Response.Listener<JSONObject>() {
|
|
711
|
+
@Override
|
|
712
|
+
public void onResponse(JSONObject response) {
|
|
713
|
+
Log.i(
|
|
714
|
+
TAG,
|
|
715
|
+
"Stats send for \"" + action + "\", version " + versionName
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
new Response.ErrorListener() {
|
|
720
|
+
@Override
|
|
721
|
+
public void onErrorResponse(VolleyError error) {
|
|
722
|
+
Log.e(TAG, "Error sending stats: " + error.toString());
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
);
|
|
726
|
+
this.requestQueue.add(request);
|
|
672
727
|
}
|
|
673
728
|
|
|
674
729
|
public BundleInfo getBundleInfo(final String id) {
|
|
@@ -138,6 +138,7 @@ public class CapacitorUpdaterPlugin
|
|
|
138
138
|
final Application application = (Application) this.getContext()
|
|
139
139
|
.getApplicationContext();
|
|
140
140
|
application.registerActivityLifecycleCallbacks(this);
|
|
141
|
+
this.onActivityStarted(this.getActivity());
|
|
141
142
|
this._checkCancelDelay(true);
|
|
142
143
|
}
|
|
143
144
|
|
|
@@ -270,7 +271,11 @@ public class CapacitorUpdaterPlugin
|
|
|
270
271
|
CapacitorUpdaterPlugin.this.implementation.setChannel(
|
|
271
272
|
channel,
|
|
272
273
|
res -> {
|
|
273
|
-
|
|
274
|
+
if (res.has("error")) {
|
|
275
|
+
call.reject(res.getString("error"));
|
|
276
|
+
} else {
|
|
277
|
+
call.resolve(res);
|
|
278
|
+
}
|
|
274
279
|
}
|
|
275
280
|
);
|
|
276
281
|
}
|
|
@@ -292,7 +297,11 @@ public class CapacitorUpdaterPlugin
|
|
|
292
297
|
@Override
|
|
293
298
|
public void run() {
|
|
294
299
|
CapacitorUpdaterPlugin.this.implementation.getChannel(res -> {
|
|
295
|
-
|
|
300
|
+
if (res.has("error")) {
|
|
301
|
+
call.reject(res.getString("error"));
|
|
302
|
+
} else {
|
|
303
|
+
call.resolve(res);
|
|
304
|
+
}
|
|
296
305
|
});
|
|
297
306
|
}
|
|
298
307
|
}
|
|
@@ -497,11 +506,12 @@ public class CapacitorUpdaterPlugin
|
|
|
497
506
|
CapacitorUpdaterPlugin.this.implementation.getLatest(
|
|
498
507
|
CapacitorUpdaterPlugin.this.updateUrl,
|
|
499
508
|
res -> {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
509
|
+
if (res.has("error")) {
|
|
510
|
+
call.reject(res.getString("error"));
|
|
511
|
+
return;
|
|
512
|
+
} else {
|
|
513
|
+
call.resolve(res);
|
|
514
|
+
}
|
|
505
515
|
final JSObject ret = new JSObject();
|
|
506
516
|
Iterator<String> keys = res.keys();
|
|
507
517
|
while (keys.hasNext()) {
|
|
@@ -19,10 +19,12 @@ extension Date {
|
|
|
19
19
|
struct SetChannelDec: Decodable {
|
|
20
20
|
let status: String?
|
|
21
21
|
let error: String?
|
|
22
|
+
let message: String?
|
|
22
23
|
}
|
|
23
24
|
public class SetChannel: NSObject {
|
|
24
25
|
var status: String = ""
|
|
25
26
|
var error: String = ""
|
|
27
|
+
var message: String = ""
|
|
26
28
|
}
|
|
27
29
|
extension SetChannel {
|
|
28
30
|
func toDict() -> [String: Any] {
|
|
@@ -40,12 +42,14 @@ struct GetChannelDec: Decodable {
|
|
|
40
42
|
let channel: String?
|
|
41
43
|
let status: String?
|
|
42
44
|
let error: String?
|
|
45
|
+
let message: String?
|
|
43
46
|
let allowSet: Bool?
|
|
44
47
|
}
|
|
45
48
|
public class GetChannel: NSObject {
|
|
46
49
|
var channel: String = ""
|
|
47
50
|
var status: String = ""
|
|
48
51
|
var error: String = ""
|
|
52
|
+
var message: String = ""
|
|
49
53
|
var allowSet: Bool = true
|
|
50
54
|
}
|
|
51
55
|
extension GetChannel {
|
|
@@ -80,6 +84,7 @@ struct AppVersionDec: Decodable {
|
|
|
80
84
|
let checksum: String?
|
|
81
85
|
let url: String?
|
|
82
86
|
let message: String?
|
|
87
|
+
let error: String?
|
|
83
88
|
let session_key: String?
|
|
84
89
|
let major: Bool?
|
|
85
90
|
}
|
|
@@ -88,6 +93,7 @@ public class AppVersion: NSObject {
|
|
|
88
93
|
var checksum: String = ""
|
|
89
94
|
var url: String = ""
|
|
90
95
|
var message: String?
|
|
96
|
+
var error: String?
|
|
91
97
|
var sessionKey: String?
|
|
92
98
|
var major: Bool?
|
|
93
99
|
}
|
|
@@ -222,7 +228,7 @@ extension CustomError: LocalizedError {
|
|
|
222
228
|
public let TAG = "✨ Capacitor-updater:"
|
|
223
229
|
public let CAP_SERVER_PATH = "serverBasePath"
|
|
224
230
|
public var customId = ""
|
|
225
|
-
public let pluginVersion = "4.13.
|
|
231
|
+
public let pluginVersion = "4.13.4"
|
|
226
232
|
public var statsUrl = ""
|
|
227
233
|
public var channelUrl = ""
|
|
228
234
|
public var appId = ""
|
|
@@ -336,7 +342,7 @@ extension CustomError: LocalizedError {
|
|
|
336
342
|
print("cannot decode privateKey", self.privateKey)
|
|
337
343
|
return
|
|
338
344
|
}
|
|
339
|
-
|
|
345
|
+
|
|
340
346
|
let sessionKeyArray = sessionKey.components(separatedBy: ":")
|
|
341
347
|
let ivData = Data(base64Encoded: sessionKeyArray[0])!
|
|
342
348
|
let sessionKeyDataEncrypted = Data(base64Encoded: sessionKeyArray[1])!
|
|
@@ -344,7 +350,7 @@ extension CustomError: LocalizedError {
|
|
|
344
350
|
let aesPrivateKey: AES128Key = AES128Key(iv: ivData, aes128Key: sessionKeyDataDecrypted)
|
|
345
351
|
let encryptedData = try Data(contentsOf: filePath)
|
|
346
352
|
let decryptedData: Data = aesPrivateKey.decrypt(data: encryptedData)!
|
|
347
|
-
|
|
353
|
+
|
|
348
354
|
try decryptedData.write(to: filePath)
|
|
349
355
|
} catch {
|
|
350
356
|
print("\(self.TAG) Cannot decode: \(filePath.path)", error)
|
|
@@ -407,11 +413,16 @@ extension CustomError: LocalizedError {
|
|
|
407
413
|
if let message = response.value?.message {
|
|
408
414
|
latest.message = message
|
|
409
415
|
}
|
|
416
|
+
if let error = response.value?.error {
|
|
417
|
+
latest.error = error
|
|
418
|
+
}
|
|
410
419
|
if let sessionKey = response.value?.session_key {
|
|
411
420
|
latest.sessionKey = sessionKey
|
|
412
421
|
}
|
|
413
422
|
case let .failure(error):
|
|
414
423
|
print("\(self.TAG) Error getting Latest", error )
|
|
424
|
+
latest.message = "Error getting Latest \(error)"
|
|
425
|
+
latest.error = "fail_response"
|
|
415
426
|
}
|
|
416
427
|
semaphore.signal()
|
|
417
428
|
}
|
|
@@ -607,12 +618,15 @@ extension CustomError: LocalizedError {
|
|
|
607
618
|
self.setBundleStatus(id: bundle.getId(), status: BundleStatus.ERROR)
|
|
608
619
|
}
|
|
609
620
|
|
|
610
|
-
func setChannel(channel: String) -> SetChannel
|
|
621
|
+
func setChannel(channel: String) -> SetChannel {
|
|
622
|
+
let setChannel = SetChannel()
|
|
611
623
|
if self.channelUrl == "" {
|
|
612
|
-
|
|
624
|
+
print("\(self.TAG) Channel URL is not set")
|
|
625
|
+
setChannel.message = "Channel URL is not set"
|
|
626
|
+
setChannel.error = "missing_config"
|
|
627
|
+
return setChannel
|
|
613
628
|
}
|
|
614
629
|
let semaphore = DispatchSemaphore(value: 0)
|
|
615
|
-
let setChannel = SetChannel()
|
|
616
630
|
var parameters: InfoObject = self.createInfoObject()
|
|
617
631
|
parameters.channel = channel
|
|
618
632
|
|
|
@@ -627,8 +641,13 @@ extension CustomError: LocalizedError {
|
|
|
627
641
|
if let error = response.value?.error {
|
|
628
642
|
setChannel.error = error
|
|
629
643
|
}
|
|
644
|
+
if let message = response.value?.message {
|
|
645
|
+
setChannel.message = message
|
|
646
|
+
}
|
|
630
647
|
case let .failure(error):
|
|
631
|
-
print("\(self.TAG) Error set Channel", error
|
|
648
|
+
print("\(self.TAG) Error set Channel", error)
|
|
649
|
+
setChannel.message = "Error set Channel \(error)"
|
|
650
|
+
setChannel.error = "fail_response"
|
|
632
651
|
}
|
|
633
652
|
semaphore.signal()
|
|
634
653
|
}
|
|
@@ -636,12 +655,15 @@ extension CustomError: LocalizedError {
|
|
|
636
655
|
return setChannel
|
|
637
656
|
}
|
|
638
657
|
|
|
639
|
-
func getChannel() -> GetChannel
|
|
658
|
+
func getChannel() -> GetChannel {
|
|
659
|
+
let getChannel = GetChannel()
|
|
640
660
|
if self.channelUrl == "" {
|
|
641
|
-
|
|
661
|
+
print("\(self.TAG) Channel URL is not set")
|
|
662
|
+
getChannel.message = "Channel URL is not set"
|
|
663
|
+
getChannel.error = "missing_config"
|
|
664
|
+
return getChannel
|
|
642
665
|
}
|
|
643
666
|
let semaphore = DispatchSemaphore(value: 0)
|
|
644
|
-
let getChannel = GetChannel()
|
|
645
667
|
let parameters: InfoObject = self.createInfoObject()
|
|
646
668
|
let request = AF.request(self.channelUrl, method: .put, parameters: parameters, encoder: JSONParameterEncoder.default)
|
|
647
669
|
|
|
@@ -662,6 +684,8 @@ extension CustomError: LocalizedError {
|
|
|
662
684
|
}
|
|
663
685
|
case let .failure(error):
|
|
664
686
|
print("\(self.TAG) Error get Channel", error )
|
|
687
|
+
getChannel.message = "Error get Channel \(error)"
|
|
688
|
+
getChannel.error = "fail_response"
|
|
665
689
|
}
|
|
666
690
|
semaphore.signal()
|
|
667
691
|
}
|
|
@@ -209,7 +209,11 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
209
209
|
@objc func getLatest(_ call: CAPPluginCall) {
|
|
210
210
|
DispatchQueue.global(qos: .background).async {
|
|
211
211
|
let res = self.implementation.getLatest(url: URL(string: self.updateUrl)!)
|
|
212
|
-
|
|
212
|
+
if res.error != nil {
|
|
213
|
+
call.reject( res.error!)
|
|
214
|
+
} else {
|
|
215
|
+
call.resolve(res.toDict())
|
|
216
|
+
}
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
219
|
|
|
@@ -220,21 +224,23 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
220
224
|
return
|
|
221
225
|
}
|
|
222
226
|
DispatchQueue.global(qos: .background).async {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
227
|
+
let res = self.implementation.setChannel(channel: channel)
|
|
228
|
+
if res.error != "" {
|
|
229
|
+
call.reject(res.error)
|
|
230
|
+
} else {
|
|
231
|
+
call.resolve(res.toDict())
|
|
226
232
|
}
|
|
227
|
-
call.resolve(res.toDict())
|
|
228
233
|
}
|
|
229
234
|
}
|
|
230
235
|
|
|
231
236
|
@objc func getChannel(_ call: CAPPluginCall) {
|
|
232
237
|
DispatchQueue.global(qos: .background).async {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
238
|
+
let res = self.implementation.getChannel()
|
|
239
|
+
if res.error != "" {
|
|
240
|
+
call.reject(res.error)
|
|
241
|
+
} else {
|
|
242
|
+
call.resolve(res.toDict())
|
|
236
243
|
}
|
|
237
|
-
call.resolve(res.toDict())
|
|
238
244
|
}
|
|
239
245
|
}
|
|
240
246
|
@objc func setCustomId(_ call: CAPPluginCall) {
|
|
@@ -62,19 +62,19 @@ public struct AES128Key {
|
|
|
62
62
|
public func decrypt(data: Data) -> Data? {
|
|
63
63
|
let encryptedData = (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count)
|
|
64
64
|
let encryptedDataLength = data.count
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
if let result = NSMutableData(length: encryptedDataLength) {
|
|
67
67
|
let keyData = (self.aes128Key as NSData).bytes.bindMemory(to: UInt8.self, capacity: self.aes128Key.count)
|
|
68
68
|
let keyLength = size_t(self.aes128Key.count)
|
|
69
69
|
let ivData = (iv as NSData).bytes.bindMemory(to: UInt8.self, capacity: self.iv.count)
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
let decryptedData = UnsafeMutablePointer<UInt8>(result.mutableBytes.assumingMemoryBound(to: UInt8.self))
|
|
72
72
|
let decryptedDataLength = size_t(result.length)
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
var decryptedLength: size_t = 0
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
let status = CCCrypt(CCOperation(kCCDecrypt), CryptoCipherConstants.aesAlgorithm, CryptoCipherConstants.aesOptions, keyData, keyLength, ivData, encryptedData, encryptedDataLength, decryptedData, decryptedDataLength, &decryptedLength)
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
if UInt32(status) == UInt32(kCCSuccess) {
|
|
79
79
|
result.length = Int(decryptedLength)
|
|
80
80
|
return result as Data
|
|
@@ -93,21 +93,21 @@ public struct AES128Key {
|
|
|
93
93
|
public struct RSAKeyPair {
|
|
94
94
|
private let privateKey: SecKey
|
|
95
95
|
private let publicKey: SecKey
|
|
96
|
-
|
|
96
|
+
|
|
97
97
|
#if DEBUG
|
|
98
98
|
public var __debug_privateKey: SecKey { self.privateKey }
|
|
99
99
|
public var __debug_publicKey: SecKey { self.publicKey }
|
|
100
100
|
#endif
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
fileprivate init(privateKey: SecKey, publicKey: SecKey) {
|
|
103
103
|
self.privateKey = privateKey
|
|
104
104
|
self.publicKey = publicKey
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
public func extractPublicKey() -> RSAPublicKey {
|
|
108
108
|
RSAPublicKey(publicKey: publicKey)
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
///
|
|
112
112
|
/// Takes the data and uses the private key to decrypt it.
|
|
113
113
|
/// Returns the decrypted data.
|
|
@@ -126,17 +126,16 @@ public struct RSAKeyPair {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
|
|
130
129
|
///
|
|
131
130
|
/// The RSA public key.
|
|
132
131
|
///
|
|
133
132
|
public struct RSAPublicKey {
|
|
134
133
|
private let publicKey: SecKey
|
|
135
|
-
|
|
136
|
-
#if DEBUG
|
|
134
|
+
|
|
135
|
+
#if DEBUG
|
|
137
136
|
public var __debug_publicKey: SecKey { self.publicKey }
|
|
138
|
-
#endif
|
|
139
|
-
|
|
137
|
+
#endif
|
|
138
|
+
|
|
140
139
|
fileprivate init(publicKey: SecKey) {
|
|
141
140
|
self.publicKey = publicKey
|
|
142
141
|
}
|
|
@@ -162,8 +161,8 @@ public struct RSAPublicKey {
|
|
|
162
161
|
public func export() -> Data? {
|
|
163
162
|
return publicKey.exportToData()
|
|
164
163
|
}
|
|
165
|
-
//
|
|
166
|
-
|
|
164
|
+
//
|
|
165
|
+
|
|
167
166
|
///
|
|
168
167
|
/// Allows you to load an RSA public key (i.e. one downloaded from the net).
|
|
169
168
|
///
|
|
@@ -180,11 +179,11 @@ public struct RSAPublicKey {
|
|
|
180
179
|
///
|
|
181
180
|
public struct RSAPrivateKey {
|
|
182
181
|
private let privateKey: SecKey
|
|
183
|
-
|
|
182
|
+
|
|
184
183
|
#if DEBUG
|
|
185
184
|
public var __debug_privateKey: SecKey { self.privateKey }
|
|
186
185
|
#endif
|
|
187
|
-
|
|
186
|
+
|
|
188
187
|
fileprivate init(privateKey: SecKey) {
|
|
189
188
|
self.privateKey = privateKey
|
|
190
189
|
}
|
|
@@ -204,26 +203,24 @@ public struct RSAPrivateKey {
|
|
|
204
203
|
return nil
|
|
205
204
|
}
|
|
206
205
|
}
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
|
|
209
207
|
///
|
|
210
208
|
/// Allows you to export the RSA public key to a format (so you can send over the net).
|
|
211
209
|
///
|
|
212
210
|
public func export() -> Data? {
|
|
213
211
|
return privateKey.exportToData()
|
|
214
212
|
}
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
|
|
217
214
|
///
|
|
218
215
|
/// Allows you to load an RSA public key (i.e. one downloaded from the net).
|
|
219
216
|
///
|
|
220
217
|
public static func load(rsaPrivateKey: String) -> RSAPrivateKey? {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
218
|
+
var privKey = rsaPrivateKey
|
|
219
|
+
privKey = privKey.replacingOccurrences(of: "-----BEGIN RSA PRIVATE KEY-----", with: "")
|
|
220
|
+
privKey = privKey.replacingOccurrences(of: "-----END RSA PRIVATE KEY-----", with: "")
|
|
221
|
+
privKey = privKey.replacingOccurrences(of: "\\n+", with: "", options: .regularExpression)
|
|
222
|
+
privKey = privKey.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
223
|
+
let rsaPrivateKeyData = Data(base64Encoded: privKey)!
|
|
227
224
|
if let privateKey: SecKey = .loadPrivateFromData(rsaPrivateKeyData) {
|
|
228
225
|
return RSAPrivateKey(privateKey: privateKey)
|
|
229
226
|
} else {
|
|
@@ -246,18 +243,18 @@ fileprivate extension SecKey {
|
|
|
246
243
|
}
|
|
247
244
|
}
|
|
248
245
|
static func loadPublicFromData(_ data: Data) -> SecKey? {
|
|
249
|
-
let keyDict: [NSObject
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
246
|
+
let keyDict: [NSObject: NSObject] = [
|
|
247
|
+
kSecAttrKeyType: kSecAttrKeyTypeRSA,
|
|
248
|
+
kSecAttrKeyClass: kSecAttrKeyClassPublic,
|
|
249
|
+
kSecAttrKeySizeInBits: CryptoCipherConstants.rsaKeySizeInBits
|
|
253
250
|
]
|
|
254
251
|
return SecKeyCreateWithData(data as CFData, keyDict as CFDictionary, nil)
|
|
255
252
|
}
|
|
256
253
|
static func loadPrivateFromData(_ data: Data) -> SecKey? {
|
|
257
|
-
let keyDict: [NSObject
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
let keyDict: [NSObject: NSObject] = [
|
|
255
|
+
kSecAttrKeyType: kSecAttrKeyTypeRSA,
|
|
256
|
+
kSecAttrKeyClass: kSecAttrKeyClassPrivate,
|
|
257
|
+
kSecAttrKeySizeInBits: CryptoCipherConstants.rsaKeySizeInBits
|
|
261
258
|
]
|
|
262
259
|
return SecKeyCreateWithData(data as CFData, keyDict as CFDictionary, nil)
|
|
263
260
|
}
|