diff --git a/package-lock.json b/package-lock.json index 5a1102060..ad862e631 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11602,9 +11602,9 @@ } }, "@moodlehq/phonegap-plugin-push": { - "version": "4.0.0-moodle.3", - "resolved": "https://registry.npmjs.org/@moodlehq/phonegap-plugin-push/-/phonegap-plugin-push-4.0.0-moodle.3.tgz", - "integrity": "sha512-oJTmcVN6QBxo8+9uHEFTLCgNJkd7jeaT1MMM3ljDhR5EkFDkHwMMat/Km0tjm+9ToD0LYWHZfvLljpCZM5u3yg==" + "version": "4.0.0-moodle.4", + "resolved": "https://registry.npmjs.org/@moodlehq/phonegap-plugin-push/-/phonegap-plugin-push-4.0.0-moodle.4.tgz", + "integrity": "sha512-2G9/VvCuSqwonBy92A8VoINgO3DTcSIpsxcefdGgOFyFM5ceijNm0fts2OOMfhWaRSLEnGMtZfPJ2h8u7P7qxg==" }, "@mrmlnc/readdir-enhanced": { "version": "2.2.1", @@ -26533,12 +26533,12 @@ "bplist-parser": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.0.6.tgz", - "integrity": "sha1-ONo0cYF9+dRKs4kuJ3B7u9daEbk=" + "integrity": "sha512-fGeghPEH4Eytvf+Mi446aKcDqvkA/+eh6r7QGiZWMQG6TzqrnsToLP379XFfqRSZ41+676hhGIm++maNST1Apw==" }, "nopt": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.9.tgz", - "integrity": "sha1-O8DXy6e/sNWmdtvtfA6+SKT9RU4=", + "integrity": "sha512-CmUZ3rzN0/4kRHum5pGRiGkhmBMzgtEDxrZVHqRJDSv8qK6s+wzaig/xeyB22Due5aZQeTiEZg/nrmMH2tapDQ==", "requires": { "abbrev": "1" } @@ -38040,7 +38040,7 @@ "tail": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/tail/-/tail-0.4.0.tgz", - "integrity": "sha1-0p3nJ1DMmdseBTr/E8NZ7PtxMAI=" + "integrity": "sha512-i5rOhX0PwkFSbjID14mmuoqrLUIqpJeBwg0esugSbb+6Y+dzgN/O3YZXzzPL7dnQJGbQLs8cwM8Zsak5kFJGcA==" }, "tapable": { "version": "1.1.3", @@ -41001,7 +41001,7 @@ "xml-escape": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/xml-escape/-/xml-escape-1.1.0.tgz", - "integrity": "sha1-OQTBQ/qOs6ADDsZG0pAqLxtwbEQ=" + "integrity": "sha512-B/T4sDK8Z6aUh/qNr7mjKAwwncIljFuUP+DO/D5hloYFj+90O88z8Wf7oSucZTHxBAsC1/CTP4rtx/x1Uf72Mg==" }, "xml-name-validator": { "version": "3.0.0", diff --git a/package.json b/package.json index 317a6a677..c22e85b0e 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "@moodlehq/cordova-plugin-qrscanner": "3.0.1-moodle.5", "@moodlehq/cordova-plugin-zip": "3.1.0-moodle.1", "@moodlehq/ionic-native-push": "5.36.0-moodle.2", - "@moodlehq/phonegap-plugin-push": "4.0.0-moodle.3", + "@moodlehq/phonegap-plugin-push": "4.0.0-moodle.4", "@ngx-translate/core": "13.0.0", "@ngx-translate/http-loader": "6.0.0", "@types/chart.js": "2.9.31", diff --git a/scripts/langindex.json b/scripts/langindex.json index 65f618eaa..959e74ac0 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -2349,6 +2349,7 @@ "core.settings.enablefirebaseanalyticsdescription": "local_moodlemobileapp", "core.settings.enablerichtexteditor": "local_moodlemobileapp", "core.settings.enablerichtexteditordescription": "local_moodlemobileapp", + "core.settings.encryptedpushsupported": "local_moodlemobileapp", "core.settings.entriesincache": "local_moodlemobileapp", "core.settings.estimatedfreespace": "local_moodlemobileapp", "core.settings.filesystemroot": "local_moodlemobileapp", diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index dc8a499b8..234e54825 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -726,7 +726,7 @@ export class CorePushNotificationsProvider { try { const data = this.getRequiredRegisterData(); - data.publickey = await this.getPublicKey(site); + data.publickey = await this.getPublicKeyForSite(site); const neededActions = await this.getRegisterDeviceActions(data, site, forceUnregister); @@ -780,11 +780,24 @@ export class CorePushNotificationsProvider { * @param site Site to register * @returns Public key, undefined if the site or the device doesn't support encryption. */ - protected async getPublicKey(site: CoreSite): Promise { + protected async getPublicKeyForSite(site: CoreSite): Promise { if (!site.wsAvailable('core_user_update_user_device_public_key')) { return; } + return await this.getPublicKey(); + } + + /** + * Get the device public key. + * + * @returns Public key, undefined if the device doesn't support encryption. + */ + async getPublicKey(): Promise { + if (!CorePlatform.isMobile()) { + return; + } + const publicKey = await Push.getPublicKey(); return publicKey ?? undefined; diff --git a/src/core/features/settings/lang.json b/src/core/features/settings/lang.json index 1a6550718..db8630f5f 100644 --- a/src/core/features/settings/lang.json +++ b/src/core/features/settings/lang.json @@ -37,6 +37,7 @@ "enablefirebaseanalyticsdescription": "If enabled, the app will collect anonymous data usage.", "enablerichtexteditor": "Enable text editor", "enablerichtexteditordescription": "If enabled, a text editor will be available when entering content.", + "encryptedpushsupported": "Encrypted push notifications supported", "entriesincache": "{{$a}} entries in cache", "estimatedfreespace": "Estimated free space", "filesystemroot": "File system root", diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.html b/src/core/features/settings/pages/deviceinfo/deviceinfo.html index 22ee220d5..be13897a2 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.html +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.html @@ -148,6 +148,13 @@

{{ deviceInfo.pushId }}

+ + +

{{ 'core.settings.encryptedpushsupported' | translate }}

+

{{ 'core.no' | translate }}

+

{{ 'core.yes' | translate }}

+
+

{{ 'core.settings.localnotifavailable' | translate }}

diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts index 7db0a83fc..b1b6d3cf3 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts @@ -58,6 +58,7 @@ interface CoreSettingsDeviceInfo { uuid?: string; pushId?: string; localNotifAvailable: string; + encryptedPushSupported?: boolean; } /** @@ -210,6 +211,11 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { const showDevOptionsOnConfig = await CoreConfig.get('showDevOptions', 0); this.devOptionsForced = CoreConstants.BUILD.isDevelopment || CoreConstants.BUILD.isTesting; this.showDevOptions = this.devOptionsForced || showDevOptionsOnConfig == 1; + + const publicKey = this.deviceInfo.pushId ? + await CoreUtils.ignoreErrors(CorePushNotifications.getPublicKey()) : + undefined; + this.deviceInfo.encryptedPushSupported = publicKey !== undefined; } /**