From f3beb1624c24012c246d17a40c4e10c1c6b3b5b5 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Tue, 31 Mar 2026 17:44:35 +0200 Subject: Add passphrase-protected private key support Wire up QOpcUaClient::passwordForPrivateKeyRequired to a QML dialog, mirroring the existing certificate trust flow (local QEventLoop + 30s timeout). --- src/OpcUaClient.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/OpcUaClient.h') diff --git a/src/OpcUaClient.h b/src/OpcUaClient.h index 1476911..7ecd11b 100644 --- a/src/OpcUaClient.h +++ b/src/OpcUaClient.h @@ -88,6 +88,11 @@ public: /** @brief Reject the pending server certificate. */ Q_INVOKABLE void rejectCertificate (); + /** @brief Provide the password for an encrypted private key. */ + Q_INVOKABLE void provideKeyPassword (const QString &password); + /** @brief Cancel the private-key password prompt (abort connection). */ + Q_INVOKABLE void cancelKeyPassword (); + /* -- Discovery -- */ QString discoveryUrl () const; @@ -136,6 +141,14 @@ signals: void certificateTrustRequested (const QString &certInfo); void connectionError (const QString &message); void statusMessage (const QString &message); + /** + * @brief Emitted when the private key is encrypted. + * + * The connection blocks until provideKeyPassword() or + * cancelKeyPassword() is called (30 s timeout, auto-cancels). + */ + void privateKeyPasswordRequired (const QString &keyFilePath, + bool previousTryWasInvalid); /* -- Discovery -- */ void discoveryUrlChanged (); @@ -156,6 +169,8 @@ private slots: const QUrl &requestUrl); void handleConnectError (QOpcUaErrorState *errorState); void handleClientError (QOpcUaClient::ClientError error); + void handlePasswordRequired (QString keyFilePath, QString *password, + bool previousTryWasInvalid); /* -- Discovery -- */ void handleFindServersFinished ( @@ -174,6 +189,8 @@ private: bool m_connected = false; QEventLoop *m_certLoop = nullptr; bool m_certAccepted = false; + QEventLoop *m_keyPassLoop = nullptr; + QString m_keyPassword; /* -- Discovery -- */ QString m_discoveryUrl; -- cgit v1.2.3