Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/crypto.js
Show All 25 Lines | |||||
import { encrypt, generateKey } from '../utils/aes-crypto-utils.js'; | import { encrypt, generateKey } from '../utils/aes-crypto-utils.js'; | ||||
import { getOlmUtility } from '../utils/olm-utils.js'; | import { getOlmUtility } from '../utils/olm-utils.js'; | ||||
async function encryptAPNsNotification( | async function encryptAPNsNotification( | ||||
cookieID: string, | cookieID: string, | ||||
notification: apn.Notification, | notification: apn.Notification, | ||||
codeVersion?: ?number, | codeVersion?: ?number, | ||||
notificationSizeValidator?: apn.Notification => boolean, | notificationSizeValidator?: apn.Notification => boolean, | ||||
blobHolder?: ?string, | |||||
): Promise<{ | ): Promise<{ | ||||
+notification: apn.Notification, | +notification: apn.Notification, | ||||
+payloadSizeExceeded: boolean, | +payloadSizeExceeded: boolean, | ||||
+encryptedPayloadHash?: string, | +encryptedPayloadHash?: string, | ||||
+encryptionOrder?: number, | +encryptionOrder?: number, | ||||
}> { | }> { | ||||
invariant( | invariant( | ||||
!notification.collapseId, | !notification.collapseId, | ||||
`Collapse ID can't be directly stored in apn.Notification object due ` + | `Collapse ID can't be directly stored in apn.Notification object due ` + | ||||
`to security reasons. Please put it in payload property`, | `to security reasons. Please put it in payload property`, | ||||
); | ); | ||||
const encryptedNotification = new apn.Notification(); | const encryptedNotification = new apn.Notification(); | ||||
encryptedNotification.id = notification.id; | encryptedNotification.id = notification.id; | ||||
encryptedNotification.payload.id = notification.id; | encryptedNotification.payload.id = notification.id; | ||||
if (blobHolder) { | |||||
encryptedNotification.payload.blobHolder = blobHolder; | |||||
} | |||||
encryptedNotification.payload.keyserverID = notification.payload.keyserverID; | encryptedNotification.payload.keyserverID = notification.payload.keyserverID; | ||||
encryptedNotification.topic = notification.topic; | encryptedNotification.topic = notification.topic; | ||||
encryptedNotification.sound = notification.aps.sound; | encryptedNotification.sound = notification.aps.sound; | ||||
encryptedNotification.pushType = 'alert'; | encryptedNotification.pushType = 'alert'; | ||||
encryptedNotification.mutableContent = true; | encryptedNotification.mutableContent = true; | ||||
const { id, keyserverID, ...payloadSansUnencryptedData } = | const { id, keyserverID, ...payloadSansUnencryptedData } = | ||||
notification.payload; | notification.payload; | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | $ReadOnlyArray<{ | ||||
+deviceToken: string, | +deviceToken: string, | ||||
+notification: apn.Notification, | +notification: apn.Notification, | ||||
+payloadSizeExceeded: boolean, | +payloadSizeExceeded: boolean, | ||||
+encryptedPayloadHash?: string, | +encryptedPayloadHash?: string, | ||||
+encryptionOrder?: number, | +encryptionOrder?: number, | ||||
}>, | }>, | ||||
> { | > { | ||||
const notificationPromises = devices.map( | const notificationPromises = devices.map( | ||||
async ({ cookieID, deviceToken }) => { | async ({ cookieID, deviceToken, blobHolder }) => { | ||||
const notif = await encryptAPNsNotification( | const notif = await encryptAPNsNotification( | ||||
cookieID, | cookieID, | ||||
notification, | notification, | ||||
codeVersion, | codeVersion, | ||||
notificationSizeValidator, | notificationSizeValidator, | ||||
blobHolder, | |||||
); | ); | ||||
return { cookieID, deviceToken, ...notif }; | return { cookieID, deviceToken, ...notif }; | ||||
}, | }, | ||||
); | ); | ||||
return Promise.all(notificationPromises); | return Promise.all(notificationPromises); | ||||
} | } | ||||
function prepareEncryptedIOSNotificationRescind( | function prepareEncryptedIOSNotificationRescind( | ||||
▲ Show 20 Lines • Show All 145 Lines • Show Last 20 Lines |