mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Finish implementing squeleton code for MQTT SSL config
This commit is contained in:
parent
a74517cb09
commit
979f64430c
@ -501,15 +501,15 @@ FramelessWindow.CustomWindow {
|
||||
|
||||
ComboBox {
|
||||
id: _certificateMode
|
||||
model: [
|
||||
qsTr("CA signed server"),
|
||||
qsTr("Self signed")
|
||||
]
|
||||
|
||||
Layout.fillWidth: true
|
||||
opacity: enabled ? 1 : 0.5
|
||||
model: Cpp_MQTT_Client.certificateModes
|
||||
enabled: !Cpp_MQTT_Client.isConnectedToHost && _ssl.checked
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
onCurrentIndexChanged: {
|
||||
if (currentIndex !== Cpp_MQTT_Client.certificateMode)
|
||||
Cpp_MQTT_Client.certificateMode = currentIndex
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
@ -519,6 +519,7 @@ FramelessWindow.CustomWindow {
|
||||
Layout.maximumWidth: height
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
icon.source: "qrc:/icons/open.svg"
|
||||
onClicked: Cpp_MQTT_Client.loadCaFile()
|
||||
enabled: _certificateMode.currentIndex == 1 && _ssl.checked
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
}
|
||||
@ -557,6 +558,10 @@ FramelessWindow.CustomWindow {
|
||||
model: Cpp_MQTT_Client.sslProtocols
|
||||
enabled: !Cpp_MQTT_Client.isConnectedToHost && _ssl.checked
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
onCurrentIndexChanged: {
|
||||
if (currentIndex !== Cpp_MQTT_Client.sslProtocol)
|
||||
Cpp_MQTT_Client.sslProtocol = currentIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,11 @@ QString Client::topic() const
|
||||
return m_topic;
|
||||
}
|
||||
|
||||
int Client::sslProtocol() const
|
||||
{
|
||||
return m_sslProtocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the MQTT version, corresponding to the list returned by the
|
||||
* @c mqttVersions() function.
|
||||
@ -118,15 +123,15 @@ int Client::mqttVersion() const
|
||||
{
|
||||
switch (m_client.version())
|
||||
{
|
||||
case QMQTT::V3_1_0:
|
||||
return 0;
|
||||
break;
|
||||
case QMQTT::V3_1_1:
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
case QMQTT::V3_1_0:
|
||||
return 0;
|
||||
break;
|
||||
case QMQTT::V3_1_1:
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,6 +203,11 @@ bool Client::isSubscribed() const
|
||||
return isConnectedToHost() && !topic().isEmpty() && clientMode() == ClientSubscriber;
|
||||
}
|
||||
|
||||
int Client::certificateMode() const
|
||||
{
|
||||
return m_certificateMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if the MQTT module is connected to a MQTT broker/server.
|
||||
*/
|
||||
@ -241,17 +251,20 @@ StringList Client::mqttVersions() const
|
||||
*/
|
||||
StringList Client::sslProtocols() const
|
||||
{
|
||||
return StringList {
|
||||
tr("System default"),
|
||||
"TLS v1.0",
|
||||
"TLS v1.1",
|
||||
"TLS v1.2",
|
||||
"DTLS v1.0",
|
||||
"DTLS v1.2",
|
||||
"DTLS v1.3"
|
||||
};
|
||||
return StringList { tr("System default"), "TLS v1.0", "TLS v1.1", "TLS v1.2",
|
||||
"DTLS v1.0", "DTLS v1.2", "DTLS v1.3" };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with the supported certificate modes
|
||||
*/
|
||||
StringList Client::certificateModes() const
|
||||
{
|
||||
return StringList { tr("CA server signed"), tr("Self signed") };
|
||||
}
|
||||
|
||||
void Client::loadCaFile() { }
|
||||
|
||||
/**
|
||||
* Tries to establish a TCP connection with the MQTT broker/server.
|
||||
*/
|
||||
@ -347,6 +360,10 @@ void Client::setTopic(const QString &topic)
|
||||
emit topicChanged();
|
||||
}
|
||||
|
||||
void Client::loadCaFile(const QString &path) { }
|
||||
|
||||
void Client::setSslProtocol(const int index) { }
|
||||
|
||||
/**
|
||||
* Enables/disables SSL/TLS communications with the MQTT broker
|
||||
*/
|
||||
@ -360,6 +377,8 @@ void Client::setSslEnabled(const bool enabled)
|
||||
emit sslEnabledChanged();
|
||||
}
|
||||
|
||||
void Client::setCertificateMode(const int index) { }
|
||||
|
||||
/**
|
||||
* Changes the username used to connect to the MQTT broker/server
|
||||
*/
|
||||
@ -396,14 +415,14 @@ void Client::setMqttVersion(const int versionIndex)
|
||||
{
|
||||
switch (versionIndex)
|
||||
{
|
||||
case 0:
|
||||
m_client.setVersion(QMQTT::V3_1_0);
|
||||
break;
|
||||
case 1:
|
||||
m_client.setVersion(QMQTT::V3_1_1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case 0:
|
||||
m_client.setVersion(QMQTT::V3_1_0);
|
||||
break;
|
||||
case 1:
|
||||
m_client.setVersion(QMQTT::V3_1_1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
emit mqttVersionChanged();
|
||||
@ -485,99 +504,99 @@ void Client::onError(const QMQTT::ClientError error)
|
||||
|
||||
switch (error)
|
||||
{
|
||||
case QMQTT::UnknownError:
|
||||
str = tr("Unknown error");
|
||||
break;
|
||||
case QMQTT::SocketConnectionRefusedError:
|
||||
str = tr("Connection refused");
|
||||
break;
|
||||
case QMQTT::SocketRemoteHostClosedError:
|
||||
str = tr("Remote host closed the connection");
|
||||
break;
|
||||
case QMQTT::SocketHostNotFoundError:
|
||||
str = tr("Host not found");
|
||||
break;
|
||||
case QMQTT::SocketAccessError:
|
||||
str = tr("Socket access error");
|
||||
break;
|
||||
case QMQTT::SocketResourceError:
|
||||
str = tr("Socket resource error");
|
||||
break;
|
||||
case QMQTT::SocketTimeoutError:
|
||||
str = tr("Socket timeout");
|
||||
break;
|
||||
case QMQTT::SocketDatagramTooLargeError:
|
||||
str = tr("Socket datagram too large");
|
||||
break;
|
||||
case QMQTT::SocketNetworkError:
|
||||
str = tr("Network error");
|
||||
break;
|
||||
case QMQTT::SocketAddressInUseError:
|
||||
str = tr("Address in use");
|
||||
break;
|
||||
case QMQTT::SocketAddressNotAvailableError:
|
||||
str = tr("Address not available");
|
||||
break;
|
||||
case QMQTT::SocketUnsupportedSocketOperationError:
|
||||
str = tr("Unsupported socket operation");
|
||||
break;
|
||||
case QMQTT::SocketUnfinishedSocketOperationError:
|
||||
str = tr("Unfinished socket operation");
|
||||
break;
|
||||
case QMQTT::SocketProxyAuthenticationRequiredError:
|
||||
str = tr("Proxy authentication required");
|
||||
break;
|
||||
case QMQTT::SocketSslHandshakeFailedError:
|
||||
str = tr("SSL handshake failed");
|
||||
break;
|
||||
case QMQTT::SocketProxyConnectionRefusedError:
|
||||
str = tr("Proxy connection refused");
|
||||
break;
|
||||
case QMQTT::SocketProxyConnectionClosedError:
|
||||
str = tr("Proxy connection closed");
|
||||
break;
|
||||
case QMQTT::SocketProxyConnectionTimeoutError:
|
||||
str = tr("Proxy connection timeout");
|
||||
break;
|
||||
case QMQTT::SocketProxyNotFoundError:
|
||||
str = tr("Proxy not found");
|
||||
break;
|
||||
case QMQTT::SocketProxyProtocolError:
|
||||
str = tr("Proxy protocol error");
|
||||
break;
|
||||
case QMQTT::SocketOperationError:
|
||||
str = tr("Operation error");
|
||||
break;
|
||||
case QMQTT::SocketSslInternalError:
|
||||
str = tr("SSL internal error");
|
||||
break;
|
||||
case QMQTT::SocketSslInvalidUserDataError:
|
||||
str = tr("Invalid SSL user data");
|
||||
break;
|
||||
case QMQTT::SocketTemporaryError:
|
||||
str = tr("Socket temprary error");
|
||||
break;
|
||||
case QMQTT::MqttUnacceptableProtocolVersionError:
|
||||
str = tr("Unacceptable MQTT protocol");
|
||||
break;
|
||||
case QMQTT::MqttIdentifierRejectedError:
|
||||
str = tr("MQTT identifier rejected");
|
||||
break;
|
||||
case QMQTT::MqttServerUnavailableError:
|
||||
str = tr("MQTT server unavailable");
|
||||
break;
|
||||
case QMQTT::MqttBadUserNameOrPasswordError:
|
||||
str = tr("Bad MQTT username or password");
|
||||
break;
|
||||
case QMQTT::MqttNotAuthorizedError:
|
||||
str = tr("MQTT authorization error");
|
||||
break;
|
||||
case QMQTT::MqttNoPingResponse:
|
||||
str = tr("MQTT no ping response");
|
||||
break;
|
||||
default:
|
||||
str = "";
|
||||
break;
|
||||
case QMQTT::UnknownError:
|
||||
str = tr("Unknown error");
|
||||
break;
|
||||
case QMQTT::SocketConnectionRefusedError:
|
||||
str = tr("Connection refused");
|
||||
break;
|
||||
case QMQTT::SocketRemoteHostClosedError:
|
||||
str = tr("Remote host closed the connection");
|
||||
break;
|
||||
case QMQTT::SocketHostNotFoundError:
|
||||
str = tr("Host not found");
|
||||
break;
|
||||
case QMQTT::SocketAccessError:
|
||||
str = tr("Socket access error");
|
||||
break;
|
||||
case QMQTT::SocketResourceError:
|
||||
str = tr("Socket resource error");
|
||||
break;
|
||||
case QMQTT::SocketTimeoutError:
|
||||
str = tr("Socket timeout");
|
||||
break;
|
||||
case QMQTT::SocketDatagramTooLargeError:
|
||||
str = tr("Socket datagram too large");
|
||||
break;
|
||||
case QMQTT::SocketNetworkError:
|
||||
str = tr("Network error");
|
||||
break;
|
||||
case QMQTT::SocketAddressInUseError:
|
||||
str = tr("Address in use");
|
||||
break;
|
||||
case QMQTT::SocketAddressNotAvailableError:
|
||||
str = tr("Address not available");
|
||||
break;
|
||||
case QMQTT::SocketUnsupportedSocketOperationError:
|
||||
str = tr("Unsupported socket operation");
|
||||
break;
|
||||
case QMQTT::SocketUnfinishedSocketOperationError:
|
||||
str = tr("Unfinished socket operation");
|
||||
break;
|
||||
case QMQTT::SocketProxyAuthenticationRequiredError:
|
||||
str = tr("Proxy authentication required");
|
||||
break;
|
||||
case QMQTT::SocketSslHandshakeFailedError:
|
||||
str = tr("SSL handshake failed");
|
||||
break;
|
||||
case QMQTT::SocketProxyConnectionRefusedError:
|
||||
str = tr("Proxy connection refused");
|
||||
break;
|
||||
case QMQTT::SocketProxyConnectionClosedError:
|
||||
str = tr("Proxy connection closed");
|
||||
break;
|
||||
case QMQTT::SocketProxyConnectionTimeoutError:
|
||||
str = tr("Proxy connection timeout");
|
||||
break;
|
||||
case QMQTT::SocketProxyNotFoundError:
|
||||
str = tr("Proxy not found");
|
||||
break;
|
||||
case QMQTT::SocketProxyProtocolError:
|
||||
str = tr("Proxy protocol error");
|
||||
break;
|
||||
case QMQTT::SocketOperationError:
|
||||
str = tr("Operation error");
|
||||
break;
|
||||
case QMQTT::SocketSslInternalError:
|
||||
str = tr("SSL internal error");
|
||||
break;
|
||||
case QMQTT::SocketSslInvalidUserDataError:
|
||||
str = tr("Invalid SSL user data");
|
||||
break;
|
||||
case QMQTT::SocketTemporaryError:
|
||||
str = tr("Socket temprary error");
|
||||
break;
|
||||
case QMQTT::MqttUnacceptableProtocolVersionError:
|
||||
str = tr("Unacceptable MQTT protocol");
|
||||
break;
|
||||
case QMQTT::MqttIdentifierRejectedError:
|
||||
str = tr("MQTT identifier rejected");
|
||||
break;
|
||||
case QMQTT::MqttServerUnavailableError:
|
||||
str = tr("MQTT server unavailable");
|
||||
break;
|
||||
case QMQTT::MqttBadUserNameOrPasswordError:
|
||||
str = tr("Bad MQTT username or password");
|
||||
break;
|
||||
case QMQTT::MqttNotAuthorizedError:
|
||||
str = tr("MQTT authorization error");
|
||||
break;
|
||||
case QMQTT::MqttNoPingResponse:
|
||||
str = tr("MQTT no ping response");
|
||||
break;
|
||||
default:
|
||||
str = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!str.isEmpty())
|
||||
|
@ -105,6 +105,14 @@ class Client : public QObject
|
||||
READ sslEnabled
|
||||
WRITE setSslEnabled
|
||||
NOTIFY sslEnabledChanged)
|
||||
Q_PROPERTY(int sslProtocol
|
||||
READ sslProtocol
|
||||
WRITE setSslProtocol
|
||||
NOTIFY sslProtocolChanged)
|
||||
Q_PROPERTY(int certificateMode
|
||||
READ certificateMode
|
||||
WRITE setCertificateMode
|
||||
NOTIFY certificateModeChanged)
|
||||
Q_PROPERTY(bool isConnectedToHost
|
||||
READ isConnectedToHost
|
||||
NOTIFY connectedChanged)
|
||||
@ -123,6 +131,9 @@ class Client : public QObject
|
||||
Q_PROPERTY(StringList sslProtocols
|
||||
READ sslProtocols
|
||||
CONSTANT)
|
||||
Q_PROPERTY(StringList certificateModes
|
||||
READ certificateModes
|
||||
CONSTANT)
|
||||
Q_PROPERTY(quint16 defaultPort
|
||||
READ defaultPort
|
||||
CONSTANT)
|
||||
@ -143,8 +154,10 @@ signals:
|
||||
void connectedChanged();
|
||||
void clientModeChanged();
|
||||
void sslEnabledChanged();
|
||||
void sslProtocolChanged();
|
||||
void mqttVersionChanged();
|
||||
void lookupActiveChanged();
|
||||
void certificateModeChanged();
|
||||
|
||||
public:
|
||||
static Client *getInstance();
|
||||
@ -155,6 +168,7 @@ public:
|
||||
QString host() const;
|
||||
QString topic() const;
|
||||
int clientMode() const;
|
||||
int sslProtocol() const;
|
||||
int mqttVersion() const;
|
||||
bool sslEnabled() const;
|
||||
QString username() const;
|
||||
@ -162,17 +176,20 @@ public:
|
||||
quint16 keepAlive() const;
|
||||
bool lookupActive() const;
|
||||
bool isSubscribed() const;
|
||||
int certificateMode() const;
|
||||
bool isConnectedToHost() const;
|
||||
|
||||
StringList qosLevels() const;
|
||||
StringList clientModes() const;
|
||||
StringList mqttVersions() const;
|
||||
StringList sslProtocols() const;
|
||||
StringList certificateModes() const;
|
||||
|
||||
quint16 defaultPort() const { return 1883; }
|
||||
QString defaultHost() const { return "127.0.0.1"; }
|
||||
|
||||
public slots:
|
||||
void loadCaFile();
|
||||
void connectToHost();
|
||||
void toggleConnection();
|
||||
void disconnectFromHost();
|
||||
@ -183,7 +200,10 @@ public slots:
|
||||
void setHost(const QString &host);
|
||||
void setClientMode(const int mode);
|
||||
void setTopic(const QString &topic);
|
||||
void loadCaFile(const QString &path);
|
||||
void setSslProtocol(const int index);
|
||||
void setSslEnabled(const bool enabled);
|
||||
void setCertificateMode(const int index);
|
||||
void setUsername(const QString &username);
|
||||
void setPassword(const QString &password);
|
||||
void setKeepAlive(const quint16 keepAlive);
|
||||
@ -204,7 +224,9 @@ private slots:
|
||||
|
||||
private:
|
||||
QString m_topic;
|
||||
int m_sslProtocol;
|
||||
bool m_lookupActive;
|
||||
int m_certificateMode;
|
||||
QMQTT::Client m_client;
|
||||
quint16 m_sentMessages;
|
||||
QVector<QByteArray> m_frames;
|
||||
|
Loading…
x
Reference in New Issue
Block a user