Results 1 to 6 of 6

Thread: connect to rest service with qt and error SSL handshake failed

  1. #1
    Join Date
    Oct 2012
    Posts
    5
    Platforms
    Windows

    Default connect to rest service with qt and error SSL handshake failed

    I am trying to connect to rest service that has ssl certificates. I have those certificates files(cacert.pem and another file .pem) locally.
    For this purpose I use qt library.
    I can connect to a rest service without certificates but I cannot connect to a service with certificates.

    I try this code(having the certificate in the release folder of the project)

    Qt Code:
    1. QNetworkAccessManager *m_network = new QNetworkAccessManager(this);
    2.  
    3. QNetworkRequest request;
    4.  
    5. QUrl wapi_url=QUrl("...");
    6.  
    7. wapi_url.setPort(8082);
    8.  
    9. request.setUrl(wapi_url);
    10.  
    11. QSslConfiguration SslConfiguration(QSslConfiguration::defaultConfiguration());
    12.  
    13. QList<QSslCertificate> caList = SslConfiguration.caCertificates();
    14.  
    15. caList.append(QSslCertificate("cacert.pem")); //Root CA
    16.  
    17. SslConfiguration.setCaCertificates(caList);
    18.  
    19. SslConfiguration.setLocalCertificate(QSslCertificate("bla_bla_server.pem"));
    20.  
    21. SslConfiguration.setProtocol(QSsl::SslV3);
    22.  
    23. SslConfiguration.setPeerVerifyMode(QSslSocket::VerifyPeer);
    24.  
    25. request.setSslConfiguration(SslConfiguration);
    26. QNetworkReply *reply = m_network->get(request);
    To copy to clipboard, switch view to plain text mode 

    but I get a SSL handshake failed error.
    Any idea how can I pass this error and connect to the rest service?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: connect to rest service with qt and error SSL handshake failed

    You could start by telling us what the error was (any text output and the QSslError value) and whether you have installed OpenSSL.

  3. #3
    Join Date
    Oct 2012
    Posts
    5
    Platforms
    Windows

    Default Re: connect to rest service with qt and error SSL handshake failed

    Yes I have installed OpenSSL.
    I connect the QNetworkReply:networkerror with a method messageError like this

    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,SLOT(messageError(QNetworkReply::NetworkError )));

    and the error I get is "SSL handshake failed" and the number is 6
    I also have added a connection like that

    connect(m_network, SIGNAL(sslErrors(QNetworkReply , const QList<QSslError> &)), this, SLOT(sslError(QNetworkReply, const QList<QSslError> &)));

    but my code doesn't go inside sslError method.
    Any idea about that?

    Thank you in advance!

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: connect to rest service with qt and error SSL handshake failed

    There is no SIGNAL or SLOT matching the signature"sslErrors(QNetworkReply , const QList<QSslError> &)". Perhaps you mean "sslErrors(QNetworkReply*,QList<QSslError>)" and are ignoring the warning printed in the console by connect().
    For consistency you could use the sslErrors() signal from the reply object.

    If there is a more general SSL library issue you will also see warnings about that in the output.

  5. #5
    Join Date
    Oct 2012
    Posts
    5
    Platforms
    Windows

    Default Re: connect to rest service with qt and error SSL handshake failed

    I don't know if I have understand well what you have proposed.
    I have added the following line

    connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslError2(const QList<QSslError>)));

    but the execution of the program does not get inside sslError2 slot.
    Last edited by panagiotisss; 21st September 2015 at 14:47.

  6. #6
    Join Date
    Oct 2012
    Posts
    5
    Platforms
    Windows

    Default Re: connect to rest service with qt and error SSL handshake failed

    I have achieved to pass this error by copying msvcr120.dll and msvcp120.dll in to bin folder of openssl
    But now I receive new errors
    QSslSocket: cannot call unresolved function SSLv3_client_method
    QSslSocket: cannot call unresolved function SSL_CTX_new
    QSslSocket: cannot call unresolved function SSL_library_init
    QSslSocket: cannot call unresolved function ERR_get_error

    I have the test line of code in qt
    qsslsocket::supportsssl()
    that returns false

    In my .pro file I have the qt+=network and I have also paste to qt bin folder the following dlls
    libeay32.dll
    libssl32.dll
    ssleay32.dll

    Any idea about that?

Similar Threads

  1. Rest Web Service - Keep-alive Connection
    By buleron in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 29th May 2015, 16:54
  2. Replies: 2
    Last Post: 16th November 2012, 03:39
  3. service and object registration on ARM gets failed.why so?
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 13th July 2010, 07:33
  4. QNetworkAccessManager: "SSL handshake failed"
    By kleag in forum Qt Programming
    Replies: 9
    Last Post: 6th November 2009, 11:41
  5. QWebView SSL Handshake failed
    By srikanth_trulyit in forum Qt Programming
    Replies: 1
    Last Post: 19th June 2009, 11:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.