From a8dc1e3f1c7df0218eb2f8841bc83fb1b0cc2643 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 29 Apr 2020 12:10:24 +0400 Subject: [PATCH] NetworkWidget: Reorganise SSL options group box Create "Dump options" and "Security options" group boxes. Add "Network dump format" combo box. Add "Open dump folder" button. --- .../Core/DolphinQt/Debugger/NetworkWidget.cpp | 146 +++++++++++++++--- .../Core/DolphinQt/Debugger/NetworkWidget.h | 20 ++- 2 files changed, 140 insertions(+), 26 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp b/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp index 94807e7d31..ddd7e97884 100644 --- a/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp @@ -5,10 +5,15 @@ #include "DolphinQt/Debugger/NetworkWidget.h" #include +#include +#include #include #include #include +#include +#include #include +#include #include #ifdef _WIN32 @@ -18,6 +23,7 @@ #include #endif +#include "Common/FileUtil.h" #include "Core/Config/MainSettings.h" #include "Core/IOS/Network/SSL.h" #include "Core/IOS/Network/Socket.h" @@ -191,7 +197,8 @@ void NetworkWidget::CreateWidgets() widget->setLayout(layout); layout->addWidget(CreateSocketTableGroup()); layout->addWidget(CreateSSLContextGroup()); - layout->addWidget(CreateSSLOptionsGroup()); + layout->addWidget(CreateDumpOptionsGroup()); + layout->addWidget(CreateSecurityOptionsGroup()); layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding)); setWidget(widget); @@ -200,6 +207,8 @@ void NetworkWidget::CreateWidgets() void NetworkWidget::ConnectWidgets() { + connect(m_dump_format_combo, QOverload::of(&QComboBox::currentIndexChanged), this, + &NetworkWidget::OnDumpFormatComboChanged); connect(m_dump_ssl_read_checkbox, &QCheckBox::stateChanged, [](int state) { Config::SetBaseOrCurrent(Config::MAIN_NETWORK_SSL_DUMP_READ, state == Qt::Checked); }); @@ -215,8 +224,10 @@ void NetworkWidget::ConnectWidgets() connect(m_verify_certificates_checkbox, &QCheckBox::stateChanged, [](int state) { Config::SetBaseOrCurrent(Config::MAIN_NETWORK_SSL_VERIFY_CERTIFICATES, state == Qt::Checked); }); - connect(m_dump_as_pcap_checkbox, &QCheckBox::stateChanged, [](int state) { - Config::SetBaseOrCurrent(Config::MAIN_NETWORK_DUMP_AS_PCAP, state == Qt::Checked); + connect(m_open_dump_folder, &QPushButton::pressed, [] { + const std::string location = File::GetUserPath(D_DUMPSSL_IDX); + const QUrl url = QUrl::fromLocalFile(QString::fromStdString(location)); + QDesktopServices::openUrl(url); }); } @@ -255,13 +266,30 @@ void NetworkWidget::Update() } m_ssl_table->resizeColumnsToContents(); - m_dump_ssl_read_checkbox->setChecked(Config::Get(Config::MAIN_NETWORK_SSL_DUMP_READ)); - m_dump_ssl_write_checkbox->setChecked(Config::Get(Config::MAIN_NETWORK_SSL_DUMP_WRITE)); + const bool is_pcap = Config::Get(Config::MAIN_NETWORK_DUMP_AS_PCAP); + const bool is_ssl_read = Config::Get(Config::MAIN_NETWORK_SSL_DUMP_READ); + const bool is_ssl_write = Config::Get(Config::MAIN_NETWORK_SSL_DUMP_WRITE); + + m_dump_ssl_read_checkbox->setChecked(is_ssl_read); + m_dump_ssl_write_checkbox->setChecked(is_ssl_write); m_dump_root_ca_checkbox->setChecked(Config::Get(Config::MAIN_NETWORK_SSL_DUMP_ROOT_CA)); m_dump_peer_cert_checkbox->setChecked(Config::Get(Config::MAIN_NETWORK_SSL_DUMP_PEER_CERT)); m_verify_certificates_checkbox->setChecked( Config::Get(Config::MAIN_NETWORK_SSL_VERIFY_CERTIFICATES)); - m_dump_as_pcap_checkbox->setChecked(Config::Get(Config::MAIN_NETWORK_DUMP_AS_PCAP)); + + const int combo_index = int([is_pcap, is_ssl_read, is_ssl_write]() -> FormatComboId { + if (is_pcap) + return FormatComboId::PCAP; + else if (is_ssl_read && is_ssl_write) + return FormatComboId::BinarySSL; + else if (is_ssl_read) + return FormatComboId::BinarySSLRead; + else if (is_ssl_write) + return FormatComboId::BinarySSLWrite; + else + return FormatComboId::None; + }()); + m_dump_format_combo->setCurrentIndex(combo_index); } QGroupBox* NetworkWidget::CreateSocketTableGroup() @@ -309,28 +337,98 @@ QGroupBox* NetworkWidget::CreateSSLContextGroup() return ssl_context_group; } -QGroupBox* NetworkWidget::CreateSSLOptionsGroup() +QGroupBox* NetworkWidget::CreateDumpOptionsGroup() { - QGroupBox* ssl_options_group = new QGroupBox(tr("SSL options")); - QGridLayout* ssl_options_layout = new QGridLayout; - ssl_options_group->setLayout(ssl_options_layout); + auto* dump_options_group = new QGroupBox(tr("Dump options")); + auto* dump_options_layout = new QVBoxLayout; + dump_options_group->setLayout(dump_options_layout); - m_dump_ssl_read_checkbox = new QCheckBox(tr("Dump SSL read")); - m_dump_ssl_write_checkbox = new QCheckBox(tr("Dump SSL write")); + m_dump_format_combo = CreateDumpFormatCombo(); + m_dump_format_combo->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_dump_ssl_read_checkbox = new QCheckBox(tr("Dump decrypted SSL reads")); + m_dump_ssl_write_checkbox = new QCheckBox(tr("Dump decrypted SSL writes")); // i18n: CA stands for certificate authority - m_dump_root_ca_checkbox = new QCheckBox(tr("Dump root CA")); + m_dump_root_ca_checkbox = new QCheckBox(tr("Dump root CA certificates")); m_dump_peer_cert_checkbox = new QCheckBox(tr("Dump peer certificates")); - m_verify_certificates_checkbox = new QCheckBox(tr("Verify certificates")); - // i18n: PCAP is a file format - m_dump_as_pcap_checkbox = new QCheckBox(tr("Dump as PCAP")); + m_open_dump_folder = new QPushButton(tr("Open dump folder")); + m_open_dump_folder->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - ssl_options_layout->addWidget(m_dump_ssl_read_checkbox, 0, 0); - ssl_options_layout->addWidget(m_dump_ssl_write_checkbox, 1, 0); - ssl_options_layout->addWidget(m_verify_certificates_checkbox, 2, 0); - ssl_options_layout->addWidget(m_dump_root_ca_checkbox, 0, 1); - ssl_options_layout->addWidget(m_dump_peer_cert_checkbox, 1, 1); - ssl_options_layout->addWidget(m_dump_as_pcap_checkbox, 2, 1); + auto* combo_label = new QLabel(tr("Network dump format:")); + combo_label->setBuddy(m_dump_format_combo); + auto* combo_layout = new QHBoxLayout; + combo_layout->addWidget(combo_label); + const int combo_label_space = + combo_label->fontMetrics().boundingRect(QStringLiteral("__")).width(); + combo_layout->addItem(new QSpacerItem(combo_label_space, 0)); + combo_layout->addWidget(m_dump_format_combo); + combo_layout->addStretch(); + dump_options_layout->addLayout(combo_layout); - ssl_options_layout->setSpacing(1); - return ssl_options_group; + dump_options_layout->addWidget(m_dump_ssl_read_checkbox); + dump_options_layout->addWidget(m_dump_ssl_write_checkbox); + dump_options_layout->addWidget(m_dump_root_ca_checkbox); + dump_options_layout->addWidget(m_dump_peer_cert_checkbox); + dump_options_layout->addWidget(m_open_dump_folder); + + dump_options_layout->setSpacing(1); + return dump_options_group; +} + +QGroupBox* NetworkWidget::CreateSecurityOptionsGroup() +{ + auto* security_options_group = new QGroupBox(tr("Security options")); + auto* security_options_layout = new QVBoxLayout; + security_options_group->setLayout(security_options_layout); + + m_verify_certificates_checkbox = new QCheckBox(tr("Verify certificates")); + security_options_layout->addWidget(m_verify_certificates_checkbox); + + security_options_layout->setSpacing(1); + return security_options_group; +} + +QComboBox* NetworkWidget::CreateDumpFormatCombo() +{ + auto* combo = new QComboBox(); + + combo->insertItem(int(FormatComboId::None), tr("None")); + // i18n: PCAP is a file format + combo->insertItem(int(FormatComboId::PCAP), tr("PCAP")); + combo->insertItem(int(FormatComboId::BinarySSL), tr("Binary SSL")); + combo->insertItem(int(FormatComboId::BinarySSLRead), tr("Binary SSL (read)")); + combo->insertItem(int(FormatComboId::BinarySSLWrite), tr("Binary SSL (write)")); + + return combo; +} + +void NetworkWidget::OnDumpFormatComboChanged(int index) +{ + const auto combo_id = static_cast(index); + + switch (combo_id) + { + case FormatComboId::PCAP: + break; + case FormatComboId::BinarySSL: + m_dump_ssl_read_checkbox->setChecked(true); + m_dump_ssl_write_checkbox->setChecked(true); + break; + case FormatComboId::BinarySSLRead: + m_dump_ssl_read_checkbox->setChecked(true); + m_dump_ssl_write_checkbox->setChecked(false); + break; + case FormatComboId::BinarySSLWrite: + m_dump_ssl_read_checkbox->setChecked(false); + m_dump_ssl_write_checkbox->setChecked(true); + break; + default: + m_dump_ssl_read_checkbox->setChecked(false); + m_dump_ssl_write_checkbox->setChecked(false); + break; + } + // Enable raw or decrypted SSL choices for PCAP + const bool is_pcap = combo_id == FormatComboId::PCAP; + m_dump_ssl_read_checkbox->setEnabled(is_pcap); + m_dump_ssl_write_checkbox->setEnabled(is_pcap); + Config::SetBaseOrCurrent(Config::MAIN_NETWORK_DUMP_AS_PCAP, is_pcap); } diff --git a/Source/Core/DolphinQt/Debugger/NetworkWidget.h b/Source/Core/DolphinQt/Debugger/NetworkWidget.h index f3c93d11a6..a37e108f5d 100644 --- a/Source/Core/DolphinQt/Debugger/NetworkWidget.h +++ b/Source/Core/DolphinQt/Debugger/NetworkWidget.h @@ -10,7 +10,9 @@ class QCheckBox; class QCloseEvent; +class QComboBox; class QGroupBox; +class QPushButton; class QShowEvent; class QTableWidget; class QTableWidgetItem; @@ -34,14 +36,28 @@ private: QGroupBox* CreateSocketTableGroup(); QGroupBox* CreateSSLContextGroup(); - QGroupBox* CreateSSLOptionsGroup(); + QGroupBox* CreateDumpOptionsGroup(); + QGroupBox* CreateSecurityOptionsGroup(); + QComboBox* CreateDumpFormatCombo(); + + void OnDumpFormatComboChanged(int index); + + enum class FormatComboId : int + { + None = 0, + PCAP, + BinarySSL, + BinarySSLRead, + BinarySSLWrite, + }; QTableWidget* m_socket_table; QTableWidget* m_ssl_table; + QComboBox* m_dump_format_combo; QCheckBox* m_dump_ssl_read_checkbox; QCheckBox* m_dump_ssl_write_checkbox; QCheckBox* m_dump_root_ca_checkbox; QCheckBox* m_dump_peer_cert_checkbox; QCheckBox* m_verify_certificates_checkbox; - QCheckBox* m_dump_as_pcap_checkbox; + QPushButton* m_open_dump_folder; };