darkwing/server/services/browser_profile_services/config/
additional.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! Browser profile additional configuration module
//!
//! This module contains structures and implementations for handling additional
//! browser profile configuration settings like WebRTC, canvas noise, platform
//! specifics, and various feature flags.

use crate::{
  database::browser_profile::{MainWebsite, Platform},
  server::{
    dtos::{
      browser_profile_dto::{BrowserProfileFullData, Canvas, Mode},
      start_dto::StartRequest,
    },
    error::Error,
  },
};
use serde::{Deserialize, Serialize};

use super::{FromStartRequest, Navigator, Screen};

/// Additional configuration settings for a browser profile
///
/// Contains various settings that control browser behavior and appearance,
/// including WebRTC configuration, canvas/WebGL settings, platform-specific
/// flags, and profile display options.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Additional {
  pub(super) is_chrome_icon: bool,
  pub(super) accelerated_2d_canvas: bool,
  pub(super) profile_name: String,
  pub(super) rect_noise: f64,
  pub(super) is_webrtc_enabled: bool,
  pub(super) webrtc_ip: String,
  pub(super) is_windows: bool,
  pub(super) is_win10: bool,
  pub(super) is_fake_media: bool,
  pub(super) profile_icon: i8,
  pub(super) is_canvas_blocked: bool,
  pub(super) ostype: i8,
  pub(super) canvas_noise_seed: i32,
  pub(super) webgl_noise_seed: i32,
  pub(super) extensions_new_naming: bool,
  pub(super) smart_paste_shift: f32,
  pub(super) is_real_webrtc: bool,
  pub(super) is_webrtc_connection_enabled: bool,
  pub(super) is_webrtc_realtime_ip_update_enabled: bool,
  pub(super) should_show_profile_name: bool,
}

/// Implementation of the FromStartRequest trait for Additional configuration
///
/// This implementation creates an Additional configuration from a browser
/// profile, start request, and other parameters. It handles the logic for
/// setting up WebRTC, canvas/WebGL noise, platform-specific settings, and other
/// configuration options.
impl FromStartRequest<Additional> for Additional {
  /// Creates an Additional configuration from the provided parameters
  ///
  /// # Arguments
  ///
  /// * `bp` - The full browser profile data
  /// * `request` - The start request containing connection information
  /// * `_navigator` - Navigator configuration (unused)
  /// * `_screen` - Screen configuration (unused)
  /// * `_token` - Authentication token (unused)
  ///
  /// # Returns
  ///
  /// Returns a Result containing the Additional configuration or an Error
  fn from_start_request(
    bp: &BrowserProfileFullData,
    request: &StartRequest,
    _navigator: &Navigator,
    _screen: &Screen,
    _token: &str,
  ) -> Result<Self, Error> {
    let is_webrtc_enabled = bp.webrtc.mode != Mode::Off;

    let connection_info_ip = request.connection_info.ip.clone();

    let webrtc_ip = match bp.webrtc.mode {
      Mode::Manual => {
        bp.webrtc.ip_address.as_ref().unwrap_or(&connection_info_ip)
      }
      Mode::Altered => &connection_info_ip,
      _ => &connection_info_ip, /* TODO(@tltsutltsu): what we should do in
                                 * that case? any other possible modes? check
                                 * in prod DB */
    };

    let is_win10 = bp.platform == Platform::Windows
      && !bp.platform_version.is_empty()
      && bp.platform_version != "15.0.0";

    let is_canvas_blocked = bp.canvas.mode == Mode::Off;

    let rect_noise = bp
      .client_rect
      .noise
      .as_ref()
      .map(|noise| {
        if noise.is_empty() {
          vec![1.0]
        } else {
          noise.clone()
        }
      })
      .unwrap_or(vec![1.0]);

    let is_fake_media = bp.media_devices.mode == Mode::Manual;
    let is_windows = bp.platform == Platform::Windows;

    let profile_icon = match bp.main_website {
      MainWebsite::Vk => 1,
      MainWebsite::Facebook => 2,
      MainWebsite::Tiktok => 3,
      MainWebsite::Google => 4,
      MainWebsite::Empty => 0,
      _ => 0,
    };

    let os_type = match bp.platform {
      Platform::Windows => 0,
      Platform::Macos => 1,
      Platform::Linux => 2,
    };

    let canvas_noise_seed = match &bp.canvas {
      Canvas {
        mode: Mode::Noise,
        noise: Some(noise),
      } if noise.len() > 1 => {
        ((noise[0] as f64 * noise[1] as f64 * (198352939.0 / 100.0)) as i32)
          .abs()
      }
      _ => 0,
    };

    let mut webgl_noise_seed = 0;

    if bp.webgl.mode == Mode::Noise {
      if let Some(noise) = &bp.webgl.noise {
        if noise.len() > 1 {
          let mut noise_0 = noise[0];
          let mut noise_1 = noise[1];

          // Ensure noise values are not 0
          if noise_0 == 0.0 {
            noise_0 = 1.0;
          }
          if noise_1 == 0.0 {
            noise_1 = 1.0;
          }

          webgl_noise_seed =
            ((noise_0 as f64 * noise_1 as f64 * (198352939.0 / 100.0)) as i32)
              .abs();
        }
      }
    }

    let is_real_webrtc = bp.webrtc.mode == Mode::Real;

    let is_webrtc_connection_enabled =
      bp.webrtc.mode == Mode::Real && bp.proxy.is_some();

    let is_webrtc_realtime_ip_update_enabled = bp.webrtc.mode != Mode::Manual;

    Ok(Self {
      is_chrome_icon: false,
      accelerated_2d_canvas: true, // always true, from the original code
      profile_name: bp.name.clone(),
      rect_noise: rect_noise[0],
      is_webrtc_enabled,
      webrtc_ip: webrtc_ip.clone(),
      is_windows,
      is_win10,
      is_fake_media,
      profile_icon,
      is_canvas_blocked,
      ostype: os_type,
      canvas_noise_seed,
      webgl_noise_seed,
      extensions_new_naming: true, // always true, historic parameter
      smart_paste_shift: 1.05,     // always 1.05, from the original code
      is_real_webrtc,
      is_webrtc_connection_enabled,
      is_webrtc_realtime_ip_update_enabled,
      should_show_profile_name: !bp.is_hidden_profile_name,
    })
  }
}