dbhub: Add list of CA certificates and restructure code

Change the layout of the preferences dialog a bit.

Remove the server selection combo box from the preferences dialog as it
will probably never be required. The way we do logins using certificates
kind of makes this obsolete, I think.

Restructure the whole remote code a little bit. Also add helper
functions here and there.

Show a list of our the CA certificates built into the application in the
preferences dialog. This list is read only of course but still
informative as it tells the user which sites are supported ny DB4S.
This commit is contained in:
Martin Kleusberg
2016-11-01 19:45:42 +01:00
parent e9894b47fa
commit 6283f97598
9 changed files with 284 additions and 212 deletions

View File

@@ -16,6 +16,8 @@ public:
bool dontShowMainWindow() { return m_dontShowMainWindow; }
MainWindow* mainWindow() { return m_mainWindow; }
protected:
bool event(QEvent* event);

View File

@@ -1691,7 +1691,7 @@ void MainWindow::reloadSettings()
// Hide or show the File → Remote menu as needed
QAction *remoteMenuAction = ui->menuRemote->menuAction();
remoteMenuAction->setVisible(Settings::getSettingsValue("MainWindow", "remotemenu").toBool());
remoteMenuAction->setVisible(Settings::getSettingsValue("remote", "active").toBool());
// Update the remote database connection settings
m_remoteDb.reloadSettings();

View File

@@ -33,6 +33,7 @@ public:
~MainWindow();
DBBrowserDB& getDb() { return db; }
const RemoteDatabase& getRemote() const { return m_remoteDb; }
struct PlotSettings
{

View File

@@ -3,6 +3,8 @@
#include "sqlitedb.h"
#include "FileDialog.h"
#include "Settings.h"
#include "Application.h"
#include "MainWindow.h"
#include <QDir>
#include <QSettings>
@@ -59,7 +61,7 @@ void PreferencesDialog::loadSettings()
ui->comboDefaultLocation->setCurrentIndex(Settings::getSettingsValue("db", "savedefaultlocation").toInt());
ui->locationEdit->setText(Settings::getSettingsValue("db", "defaultlocation").toString());
ui->checkUpdates->setChecked(Settings::getSettingsValue("checkversion", "enabled").toBool());
ui->checkUseRemotes->setChecked(Settings::getSettingsValue("MainWindow", "remotemenu").toBool());
ui->checkHideSchemaLinebreaks->setChecked(Settings::getSettingsValue("db", "hideschemalinebreaks").toBool());
ui->foreignKeysCheckBox->setChecked(Settings::getSettingsValue("db", "foreignkeys").toBool());
ui->spinPrefetchSize->setValue(Settings::getSettingsValue("db", "prefetchsize").toInt());
@@ -108,6 +110,35 @@ void PreferencesDialog::loadSettings()
}
}
// Remote settings
ui->checkUseRemotes->setChecked(Settings::getSettingsValue("remote", "active").toBool());
auto ca_certs = static_cast<Application*>(qApp)->mainWindow()->getRemote().caCertificates();
ui->tableCaCerts->setRowCount(ca_certs.size());
for(int i=0;i<ca_certs.size();i++)
{
QSslCertificate cert = ca_certs.at(i);
QTableWidgetItem* cert_cn = new QTableWidgetItem(cert.subjectInfo(QSslCertificate::CommonName).at(0));
cert_cn->setFlags(Qt::ItemIsSelectable);
ui->tableCaCerts->setItem(i, 0, cert_cn);
QTableWidgetItem* cert_o = new QTableWidgetItem(cert.subjectInfo(QSslCertificate::Organization).at(0));
cert_o->setFlags(Qt::ItemIsSelectable);
ui->tableCaCerts->setItem(i, 1, cert_o);
QTableWidgetItem* cert_from = new QTableWidgetItem(cert.effectiveDate().toString());
cert_from->setFlags(Qt::ItemIsSelectable);
ui->tableCaCerts->setItem(i, 2, cert_from);
QTableWidgetItem* cert_to = new QTableWidgetItem(cert.expiryDate().toString());
cert_to->setFlags(Qt::ItemIsSelectable);
ui->tableCaCerts->setItem(i, 3, cert_to);
QTableWidgetItem* cert_serialno = new QTableWidgetItem(QString(cert.serialNumber()));
cert_serialno->setFlags(Qt::ItemIsSelectable);
ui->tableCaCerts->setItem(i, 4, cert_serialno);
}
// Gracefully handle the preferred Editor font not being available
matchingFont = ui->comboEditorFont->findText(Settings::getSettingsValue("editor", "font").toString(), Qt::MatchExactly);
if (matchingFont == -1)
@@ -138,7 +169,6 @@ void PreferencesDialog::saveSettings()
Settings::setSettingsValue("db", "defaultfieldtype", ui->defaultFieldTypeComboBox->currentIndex());
Settings::setSettingsValue("MainWindow", "remotemenu", ui->checkUseRemotes->isChecked());
Settings::setSettingsValue("checkversion", "enabled", ui->checkUpdates->isChecked());
Settings::setSettingsValue("databrowser", "font", ui->comboDataBrowserFont->currentText());
@@ -176,6 +206,8 @@ void PreferencesDialog::saveSettings()
Settings::setSettingsValue("extensions", "list", extList);
Settings::setSettingsValue("extensions", "disableregex", ui->checkRegexDisabled->isChecked());
Settings::setSettingsValue("remote", "active", ui->checkUseRemotes->isChecked());
// Warn about restarting to change language
QVariant newLanguage = ui->languageComboBox->itemData(ui->languageComboBox->currentIndex());
if (newLanguage != Settings::getSettingsValue("General", "language"))
@@ -336,3 +368,8 @@ void PreferencesDialog::saveColorSetting(QFrame *frame, const QString & settingN
Settings::setSettingsValue("databrowser", settingName + "_colour",
frame->palette().color(frame->backgroundRole()));
}
void PreferencesDialog::activateRemoteTab(bool active)
{
ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->tabRemote), active);
}

