Skip to content

Fix PN metadata leak, PN navigation to chat, and unexpected PNs from other accounts #6893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ logger_settings.ini
conan*.txt
conanbuildinfo.*
conan.cmake
/default.realm/
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ android-ports: ##@other Add proxies to Android Device/Simulator
adb reverse tcp:4567 tcp:4567
adb forward tcp:5561 tcp:5561

android-logcat:
adb logcat | grep -e StatusModule -e ReactNativeJS -e StatusNativeLogs

startdev-%:
$(eval SYSTEM := $(word 2, $(subst -, , $@)))
Expand Down
2 changes: 1 addition & 1 deletion STATUS_GO_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181221-204011-e80de6
0.19.0-beta.1
4 changes: 4 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

# Firebase
-keep class io.invertase.firebase.** { *; }
-dontwarn io.invertase.firebase.**
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.ios
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pipeline {
timestamps()
disableConcurrentBuilds()
/* Prevent Jenkins jobs from running forever */
timeout(time: 35, unit: 'MINUTES')
timeout(time: 45, unit: 'MINUTES')
/* Limit builds retained */
buildDiscarder(logRotator(
numToKeepStr: '10',
Expand Down
33 changes: 17 additions & 16 deletions doc/codebase-structure-and-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Each business logic module is managed in a module directory.

*There is no rigid structure on how to organize code inside modules outside of core and db namespaces*

```
```txt
- events.cljs
- subs.cljs
- notifications
Expand Down Expand Up @@ -37,13 +37,13 @@ Core namespace must only contain functions that can be called outside of the mod

- fx producing functions called by events and other modules

```clojure
(def get-current-account
module.db/get-current-account)
```clojure
(def get-current-account
module.db/get-current-account)

(defn set-current-account [{db :db :as cofx}]
{:db (module.db/set-current-account db)})
```
(defn set-current-account [{db :db :as cofx}]
{:db (module.db/set-current-account db)})
```

## db.cljs

Expand All @@ -61,13 +61,14 @@ These guidelines make db.cljs namespaces the place to go when making changes to
- events must always be declared with `register-handler-fx`, no `register-handler-db`
- events must never use the `trim-v` interceptor
- events must only contain a function call defined in a module
```clojure
(handlers/register-handler-fx
:notifications/handle-push-notification
(fn [cofx [_ event]]
(notifications/handle-push-notification event cofx)))
```
```clojure
(handlers/register-handler-fx
:notifications/handle-push-notification-open
(fn [cofx [_ event]]
(notifications/handle-push-notification-open event cofx)))
```
- events must use synthetic namespaces:
- `:module.ui/` for user triggered events
- `:module.callback/` for callback events, which are events bringing back the result of an fx to the event loop, the name of the event should end with `-success` or `-error` most of the time. Other possibilities can be `-granted`, `-denied` for instance.
- `:module/` for internal events, examples are time based events marked `-timed-out`, external changes marked `-changed` or reception of external events marked `-received`.

- `:module.ui/` for user triggered events
- `:module.callback/` for callback events, which are events bringing back the result of an fx to the event loop, the name of the event should end with `-success` or `-error` most of the time. Other possibilities can be `-granted`, `-denied` for instance.
- `:module/` for internal events, examples are time based events marked `-timed-out`, external changes marked `-changed` or reception of external events marked `-received`.
4 changes: 2 additions & 2 deletions mobile_files/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6005,8 +6005,8 @@ react-native-splash-screen@3.1.1:
integrity sha512-PU2YocOSGbLjL9Vgcq/cwMNuHHKNjjuPpa1IPMuWo+6EB/fSZ5VOmxSa7+eucQe3631s3NhGuk3eHKahU03a4Q==

"react-native-status-keycard@https://github.com/status-im/react-native-status-keycard":
version "2.0.1"
resolved "https://github.com/status-im/react-native-status-keycard#5a16166a97035d4edf94ad5278910df5740a4361"
version "2.0.2"
resolved "https://github.com/status-im/react-native-status-keycard#b2cf1b0a7ab98246e331aa8a048e6e1ca7dfa197"

react-native-svg@6.5.2:
version "6.5.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ QList<ModuleMethod *> DesktopNotification::methodsToExport() {

QVariantMap DesktopNotification::constantsToExport() { return QVariantMap(); }

void DesktopNotification::sendNotification(QString title, QString body, bool prioritary) {
void DesktopNotification::displayNotification(QString title, QString body, bool prioritary) {
Q_D(DesktopNotification);
qCDebug(NOTIFICATION) << "::sendNotification";
qCDebug(NOTIFICATION) << "::displayNotification";

if (m_appHasFocus) {
qCDebug(NOTIFICATION) << "Not sending notification since an application window is active";
qCDebug(NOTIFICATION) << "Not displaying notification since an application window is active";
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DesktopNotification : public QObject, public ModuleInterface {
QList<ModuleMethod*> methodsToExport() override;
QVariantMap constantsToExport() override;

Q_INVOKABLE void sendNotification(QString title, QString body, bool prioritary);
Q_INVOKABLE void displayNotification(QString title, QString body, bool prioritary);
Q_INVOKABLE void setDockBadgeLabel(const QString label);
private:
QScopedPointer<DesktopNotificationPrivate> d_ptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public String getName() {
}

@Override
public void onHostResume() { // Actvity `onResume`
public void onHostResume() { // Activity `onResume`
module = this;
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
Expand Down Expand Up @@ -459,7 +459,7 @@ public void run() {
}

@ReactMethod
public void notifyUsers(final String message, final String payloadJSON, final String tokensJSON, final Callback callback) {
public void notifyUsers(final String dataPayloadJSON, final String tokensJSON, final Callback callback) {
Log.d(TAG, "notifyUsers");
if (!checkAvailability()) {
callback.invoke(false);
Expand All @@ -469,7 +469,7 @@ public void notifyUsers(final String message, final String payloadJSON, final St
Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.NotifyUsers(message, payloadJSON, tokensJSON);
String res = Statusgo.NotifyUsers(dataPayloadJSON, tokensJSON);

callback.invoke(res);
}
Expand Down
8 changes: 4 additions & 4 deletions modules/react-native-status/desktop/rctstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ void RCTStatus::createAccount(QString password, double callbackId) {
}


void RCTStatus::notifyUsers(QString token, QString payloadJSON, QString tokensJSON, double callbackId) {
void RCTStatus::notifyUsers(QString dataPayloadJSON, QString tokensJSON, double callbackId) {
Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::notifyUsers call - callbackId:" << callbackId;
QtConcurrent::run([&](QString token, QString payloadJSON, QString tokensJSON, double callbackId) {
const char* result = NotifyUsers(token.toUtf8().data(), payloadJSON.toUtf8().data(), tokensJSON.toUtf8().data());
QtConcurrent::run([&](QString dataPayloadJSON, QString tokensJSON, double callbackId) {
const char* result = NotifyUsers(dataPayloadJSON.toUtf8().data(), tokensJSON.toUtf8().data());
logStatusGoResult("::notifyUsers Notify", result);
d->bridge->invokePromiseCallback(callbackId, QVariantList{result});
}, token, payloadJSON, tokensJSON, callbackId);
}, dataPayloadJSON, tokensJSON, callbackId);
}


Expand Down
2 changes: 1 addition & 1 deletion modules/react-native-status/desktop/rctstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RCTStatus : public QObject, public ModuleInterface {
Q_INVOKABLE void startNode(QString configString);
Q_INVOKABLE void stopNode();
Q_INVOKABLE void createAccount(QString password, double callbackId);
Q_INVOKABLE void notifyUsers(QString token, QString payloadJSON, QString tokensJSON, double callbackId);
Q_INVOKABLE void notifyUsers(QString dataPayloadJSON, QString tokensJSON, double callbackId);
Q_INVOKABLE void sendLogs(QString dbJSON);
Q_INVOKABLE void addPeer(QString enode, double callbackId);
Q_INVOKABLE void recoverAccount(QString passphrase, QString password, double callbackId);
Expand Down
5 changes: 2 additions & 3 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,10 @@ -(void)setBridge:(RCTBridge *)newBridge
////////////////////////////////////////////////////////////////////
#pragma mark - NotifyUsers method
//////////////////////////////////////////////////////////////////// notifyUsers
RCT_EXPORT_METHOD(notifyUsers:(NSString *)message
payloadJSON:(NSString *)payloadJSON
RCT_EXPORT_METHOD(notifyUsers:(NSString *)dataPayloadJSON
tokensJSON:(NSString *)tokensJSON
callback:(RCTResponseSenderBlock)callback) {
char * result = NotifyUsers((char *) [message UTF8String], (char *) [payloadJSON UTF8String], (char *) [tokensJSON UTF8String]);
char * result = NotifyUsers((char *) [dataPayloadJSON UTF8String], (char *) [tokensJSON UTF8String]);
callback(@[[NSString stringWithUTF8String: result]]);
#if DEBUG
NSLog(@"NotifyUsers() method called");
Expand Down
8 changes: 4 additions & 4 deletions scripts/start-react-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ YELLOW='\033[1;33m'
NC='\033[0m'

METRO_PORT=8081
METRO_PID="$(lsof -i :${METRO_PORT} | awk 'NR!=1 {print $2}')"
if [ ! -z $METRO_PID ]; then
echo -e "${YELLOW}TCP port ${METRO_PORT} is required by the Metro packager.\nThe following process currently has the port open, preventing Metro from starting:${NC}"
METRO_PID="$(lsof -i :${METRO_PORT} | awk 'NR!=1 {print $2}' | sort -u | tr '\r\n' ' ')"
if [ ! -z "$METRO_PID" ]; then
echo -e "${YELLOW}TCP port ${METRO_PORT} is required by the Metro packager.\nThe following processes currently have the port open, preventing Metro from starting:${NC}"
ps -fp $METRO_PID
echo -e "${YELLOW}Do you want to terminate it (y/n)?${NC}"
echo -e "${YELLOW}Do you want to terminate them (y/n)?${NC}"
read -n 1 term
[[ $term == 'y' ]] && kill $METRO_PID
fi
Expand Down
45 changes: 18 additions & 27 deletions src/status_im/chat/models/message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
(get-in db [:account/account :desktop-notifications?])
(< (time/seconds-ago (time/to-date timestamp)) constants/one-earth-day))
(let [{:keys [title body prioritary?]} (build-desktop-notification cofx message)]
(.sendNotification react/desktop-notification title body prioritary?)))
(.displayNotification react/desktop-notification title body prioritary?)))
(fx/merge cofx
{:db (cond->
(-> db
Expand Down Expand Up @@ -156,19 +156,6 @@
message
(assoc message :clock-value (utils.clocks/send last-clock-value))))

(fx/defn display-notification
[cofx chat-id]
(when config/in-app-notifications-enabled?
(let [view-id (get-in cofx [:db :view-id])
from (accounts.db/current-public-key cofx)
current-chat-id (get-in cofx [:db :current-chat-id])]
(when-not (and (= :chat view-id)
(= current-chat-id chat-id))
{:notifications/display-notification {:title (i18n/label :notifications-new-message-title)
:body (i18n/label :notifications-new-message-body)
:to chat-id
:from from}}))))

(defn check-response-to
[{{:keys [response-to response-to-v2]} :content :as message}
old-id->message]
Expand Down Expand Up @@ -208,7 +195,6 @@
current-chat? :seen
:else :received))
(commands-receiving/receive message)
(display-notification chat-id)
(send-message-seen chat-id message-id (and (not group-chat)
current-chat?
(not (= constants/system from))
Expand Down Expand Up @@ -389,14 +375,14 @@
(add-own-status chat-id message-id :sending)
(send chat-id message-id wrapped-record))))

(fx/defn send-push-notification [cofx fcm-token status]
(fx/defn send-push-notification [cofx message-id fcm-token status]
(log/debug "#6772 - send-push-notification" message-id fcm-token)
(when (and fcm-token (= status :sent))
{:send-notification {:message (js/JSON.stringify #js {:from (accounts.db/current-public-key cofx)
:to (get-in cofx [:db :current-chat-id])})
:payload {:title (i18n/label :notifications-new-message-title)
:body (i18n/label :notifications-new-message-body)
:sound notifications/sound-name}
:tokens [fcm-token]}}))
(let [payload {:from (accounts.db/current-public-key cofx)
:to (get-in cofx [:db :current-chat-id])
:id message-id}]
{:send-notification {:data-payload (notifications/encode-notification-payload payload)
:tokens [fcm-token]}})))

(fx/defn update-message-status [{:keys [db]} chat-id message-id status]
(let [from (get-in db [:chats chat-id :messages message-id :from])
Expand Down Expand Up @@ -477,8 +463,13 @@

(re-frame/reg-fx
:send-notification
(fn [{:keys [message payload tokens]}]
(let [payload-json (types/clj->json payload)
tokens-json (types/clj->json tokens)]
(log/debug "send-notification message: " message " payload-json: " payload-json " tokens-json: " tokens-json)
(status/notify-users {:message message :payload payload-json :tokens tokens-json} #(log/debug "send-notification cb result: " %)))))
(fn [{:keys [data-payload tokens]}]
"Sends a notification to another device. data-payload is a Clojure map of strings to strings"
(let [data-payload-json (types/clj->json data-payload)
tokens-json (types/clj->json tokens)]
(log/debug "send-notification data-payload-json:" data-payload-json "tokens-json:" tokens-json)
;; NOTE: react-native-firebase doesn't have a good implementation of sendMessage
;; (supporting e.g. priority or content_available properties),
;; therefore we must use an implementation in status-go.
(status/notify-users {:data-payload data-payload-json :tokens tokens-json}
#(log/debug "send-notification cb result: " %)))))
6 changes: 5 additions & 1 deletion src/status_im/core.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(ns status-im.core
(:require [re-frame.core :as re-frame]
[status-im.utils.error-handler :as error-handler]
[status-im.utils.platform :as platform]
[status-im.ui.components.react :as react]
[status-im.notifications.background :as background-messaging]
[reagent.core :as reagent]
status-im.transport.impl.receive
status-im.transport.impl.send
Expand All @@ -18,4 +20,6 @@
(log/set-level! config/log-level)
(error-handler/register-exception-handler!)
(re-frame/dispatch [:init/app-started])
(.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root)))
(.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root))
(when platform/android?
(.registerHeadlessTask react/app-registry "RNFirebaseBackgroundMessage" background-messaging/message-handler-fn)))
11 changes: 8 additions & 3 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,9 @@
;; notifications module

(handlers/register-handler-fx
:notifications/notification-event-received
(fn [cofx [_ event]]
(notifications/handle-push-notification cofx event)))
:notifications/notification-open-event-received
(fn [cofx [_ decoded-payload ctx]]
(notifications/handle-push-notification-open cofx decoded-payload ctx)))

(handlers/register-handler-fx
:notifications.callback/get-fcm-token-success
Expand All @@ -842,6 +842,11 @@
(fn [cofx _]
(accounts/show-mainnet-is-default-alert cofx)))

(handlers/register-handler-fx
:notifications.callback/on-message
(fn [cofx [_ decoded-payload opts]]
(notifications/handle-on-message cofx decoded-payload opts)))

;; hardwallet module

(handlers/register-handler-fx
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/hardwallet/card.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
(then #(re-frame/dispatch [:hardwallet.callback/check-nfc-support-success %])))))

(defn check-nfc-enabled []
(when platform/android?
(when (and platform/android?
config/hardwallet-enabled?)
(.. keycard
nfcIsEnabled
(then #(re-frame/dispatch [:hardwallet.callback/check-nfc-enabled-success %])))))
Expand Down
Loading