improve connect page and translation handling even more

This commit is contained in:
Michael Zanetti 2018-06-05 23:21:38 +02:00
parent 5c90c0ff75
commit 33809bf988
5 changed files with 70 additions and 58 deletions

View File

@ -91,6 +91,7 @@ QString DiscoveryDevice::toUrl(int portConfigIndex)
PortConfig *pc = m_portConfigs->get(portConfigIndex); PortConfig *pc = m_portConfigs->get(portConfigIndex);
if (!pc) { if (!pc) {
qWarning() << "No portconfig for index" << portConfigIndex; qWarning() << "No portconfig for index" << portConfigIndex;
return QString();
} }
QString ret = pc->protocol() == PortConfig::ProtocolNymeaRpc ? "nymea" : "ws"; QString ret = pc->protocol() == PortConfig::ProtocolNymeaRpc ? "nymea" : "ws";
ret += pc->sslEnabled() ? "s" : ""; ret += pc->sslEnabled() ? "s" : "";

View File

@ -102,7 +102,7 @@ void UpnpDiscovery::writeDiscoveryPacket()
"MX:2\r\n" "MX:2\r\n"
"ST: ssdp:all\r\n\r\n"); "ST: ssdp:all\r\n\r\n");
qDebug() << "sending discovery package"; // qDebug() << "sending discovery package";
foreach (QUdpSocket* socket, m_sockets) { foreach (QUdpSocket* socket, m_sockets) {
quint64 ret = socket->writeDatagram(ssdpSearchMessage, QHostAddress("239.255.255.250"), 1900); quint64 ret = socket->writeDatagram(ssdpSearchMessage, QHostAddress("239.255.255.250"), 1900);
if (ret != ssdpSearchMessage.length()) { if (ret != ssdpSearchMessage.length()) {
@ -151,7 +151,6 @@ void UpnpDiscovery::readData()
if (key.contains("Server") || key.contains("SERVER")) { if (key.contains("Server") || key.contains("SERVER")) {
if (value.contains("nymea")) { if (value.contains("nymea")) {
qDebug() << " --> " << key << value;
isNymea = true; isNymea = true;
} }
} }
@ -162,10 +161,6 @@ void UpnpDiscovery::readData()
} }
} }
if (isNymea) {
qDebug() << "Found nymea device:" << location;
}
if (!m_foundDevices.contains(location) && isNymea) { if (!m_foundDevices.contains(location) && isNymea) {
m_foundDevices.append(location); m_foundDevices.append(location);
qDebug() << "Getting server data from:" << location; qDebug() << "Getting server data from:" << location;

View File

@ -43,13 +43,19 @@ void NymeaConnection::disconnect()
m_currentInterface->disconnect(); m_currentInterface->disconnect();
} }
void NymeaConnection::acceptCertificate(const QByteArray &fingerprint) void NymeaConnection::acceptCertificate(const QString &url, const QByteArray &fingerprint)
{ {
QSettings settings; QSettings settings;
settings.beginGroup("acceptedCertificates"); settings.beginGroup("acceptedCertificates");
settings.setValue(m_currentUrl.toString(), fingerprint); settings.setValue(QUrl(url).host(), fingerprint);
settings.endGroup(); settings.endGroup();
connect(m_currentUrl.toString()); }
bool NymeaConnection::isTrusted(const QString &url)
{
QSettings settings;
settings.beginGroup("acceptedCertificates");
return settings.contains(QUrl(url).host());
} }
bool NymeaConnection::connected() bool NymeaConnection::connected()
@ -90,7 +96,7 @@ void NymeaConnection::onSslErrors(const QList<QSslError> &errors)
QSettings settings; QSettings settings;
settings.beginGroup("acceptedCertificates"); settings.beginGroup("acceptedCertificates");
QByteArray storedFingerPrint = settings.value(m_currentUrl.toString()).toByteArray(); QByteArray storedFingerPrint = settings.value(m_currentUrl.host()).toByteArray();
settings.endGroup(); settings.endGroup();
QByteArray certificateFingerprint; QByteArray certificateFingerprint;
@ -115,7 +121,7 @@ void NymeaConnection::onSslErrors(const QList<QSslError> &errors)
// info << tr("Name Qualifier:")<< error.certificate().issuerInfo(QSslCertificate::DistinguishedNameQualifier); // info << tr("Name Qualifier:")<< error.certificate().issuerInfo(QSslCertificate::DistinguishedNameQualifier);
// info << tr("Email:")<< error.certificate().issuerInfo(QSslCertificate::EmailAddress); // info << tr("Email:")<< error.certificate().issuerInfo(QSslCertificate::EmailAddress);
emit verifyConnectionCertificate(info, certificateFingerprint); emit verifyConnectionCertificate(m_currentUrl.toString(), info, certificateFingerprint);
} }
} else { } else {
// Reject the connection on all other errors... // Reject the connection on all other errors...

View File

@ -21,7 +21,8 @@ public:
Q_INVOKABLE void connect(const QString &url); Q_INVOKABLE void connect(const QString &url);
Q_INVOKABLE void disconnect(); Q_INVOKABLE void disconnect();
Q_INVOKABLE void acceptCertificate(const QByteArray &fingerprint); Q_INVOKABLE void acceptCertificate(const QString &url, const QByteArray &fingerprint);
Q_INVOKABLE bool isTrusted(const QString &url);
bool connected(); bool connected();
@ -31,7 +32,7 @@ public:
void sendData(const QByteArray &data); void sendData(const QByteArray &data);
signals: signals:
void verifyConnectionCertificate(const QStringList &issuerInfo, const QByteArray &fingerprint); void verifyConnectionCertificate(const QString &url, const QStringList &issuerInfo, const QByteArray &fingerprint);
void connectedChanged(bool connected); void connectedChanged(bool connected);
void connectionError(); void connectionError();
void dataAvailable(const QByteArray &data); void dataAvailable(const QByteArray &data);

View File

@ -24,7 +24,7 @@ Page {
target: Engine.connection target: Engine.connection
onVerifyConnectionCertificate: { onVerifyConnectionCertificate: {
print("verify cert!") print("verify cert!")
var popup = certDialogComponent.createObject(app, {issuerInfo: issuerInfo, fingerprint: fingerprint}); var popup = certDialogComponent.createObject(app, {url: url, issuerInfo: issuerInfo, fingerprint: fingerprint});
popup.open(); popup.open();
} }
onConnectionError: { onConnectionError: {
@ -118,41 +118,12 @@ Page {
clip: true clip: true
delegate: SwipeDelegate { delegate: SwipeDelegate {
id: discoveryDeviceDelegate
width: parent.width width: parent.width
height: app.delegateHeight height: app.delegateHeight
objectName: "discoveryDelegate" + index objectName: "discoveryDelegate" + index
contentItem: RowLayout { property var discoveryDevice: discovery.discoveryModel.get(index)
ColumnLayout { property string defaultPortConfigIndex: {
Layout.fillWidth: true
Label {
text: model.name
Layout.fillWidth: true
elide: Text.ElideRight
}
Label {
text: model.hostAddress
font.pixelSize: app.smallFont
}
}
ColorIcon {
Layout.fillHeight: true
Layout.preferredWidth: height
name: "../images/network-secure.svg"
visible: {
var discoveryDevice = discovery.discoveryModel.get(index);
for (var i = 0; i < discoveryDevice.portConfigs.count; i++) {
if (discoveryDevice.portConfigs.get(i).sslEnabled) {
return true;
}
}
return false;
}
}
}
onClicked: {
var discoveryDevice = discovery.discoveryModel.get(index);
print("discoveryDevice:", discoveryDevice.name, discoveryDevice.uuid, discoveryDevice.hostAddress)
var usedConfigIndex = 0; var usedConfigIndex = 0;
for (var i = 1; i < discoveryDevice.portConfigs.count; i++) { for (var i = 1; i < discoveryDevice.portConfigs.count; i++) {
var oldConfig = discoveryDevice.portConfigs.get(usedConfigIndex); var oldConfig = discoveryDevice.portConfigs.get(usedConfigIndex);
@ -172,7 +143,36 @@ Page {
usedConfigIndex = i; usedConfigIndex = i;
} }
} }
Engine.connection.connect(discoveryDevice.toUrl(usedConfigIndex)) return usedConfigIndex
}
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
Label {
text: model.name
Layout.fillWidth: true
elide: Text.ElideRight
}
Label {
text: model.hostAddress
font.pixelSize: app.smallFont
}
}
ColorIcon {
Layout.fillHeight: true
Layout.preferredWidth: height
property bool hasSecurePort: discoveryDeviceDelegate.discoveryDevice.portConfigs.get(discoveryDeviceDelegate.defaultPortConfigIndex).sslEnabled
property bool isTrusted: Engine.connection.isTrusted(discoveryDeviceDelegate.discoveryDevice.toUrl(discoveryDeviceDelegate.defaultPortConfigIndex))
visible: hasSecurePort
name: "../images/network-secure.svg"
color: isTrusted ? app.guhAccent : keyColor
}
}
onClicked: {
Engine.connection.connect(discoveryDevice.toUrl(defaultPortConfigIndex))
pageStack.push(connectingPage) pageStack.push(connectingPage)
} }
@ -191,7 +191,6 @@ Page {
popup.open() popup.open()
} }
} }
} }
Column { Column {
@ -373,9 +372,12 @@ Page {
y: (parent.height - height) / 2 y: (parent.height - height) / 2
standardButtons: Dialog.Yes | Dialog.No standardButtons: Dialog.Yes | Dialog.No
property string url
property var fingerprint property var fingerprint
property var issuerInfo property var issuerInfo
readonly property bool hasOldFingerprint: Engine.connection.isTrusted(url)
ColumnLayout { ColumnLayout {
id: certLayout id: certLayout
anchors.fill: parent anchors.fill: parent
@ -387,16 +389,16 @@ Page {
ColorIcon { ColorIcon {
Layout.preferredHeight: app.iconSize * 2 Layout.preferredHeight: app.iconSize * 2
Layout.preferredWidth: height Layout.preferredWidth: height
name: "../images/dialog-warning-symbolic.svg" name: certDialog.hasOldFingerprint ? "../images/lock-broken.svg" : "../images/info.svg"
color: app.guhAccent color: certDialog.hasOldFingerprint ? "red" : app.guhAccent
} }
Label { Label {
id: titleLabel id: titleLabel
Layout.fillWidth: true Layout.fillWidth: true
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
text: qsTr("Warning") text: certDialog.hasOldFingerprint ? qsTr("Warning") : qsTr("Hi there!")
color: app.guhAccent color: certDialog.hasOldFingerprint ? "red" : app.guhAccent
font.pixelSize: app.largeFont font.pixelSize: app.largeFont
} }
} }
@ -404,13 +406,13 @@ Page {
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
text: qsTr("The authenticity of this %1 box cannot be verified.").arg(app.systemName) text: certDialog.hasOldFingerprint ? qsTr("The certificate of this %1 box has changed!").arg(app.systemName) : qsTr("It seems this is the first time you connect to this %1 box.").arg(app.systemName)
} }
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
text: qsTr("If this is the first time you connect to this box, this is expected. Once you trust a box, you should never see this message again for that one. If you see this message multiple times for the same box, something suspicious is going on!") text: certDialog.hasOldFingerprint ? qsTr("Did you change the box's configuration? Verify if this information is correct.") : qsTr("This is the box's certificate. Once you trust it, an encrypted connection will be established.")
} }
ThinDivider {} ThinDivider {}
@ -423,6 +425,10 @@ Page {
contentHeight: certGridLayout.implicitHeight contentHeight: certGridLayout.implicitHeight
clip: true clip: true
ScrollBar.vertical: ScrollBar {
policy: contentHeight > height ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded
}
GridLayout { GridLayout {
id: certGridLayout id: certGridLayout
columns: 2 columns: 2
@ -452,14 +458,15 @@ Page {
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
text: qsTr("Do you want to trust this device?") text: certDialog.hasOldFingerprint ? qsTr("Do you want to connect nevertheless?") : qsTr("Do you want to trust this device?")
font.bold: true font.bold: true
} }
} }
onAccepted: { onAccepted: {
Engine.connection.acceptCertificate(certDialog.fingerprint) Engine.connection.acceptCertificate(certDialog.url, certDialog.fingerprint)
Engine.connection.connect(certDialog.url)
} }
} }
} }
@ -576,8 +583,10 @@ Page {
ColorIcon { ColorIcon {
Layout.preferredHeight: app.iconSize Layout.preferredHeight: app.iconSize
Layout.preferredWidth: height Layout.preferredWidth: height
name: model.sslEnabled ? "../images/network-secure.svg" : "../images/lock-broken.svg" visible: model.sslEnabled
color: model.sslEnabled ? app.guhAccent : "red" name: "../images/network-secure.svg"
property bool isTrusted: Engine.connection.isTrusted(dialog.discoveryDevice.toUrl(index))
color: isTrusted ? app.guhAccent : keyColor
} }
} }
onClicked: { onClicked: {