native-update 3.4.1 → 4.0.0
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/AI-INTEGRATION-GUIDE.md +26 -16
- package/NativeUpdate.podspec +2 -2
- package/README.md +554 -0
- package/android/build.gradle +43 -34
- package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/android/proguard-rules.pro +0 -3
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +45 -49
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +12 -10
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +12 -21
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +3 -34
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +206 -72
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +74 -37
- package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +169 -179
- package/android/variables.gradle +2 -2
- package/cli/.yarn/install-state.gz +0 -0
- package/cli/commands/bundle-verify.js +4 -1
- package/cli/commands/keys-generate.js +12 -46
- package/cli/index.js +4 -7
- package/cli/package.json +2 -1
- package/dist/esm/core/config.d.ts +3 -0
- package/dist/esm/core/config.js +17 -0
- package/dist/esm/core/plugin-manager.js +4 -2
- package/dist/esm/core/security.js +2 -5
- package/dist/esm/core/update-check.d.ts +2 -0
- package/dist/esm/core/update-check.js +5 -3
- package/dist/esm/definitions.d.ts +43 -2
- package/dist/esm/live-update/delta-processor.d.ts +6 -20
- package/dist/esm/live-update/delta-processor.js +75 -119
- package/dist/esm/plugin.d.ts +0 -3
- package/dist/esm/plugin.js +172 -12
- package/dist/esm/security/crypto.js +2 -5
- package/dist/esm/web.d.ts +1 -9
- package/dist/esm/web.js +4 -56
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +66 -0
- package/docs/KNOWN_LIMITATIONS.md +4 -3
- package/docs/MIGRATION.md +32 -3
- package/docs/server-requirements.md +40 -29
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +6 -2
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +21 -30
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +269 -61
- package/ios/Plugin/NativeUpdatePlugin.m +8 -1
- package/ios/Plugin/NativeUpdatePlugin.swift +71 -34
- package/ios/Plugin/Security/SecurityManager.swift +100 -99
- package/package.json +27 -15
- package/Readme.md +0 -565
package/dist/esm/plugin.js
CHANGED
|
@@ -3,6 +3,7 @@ import { SyncStatus, BundleStatus, UpdateErrorCode } from './definitions';
|
|
|
3
3
|
import { PluginManager } from './core/plugin-manager';
|
|
4
4
|
import { NativeUpdateError, ErrorCode } from './core/errors';
|
|
5
5
|
import { checkForUpdate } from './core/update-check';
|
|
6
|
+
import { DeltaProcessor } from './live-update/delta-processor';
|
|
6
7
|
/**
|
|
7
8
|
* Web implementation of the Native Update Plugin
|
|
8
9
|
*/
|
|
@@ -19,11 +20,12 @@ class NativeUpdatePluginWeb {
|
|
|
19
20
|
// Setup window event bridge for AppUpdateNotifier events
|
|
20
21
|
this.setupWindowEventBridge();
|
|
21
22
|
}
|
|
22
|
-
isInitialized() {
|
|
23
|
+
async isInitialized() {
|
|
23
24
|
return this.initialized && this.pluginManager.isInitialized();
|
|
24
25
|
}
|
|
25
26
|
async reset() {
|
|
26
27
|
await this.pluginManager.reset();
|
|
28
|
+
this.initialized = false;
|
|
27
29
|
}
|
|
28
30
|
async cleanup() {
|
|
29
31
|
await this.pluginManager.cleanup();
|
|
@@ -52,6 +54,11 @@ class NativeUpdatePluginWeb {
|
|
|
52
54
|
updateStrategy: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.updateStrategy,
|
|
53
55
|
publicKey: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.publicKey,
|
|
54
56
|
requireSignature: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.requireSignature,
|
|
57
|
+
allowUnsignedDevelopmentUpdates: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.allowUnsignedDevelopmentUpdates,
|
|
58
|
+
maxBundleSize: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.maxBundleSize,
|
|
59
|
+
maxUncompressedBundleSize: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.maxUncompressedBundleSize,
|
|
60
|
+
allowedHosts: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.allowedHosts,
|
|
61
|
+
enableDeltaUpdates: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.enableDeltaUpdates,
|
|
55
62
|
checksumAlgorithm: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.checksumAlgorithm,
|
|
56
63
|
checkInterval: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.checkInterval,
|
|
57
64
|
security: config.security,
|
|
@@ -65,9 +72,7 @@ class NativeUpdatePluginWeb {
|
|
|
65
72
|
await this.initialize(initConfig);
|
|
66
73
|
}
|
|
67
74
|
else {
|
|
68
|
-
|
|
69
|
-
const configManager = this.pluginManager.getConfigManager();
|
|
70
|
-
configManager.configure(initConfig);
|
|
75
|
+
throw new NativeUpdateError(ErrorCode.INVALID_CONFIG, 'Configuration is locked after initialization. Call reset() before configuring again.');
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
async getSecurityInfo() {
|
|
@@ -97,6 +102,8 @@ class NativeUpdatePluginWeb {
|
|
|
97
102
|
version: updateInfo.latestVersion,
|
|
98
103
|
checksum: updateInfo.checksum,
|
|
99
104
|
signature: updateInfo.signature,
|
|
105
|
+
signatureAlgorithm: updateInfo.signatureAlgorithm,
|
|
106
|
+
delta: updateInfo.delta,
|
|
100
107
|
});
|
|
101
108
|
await this.applyUpdate(bundle.bundleId);
|
|
102
109
|
return {
|
|
@@ -126,7 +133,29 @@ class NativeUpdatePluginWeb {
|
|
|
126
133
|
async download(options) {
|
|
127
134
|
const downloadManager = this.pluginManager.getDownloadManager();
|
|
128
135
|
const bundleManager = this.pluginManager.getBundleManager();
|
|
129
|
-
|
|
136
|
+
let blob;
|
|
137
|
+
const activeBundle = await bundleManager.getActiveBundle();
|
|
138
|
+
if (options.delta && (activeBundle === null || activeBundle === void 0 ? void 0 : activeBundle.version) === options.delta.fromVersion) {
|
|
139
|
+
const activeBlob = await downloadManager.loadBlob(activeBundle.bundleId);
|
|
140
|
+
const result = await new DeltaProcessor().downloadWithDelta({
|
|
141
|
+
updateAvailable: true,
|
|
142
|
+
version: options.version,
|
|
143
|
+
bundleUrl: options.url,
|
|
144
|
+
checksum: options.checksum,
|
|
145
|
+
size: undefined,
|
|
146
|
+
delta: {
|
|
147
|
+
available: true,
|
|
148
|
+
patchUrl: options.delta.patchUrl,
|
|
149
|
+
patchSize: options.delta.patchSize,
|
|
150
|
+
patchChecksum: options.delta.patchChecksum,
|
|
151
|
+
targetChecksum: options.delta.targetChecksum,
|
|
152
|
+
},
|
|
153
|
+
}, activeBlob ? await activeBlob.arrayBuffer() : null);
|
|
154
|
+
blob = new Blob([result.bundleData], { type: 'application/zip' });
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
blob = await downloadManager.downloadWithRetry(options.url, options.version);
|
|
158
|
+
}
|
|
130
159
|
// Verify checksum/signature against ACTUAL downloaded bytes before
|
|
131
160
|
// persisting. Without this, an attacker who swaps the URL or proxies
|
|
132
161
|
// a tampered bundle can plant arbitrary code and the next set() will
|
|
@@ -144,6 +173,7 @@ class NativeUpdatePluginWeb {
|
|
|
144
173
|
status: BundleStatus.READY,
|
|
145
174
|
checksum: options.checksum,
|
|
146
175
|
signature: options.signature,
|
|
176
|
+
signatureAlgorithm: options.signatureAlgorithm,
|
|
147
177
|
verified: true,
|
|
148
178
|
};
|
|
149
179
|
await bundleManager.saveBundleInfo(bundleInfo);
|
|
@@ -214,9 +244,13 @@ class NativeUpdatePluginWeb {
|
|
|
214
244
|
notes: result.notes,
|
|
215
245
|
size: result.size,
|
|
216
246
|
checksum: result.checksum,
|
|
247
|
+
signature: result.signature,
|
|
248
|
+
signatureAlgorithm: result.signatureAlgorithm,
|
|
249
|
+
delta: result.delta,
|
|
217
250
|
};
|
|
218
251
|
}
|
|
219
252
|
async setChannel(channel) {
|
|
253
|
+
const channelName = typeof channel === 'string' ? channel : channel.channel;
|
|
220
254
|
// Store the channel preference
|
|
221
255
|
const preferences = this.pluginManager
|
|
222
256
|
.getConfigManager()
|
|
@@ -224,7 +258,7 @@ class NativeUpdatePluginWeb {
|
|
|
224
258
|
if (preferences) {
|
|
225
259
|
await preferences.set({
|
|
226
260
|
key: 'update_channel',
|
|
227
|
-
value:
|
|
261
|
+
value: channelName,
|
|
228
262
|
});
|
|
229
263
|
}
|
|
230
264
|
}
|
|
@@ -233,13 +267,14 @@ class NativeUpdatePluginWeb {
|
|
|
233
267
|
* time and cannot be mutated at runtime. Runtime mutation is an XSS
|
|
234
268
|
* attack vector — a compromised WebView could repoint updates to a
|
|
235
269
|
* malicious host. Call `initialize()` again with the new config if you
|
|
236
|
-
* legitimately need to switch servers
|
|
270
|
+
* legitimately need to switch servers, call reset() and initialize()
|
|
271
|
+
* again.
|
|
237
272
|
*/
|
|
238
273
|
async setUpdateUrl(url) {
|
|
239
274
|
void url;
|
|
240
275
|
const logger = this.pluginManager.getLogger();
|
|
241
276
|
logger.warn('setUpdateUrl() is deprecated and ignored. Update URL is locked after initialize(). ' +
|
|
242
|
-
'Call initialize()
|
|
277
|
+
'Call reset(), then initialize() with an updated serverUrl to switch servers.');
|
|
243
278
|
}
|
|
244
279
|
async validateUpdate(options) {
|
|
245
280
|
const securityValidator = this.pluginManager.getSecurityValidator();
|
|
@@ -312,7 +347,7 @@ class NativeUpdatePluginWeb {
|
|
|
312
347
|
* Check for available updates (convenience wrapper around getLatest + current version)
|
|
313
348
|
*/
|
|
314
349
|
async checkForUpdate() {
|
|
315
|
-
var _a, _b;
|
|
350
|
+
var _a, _b, _c;
|
|
316
351
|
const bundleManager = this.pluginManager.getBundleManager();
|
|
317
352
|
const configManager = this.pluginManager.getConfigManager();
|
|
318
353
|
try {
|
|
@@ -363,6 +398,8 @@ class NativeUpdatePluginWeb {
|
|
|
363
398
|
size: data.size,
|
|
364
399
|
checksum: data.checksum,
|
|
365
400
|
signature: (_b = data.signature) !== null && _b !== void 0 ? _b : undefined,
|
|
401
|
+
signatureAlgorithm: data.signature ? 'RSA-SHA256' : undefined,
|
|
402
|
+
delta: (_c = data.delta) !== null && _c !== void 0 ? _c : undefined,
|
|
366
403
|
};
|
|
367
404
|
}
|
|
368
405
|
catch (error) {
|
|
@@ -388,6 +425,8 @@ class NativeUpdatePluginWeb {
|
|
|
388
425
|
const version = (options === null || options === void 0 ? void 0 : options.version) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.latestVersion) || '';
|
|
389
426
|
const checksum = (options === null || options === void 0 ? void 0 : options.checksum) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.checksum) || '';
|
|
390
427
|
const signature = (options === null || options === void 0 ? void 0 : options.signature) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.signature) || '';
|
|
428
|
+
const signatureAlgorithm = (options === null || options === void 0 ? void 0 : options.signatureAlgorithm) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.signatureAlgorithm);
|
|
429
|
+
const delta = (options === null || options === void 0 ? void 0 : options.delta) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.delta);
|
|
391
430
|
if (!url || !version) {
|
|
392
431
|
throw new NativeUpdateError(ErrorCode.INVALID_CONFIG, 'URL and version are required for download');
|
|
393
432
|
}
|
|
@@ -416,6 +455,9 @@ class NativeUpdatePluginWeb {
|
|
|
416
455
|
size: validatedBlob.size,
|
|
417
456
|
status: BundleStatus.READY,
|
|
418
457
|
checksum,
|
|
458
|
+
signature: signature || undefined,
|
|
459
|
+
signatureAlgorithm,
|
|
460
|
+
metadata: delta ? { delta } : undefined,
|
|
419
461
|
verified: true, // Validated before saving
|
|
420
462
|
};
|
|
421
463
|
// Save bundle info
|
|
@@ -453,7 +495,7 @@ class NativeUpdatePluginWeb {
|
|
|
453
495
|
*/
|
|
454
496
|
async cancelDownload(bundleId) {
|
|
455
497
|
const downloadManager = this.pluginManager.getDownloadManager();
|
|
456
|
-
downloadManager.cancelDownload(bundleId);
|
|
498
|
+
downloadManager.cancelDownload(typeof bundleId === 'string' ? bundleId : bundleId.bundleId);
|
|
457
499
|
}
|
|
458
500
|
/**
|
|
459
501
|
* Cancel all active downloads
|
|
@@ -467,7 +509,7 @@ class NativeUpdatePluginWeb {
|
|
|
467
509
|
*/
|
|
468
510
|
async isDownloading(bundleId) {
|
|
469
511
|
const downloadManager = this.pluginManager.getDownloadManager();
|
|
470
|
-
return downloadManager.isDownloading(bundleId);
|
|
512
|
+
return downloadManager.isDownloading(typeof bundleId === 'string' ? bundleId : bundleId.bundleId);
|
|
471
513
|
}
|
|
472
514
|
/**
|
|
473
515
|
* Get the count of active downloads
|
|
@@ -677,7 +719,125 @@ class NativeUpdatePluginWeb {
|
|
|
677
719
|
/**
|
|
678
720
|
* Register the plugin
|
|
679
721
|
*/
|
|
680
|
-
const
|
|
722
|
+
const NativeUpdateBridge = registerPlugin('NativeUpdate', {
|
|
681
723
|
web: () => new NativeUpdatePluginWeb(),
|
|
682
724
|
});
|
|
725
|
+
const NativeUpdate = new Proxy(NativeUpdateBridge, {
|
|
726
|
+
get(target, property, receiver) {
|
|
727
|
+
if (property === 'isInitialized') {
|
|
728
|
+
return async () => {
|
|
729
|
+
const result = await target.isInitialized();
|
|
730
|
+
return typeof result === 'boolean'
|
|
731
|
+
? result
|
|
732
|
+
: !!(result && typeof result === 'object' && 'initialized' in result && result.initialized);
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
if (property === 'list') {
|
|
736
|
+
return async () => {
|
|
737
|
+
const result = await target.list();
|
|
738
|
+
if (Array.isArray(result))
|
|
739
|
+
return result;
|
|
740
|
+
if (result && typeof result === 'object' && 'bundles' in result && Array.isArray(result.bundles)) {
|
|
741
|
+
return result.bundles;
|
|
742
|
+
}
|
|
743
|
+
return [];
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
if (property === 'setChannel') {
|
|
747
|
+
return (channel) => target.setChannel({ channel });
|
|
748
|
+
}
|
|
749
|
+
if (property === 'setUpdateUrl') {
|
|
750
|
+
return (url) => target.setUpdateUrl({ url });
|
|
751
|
+
}
|
|
752
|
+
if (property === 'scheduleBackgroundCheck') {
|
|
753
|
+
return (interval) => target.scheduleBackgroundCheck({ interval });
|
|
754
|
+
}
|
|
755
|
+
if (property === 'requestNotificationPermissions') {
|
|
756
|
+
return async () => {
|
|
757
|
+
const result = await target.requestNotificationPermissions();
|
|
758
|
+
return typeof result === 'boolean'
|
|
759
|
+
? result
|
|
760
|
+
: !!(result && typeof result === 'object' && 'granted' in result && result.granted);
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
if (property === 'checkForUpdate') {
|
|
764
|
+
return async () => {
|
|
765
|
+
const [latest, current] = await Promise.all([target.getLatest(), target.current()]);
|
|
766
|
+
return {
|
|
767
|
+
available: latest.available,
|
|
768
|
+
latestVersion: latest.version,
|
|
769
|
+
currentVersion: current.version,
|
|
770
|
+
url: latest.url,
|
|
771
|
+
mandatory: latest.mandatory,
|
|
772
|
+
notes: latest.notes,
|
|
773
|
+
size: latest.size,
|
|
774
|
+
checksum: latest.checksum,
|
|
775
|
+
signature: latest.signature,
|
|
776
|
+
signatureAlgorithm: latest.signatureAlgorithm,
|
|
777
|
+
delta: latest.delta,
|
|
778
|
+
};
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
if (property === 'downloadUpdate') {
|
|
782
|
+
return async (options = {}) => {
|
|
783
|
+
var _a, _b, _c, _d, _e, _f;
|
|
784
|
+
const latest = options.url && options.version && options.checksum
|
|
785
|
+
? undefined
|
|
786
|
+
: await target.getLatest();
|
|
787
|
+
const url = (_a = options.url) !== null && _a !== void 0 ? _a : latest === null || latest === void 0 ? void 0 : latest.url;
|
|
788
|
+
const version = (_b = options.version) !== null && _b !== void 0 ? _b : latest === null || latest === void 0 ? void 0 : latest.version;
|
|
789
|
+
const checksum = (_c = options.checksum) !== null && _c !== void 0 ? _c : latest === null || latest === void 0 ? void 0 : latest.checksum;
|
|
790
|
+
if (!url || !version || !checksum) {
|
|
791
|
+
throw new NativeUpdateError(ErrorCode.UPDATE_NOT_AVAILABLE, 'No downloadable update is available');
|
|
792
|
+
}
|
|
793
|
+
return target.download({
|
|
794
|
+
url,
|
|
795
|
+
version,
|
|
796
|
+
checksum,
|
|
797
|
+
signature: (_d = options.signature) !== null && _d !== void 0 ? _d : latest === null || latest === void 0 ? void 0 : latest.signature,
|
|
798
|
+
signatureAlgorithm: (_e = options.signatureAlgorithm) !== null && _e !== void 0 ? _e : latest === null || latest === void 0 ? void 0 : latest.signatureAlgorithm,
|
|
799
|
+
delta: (_f = options.delta) !== null && _f !== void 0 ? _f : latest === null || latest === void 0 ? void 0 : latest.delta,
|
|
800
|
+
});
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
if (property === 'applyUpdate') {
|
|
804
|
+
return async (bundleId) => {
|
|
805
|
+
const bundles = await NativeUpdate.list();
|
|
806
|
+
const bundle = bundleId
|
|
807
|
+
? bundles.find(candidate => candidate.bundleId === bundleId)
|
|
808
|
+
: bundles
|
|
809
|
+
.filter(candidate => candidate.status === BundleStatus.READY)
|
|
810
|
+
.sort((left, right) => right.downloadTime - left.downloadTime)[0];
|
|
811
|
+
if (!bundle) {
|
|
812
|
+
throw new NativeUpdateError(ErrorCode.FILE_NOT_FOUND, 'No ready bundle found to apply');
|
|
813
|
+
}
|
|
814
|
+
await target.set(bundle);
|
|
815
|
+
await target.reload();
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
if (property === 'cancelDownload') {
|
|
819
|
+
return (bundleId) => target.cancelDownload({ bundleId });
|
|
820
|
+
}
|
|
821
|
+
if (property === 'isDownloading') {
|
|
822
|
+
return async (bundleId) => {
|
|
823
|
+
const result = await target.isDownloading({ bundleId });
|
|
824
|
+
return typeof result === 'boolean'
|
|
825
|
+
? result
|
|
826
|
+
: !!(result && typeof result === 'object' && 'isDownloading' in result && result.isDownloading);
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
if (property === 'getActiveDownloadCount') {
|
|
830
|
+
return async () => {
|
|
831
|
+
const result = await target.getActiveDownloadCount();
|
|
832
|
+
return typeof result === 'number'
|
|
833
|
+
? result
|
|
834
|
+
: result && typeof result === 'object' && 'count' in result && typeof result.count === 'number'
|
|
835
|
+
? result.count
|
|
836
|
+
: 0;
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
const value = Reflect.get(target, property, receiver);
|
|
840
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
841
|
+
},
|
|
842
|
+
});
|
|
683
843
|
export { NativeUpdate };
|
|
@@ -36,15 +36,12 @@ export class CryptoUtils {
|
|
|
36
36
|
const signatureBuffer = this.base64ToArrayBuffer(signature);
|
|
37
37
|
const publicKeyBuffer = this.base64ToArrayBuffer(pemBody);
|
|
38
38
|
const key = await crypto.subtle.importKey('spki', publicKeyBuffer, {
|
|
39
|
-
name: '
|
|
39
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
40
40
|
hash: 'SHA-256',
|
|
41
41
|
}, false, ['verify']);
|
|
42
42
|
const encoder = new TextEncoder();
|
|
43
43
|
const dataBuffer = typeof data === 'string' ? encoder.encode(data) : data;
|
|
44
|
-
return await crypto.subtle.verify({
|
|
45
|
-
name: 'RSA-PSS',
|
|
46
|
-
saltLength: 32,
|
|
47
|
-
}, key, signatureBuffer, dataBuffer);
|
|
44
|
+
return await crypto.subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, key, signatureBuffer, dataBuffer);
|
|
48
45
|
}
|
|
49
46
|
catch (error) {
|
|
50
47
|
// Verification failure must NOT throw — we want a clean false so
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -88,7 +88,7 @@ export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCo
|
|
|
88
88
|
*/
|
|
89
89
|
private validateChecksum;
|
|
90
90
|
/**
|
|
91
|
-
* Validate
|
|
91
|
+
* Validate the backend's RSA-SHA256 (PKCS#1 v1.5) signature.
|
|
92
92
|
*
|
|
93
93
|
* Fails closed: if the host app configured a public key or
|
|
94
94
|
* requireSignature, a missing signature throws. Silent-pass was a P0 gap.
|
|
@@ -97,18 +97,10 @@ export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCo
|
|
|
97
97
|
* @param signature - The signature to verify (base64 encoded)
|
|
98
98
|
*/
|
|
99
99
|
private validateSignature;
|
|
100
|
-
/**
|
|
101
|
-
* Fallback signature validation using ECDSA
|
|
102
|
-
*/
|
|
103
|
-
private validateSignatureECDSA;
|
|
104
100
|
/**
|
|
105
101
|
* Import RSA public key from PEM format
|
|
106
102
|
*/
|
|
107
103
|
private importPublicKey;
|
|
108
|
-
/**
|
|
109
|
-
* Import ECDSA public key from PEM format
|
|
110
|
-
*/
|
|
111
|
-
private importPublicKeyECDSA;
|
|
112
104
|
/**
|
|
113
105
|
* Safe localStorage accessor. Returns `null` in environments where
|
|
114
106
|
* `localStorage` isn't available — SSR, Node-only test runners that
|
package/dist/esm/web.js
CHANGED
|
@@ -758,7 +758,7 @@ export class NativeUpdateWeb extends WebPlugin {
|
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
760
|
/**
|
|
761
|
-
* Validate
|
|
761
|
+
* Validate the backend's RSA-SHA256 (PKCS#1 v1.5) signature.
|
|
762
762
|
*
|
|
763
763
|
* Fails closed: if the host app configured a public key or
|
|
764
764
|
* requireSignature, a missing signature throws. Silent-pass was a P0 gap.
|
|
@@ -794,11 +794,8 @@ export class NativeUpdateWeb extends WebPlugin {
|
|
|
794
794
|
const signatureBuffer = Uint8Array.from(atob(signature), c => c.charCodeAt(0));
|
|
795
795
|
// Import public key
|
|
796
796
|
const publicKey = await this.importPublicKey(publicKeyPem);
|
|
797
|
-
// Verify signature
|
|
798
|
-
const isValid = await crypto.subtle.verify({
|
|
799
|
-
name: 'RSA-PSS',
|
|
800
|
-
saltLength: 32,
|
|
801
|
-
}, publicKey, signatureBuffer, dataBuffer);
|
|
797
|
+
// Verify the RSA-SHA256 signature used by the backend.
|
|
798
|
+
const isValid = await crypto.subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, publicKey, signatureBuffer, dataBuffer);
|
|
802
799
|
if (!isValid) {
|
|
803
800
|
logger.warn('Signature validation failed');
|
|
804
801
|
}
|
|
@@ -806,41 +803,6 @@ export class NativeUpdateWeb extends WebPlugin {
|
|
|
806
803
|
}
|
|
807
804
|
catch (error) {
|
|
808
805
|
logger.error('Signature validation error', error);
|
|
809
|
-
// Try ECDSA as fallback
|
|
810
|
-
return this.validateSignatureECDSA(data, signature);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* Fallback signature validation using ECDSA
|
|
815
|
-
*/
|
|
816
|
-
async validateSignatureECDSA(data, signature) {
|
|
817
|
-
var _a;
|
|
818
|
-
const publicKeyPem = ((_a = this.config.liveUpdate) === null || _a === void 0 ? void 0 : _a.publicKey) ||
|
|
819
|
-
this.config.publicKey;
|
|
820
|
-
if (!publicKeyPem) {
|
|
821
|
-
// ECDSA is only reached as a fallback from validateSignature, which
|
|
822
|
-
// already confirmed a key is configured. Reaching here without one
|
|
823
|
-
// is a logic error — fail closed rather than silently passing.
|
|
824
|
-
return false;
|
|
825
|
-
}
|
|
826
|
-
try {
|
|
827
|
-
let dataBuffer;
|
|
828
|
-
if (typeof data === 'string') {
|
|
829
|
-
dataBuffer = new TextEncoder().encode(data).buffer;
|
|
830
|
-
}
|
|
831
|
-
else {
|
|
832
|
-
dataBuffer = data;
|
|
833
|
-
}
|
|
834
|
-
const signatureBuffer = Uint8Array.from(atob(signature), c => c.charCodeAt(0));
|
|
835
|
-
const publicKey = await this.importPublicKeyECDSA(publicKeyPem);
|
|
836
|
-
const isValid = await crypto.subtle.verify({
|
|
837
|
-
name: 'ECDSA',
|
|
838
|
-
hash: 'SHA-256',
|
|
839
|
-
}, publicKey, signatureBuffer, dataBuffer);
|
|
840
|
-
return isValid;
|
|
841
|
-
}
|
|
842
|
-
catch (error) {
|
|
843
|
-
logger.error('ECDSA signature validation error', error);
|
|
844
806
|
return false;
|
|
845
807
|
}
|
|
846
808
|
}
|
|
@@ -855,24 +817,10 @@ export class NativeUpdateWeb extends WebPlugin {
|
|
|
855
817
|
.replace(/\s/g, '');
|
|
856
818
|
const binaryDer = Uint8Array.from(atob(pemContents), c => c.charCodeAt(0));
|
|
857
819
|
return crypto.subtle.importKey('spki', binaryDer, {
|
|
858
|
-
name: '
|
|
820
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
859
821
|
hash: 'SHA-256',
|
|
860
822
|
}, false, ['verify']);
|
|
861
823
|
}
|
|
862
|
-
/**
|
|
863
|
-
* Import ECDSA public key from PEM format
|
|
864
|
-
*/
|
|
865
|
-
async importPublicKeyECDSA(pem) {
|
|
866
|
-
const pemContents = pem
|
|
867
|
-
.replace(/-----BEGIN PUBLIC KEY-----/, '')
|
|
868
|
-
.replace(/-----END PUBLIC KEY-----/, '')
|
|
869
|
-
.replace(/\s/g, '');
|
|
870
|
-
const binaryDer = Uint8Array.from(atob(pemContents), c => c.charCodeAt(0));
|
|
871
|
-
return crypto.subtle.importKey('spki', binaryDer, {
|
|
872
|
-
name: 'ECDSA',
|
|
873
|
-
namedCurve: 'P-256',
|
|
874
|
-
}, false, ['verify']);
|
|
875
|
-
}
|
|
876
824
|
/**
|
|
877
825
|
* Safe localStorage accessor. Returns `null` in environments where
|
|
878
826
|
* `localStorage` isn't available — SSR, Node-only test runners that
|