Skip to content

Commit

Permalink
Secure socketIO connection on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkabuki committed Oct 17, 2023
1 parent 32b564a commit 8f476a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/mobile/ios/CommunicationModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/mobile/ios/Quiet/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@property uint16_t dataPort;

@property NSString *socketIOSecret;

@property NSString *dataPath;

@property RCTBridge *bridge;
Expand Down
5 changes: 3 additions & 2 deletions packages/mobile/ios/Quiet/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
});
}
Expand All @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8f476a2

Please sign in to comment.