From 8f476a279357f1141f4a21427a0a2b36552329d1 Mon Sep 17 00:00:00 2001 From: vinkabuki Date: Tue, 17 Oct 2023 13:12:29 +0200 Subject: [PATCH] Secure socketIO connection on iOS --- packages/mobile/ios/CommunicationModule.swift | 4 ++-- packages/mobile/ios/Quiet/AppDelegate.h | 2 ++ packages/mobile/ios/Quiet/AppDelegate.m | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/mobile/ios/CommunicationModule.swift b/packages/mobile/ios/CommunicationModule.swift index 6b5fb1821a..75c132e14b 100644 --- a/packages/mobile/ios/CommunicationModule.swift +++ b/packages/mobile/ios/CommunicationModule.swift @@ -10,8 +10,8 @@ class CommunicationModule: RCTEventEmitter { static let WEBSOCKET_CONNECTION_CHANNEL = "_WEBSOCKET_CONNECTION_" @objc - func sendDataPort(port: UInt16) { - self.sendEvent(withName: CommunicationModule.BACKEND_EVENT_IDENTIFIER, body: ["channelName": CommunicationModule.WEBSOCKET_CONNECTION_CHANNEL, "payload": ["dataPort": port]]) + func sendDataPort(port: UInt16, socketIOSecret: String) { + self.sendEvent(withName: CommunicationModule.BACKEND_EVENT_IDENTIFIER, body: ["channelName": CommunicationModule.WEBSOCKET_CONNECTION_CHANNEL, "payload": ["dataPort": port, "socketIOSecret": socketIOSecret]]) } @objc diff --git a/packages/mobile/ios/Quiet/AppDelegate.h b/packages/mobile/ios/Quiet/AppDelegate.h index 0f44aa8b5e..51fed2c14d 100644 --- a/packages/mobile/ios/Quiet/AppDelegate.h +++ b/packages/mobile/ios/Quiet/AppDelegate.h @@ -12,6 +12,8 @@ @property uint16_t dataPort; +@property NSString *socketIOSecret; + @property NSString *dataPath; @property RCTBridge *bridge; diff --git a/packages/mobile/ios/Quiet/AppDelegate.m b/packages/mobile/ios/Quiet/AppDelegate.m index 9f3984ca96..f7adb5b739 100644 --- a/packages/mobile/ios/Quiet/AppDelegate.m +++ b/packages/mobile/ios/Quiet/AppDelegate.m @@ -104,7 +104,7 @@ - (void) initWebsocketConnection { NSTimeInterval delayInSeconds = 5; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void) { - [[self.bridge moduleForName:@"CommunicationModule"] sendDataPortWithPort:self.dataPort]; + [[self.bridge moduleForName:@"CommunicationModule"] sendDataPortWithPort:self.dataPort socketIOSecret:self.socketIOSecret]; }); }); } @@ -116,6 +116,7 @@ - (void) spinupBackend:(BOOL)init { FindFreePort *findFreePort = [FindFreePort new]; self.dataPort = [findFreePort getFirstStartingFromPort:11000]; + self.socketIOSecret = @"SECRET"; uint16_t socksPort = [findFreePort getFirstStartingFromPort:12000]; uint16_t controlPort = [findFreePort getFirstStartingFromPort:14000]; @@ -196,7 +197,7 @@ - (NSData *) getAuthCookieData { - (void) launchBackend:(uint16_t)controlPort:(uint16_t)httpTunnelPort:(NSString *)authCookie { self.nodeJsMobile = [RNNodeJsMobile new]; - [self.nodeJsMobile callStartNodeProject:[NSString stringWithFormat:@"bundle.cjs --dataPort %hu --dataPath %@ --controlPort %hu --httpTunnelPort %hu --authCookie %@ --platform %@", self.dataPort, self.dataPath, controlPort, httpTunnelPort, authCookie, platform]]; + [self.nodeJsMobile callStartNodeProject:[NSString stringWithFormat:@"bundle.cjs --dataPort %hu --dataPath %@ --controlPort %hu --httpTunnelPort %hu --authCookie %@ --platform %@ --socketIOSecret %@", self.dataPort, self.dataPath, controlPort, httpTunnelPort, authCookie, platform, self.socketIOSecret]]; } - (void) reviweServices:(uint16_t)controlPort:(uint16_t)httpTunnelPort:(NSString *)authCookie {