Results 1 to 10 of 10

Thread: QNetworkAccessManager: "SSL handshake failed"

  1. #1
    Join Date
    Feb 2009
    Location
    France
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QNetworkAccessManager: "SSL handshake failed"

    Hello,

    I'm trying to access to a SOAP web service protected by certificate (the server one is auto-signed, the client one should be presented).
    I'm using Qt4.5 from qt-copy (in kde) under GNU/Linux but I had the same problem with Qt4.4.x

    I'm using the following code:
    Qt Code:
    1. qDebug() << "setting up SSL configuration: " << m_sslKeyFile;
    2. QSslConfiguration sslConfiguration = request.sslConfiguration();
    3. QFile sslCertificateFile(m_sslKeyFile);
    4. if (sslCertificateFile.open(QIODevice::ReadOnly))
    5. {
    6. QSslCertificate certif(&sslCertificateFile);
    7. sslCertificateFile.close();
    8. if (certif.isNull())
    9. {
    10. qDebug() << "Failed to load certificate";
    11. }
    12. qDebug() << "certif version=" << certif.version() << ", serial=" << certif.serialNumber()
    13. << ", issuer=" << certif.issuerInfo(QSslCertificate::Organization)
    14. << " and subject=" << certif.subjectInfo(QSslCertificate::CommonName);
    15. sslConfiguration.setLocalCertificate(certif);
    16. sslCertificateFile.close();
    17. sslCertificateFile.open(QIODevice::ReadOnly);
    18. QSslKey key(&sslCertificateFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
    19. qDebug() << "key isNull ? " << key.isNull();
    20. sslConfiguration.setPrivateKey(key);
    21. sslConfiguration.setProtocol(QSsl::SslV2);
    22. sslConfiguration.setPeerVerifyMode(QSslSocket::QueryPeer);
    23. request.setSslConfiguration(sslConfiguration);
    24. }
    25. ...
    26. qDebug() << "send post";
    27. m_networkReply = m_networkAccessManager->post(request, m_tempFile); // m_networkAccessManager est QNetworkAccessManager
    28. ...
    29. void QSoapServiceClient::slotNetworkReplyError(QNetworkReply::NetworkError)
    30. {
    31. qDebug() << "QSoapServiceClient::slotNetworkReplyError: " << m_networkReply->errorString();
    32. m_answer = "";
    33. }
    To copy to clipboard, switch view to plain text mode 

    And I obtain at runtime:
    Qt Code:
    1. setting up SSL configuration: "/path/to/pem/file"
    2. certif version= "" , serial= "" , issuer= "xxx" and subject= "yyy"
    3. key isNull ? false
    4. send post
    5. connecting reply signals
    6. sent
    7. QSoapServiceClient::slotNetworkReplyError: "SSL handshake failed"
    To copy to clipboard, switch view to plain text mode 

    Note that by using a QProcess launching curl with options -k and -E, it works... Thus the certificate is OK. It's really my code which is bad but I cannot see where...

    Any idea ?
    Last edited by jacek; 13th February 2009 at 23:38. Reason: wrapped too long line

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    Maybe you should run wireshark and compare what your application and curl do?

  3. #3
    Join Date
    Feb 2009
    Location
    France
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    jacek: That was a good idea! I did the test with wireshark and found a difference: the curl call uses TLSv1 while the QNetworkAccessManager one use SSLv3.

    Thus, I tried to force the use of TLSv1 with no success. I did:
    Qt Code:
    1. sslConfiguration.setProtocol(QSsl::TlsV1);
    2. request.setSslConfiguration(sslConfiguration);
    3. qDebug() << "send post" << request.sslConfiguration().protocol();
    4. m_networkReply = m_networkAccessManager->post(request, m_tempFile);
    To copy to clipboard, switch view to plain text mode 
    Then the qDebug write 'send post 2' where 2 is the value for TLSv1, but wireshark still shows a connection with SSLv3.

    I tried to llok at the Qt code to see if there was not a problem in the handling of this configuration but was not able to find anything...

    More ideas ? Does it look like a Qt bug ? Do you think that I am ready to report it or should I do more tests ?

  4. #4
    Join Date
    Oct 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    Hi,
    did anyone solve this?
    I'm facing same problem! Everytime I try to connect I recieve the handshake failed!


    Where do you get the "request" variablefrom?? This one doesnt work for me so far!

    I tried to do a reimplement of the code above but

    Qt Code:
    1. void MainWindow::setUpSSL()
    2. {
    3. QFile file(":/cert/client.pem");
    4. // QtSoapHttpTransport http;/*defined in h*/
    5. QNetworkReply *request = http.networkReply(); // this fails....ok its a NULL ptr. when is it initialied? Or better what to use to set the cert?
    6. Q_ASSERT(file.open(QIODevice::ReadOnly));
    7. QSslCertificate cert(&file, QSsl::Pem);
    8. file.close();
    9.  
    10. if(cert.isValid() && !cert.isNull())
    11. {
    12.  
    13. QSslConfiguration sslConfiguration = request->sslConfiguration();
    14. sslConfiguration.setLocalCertificate(cert);
    15. file.close();
    16. file.open(QIODevice::ReadOnly);
    17. QSslKey key(&file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
    18. qDebug() << "key isNull ? " << key.isNull();
    19. sslConfiguration.setPrivateKey(key);
    20. sslConfiguration.setProtocol(QSsl::SslV2);
    21. sslConfiguration.setPeerVerifyMode(QSslSocket::QueryPeer);
    22. request->setSslConfiguration(sslConfiguration);
    23. }
    24. qDebug() << "sending post";
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 



    BTW:
    I find it quite strange that I only get the readyResponse Signal
    I'm connected to several others
    Qt Code:
    1. connect(http.networkAccessManager(), SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))
    2. ,this, SLOT(authReq(QNetworkReply*,QAuthenticator*)));
    3.  
    4. connect(http.networkAccessManager(),SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(on_sslErr(QNetworkReply*,QList<QSslError>)));
    5. connect(http.networkAccessManager(), SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this,SLOT(on_proxyReq(QNetworkProxy,QAuthenticator*)));
    6.  
    7. connect(&http, SIGNAL(responseReady()), SLOT(readResponse()));
    To copy to clipboard, switch view to plain text mode 

    Only Slot readresponse is called!.
    Connect works fine (no messages in output pane)


    Where amI doing something wrong??
    Last edited by AuE; 21st October 2009 at 08:20.

  5. #5
    Join Date
    Oct 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    Anyone of you has an idea or maybe some sample code how to connect to a server usig own certificate and ssl?

    App Output

    Network transport error (6): SSL handshake failed

    "Unknown error"
    "SSL handshake failed"
    ################################################## ##################################################
    CA cert: (QSslCertificate("","","smth","MyCompany GmbH","MyCompany GmbH",QMap() , QDateTime("Mon Oct 30 15:49:02 2006") , QDateTime("Sun Oct 30 15:49:02 2011") ) )
    Local cert QSslCertificate( "" , "" , "smth" , "MyCompany GmbH" , "MyCompany GmbH" , QMap() , QDateTime("Mon Oct 30 15:49:02 2006") , QDateTime("Sun Oct 30 15:49:02 2011") )
    SSL Protocoll 1
    Private Key QSslKey( PrivateKey , RSA , -1 )
    ################################################## ##################################################
    "<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" >
    <SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <Faultcode xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" >SOAP-ENV:Client</Faultcode>
    <Faultstring xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" >Network transport error (6): SSL handshake failed</Faultstring>
    </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    "
    Last edited by AuE; 21st October 2009 at 11:20.

  6. #6
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    I too have had problems getting client certificates to work with Qt4.5.x, both with clients coded with Qt itself, and with libcurl.

    I raised a bug in Tasktracker sometime ago (258725) but for some reason, it doesn't seem to show up when I do a search (do Nokia hide some of them, for some reason ?)

    If anyone is sufficiently interested, I can send them a tarball of the code and bug report that I submitted to Tasktracker.

  7. #7
    Join Date
    Oct 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    Hey!

    How did you do this? Would love to see some code!
    And did you solve it anyway?

    When to set the QSslConfiguration?
    How to get my Ssl cfg into the QtSoapHttpTransport class?

  8. #8
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    >How did you do this?

    I assume that you mean me ? If so, how did I do what ? How did I submit a bug report to Nokia ?

    >Would love to see some code!

    You want to see the code for the submitted bug report ?

    >And did you solve it anyway?

    No. It's still an outstanding problem. AFAICS there's a bug in Qt's SSL logic, and I'm hoping that they'll look at it someday. I've had no response to the bug report so far.

  9. #9
    Join Date
    Oct 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    No,I mean how you found out that there is a bug!
    The strange thing is: I connect to gammel.de using setHost("gammel.de", true);
    and there I try to get the method "j_security_check" n the same subfolder.,
    As soon as I do thos I receive the sslError Signal. Telling me that I do not have ca cert and so on!

    But when I do this local this doesnt work! I just receive readyRead and the message is Fault!

    May I see your code?

    What do you think the the error comes from?
    ow/where when do you submit your Sslconfiguraion?

    Qt Code:
    1. QSslConfiguration sslConfiguration = request->sslConfiguration();
    2. sslConfiguration.setLocalCertificate(cert);
    3. file.close();
    4. QString passphrase = "antivir_default";
    5. file.open(QIODevice::ReadOnly);
    6.  
    7. QSslKey key(&file, QSsl::Rsa, QSsl::Pem,QSsl::PrivateKey , passphrase.toAscii());
    8.  
    9. sslConfiguration.setCaCertificates(QList<QSslCertificate>() << cert);
    10. sslConfiguration.setPrivateKey(key);
    11. sslConfiguration.setProtocol(QSsl::TlsV1);
    12. sslConfiguration.setPeerVerifyMode(QSslSocket::QueryPeer);
    To copy to clipboard, switch view to plain text mode 


    Where request is QNetworkReply *request = http.networkReply(); // this fails....ok its a NULL ptr. when is it initialied? Or better what to use to set the cert?
    and http is QtSoapHttpTransport http;

    So I thought with request->setSslConfiguration(sslConfiguration);
    this would be used for next request but doesnt!

  10. #10
    Join Date
    Oct 2009
    Posts
    37
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QNetworkAccessManager: "SSL handshake failed"

    Hi,

    Does it work when you do setProtocol(QSsl::AnyProtocol) ?
    Disclaimer: Although I work on Qt for Nokia, anything I post here is personal

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.