From 7ea5a0b07a5da20248a89edebf7d76ed8766b66b Mon Sep 17 00:00:00 2001 From: Vin Kabuki Date: Thu, 14 Sep 2023 14:15:05 +0200 Subject: [PATCH] Add method for dynamic auth cookie --- packages/backend/src/backendManager.ts | 4 +--- packages/backend/src/nest/tor/tor-control.service.ts | 9 ++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/backendManager.ts b/packages/backend/src/backendManager.ts index fe951d4cc3..9f3e9e21c6 100644 --- a/packages/backend/src/backendManager.ts +++ b/packages/backend/src/backendManager.ts @@ -94,8 +94,7 @@ export const runBackendMobile = async (): Promise => { const rn_bridge = initRnBridge() - let app: INestApplicationContext - app = await NestFactory.createApplicationContext( + const app: INestApplicationContext = await NestFactory.createApplicationContext( AppModule.forOptions({ socketIOPort: options.dataPort, httpTunnelPort: options.httpTunnelPort ? options.httpTunnelPort : null, @@ -118,7 +117,6 @@ export const runBackendMobile = async (): Promise => { }) rn_bridge.channel.on('open', async (msg: OpenServices) => { const connectionsManager = app.get(ConnectionsManagerService) - // BARTEK: Ugly temporary solution - we should update provider instead directly replacing value! const torControlParams = app.get(TorControl) torControlParams.torControlParams.auth.value = msg.authCookie await connectionsManager.openSocket() diff --git a/packages/backend/src/nest/tor/tor-control.service.ts b/packages/backend/src/nest/tor/tor-control.service.ts index 755ecfdcd9..5fa1426bea 100644 --- a/packages/backend/src/nest/tor/tor-control.service.ts +++ b/packages/backend/src/nest/tor/tor-control.service.ts @@ -1,4 +1,4 @@ -import { Inject, Injectable, OnModuleInit } from '@nestjs/common' +import { Inject, Injectable } from '@nestjs/common' import net from 'net' import { CONFIG_OPTIONS, TOR_CONTROL_PARAMS } from '../const' import { ConfigOptions } from '../types' @@ -6,7 +6,7 @@ import { TorControlAuthType, TorControlParams } from './tor.types' import Logger from '../common/logger' @Injectable() -export class TorControl implements OnModuleInit { +export class TorControl { connection: net.Socket | null authString: string private readonly logger = Logger(TorControl.name) @@ -15,7 +15,7 @@ export class TorControl implements OnModuleInit { @Inject(CONFIG_OPTIONS) public configOptions: ConfigOptions ) {} - onModuleInit() { + private updateAuthString() { if (this.torControlParams.auth.type === TorControlAuthType.PASSWORD) { this.authString = 'AUTHENTICATE "' + this.torControlParams.auth.value + '"\r\n' } @@ -46,8 +46,7 @@ export class TorControl implements OnModuleInit { reject(new Error(`TOR: Control port error: ${data.toString() as string}`)) } }) - // BARTEK - Add support for dynamic authCookie - this.onModuleInit() + this.updateAuthString() this.connection.write(this.authString) }) }