Results 1 to 10 of 10

Thread: SSL Problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default SSL Problem

    I compiled Qt with OpenSSL, it works fine on most https sites , but when I tried to visit sites such as
    https://login.yahoo.com
    I get "SSL Handshake Failed" error.

    I thought it's my program's problem, so I used the browser comes with Qt Demo, it's the same thing.

    Any idea how to fix it? Thank you in advance.

    Qt version: 4.5.1
    OpenSSL version: 0.9.8.11

  2. #2
    Join Date
    Feb 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SSL Problem

    I think I found the reason for handshake failure.

    The default "QSslConfiguration::setPeerVerifyMode" in Qt is "AutoVerifyPeer". And those sites that are giving me problems don't have identity information in their certificate. Therefore the verification fails.

    I guess the question now is how do I modify QSslConfiguration of a QNetworkAccessManager in QWebPage?

  3. #3
    Join Date
    Jun 2009
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SSL Problem

    Hi,

    Did you solve this issue. Im also facing the similar problem. Kindly post how do you set the sslconfiguration of qwebview

    Thanks,
    Srikanth

  4. #4
    Join Date
    Jan 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SSL Problem

    Hi, all

    I am writting some program which should connect to site using SSL. The site has right (not self-signed) certificate. But there are two problems (or, may be, one). The CA certificate is not wide-known certificate (in other words, the site uses chain certificate), and the site doesn't send them together. Indeed it is not a problem for browsers (they get site certificate with X509v3 Key Usage: Digital Signature, Key Encipherment, extract the Authority Information Access, and after that download the CA certificate with X509v3 Key Usage: Certificate Sign, CRL Sign).

    So, the question: how can I get the same behaviour from my program? Whether I should use QSslSocket or I can manage the task using QNetworkAccessManager?

    I tried to get the certificate list in sslError function, but I can not see the site certificate there, only root CA's from my host computer.

  5. #5
    Join Date
    Sep 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SSL Problem

    Hi, rolad8454

    I face the same problem like you, have you got the solution for modify QSslConfiguration ..?

    I tried call the function QSslConfiguration::setPeerVerifyMode(QSslSocket::V erifyNone), then I get the mode value, only to find the Mode is still the default value AutoVerifyPeer. It seems that the setPeerVerifyMode don't have any effect.

    Quote Originally Posted by roland8454 View Post
    I think I found the reason for handshake failure.

    The default "QSslConfiguration::setPeerVerifyMode" in Qt is "AutoVerifyPeer". And those sites that are giving me problems don't have identity information in their certificate. Therefore the verification fails.

    I guess the question now is how do I modify QSslConfiguration of a QNetworkAccessManager in QWebPage?

  6. #6
    Join Date
    Feb 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SSL Problem

    It's been a long time since I fixed that problem. I'm not quite sure exactly what I did. But I'm going to give it a try.

    1. Make sure you build Qt with OpenSSL correctly following my instructions here:
    http://www.rolandli.com/2009/05/22/b...t-with-openssl

    2. I think what I did was reimplemented createRequest function in QNetworkAccess Manager

    header file:
    Qt Code:
    1. class myNetworkAccessManager : public QNetworkAccessManager
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. myNetworkAccessManager ();
    7.  
    8. protected:
    9. QNetworkReply * createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 );
    10. };
    To copy to clipboard, switch view to plain text mode 


    source file:
    Qt Code:
    1. myNetworkAccessManager ::myNetworkAccessManager (){
    2. }
    3.  
    4. QNetworkReply * myNetworkAccessManager ::createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData ){
    5. QSslConfiguration config = req.sslConfiguration();
    6. config.setPeerVerifyMode(QSslSocket::VerifyNone);
    7. config.setProtocol(QSsl::TlsV1);
    8. QNetworkRequest request(req);
    9. request.setSslConfiguration(config);
    10. return QNetworkAccessManager::createRequest(op, request, outgoingData);
    11. }
    To copy to clipboard, switch view to plain text mode 

    Hope this helps. Good luck!

  7. #7
    Join Date
    Feb 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SSL Problem

    This is what works for me.

    class SslNetworkAccessManager : public QNetworkAccessManager
    {
    Q_OBJECT
    public:
    SslNetworkAccessManager();


    protected:
    QNetworkReply* createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0);
    };

    And the implementation:


    SslNetworkAccessManager::SslNetworkAccessManager()
    {
    }



    QNetworkReply* SslNetworkAccessManager::createRequest(Operation op, const QNetworkRequest& req, QIODevice* outgoingData)
    {
    QNetworkReply* reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
    reply->ignoreSslErrors();
    return reply;
    }

  8. #8
    Join Date
    Mar 2012
    Location
    India
    Posts
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Re: SSL Problem

    Hi All,

    I am new in Qt programming, i need your help to resolve an issue.
    I want to display certificate information of secured website in "Qt demo brower", for this i write code to display but i am unable to get "defaultCaCertificate", "caCertificate" and "peerCertificateChain".
    Do we need any type of initilization before using these APIs ?

    Every time when i call below code it retrive 0 items in dCaCertificates.
    QList<QSslCertificate> dCaCertificates = QSslSocket::defaultCaCertificates();

    But i am able to get system certificates using below code:
    QList<QSslCertificate> sysCertificates = QSslSocket::systemCaCertificates();

    Please help me, its urgent.

    Regards,
    Pranay

  9. #9
    Join Date
    Mar 2012
    Location
    India
    Posts
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: SSL Problem

    Hi Pranay,

    If you want to get and display certificate details in Qt demo browser, here is the code:
    First of all to peerCertificateChain details, one can use the SLOT sslError, the argument within this SLOT named QNetworkReply have all the details of peerCertificateChain and peerCertificate.

    void NetworkAccessManager::sslError(QNetworkReply *reply, const QList<QSslError> &error)
    {
    QList<QSslCertificate> peerCertificateChain = reply->sslConfiguration().peerCertificateChain();
    }

    Thanks & Regards,
    Software

  10. #10
    Join Date
    Jan 2013
    Posts
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SSL Problem

    @10ventura
    Just signed up to say thank-you for your Implementation of Subclassing QNetworkAccessManager, after doing that, this resolved my problem.

    However my problem of getting "Invalid SSL Handshake" was when i tried moving my class which was using QNetworkAccessManager to another thread that subclassed QObject (for signals and slots) using className->moveToThread(threadName).

    If i didn't move to another thread my SLOT to receive SSL Errors worked and was able to "reply->setIgnoreSSLErrors".

    Regardless of the different situation,

    Thank you again :-)


    EDIT: After doing this i was able to receive a reply, however after receiving.. my connect(manager, SIGNAL(finished(QNetworkReply*)), manager, SLOT(deleteLater())); would cause my program to crash..
    After removing the line, it doens't crash. Any thoughts?

    2nd Edit: I use this new Subclass of QNetworkAccessManager by creating a new class every time i make new requests. Only the first time it is called, having the slot connected to delete the manager is it crashing the program, further on when a new instance of class is created, it connects and deletes the manager without crashing..

    NetworkAccessManager *manager = new NetworkAccessManager();
    //connect(manager, SIGNAL(finished(QNetworkReply*)), manager, SLOT(deleteLater())); //This line causes program to terminate/crash
    connect(manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)) , this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));

    ..then later when i make another request
    NetworkAccessManager *manager = new NetworkAccessManager();
    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(getAlbumCoverImageDataReply(QNetworkReply*))) ;
    connect(manager, SIGNAL(finished(QNetworkReply*)), manager, SLOT(deleteLater())); //doesn't crash app?
    connect(manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)) , this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));


    Thanks.
    Last edited by zerokewl; 26th August 2013 at 05:37.

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  2. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.