Unsolved Problem with secure websocket example
-
I'm afraid there isn't. the QML WebSocket is just a wrapper around the C++ one and
- ignoreSslErrors is not a slot nor
Q_INVOKABLE
- I don't think QML can handle
QList<QSslError>
- ignoreSslErrors is not a slot nor
-
Is this then a limitation?
Can't I at all use WebSocket element of QML to connect to a secure websocket server having self-signed certificate? (I am insisting on using QML WebSocket element because I want to use WebChannel for accessing server data structure on QML and HTML)
Would it be possible to raise this with Qt Development team? Which forum should I raise this to?
Regards,
-
Can't you just separate the logic from the ui and keep WebSocket on the C++ side?
Would it be possible to raise this with Qt Development team? Which forum should I raise this to?
In theory yes, and https://bugreports.qt.io would be the place to do it but it's not easy to implement so I wouldn't hope in a quick solution
-
@niku-ifm it looks like you have a digital certificate issue and not a QML one. I mean, have you tried connecting with HTML (i.e. web browser) even locally (from same location you're running your QML client) to your current sslechoserver? I'd bet you'll also have your browser complaining about security issues.
Could it be possible you list the properties of the server certificate you've created? -
Thank you for your reply Pablo,
Yes, browser do complain about it.
Quite possible that I have messed up with certificate generation, I would like to share my cert and key file here but I cant upload any file here. I dont mind sharing it because its just a self signed certificate. I am also wondering on this point that whether QML WebSocket really works with self signed certificate?Also could you please tell me what properties do you want me to list here?
regards,
-
if it helps, this is what i usually use to do testing: https://www.akadia.com/services/ssh_test_certificate.html
-
@VRonin As you said, I can keep the websocket logic on C++ side but how would I create the webchannel and get the data which is exposed on webchannel from WebSocketServer.
As I said earlier, this QML websocket code is part of Client application which connects to WebSocketServer application and calls some C++ methods on WebSocketServer through WebChannel.
-
@VRonin , as suggested by you, I tried creating WebSocket on C++ side. But using WebChannel with it wasn't possible.
From WebChannel.js, WebChannel takes QML WebSocket as input. I tried passing a C++ side created WebSocket to it but it doesnt work. It gives error from the JS file itself. So this option is gone for me :( -
@Pablo-J.-Rogina
I used following command to create my certificate and private key. Do you see any problem with this command?openssl req -newkey rsa:2048 -nodes -keyout setup.key -x509 -days 36500 -out setup.crt
Regards,
-
@niku-ifm it looks like the QtWebSockets in QML has the limitation of preventing ignoring SSL errors, as @VRonin already pointed out before.
From running the QML WebSocket Client Example connecting to the SSL Echo Server Example
I was able to use the certificate provided with the server example (localhost.cert) and the QML client displayed this error: "qml: Error: The certificate is self-signed, and untrusted", which was not related to DNS as the common name (CN) in the certificate was "localhost" and the URL I used was "wss://localhost:1234" but it is an expected error that I think cannot avoided in the QML WebSocket component.However, if using secure web sockets in QML is a must condition for you, I guess you could implement a WebSocket class in C++ as the current QML implementation is doing but adding the missing pieces, in particular a way of handling SSL errors from QML, following the guidelines of invoking C++ functionality from QML (i.e. the class must be registered as an instantiable QML type).
Happy coding!