Skip to content

Commit

Permalink
Add method for dynamic auth cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkabuki committed Sep 14, 2023
1 parent 6c08670 commit 7ea5a0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 1 addition & 3 deletions packages/backend/src/backendManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export const runBackendMobile = async (): Promise<any> => {

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,
Expand All @@ -118,7 +117,6 @@ export const runBackendMobile = async (): Promise<any> => {
})
rn_bridge.channel.on('open', async (msg: OpenServices) => {
const connectionsManager = app.get<ConnectionsManagerService>(ConnectionsManagerService)
// BARTEK: Ugly temporary solution - we should update provider instead directly replacing value!
const torControlParams = app.get<TorControl>(TorControl)
torControlParams.torControlParams.auth.value = msg.authCookie
await connectionsManager.openSocket()
Expand Down
9 changes: 4 additions & 5 deletions packages/backend/src/nest/tor/tor-control.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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'
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)
Expand All @@ -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'
}
Expand Down Expand Up @@ -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)
})
}
Expand Down

0 comments on commit 7ea5a0b

Please sign in to comment.