Skip to content

Instantly share code, notes, and snippets.

View marcinwasowicz's full-sized avatar

marcinwasowicz

View GitHub Profile
@marcinwasowicz
marcinwasowicz / gist:039d35ce01414f3cfafa0d5b54cdea0c
Created November 3, 2023 10:54
Test encrypted web notifications
diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js
index c75f2c248..44ea265e8 100644
--- a/keyserver/src/push/send.js
+++ b/keyserver/src/push/send.js
@@ -361,15 +361,24 @@ async function sendPushNotif(input: {
};
const deliveryPromise: Promise<PushResult> = (async () => {
- const targetedNotifications = await prepareWebNotification(
- {
@marcinwasowicz
marcinwasowicz / gist:20ee184547487d05aa5421af8c77b107
Created October 31, 2023 17:18
Use olm WASM in service worker
diff --git a/web/push-notif/service-worker.js b/web/push-notif/service-worker.js
index a03e36af4..4eeedaff7 100644
--- a/web/push-notif/service-worker.js
+++ b/web/push-notif/service-worker.js
@@ -1,5 +1,5 @@
// @flow
-
+import olm from '@commapp/olm';
import localforage from 'localforage';
@marcinwasowicz
marcinwasowicz / gist:f81464d953894bb65f7fd0a891f7def8
Created October 6, 2023 16:39
Notifications Crypto Module pretty print
std::string NotificationsCryptoModule::prettyPrint() {
std::string picklingKey = NotificationsCryptoModule::getPicklingKey();
crypto::Persist persist = this->statefulCryptoModule.storeAsB64(picklingKey);
folly::dynamic sessions = folly::dynamic::object;
for (auto &sessionKeyValuePair : persist.sessions) {
std::string targetUserID = sessionKeyValuePair.first;
crypto::OlmBuffer sessionData = sessionKeyValuePair.second;
sessions[targetUserID] =
std::string(sessionData.begin(), sessionData.end());
@marcinwasowicz
marcinwasowicz / gist:4a794560ef7cdac30dc15da75918a99d
Created September 14, 2023 09:45
Text Android encrypted notifications coalescing
diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js
index 894dbf0a4..181c52db8 100644
--- a/keyserver/src/push/send.js
+++ b/keyserver/src/push/send.js
@@ -912,14 +912,14 @@ async function prepareAndroidNotification(
dbID,
} = convertedData;
- const isTextNotification = newRawMessageInfos.every(
- newRawMessageInfo => newRawMessageInfo.type === messageTypes.TEXT,
@marcinwasowicz
marcinwasowicz / gist:5011d3c1d5418e1a3af06f6be182e739
Created September 13, 2023 13:59
Send each notif twice to trigger olm error on iOS.
diff --git a/keyserver/src/push/utils.js b/keyserver/src/push/utils.js
index d9c9b2955..1be2e148f 100644
--- a/keyserver/src/push/utils.js
+++ b/keyserver/src/push/utils.js
@@ -61,11 +61,14 @@ async function apnPush({
}
invariant(apnProvider, `keyserver/secrets/${pushProfile}.json should exist`);
- const results = await Promise.all(
- targetedNotifications.map(({ notification, deviceToken }) => {
@marcinwasowicz
marcinwasowicz / gist:a318bb475e575df662429702905b4a01
Created September 12, 2023 12:14
Keyserver changes to test encrypted notifications coalescing on the keyserver
diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js
index 7c705a864..78fddfe24 100644
--- a/keyserver/src/push/send.js
+++ b/keyserver/src/push/send.js
@@ -714,14 +714,14 @@ async function prepareAPNsNotification(
platformDetails,
} = convertedData;
- const isTextNotification = newRawMessageInfos.every(
- newRawMessageInfo => newRawMessageInfo.type === messageTypes.TEXT,
@marcinwasowicz
marcinwasowicz / gist:4cca17794123b110134bf393d21e0b14
Created August 22, 2023 13:51
Modify NSE to decrypt each notification field on separate thread.
diff --git a/native/ios/NotificationService/NotificationService.mm b/native/ios/NotificationService/NotificationService.mm
index be7a02838..c623e7ef2 100644
--- a/native/ios/NotificationService/NotificationService.mm
+++ b/native/ios/NotificationService/NotificationService.mm
@@ -200,13 +200,17 @@ CFStringRef newMessageInfosDarwinNotification =
}
- (void)decryptBestAttemptContent {
- NSString *decryptedSerializedPayload = [self
- singleDecrypt:self.bestAttemptContent.userInfo[encryptedPayloadKey]];
@marcinwasowicz
marcinwasowicz / gist:a18b31f8bee1d56cc50fb71809077dcb
Created August 22, 2023 13:50
Modify keyserver to encrypt iOS notification field by field
@@ -40,30 +40,17 @@ async function encryptIOSNotification(
};
try {
- const unencryptedSerializedPayload = JSON.stringify(unencryptedPayload);
+ const { encryptedMessages: encryptedPayload, dbPersistConditionViolated } =
+ await encryptAndUpdateOlmSession(
+ cookieID,
+ 'notifications',
+ unencryptedPayload,
@marcinwasowicz
marcinwasowicz / gist:38435924b5850515649253a2e490572e
Created August 14, 2023 10:03
Test `PlatformSpecificTools#isStaffRelease`
diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java b/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java
index c0b158d98..d15f8919f 100644
--- a/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java
+++ b/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java
@@ -23,6 +23,7 @@ import app.comm.android.fbjni.GlobalDBSingleton;
import app.comm.android.fbjni.MessageOperationsUtilities;
import app.comm.android.fbjni.NetworkModule;
import app.comm.android.fbjni.NotificationsCryptoModule;
+import app.comm.android.fbjni.PlatformSpecificTools;
import app.comm.android.fbjni.ThreadOperations;
@marcinwasowicz
marcinwasowicz / gist:8fa40faca25c52403d87a91d9333e1f2
Created July 29, 2023 11:29
Dirty code to test blob service fetch from NSE.
diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js
index dcea65c21..3c75fe9c9 100644
--- a/keyserver/src/push/send.js
+++ b/keyserver/src/push/send.js
@@ -732,12 +732,37 @@ async function prepareAPNsNotification(
platformDetails.codeVersion > 222
) {
const cookieIDs = devices.map(({ cookieID }) => cookieID);
- const [notifications, notificationsWithMessageInfos] = await Promise.all([
- prepareEncryptedIOSNotifications(cookieIDs, notification),