View File

@@ -28,6 +28,7 @@ private slots:
virtual void showColourDialog(QTreeWidgetItem* item, int column);
virtual void addExtension();
virtual void removeExtension();
virtual void activateRemoteTab(bool active);
private:
Ui::PreferencesDialog *ui;

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>590</width>
<height>555</height>
<height>614</height>
</rect>
</property>
<property name="windowTitle">
@@ -26,180 +26,137 @@
<attribute name="title">
<string>&amp;General</string>
</attribute>
<widget class="QWidget" name="formLayoutWidget">
<property name="geometry">
<rect>
<x>32</x>
<y>20</y>
<width>503</width>
<height>251</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Default &amp;location</string>
</property>
<property name="buddy">
<cstring>locationEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QComboBox" name="comboDefaultLocation">
<item>
<property name="text">
<string>Remember last location</string>
</property>
</item>
<item>
<property name="text">
<string>Always use this location</string>
</property>
</item>
<item>
<property name="text">
<string>Remember last location for session only</string>
</property>
</item>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="locationEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>316</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="setLocationButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Lan&amp;guage</string>
</property>
<property name="buddy">
<cstring>languageComboBox</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelUseRemotes">
<property name="text">
<string>Show remote options</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelUpdates">
<property name="text">
<string>Automatic &amp;updates</string>
</property>
<property name="buddy">
<cstring>checkUpdates</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="checkUpdates">
<property name="text">
<string>enabled</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="languageComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<property name="minimumContentsLength">
<number>35</number>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>15</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="checkUseRemotes">
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Default &amp;location</string>
</property>
<property name="buddy">
<cstring>locationEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QComboBox" name="comboDefaultLocation">
<item>
<property name="text">
<string>enabled</string>
<string>Remember last location</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelRemoteServer">
</item>
<item>
<property name="text">
<string>Remote server</string>
<string>Always use this location</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboRemoteServer">
<item>
<property name="text">
<string>dbhub.io</string>
</item>
<item>
<property name="text">
<string>Remember last location for session only</string>
</property>
</item>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="locationEdit">
<property name="enabled">
<bool>false</bool>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>316</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="setLocationButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Lan&amp;guage</string>
</property>
<property name="buddy">
<cstring>languageComboBox</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="languageComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<property name="minimumContentsLength">
<number>35</number>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>15</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelUseRemotes">
<property name="text">
<string>Show remote options</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkUseRemotes">
<property name="text">
<string>enabled</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelUpdates">
<property name="text">
<string>Automatic &amp;updates</string>
</property>
<property name="buddy">
<cstring>checkUpdates</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="checkUpdates">
<property name="text">
<string>enabled</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab">
<attribute name="title">
@@ -1049,6 +1006,55 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabRemote">
<attribute name="title">
<string>Remote</string>
</attribute>
<layout class="QFormLayout" name="formLayout_5">
<item row="0" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>CA certificates</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QTableWidget" name="tableCaCerts">
<column>
<property name="text">
<string>Subject CN</string>
</property>
<property name="toolTip">
<string>Common Name</string>
</property>
</column>
<column>
<property name="text">
<string>Subject O</string>
</property>
<property name="toolTip">
<string>Organization</string>
</property>
</column>
<column>
<property name="text">
<string>Valid from</string>
</property>
</column>
<column>
<property name="text">
<string>Valid to</string>
</property>
</column>
<column>
<property name="text">
<string>Serial number</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
@@ -1118,8 +1124,8 @@
<slot>saveSettings()</slot>
<hints>
<hint type="sourcelabel">
<x>281</x>
<y>525</y>
<x>287</x>
<y>607</y>
</hint>
<hint type="destinationlabel">
<x>155</x>
@@ -1134,8 +1140,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>349</x>
<y>525</y>
<x>355</x>
<y>607</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
@@ -1151,7 +1157,7 @@
<hints>
<hint type="sourcelabel">
<x>571</x>
<y>99</y>
<y>97</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
@@ -1167,7 +1173,7 @@
<hints>
<hint type="sourcelabel">
<x>571</x>
<y>137</y>
<y>135</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
@@ -1198,8 +1204,8 @@
<slot>chooseLocation()</slot>
<hints>
<hint type="sourcelabel">
<x>567</x>
<y>100</y>
<x>571</x>
<y>114</y>
</hint>
<hint type="destinationlabel">
<x>294</x>
@@ -1214,12 +1220,12 @@
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>375</x>
<y>202</y>
<x>365</x>
<y>207</y>
</hint>
<hint type="destinationlabel">
<x>64</x>
<y>243</y>
<x>55</x>
<y>252</y>
</hint>
</hints>
</connection>
@@ -1230,12 +1236,28 @@
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>375</x>
<y>202</y>
<x>365</x>
<y>207</y>
</hint>
<hint type="destinationlabel">
<x>375</x>
<y>251</y>
<x>365</x>
<y>252</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkUseRemotes</sender>
<signal>toggled(bool)</signal>
<receiver>PreferencesDialog</receiver>
<slot>activateRemoteTab(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>161</x>
<y>172</y>
</hint>
<hint type="destinationlabel">
<x>382</x>
<y>572</y>
</hint>
</hints>
</connection>
@@ -1246,5 +1268,6 @@
<slot>showColourDialog(QTreeWidgetItem*,int)</slot>
<slot>addExtension()</slot>
<slot>removeExtension()</slot>
<slot>activateRemoteTab(bool)</slot>
</slots>
</ui>

View File

@@ -14,25 +14,6 @@ RemoteDatabase::RemoteDatabase() :
m_manager(new QNetworkAccessManager),
m_progress(nullptr),
m_currentReply(nullptr)
{
// Load settings and set up some more stuff while doing so
reloadSettings();
// TODO Add support for proxies here
// Set up signals
connect(m_manager, &QNetworkAccessManager::finished, this, &RemoteDatabase::gotReply);
connect(m_manager, &QNetworkAccessManager::encrypted, this, &RemoteDatabase::gotEncrypted);
connect(m_manager, &QNetworkAccessManager::sslErrors, this, &RemoteDatabase::gotError);
}
RemoteDatabase::~RemoteDatabase()
{
delete m_manager;
delete m_progress;
}
void RemoteDatabase::reloadSettings()
{
// Set up SSL configuration
m_sslConfiguration = QSslConfiguration::defaultConfiguration();
@@ -59,6 +40,25 @@ void RemoteDatabase::reloadSettings()
QSslKey clientKey(&fileClientKey, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "password");
fileClientKey.close();
m_sslConfiguration.setPrivateKey(clientKey);
// Load settings and set up some more stuff while doing so
reloadSettings();
// Set up signals
connect(m_manager, &QNetworkAccessManager::finished, this, &RemoteDatabase::gotReply);
connect(m_manager, &QNetworkAccessManager::encrypted, this, &RemoteDatabase::gotEncrypted);
connect(m_manager, &QNetworkAccessManager::sslErrors, this, &RemoteDatabase::gotError);
}
RemoteDatabase::~RemoteDatabase()
{
delete m_manager;
delete m_progress;
}
void RemoteDatabase::reloadSettings()
{
// TODO Add support for proxies here
}
void RemoteDatabase::fetchDatabase(const QString& url)
@@ -201,3 +201,9 @@ void RemoteDatabase::updateProgress(qint64 bytesReceived, qint64 bytesTotal)
m_progress->hide();
}
}
const QList<QSslCertificate>& RemoteDatabase::caCertificates() const
{
static QList<QSslCertificate> certs = m_sslConfiguration.caCertificates();
return certs;
}

View File

@@ -20,6 +20,8 @@ public:
void reloadSettings();
const QList<QSslCertificate>& caCertificates() const;
void fetchDatabase(const QString& url);
signals:

View File

@@ -109,10 +109,6 @@ QVariant Settings::getSettingsDefaultValue(const QString& group, const QString&
if(group == "MainWindow" && name == "windowState")
return "";
// Enable the File → Remote menu by default
if(group == "MainWindow" && name == "remotemenu")
return true;
// SQLLogDock/Log?
if(group == "SQLLogDock" && name == "Log")
return "Application";
@@ -250,6 +246,10 @@ QVariant Settings::getSettingsDefaultValue(const QString& group, const QString&
return 4;
}
// Enable the File → Remote menu by default
if(group == "remote" && name == "active")
return true;
// Unknown combination of group and name? Return an invalid QVariant!
return QVariant();
}