Skip to content

Commit

Permalink
Revert "WIP: secure sockets mobile"
Browse files Browse the repository at this point in the history
This reverts commit 7f0af19.
  • Loading branch information
Kacper-RF committed Oct 13, 2023
1 parent 1042867 commit af71cee
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/nest/socket/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SaveCSRPayload,
CommunityMetadata,
} from '@quiet/types'
import cors, { CorsOptions } from 'cors'
import EventEmitter from 'events'
import { CONFIG_OPTIONS, SERVER_IO_PROVIDER } from '../const'
import { ConfigOptions, ServerIoProviderTypes } from '../types'
Expand Down Expand Up @@ -202,7 +203,6 @@ export class SocketService extends EventEmitter implements OnModuleInit {
this.logger(`Creating network for community ${community.id}`)
this.emit(SocketActionTypes.CREATE_NETWORK, community)
})

socket.on(SocketActionTypes.LEAVE_COMMUNITY, async () => {
this.logger('Leaving community')
this.emit(SocketActionTypes.LEAVE_COMMUNITY)
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/renderer/sagas/socket/socket.saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function subscribeSocketLifecycle(socket?: Socket) {
console.log('closing socket connection')
emit(socketActions.suspendConnection())
})
return () => { }
return () => {}
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class BackendWorker(private val context: Context, workerParams: WorkerParameters
withContext(Dispatchers.IO) {
// Get and store data port for usage in methods across the app
val dataPort = Utils.getOpenPort(11000)
val socketIOSecret = "secret"

// Init nodejs project
launch {
Expand All @@ -113,7 +112,7 @@ class BackendWorker(private val context: Context, workerParams: WorkerParameters
* In any case, websocket won't connect until data server starts listening
*/
delay(WEBSOCKET_CONNECTION_DELAY)
startWebsocketConnection(dataPort, socketIOSecret)
startWebsocketConnection(dataPort)
}

val dataPath = Utils.createDirectory(context)
Expand All @@ -123,7 +122,7 @@ class BackendWorker(private val context: Context, workerParams: WorkerParameters

val platform = "mobile"

startNodeProjectWithArguments("bundle.cjs --torBinary $torBinary --dataPath $dataPath --dataPort $dataPort --platform $platform --socketIOSecret $socketIOSecret")
startNodeProjectWithArguments("bundle.cjs --torBinary $torBinary --dataPath $dataPath --dataPort $dataPort --platform $platform")
}

println("FINISHING BACKEND WORKER")
Expand Down Expand Up @@ -191,10 +190,10 @@ class BackendWorker(private val context: Context, workerParams: WorkerParameters
notificationHandler.notify(message, username)
}

private fun startWebsocketConnection(port: Int, socketIOSecret: Any) {
private fun startWebsocketConnection(port: Int) {
Log.d("WEBSOCKET CONNECTION", "Starting on $port")
// Proceed only if data port is defined
val websocketConnectionPayload = WebsocketConnectionPayload(port, socketIOSecret)
val websocketConnectionPayload = WebsocketConnectionPayload(port)
CommunicationModule.handleIncomingEvents(
CommunicationModule.WEBSOCKET_CONNECTION_CHANNEL,
Gson().toJson(websocketConnectionPayload),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.quietmobile.Scheme

data class WebsocketConnectionPayload (
val dataPort: Int,
val socketIOSecret: Any
val dataPort: Int
)
1 change: 0 additions & 1 deletion packages/mobile/src/store/init/init.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface InitCheckPayload {

export interface WebsocketConnectionPayload {
dataPort: number
socketIOSecret?: string
}

export interface CloseConnectionPayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,17 @@ import { io, Socket } from 'socket.io-client'
import { put, call, cancel, fork, takeEvery, FixedTask } from 'typed-redux-saga'
import { PayloadAction } from '@reduxjs/toolkit'
import { socket as stateManager } from '@quiet/state-manager'
import { encodeSecret } from '@quiet/common'
import { initActions } from '../init.slice'
import { eventChannel } from 'redux-saga'

export function* startConnectionSaga(
action: PayloadAction<ReturnType<typeof initActions.startWebsocketConnection>['payload']>
): Generator {
const { dataPort, socketIOSecret } = action.payload
const { dataPort } = action.payload

console.log('socketIOSecret', socketIOSecret)

if (!socketIOSecret) return

const token = encodeSecret(socketIOSecret)
const socket = yield* call(io, `http://127.0.0.1:${dataPort}`, {
withCredentials: true,
extraHeaders: {
authorization: `Basic ${token}`,
},
})
const socket = yield* call(io, `http://127.0.0.1:${dataPort}`)
yield* fork(handleSocketLifecycleActions, socket, dataPort)

// Handle opening/restoring connection
yield* takeEvery(initActions.setWebsocketConnected, setConnectedSaga, socket)
}
Expand Down Expand Up @@ -56,7 +46,7 @@ function subscribeSocketLifecycle(socket: Socket, dataPort: number) {
console.log('closing socket connection')
emit(initActions.suspendWebsocketConnection())
})
return () => { }
return () => {}
})
}

Expand Down

0 comments on commit af71cee

Please sign in to comment.