| 1 | // Copyright 2020 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "DolphinQt/Debugger/NetworkWidget.h" |
| 5 | |
| 6 | #include <QCheckBox> |
| 7 | #include <QComboBox> |
| 8 | #include <QDesktopServices> |
| 9 | #include <QGridLayout> |
| 10 | #include <QGroupBox> |
| 11 | #include <QHeaderView> |
| 12 | #include <QLabel> |
| 13 | #include <QPushButton> |
| 14 | #include <QTableWidget> |
| 15 | #include <QUrl> |
| 16 | #include <QVBoxLayout> |
| 17 | |
| 18 | #ifdef _WIN32 |
| 19 | #include <winsock2.h> |
| 20 | #else |
| 21 | #include <sys/socket.h> |
| 22 | #endif |
| 23 | |
| 24 | #include <bit> |
| 25 | |
| 26 | #include "Common/FileUtil.h" |
| 27 | #include "Common/Network.h" |
| 28 | #include "Core/Config/MainSettings.h" |
| 29 | #include "Core/Core.h" |
| 30 | #include "Core/HW/DVD/AMMediaboard.h" |
| 31 | #include "Core/IOS/Network/SSL.h" |
| 32 | #include "Core/IOS/Network/Socket.h" |
| 33 | #include "Core/System.h" |
| 34 | #include "DolphinQt/Host.h" |
| 35 | #include "DolphinQt/Settings.h" |
| 36 | |
| 37 | namespace |
| 38 | { |
| 39 | QTableWidgetItem* GetSocketDomain(s32 host_fd) |
| 40 | { |
| 41 | if (host_fd < 0) |
| 42 | return new QTableWidgetItem(); |
| 43 | |
| 44 | sockaddr sa; |
| 45 | socklen_t sa_len = sizeof(sa); |
| 46 | const int ret = getsockname(host_fd, &sa, &sa_len); |
| 47 | if (ret != 0) |
| 48 | return new QTableWidgetItem(QTableWidget::tr("Unknown")); |
| 49 | |
| 50 | switch (sa.sa_family) |
| 51 | { |
| 52 | case 2: |
| 53 | return new QTableWidgetItem(QStringLiteral("AF_INET")); |
| 54 | case 23: |
| 55 | return new QTableWidgetItem(QStringLiteral("AF_INET6")); |
| 56 | default: |
| 57 | return new QTableWidgetItem(QString::number(sa.sa_family)); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | QTableWidgetItem* GetSocketType(s32 host_fd) |
| 62 | { |
| 63 | if (host_fd < 0) |
| 64 | return new QTableWidgetItem(); |
| 65 | |
| 66 | int so_type; |
| 67 | socklen_t opt_len = sizeof(so_type); |
| 68 | const int ret = |
| 69 | getsockopt(host_fd, SOL_SOCKET, SO_TYPE, reinterpret_cast<char*>(&so_type), &opt_len); |
| 70 | if (ret != 0) |
| 71 | return new QTableWidgetItem(QTableWidget::tr("Unknown")); |
| 72 | |
| 73 | switch (so_type) |
| 74 | { |
| 75 | case 1: |
| 76 | return new QTableWidgetItem(QStringLiteral("SOCK_STREAM")); |
| 77 | case 2: |
| 78 | return new QTableWidgetItem(QStringLiteral("SOCK_DGRAM")); |
| 79 | default: |
| 80 | return new QTableWidgetItem(QString::number(so_type)); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | QTableWidgetItem* GetSocketState(s32 host_fd) |
| 85 | { |
| 86 | if (host_fd < 0) |
| 87 | return new QTableWidgetItem(); |
| 88 | |
| 89 | sockaddr_in peer_addr; |
| 90 | socklen_t peer_addr_len = sizeof(sockaddr_in); |
| 91 | if (getpeername(host_fd, reinterpret_cast<sockaddr*>(&peer_addr), &peer_addr_len) == 0) |
| 92 | return new QTableWidgetItem(QTableWidget::tr("Connected")); |
| 93 | |
| 94 | int so_accept = 0; |
| 95 | socklen_t opt_len = sizeof(so_accept); |
| 96 | const int ret = |
| 97 | getsockopt(host_fd, SOL_SOCKET, SO_ACCEPTCONN, reinterpret_cast<char*>(&so_accept), &opt_len); |
| 98 | if (ret == 0 && so_accept > 0) |
| 99 | return new QTableWidgetItem(QTableWidget::tr("Listening")); |
| 100 | return new QTableWidgetItem(QTableWidget::tr("Unbound")); |
| 101 | } |
| 102 | |
| 103 | QTableWidgetItem* GetSocketBlocking(const IOS::HLE::WiiSockMan& socket_manager, s32 wii_fd) |
| 104 | { |
| 105 | if (socket_manager.GetHostSocket(wii_fd) < 0) |
| 106 | return new QTableWidgetItem(); |
| 107 | const bool is_blocking = socket_manager.IsSocketBlocking(wii_fd); |
| 108 | return new QTableWidgetItem(is_blocking ? QTableWidget::tr("Yes") : QTableWidget::tr("No")); |
| 109 | } |
| 110 | |
| 111 | QString GetAddressAndPort(const sockaddr_in& addr) |
| 112 | { |
| 113 | char buffer[16]; |
| 114 | const char* addr_str = inet_ntop(AF_INET, &addr.sin_addr, buffer, sizeof(buffer)); |
| 115 | if (!addr_str) |
| 116 | return {}; |
| 117 | |
| 118 | return QStringLiteral("%1:%2").arg(QString::fromLatin1(addr_str)).arg(ntohs(addr.sin_port)); |
| 119 | } |
| 120 | |
| 121 | QTableWidgetItem* GetSocketName(s32 host_fd) |
| 122 | { |
| 123 | if (host_fd < 0) |
| 124 | return new QTableWidgetItem(); |
| 125 | |
| 126 | sockaddr_in sock_addr; |
| 127 | socklen_t sock_addr_len = sizeof(sockaddr_in); |
| 128 | if (getsockname(host_fd, reinterpret_cast<sockaddr*>(&sock_addr), &sock_addr_len) != 0) |
| 129 | return new QTableWidgetItem(QTableWidget::tr("Unknown")); |
| 130 | |
| 131 | const QString sock_name = GetAddressAndPort(sock_addr); |
| 132 | if (sock_name.isEmpty()) |
| 133 | return new QTableWidgetItem(QTableWidget::tr("Unknown")); |
| 134 | |
| 135 | sockaddr_in peer_addr; |
| 136 | socklen_t peer_addr_len = sizeof(sockaddr_in); |
| 137 | if (getpeername(host_fd, reinterpret_cast<sockaddr*>(&peer_addr), &peer_addr_len) != 0) |
| 138 | return new QTableWidgetItem(sock_name); |
| 139 | |
| 140 | const QString peer_name = GetAddressAndPort(peer_addr); |
| 141 | if (peer_name.isEmpty()) |
| 142 | return new QTableWidgetItem(sock_name); |
| 143 | |
| 144 | return new QTableWidgetItem(QStringLiteral("%1->%2").arg(sock_name).arg(peer_name)); |
| 145 | } |
| 146 | |
| 147 | QTableWidgetItem* GetSocketRedirections(s32 host_fd, |
| 148 | const AMMediaboard::IPRedirections& ip_redirections) |
| 149 | { |
| 150 | if (host_fd < 0 || ip_redirections.empty()) |
| 151 | return new QTableWidgetItem(); |
| 152 | |
| 153 | sockaddr_in sock_addr; |
| 154 | socklen_t sock_addr_len = sizeof(sockaddr_in); |
| 155 | if (getsockname(host_fd, reinterpret_cast<sockaddr*>(&sock_addr), &sock_addr_len) != 0) |
| 156 | return new QTableWidgetItem(); |
| 157 | const Common::IPv4Port sock_ip_port{std::bit_cast<Common::IPAddress>(sock_addr.sin_addr), |
| 158 | sock_addr.sin_port}; |
| 159 | |
| 160 | sockaddr_in peer_addr; |
| 161 | socklen_t peer_addr_len = sizeof(sockaddr_in); |
| 162 | bool has_peer = |
| 163 | getpeername(host_fd, reinterpret_cast<sockaddr*>(&peer_addr), &peer_addr_len) == 0; |
| 164 | const Common::IPv4Port peer_ip_port = |
| 165 | has_peer ? Common::IPv4Port{std::bit_cast<Common::IPAddress>(peer_addr.sin_addr), |
| 166 | peer_addr.sin_port} : |
| 167 | Common::IPv4Port{}; |
| 168 | |
| 169 | QStringList sock_rules; |
| 170 | QStringList peer_rules; |
| 171 | for (const auto& rule : ip_redirections) |
| 172 | { |
| 173 | if (rule.replacement.IsMatch(sock_ip_port)) |
| 174 | sock_rules << QString::fromStdString(rule.ToString()); |
| 175 | if (!has_peer) |
| 176 | continue; |
| 177 | if (rule.replacement.IsMatch(peer_ip_port)) |
| 178 | peer_rules << QString::fromStdString(rule.ToString()); |
| 179 | } |
| 180 | |
| 181 | if (sock_rules.isEmpty() && peer_rules.isEmpty()) |
| 182 | return new QTableWidgetItem(); |
| 183 | if (peer_rules.isEmpty()) |
| 184 | return new QTableWidgetItem(sock_rules.join(QStringLiteral("\n"))); |
| 185 | return new QTableWidgetItem(QStringLiteral("Sock rules:\n%1\n" |
| 186 | "\nPeer rules:%2") |
| 187 | .arg(sock_rules.join(QStringLiteral("\n"))) |
| 188 | .arg(peer_rules.join(QStringLiteral("\n")))); |
| 189 | } |
| 190 | } // namespace |
| 191 | |
| 192 | NetworkWidget::NetworkWidget(QWidget* parent) : QDockWidget(parent) |
| 193 | { |
| 194 | setWindowTitle(tr("Network")); |
| 195 | setObjectName(QStringLiteral("network")); |
| 196 | |
| 197 | setHidden(!Settings::Instance().IsNetworkVisible() || !Settings::Instance().IsDebugModeEnabled()); |
| 198 | |
| 199 | setAllowedAreas(Qt::AllDockWidgetAreas); |
| 200 | |
| 201 | CreateWidgets(); |
| 202 | |
| 203 | auto& settings = Settings::GetQSettings(); |
| 204 | |
| 205 | restoreGeometry(settings.value(QStringLiteral("networkwidget/geometry")).toByteArray()); |
| 206 | // macOS: setHidden() needs to be evaluated before setFloating() for proper window presentation |
| 207 | // according to Settings |
| 208 | setFloating(settings.value(QStringLiteral("networkwidget/floating")).toBool()); |
| 209 | |
| 210 | ConnectWidgets(); |
| 211 | |
| 212 | connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, &NetworkWidget::Update); |
| 213 | |
| 214 | connect(&Settings::Instance(), &Settings::NetworkVisibilityChanged, this, |
| 215 | [this](bool visible) { setHidden(!visible); }); |
| 216 | |
| 217 | connect(&Settings::Instance(), &Settings::DebugModeToggled, this, [this](bool enabled) { |
| 218 | setHidden(!enabled || !Settings::Instance().IsNetworkVisible()); |
| 219 | }); |
| 220 | } |
| 221 | |
| 222 | NetworkWidget::~NetworkWidget() |
| 223 | { |
| 224 | auto& settings = Settings::GetQSettings(); |
| 225 | |
| 226 | settings.setValue(QStringLiteral("networkwidget/geometry"), saveGeometry()); |
| 227 | settings.setValue(QStringLiteral("networkwidget/floating"), isFloating()); |
| 228 | } |
| 229 | |
| 230 | void NetworkWidget::closeEvent(QCloseEvent*) |
| 231 | { |
| 232 | Settings::Instance().SetNetworkVisible(false); |
| 233 | } |
| 234 | |
| 235 | void NetworkWidget::showEvent(QShowEvent*) |
| 236 | { |
| 237 | Update(); |
| 238 | } |
| 239 | |
| 240 | void NetworkWidget::CreateWidgets() |
| 241 | { |
| 242 | auto* widget = new QWidget; |
| 243 | auto* layout = new QVBoxLayout; |
| 244 | widget->setLayout(layout); |
| 245 | layout->addWidget(CreateSocketTableGroup()); |
| 246 | layout->addWidget(CreateSSLContextGroup()); |
| 247 | layout->addWidget(CreateDumpOptionsGroup()); |
| 248 | layout->addWidget(CreateSecurityOptionsGroup()); |
| 249 | layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding)); |
| 250 | setWidget(widget); |
| 251 | |
| 252 | Update(); |
| 253 | } |
| 254 | |
| 255 | void NetworkWidget::ConnectWidgets() |
| 256 | { |
| 257 | connect(m_dump_format_combo, &QComboBox::currentIndexChanged, this, |
| 258 | &NetworkWidget::OnDumpFormatComboChanged); |
| 259 | |
| 260 | #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0) |
| 261 | using CheckState = Qt::CheckState; |
| 262 | static constexpr auto checkStateChanged = &QCheckBox::checkStateChanged; |
| 263 | #else |
| 264 | using CheckState = int; |
| 265 | static constexpr auto checkStateChanged = &QCheckBox::stateChanged; |
| 266 | #endif |
| 267 | |
| 268 | connect(m_dump_ssl_read_checkbox, checkStateChanged, [](CheckState state) { |
| 269 | Config::SetBaseOrCurrent(Config::MAIN_NETWORK_SSL_DUMP_READ, state == Qt::Checked); |
| 270 | }); |
| 271 | connect(m_dump_ssl_write_checkbox, checkStateChanged, [](CheckState state) { |
| 272 | Config::SetBaseOrCurrent(Config::MAIN_NETWORK_SSL_DUMP_WRITE, state == Qt::Checked); |
| 273 | }); |
| 274 | connect(m_dump_root_ca_checkbox, checkStateChanged, [](CheckState state) { |
| 275 | Config::SetBaseOrCurrent(Config::MAIN_NETWORK_SSL_DUMP_ROOT_CA, state == Qt::Checked); |
| 276 | }); |
| 277 | connect(m_dump_peer_cert_checkbox, checkStateChanged, [](CheckState state) { |
| 278 | Config::SetBaseOrCurrent(Config::MAIN_NETWORK_SSL_DUMP_PEER_CERT, state == Qt::Checked); |
| 279 | }); |
| 280 | connect(m_verify_certificates_checkbox, checkStateChanged, [](CheckState state) { |
| 281 | Config::SetBaseOrCurrent(Config::MAIN_NETWORK_SSL_VERIFY_CERTIFICATES, state == Qt::Checked); |
| 282 | }); |
| 283 | connect(m_dump_bba_checkbox, checkStateChanged, [](CheckState state) { |
| 284 | Config::SetBaseOrCurrent(Config::MAIN_NETWORK_DUMP_BBA, state == Qt::Checked); |
| 285 | }); |
| 286 | |
| 287 | connect(m_open_dump_folder, &QPushButton::clicked, [] { |
| 288 | const std::string location = File::GetUserPath(D_DUMPSSL_IDX); |
| 289 | const QUrl url = QUrl::fromLocalFile(QString::fromStdString(location)); |
| 290 | QDesktopServices::openUrl(url); |
| 291 | }); |
| 292 | } |
| 293 | |
| 294 | void NetworkWidget::UpdateWiiSocketTable(Core::System& system) |
| 295 | { |
| 296 | // Show Wii socket blocking state |
| 297 | m_socket_table->showColumn(4); |
| 298 | // Hide Triforce IP redirections |
| 299 | m_socket_table->hideColumn(6); |
| 300 | |
| 301 | auto* ios = system.GetIOS(); |
| 302 | if (!ios) |
| 303 | return; |
| 304 | |
| 305 | auto socket_manager = ios->GetSocketManager(); |
| 306 | if (!socket_manager) |
| 307 | return; |
| 308 | |
| 309 | for (s32 wii_fd = 0; wii_fd < IOS::HLE::WII_SOCKET_FD_MAX; wii_fd++) |
| 310 | { |
| 311 | m_socket_table->insertRow(wii_fd); |
| 312 | const s32 host_fd = socket_manager->GetHostSocket(wii_fd); |
| 313 | m_socket_table->setItem(wii_fd, 0, new QTableWidgetItem(QString::number(wii_fd))); |
| 314 | m_socket_table->setItem(wii_fd, 1, GetSocketDomain(host_fd)); |
| 315 | m_socket_table->setItem(wii_fd, 2, GetSocketType(host_fd)); |
| 316 | m_socket_table->setItem(wii_fd, 3, GetSocketState(host_fd)); |
| 317 | m_socket_table->setItem(wii_fd, 4, GetSocketBlocking(*socket_manager, wii_fd)); |
| 318 | m_socket_table->setItem(wii_fd, 5, GetSocketName(host_fd)); |
| 319 | } |
| 320 | |
| 321 | for (s32 ssl_id = 0; ssl_id < IOS::HLE::NET_SSL_MAXINSTANCES; ssl_id++) |
| 322 | { |
| 323 | m_ssl_table->insertRow(ssl_id); |
| 324 | s32 host_fd = -1; |
| 325 | if (IOS::HLE::IsSSLIDValid(ssl_id)) |
| 326 | { |
| 327 | const auto& ssl = IOS::HLE::NetSSLDevice::_SSL[ssl_id]; |
| 328 | host_fd = ssl.hostfd; |
| 329 | m_ssl_table->setItem(ssl_id, 5, new QTableWidgetItem(QString::fromStdString(ssl.hostname))); |
| 330 | } |
| 331 | m_ssl_table->setItem(ssl_id, 0, new QTableWidgetItem(QString::number(ssl_id))); |
| 332 | m_ssl_table->setItem(ssl_id, 1, GetSocketDomain(host_fd)); |
| 333 | m_ssl_table->setItem(ssl_id, 2, GetSocketType(host_fd)); |
| 334 | m_ssl_table->setItem(ssl_id, 3, GetSocketState(host_fd)); |
| 335 | m_ssl_table->setItem(ssl_id, 4, GetSocketName(host_fd)); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | void NetworkWidget::UpdateTriforceSocketTable() |
| 340 | { |
| 341 | // No easy way to get socket blocking state on Windows |
| 342 | m_socket_table->hideColumn(4); |
| 343 | // Show active IP redirections |
| 344 | m_socket_table->showColumn(6); |
| 345 | const auto ip_redirections = AMMediaboard::GetIPRedirections(); |
| 346 | for (s32 triforce_fd = 0; triforce_fd != AMMediaboard::SOCKET_FD_MAX; ++triforce_fd) |
| 347 | { |
| 348 | m_socket_table->insertRow(triforce_fd); |
| 349 | const s32 host_fd = AMMediaboard::DebuggerGetSocket(triforce_fd); |
| 350 | m_socket_table->setItem(triforce_fd, 0, new QTableWidgetItem(QString::number(triforce_fd))); |
| 351 | m_socket_table->setItem(triforce_fd, 1, GetSocketDomain(host_fd)); |
| 352 | m_socket_table->setItem(triforce_fd, 2, GetSocketType(host_fd)); |
| 353 | m_socket_table->setItem(triforce_fd, 3, GetSocketState(host_fd)); |
| 354 | m_socket_table->setItem(triforce_fd, 4, new QTableWidgetItem(QTableWidget::tr("Unknown"))); |
| 355 | m_socket_table->setItem(triforce_fd, 5, GetSocketName(host_fd)); |
| 356 | m_socket_table->setItem(triforce_fd, 6, GetSocketRedirections(host_fd, ip_redirections)); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | void NetworkWidget::Update() |
| 361 | { |
| 362 | if (!isVisible()) |
| 363 | return; |
| 364 | |
| 365 | auto& system = Core::System::GetInstance(); |
| 366 | if (Core::GetState(system) != Core::State::Paused) |
| 367 | { |
| 368 | m_socket_table->setDisabled(true); |
| 369 | m_ssl_table->setDisabled(true); |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | // needed because there's a race condition on the IOS instance otherwise |
| 374 | const Core::CPUThreadGuard guard(system); |
| 375 | m_socket_table->setDisabled(false); |
| 376 | m_socket_table->setRowCount(0); |
| 377 | m_ssl_table->setRowCount(0); |
| 378 | if (system.IsTriforce()) |
| 379 | { |
| 380 | UpdateTriforceSocketTable(); |
| 381 | } |
| 382 | else if (system.IsWii()) |
| 383 | { |
| 384 | m_ssl_table->setDisabled(false); |
| 385 | UpdateWiiSocketTable(system); |
| 386 | } |
| 387 | m_socket_table->resizeColumnsToContents(); |
| 388 | m_socket_table->resizeRowsToContents(); |
| 389 | m_ssl_table->resizeColumnsToContents(); |
| 390 | |
| 391 | const bool is_pcap = Config::Get(Config::MAIN_NETWORK_DUMP_AS_PCAP); |
| 392 | const bool is_ssl_read = Config::Get(Config::MAIN_NETWORK_SSL_DUMP_READ); |
| 393 | const bool is_ssl_write = Config::Get(Config::MAIN_NETWORK_SSL_DUMP_WRITE); |
| 394 | |
| 395 | m_dump_ssl_read_checkbox->setChecked(is_ssl_read); |
| 396 | m_dump_ssl_write_checkbox->setChecked(is_ssl_write); |
| 397 | m_dump_root_ca_checkbox->setChecked(Config::Get(Config::MAIN_NETWORK_SSL_DUMP_ROOT_CA)); |
| 398 | m_dump_peer_cert_checkbox->setChecked(Config::Get(Config::MAIN_NETWORK_SSL_DUMP_PEER_CERT)); |
| 399 | m_verify_certificates_checkbox->setChecked( |
| 400 | Config::Get(Config::MAIN_NETWORK_SSL_VERIFY_CERTIFICATES)); |
| 401 | |
| 402 | const int combo_index = int([is_pcap, is_ssl_read, is_ssl_write]() -> FormatComboId { |
| 403 | if (is_pcap) |
| 404 | return FormatComboId::PCAP; |
| 405 | |
| 406 | if (is_ssl_read && is_ssl_write) |
| 407 | return FormatComboId::BinarySSL; |
| 408 | |
| 409 | if (is_ssl_read) |
| 410 | return FormatComboId::BinarySSLRead; |
| 411 | |
| 412 | if (is_ssl_write) |
| 413 | return FormatComboId::BinarySSLWrite; |
| 414 | |
| 415 | return FormatComboId::None; |
| 416 | }()); |
| 417 | m_dump_format_combo->setCurrentIndex(combo_index); |
| 418 | } |
| 419 | |
| 420 | QGroupBox* NetworkWidget::CreateSocketTableGroup() |
| 421 | { |
| 422 | auto* const socket_table_group = new QGroupBox(tr("Socket table")); |
| 423 | auto* const socket_table_layout = new QGridLayout; |
| 424 | socket_table_group->setLayout(socket_table_layout); |
| 425 | |
| 426 | m_socket_table = new QTableWidget(); |
| 427 | // i18n: FD stands for file descriptor (and in this case refers to sockets, not regular files) |
| 428 | QStringList header{tr("FD"), tr("Domain"), tr("Type"), tr("State"), |
| 429 | tr("Blocking"), tr("Name"), tr("Redirections")}; |
| 430 | m_socket_table->setColumnCount(static_cast<int>(header.size())); |
| 431 | |
| 432 | m_socket_table->setHorizontalHeaderLabels(header); |
| 433 | m_socket_table->setTabKeyNavigation(false); |
| 434 | m_socket_table->verticalHeader()->setVisible(false); |
| 435 | m_socket_table->setEditTriggers(QAbstractItemView::NoEditTriggers); |
| 436 | m_socket_table->setSelectionMode(QAbstractItemView::NoSelection); |
| 437 | m_socket_table->setWordWrap(false); |
| 438 | |
| 439 | socket_table_layout->addWidget(m_socket_table, 0, 0); |
| 440 | socket_table_layout->setSpacing(1); |
| 441 | return socket_table_group; |
| 442 | } |
| 443 | |
| 444 | QGroupBox* NetworkWidget::CreateSSLContextGroup() |
| 445 | { |
| 446 | auto* const ssl_context_group = new QGroupBox(tr("SSL context")); |
| 447 | auto* const ssl_context_layout = new QGridLayout; |
| 448 | ssl_context_group->setLayout(ssl_context_layout); |
| 449 | |
| 450 | m_ssl_table = new QTableWidget(); |
| 451 | QStringList header{tr("ID"), tr("Domain"), tr("Type"), tr("State"), tr("Name"), tr("Hostname")}; |
| 452 | m_ssl_table->setColumnCount(static_cast<int>(header.size())); |
| 453 | |
| 454 | m_ssl_table->setHorizontalHeaderLabels(header); |
| 455 | m_ssl_table->setTabKeyNavigation(false); |
| 456 | m_ssl_table->verticalHeader()->setVisible(false); |
| 457 | m_ssl_table->setEditTriggers(QAbstractItemView::NoEditTriggers); |
| 458 | m_ssl_table->setSelectionMode(QAbstractItemView::NoSelection); |
| 459 | m_ssl_table->setWordWrap(false); |
| 460 | |
| 461 | ssl_context_layout->addWidget(m_ssl_table, 0, 0); |
| 462 | ssl_context_layout->setSpacing(1); |
| 463 | return ssl_context_group; |
| 464 | } |
| 465 | |
| 466 | QGroupBox* NetworkWidget::CreateDumpOptionsGroup() |
| 467 | { |
| 468 | auto* const dump_options_group = new QGroupBox(tr("Dump options")); |
| 469 | auto* const dump_options_layout = new QVBoxLayout; |
| 470 | dump_options_group->setLayout(dump_options_layout); |
| 471 | |
| 472 | m_dump_format_combo = CreateDumpFormatCombo(); |
| 473 | m_dump_format_combo->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
| 474 | m_dump_ssl_read_checkbox = new QCheckBox(tr("Dump decrypted SSL reads")); |
| 475 | m_dump_ssl_write_checkbox = new QCheckBox(tr("Dump decrypted SSL writes")); |
| 476 | // i18n: CA stands for certificate authority |
| 477 | m_dump_root_ca_checkbox = new QCheckBox(tr("Dump root CA certificates")); |
| 478 | m_dump_peer_cert_checkbox = new QCheckBox(tr("Dump peer certificates")); |
| 479 | m_dump_bba_checkbox = new QCheckBox(tr("Dump GameCube BBA traffic")); |
| 480 | m_open_dump_folder = new QPushButton(tr("Open dump folder")); |
| 481 | m_open_dump_folder->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
| 482 | |
| 483 | auto* const combo_label = new QLabel(tr("Network dump format:")); |
| 484 | combo_label->setBuddy(m_dump_format_combo); |
| 485 | auto* const combo_layout = new QHBoxLayout; |
| 486 | combo_layout->addWidget(combo_label); |
| 487 | const int combo_label_space = |
| 488 | combo_label->fontMetrics().boundingRect(QStringLiteral("__")).width(); |
| 489 | combo_layout->addItem(new QSpacerItem(combo_label_space, 0)); |
| 490 | combo_layout->addWidget(m_dump_format_combo); |
| 491 | combo_layout->addStretch(); |
| 492 | dump_options_layout->addLayout(combo_layout); |
| 493 | |
| 494 | dump_options_layout->addWidget(m_dump_ssl_read_checkbox); |
| 495 | dump_options_layout->addWidget(m_dump_ssl_write_checkbox); |
| 496 | dump_options_layout->addWidget(m_dump_root_ca_checkbox); |
| 497 | dump_options_layout->addWidget(m_dump_peer_cert_checkbox); |
| 498 | dump_options_layout->addWidget(m_dump_bba_checkbox); |
| 499 | dump_options_layout->addWidget(m_open_dump_folder); |
| 500 | |
| 501 | dump_options_layout->setSpacing(1); |
| 502 | return dump_options_group; |
| 503 | } |
| 504 | |
| 505 | QGroupBox* NetworkWidget::CreateSecurityOptionsGroup() |
| 506 | { |
| 507 | auto* const security_options_group = new QGroupBox(tr("Security options")); |
| 508 | auto* const security_options_layout = new QVBoxLayout; |
| 509 | security_options_group->setLayout(security_options_layout); |
| 510 | |
| 511 | m_verify_certificates_checkbox = new QCheckBox(tr("Verify certificates")); |
| 512 | security_options_layout->addWidget(m_verify_certificates_checkbox); |
| 513 | |
| 514 | security_options_layout->setSpacing(1); |
| 515 | return security_options_group; |
| 516 | } |
| 517 | |
| 518 | QComboBox* NetworkWidget::CreateDumpFormatCombo() |
| 519 | { |
| 520 | auto* combo = new QComboBox(); |
| 521 | |
| 522 | combo->insertItem(int(FormatComboId::None), tr("None")); |
| 523 | // i18n: PCAP is a file format |
| 524 | combo->insertItem(int(FormatComboId::PCAP), tr("PCAP")); |
| 525 | combo->insertItem(int(FormatComboId::BinarySSL), tr("Binary SSL")); |
| 526 | combo->insertItem(int(FormatComboId::BinarySSLRead), tr("Binary SSL (read)")); |
| 527 | combo->insertItem(int(FormatComboId::BinarySSLWrite), tr("Binary SSL (write)")); |
| 528 | |
| 529 | return combo; |
| 530 | } |
| 531 | |
| 532 | void NetworkWidget::OnDumpFormatComboChanged(int index) |
| 533 | { |
| 534 | const auto combo_id = static_cast<FormatComboId>(index); |
| 535 | |
| 536 | switch (combo_id) |
| 537 | { |
| 538 | case FormatComboId::PCAP: |
| 539 | break; |
| 540 | case FormatComboId::BinarySSL: |
| 541 | m_dump_ssl_read_checkbox->setChecked(true); |
| 542 | m_dump_ssl_write_checkbox->setChecked(true); |
| 543 | m_dump_bba_checkbox->setChecked(false); |
| 544 | break; |
| 545 | case FormatComboId::BinarySSLRead: |
| 546 | m_dump_ssl_read_checkbox->setChecked(true); |
| 547 | m_dump_ssl_write_checkbox->setChecked(false); |
| 548 | m_dump_bba_checkbox->setChecked(false); |
| 549 | break; |
| 550 | case FormatComboId::BinarySSLWrite: |
| 551 | m_dump_ssl_read_checkbox->setChecked(false); |
| 552 | m_dump_ssl_write_checkbox->setChecked(true); |
| 553 | m_dump_bba_checkbox->setChecked(false); |
| 554 | break; |
| 555 | default: |
| 556 | m_dump_ssl_read_checkbox->setChecked(false); |
| 557 | m_dump_ssl_write_checkbox->setChecked(false); |
| 558 | m_dump_bba_checkbox->setChecked(false); |
| 559 | break; |
| 560 | } |
| 561 | // Enable raw or decrypted SSL choices for PCAP |
| 562 | const bool is_pcap = combo_id == FormatComboId::PCAP; |
| 563 | m_dump_ssl_read_checkbox->setEnabled(is_pcap); |
| 564 | m_dump_ssl_write_checkbox->setEnabled(is_pcap); |
| 565 | m_dump_bba_checkbox->setEnabled(is_pcap); |
| 566 | Config::SetBaseOrCurrent(Config::MAIN_NETWORK_DUMP_AS_PCAP, is_pcap); |
| 567 | } |