Results 1 to 4 of 4

Thread: QSslSocket : Having troubles

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default QSslSocket : Having troubles

    Hi !

    I'm under Windows 2000 Pro, using the beautifull Qt4.3 open source version.
    This has not been recompiled, and it is configured in shared/debug.
    I've downloaed and installed the OpenSSL library, but I don't think this will help me.

    I was using a QtcpSocket on Qt4.2.3 to connect an IMAP server.
    Now I replaced it by a QSslSocket, that inherits from QtcpSocket, but I'm having troubles.



    Myclass.h :
    Qt Code:
    1. #include <QObject>
    2. #include <QTcpSocket>
    3. #include <QList>
    4. #include <QString>
    5. #include <QSslSocket>
    6. #include <QProcess>
    7.  
    8. class MailChecker : public QObject
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MailChecker();
    14. void Check();
    15.  
    16. private slots:
    17. void SLOT_socket_proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *);
    18. void SLOT_socket_sslErrors(const QList<QSslError>);
    19. void SLOT_socket_stateChanged(QAbstractSocket::SocketState);
    20. void SLOT_socket_connected();
    21. void SLOT_socket_disconnected();
    22. void SLOT_socket_encrypted();
    23. void SLOT_socket_hostFound();
    24.  
    25. private:
    26. QSslSocket *sockect_ssl;
    27.  
    28. // Socket management
    29. void openSocket();
    30. void closeSocket();
    31. bool readLineFromSocket(QByteArray&);
    32. bool writeToSocket(const QString &);
    33. };
    To copy to clipboard, switch view to plain text mode 


    Myclass.cpp :
    Qt Code:
    1. MailChecker::MailChecker() : QObject()
    2. { sockect_ssl = new QSslSocket(this);
    3.  
    4. connect(sockect_ssl, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy & proxy, QAuthenticator * authenticator)),
    5. this, SLOT(SLOT_socket_proxyAuthenticationRequired(const QNetworkProxy & proxy, QAuthenticator * authenticator)));
    6. connect(sockect_ssl, SIGNAL(sslErrors(const QList<QSslError>)),this, SLOT(SLOT_socket_sslErrors(const QList<QSslError>)));
    7. connect(sockect_ssl, SIGNAL(stateChanged), this, SLOT(SLOT_socket_stateChanged(QAbstractSocket::SocketState socketState)));
    8. connect(sockect_ssl, SIGNAL(connected()), this, SLOT(SLOT_socket_connected()));
    9. connect(sockect_ssl, SIGNAL(disconnected()),this, SLOT(SLOT_socket_disconnected()));
    10. connect(sockect_ssl, SIGNAL(encrypted()), this, SLOT(SLOT_socket_encrypted()));
    11. connect(sockect_ssl, SIGNAL(hostFound()), this, SLOT(SLOT_socket_hostFound()));
    12. }
    13. // ---------------------------------------------------------------------------------
    14. void MailChecker::SLOT_socket_proxyAuthenticationRequired(const QNetworkProxy & proxy, QAuthenticator * authenticator)
    15. {
    16. cout << "PROXY AUTHENTIFICATION REQUIRED" << endl;
    17. }
    18.  
    19. void MailChecker::SLOT_socket_sslErrors(const QList<QSslError> errors)
    20. {
    21. cout << "SSL ERRORS !" << endl;
    22. }
    23.  
    24. void MailChecker::SLOT_socket_stateChanged(QAbstractSocket::SocketState socketState)
    25. {
    26. cout << "STATE CHANGED" << endl;
    27. }
    28.  
    29. void MailChecker::SLOT_socket_connected()
    30. {
    31. cout << "CONNECTED" << endl;
    32. }
    33.  
    34. void MailChecker::SLOT_socket_disconnected()
    35. {
    36. cout << "DISCONNECTED" << endl;
    37. }
    38.  
    39. void MailChecker::SLOT_socket_encrypted()
    40. {
    41. cout << "ENCRYPTED" << endl;
    42. }
    43.  
    44. void MailChecker::SLOT_socket_hostFound()
    45. {
    46. cout << "HOST FOUND" << endl;
    47. }
    48. // ---------------------------------------------------------------------------------
    49. void MailChecker::openSocket()
    50. {
    51. sockect_ssl = new QSslSocket();
    52. }
    53.  
    54. void MailChecker::closeSocket()
    55. {
    56. if ( sockect_ssl )
    57. {
    58. sockect_ssl->close();
    59. sockect_ssl->deleteLater();
    60. }
    61. }
    62.  
    63. bool MailChecker::readLineFromSocket( QByteArray& data )
    64. {
    65. while ( !sockect_ssl->canReadLine() )
    66. {
    67. if ( !sockect_ssl->waitForReadyRead( 30 * 1000 ) )
    68. {
    69. closeSocket();
    70. return 0;
    71. }
    72. }
    73. if (sockect_ssl->readLine(data.data(), data.size()) == -1)
    74. {
    75. closeSocket();
    76. return false;
    77. }
    78. return true;
    79. }
    80.  
    81. bool MailChecker::writeToSocket( const QString & str )
    82. {
    83. QByteArray ba = str.toLocal8Bit();
    84.  
    85. qint64 wrote = 0;
    86. while ( wrote < (qint64)ba.size() )
    87. {
    88. qint64 ret = sockect_ssl->write( ba.data() + wrote, ba.size() - wrote );
    89. if ( ret == -1 )
    90. return false; // error
    91. wrote += ret;
    92. }
    93. sockect_ssl->waitForBytesWritten();
    94. return true;
    95. }
    To copy to clipboard, switch view to plain text mode 
    My first trouble is that the Slot are never called by my application... And they should be.
    I don't understand why...



    (1) Using the QSslSocket like a QTcpSocket (no encryption) :
    Qt Code:
    1. void MailChecker::Check()
    2. {
    3. sockect_ssl->connectToHost(IMAP_host, IMAP_port);
    4.  
    5. if (sockect_ssl->waitForConnected(15000))
    6. {
    7. if (readLineFromSocket(line))
    8. {
    9. ...
    10. }
    11. else
    12. {
    13. cout << "\n ERROR - Unable to read server response. " << endl;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    This worked well for my old class using the QTcpSocket.
    Now, this works well too, with the QSslSocket... But the data isn't encrypted.



    (2) Using the QSslSocket with encryption :
    Qt Code:
    1. void MailChecker::Check()
    2. {
    3. sockect_ssl->connectToHostEncrypted(IMAP_host, IMAP_port);
    4.  
    5. if (sockect_ssl->waitForConnected(15000))
    6. {
    7. if (readLineFromSocket(line))
    8. {
    9. ...
    10. }
    11. else
    12. {
    13. cout << "\n ERROR - Unable to read server response. " << endl;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    This should work. This is like the example given is the documentation...
    But I get the ERROR message immediately : the socket hasn't waited for 15s. trying to connect to host with the encrypted mode.



    (3) Using the QSslSocket with encryption :
    Qt Code:
    1. void MailChecker::Check()
    2. {
    3. sockect_ssl->connectToHost(IMAP_host, IMAP_port);
    4.  
    5. if (sockect_ssl->waitForConnected(15000))
    6. {
    7. sockect_ssl->startClientEncryption();
    8. if (readLineFromSocket(line))
    9. {
    10. ...
    11. }
    12. else
    13. {
    14. cout << "\n ERROR - Unable to read server response. " << endl;
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    This is the sameThis code should do the same job as the (2) solution, but is provided for a TLS support. In my case, I get the ERROR like before, without any wait for connection.


    If someone has an idea ?
    Thanks
    Last edited by jacek; 22nd June 2007 at 16:53. 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: QSslSocket : Having troubles

    Quote Originally Posted by Nyphel View Post
    My first trouble is that the Slot are never called by my application... And they should be.
    Are there any messages on the console?

    (You have to add "CONFIG += console" to the .pro file to see the console.)

  3. The following user says thank you to jacek for this useful post:

    Nyphel (26th June 2007)

  4. #3
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket : Having troubles

    The debug informations allowed me to adjust 3 connect declarations for my Signals/Slots... But they're still not called.

    Moreover, for the following source code I get some debug advices :
    Qt Code:
    1. sockect_ssl = new QSslSocket(this);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QSslSocket: cannot find ssleay32 library: QLibrary::load_sys: Cannot load ssleay32 (Le module spécifié est introuvable.).
    2. QSslSocketBackendPrivate::ensureInitialized: unable to resolve all symbols
    3. QSslSocket: cannot find ssleay32 library: QLibrary::load_sys: Cannot load ssleay32 (Le module spécifié est introuvable.).
    4. QSslSocketBackendPrivate::ensureInitialized: unable to resolve all symbols
    5. QSslSocket: cannot find ssleay32 library: QLibrary::load_sys: Cannot load ssleay32 (Le module spécifié est introuvable.).
    6. QSslSocketBackendPrivate::ensureInitialized: unable to resolve all symbols
    7. QSslSocket: cannot find ssleay32 library: QLibrary::load_sys: Cannot load ssleay32 (Le module spécifié est introuvable.).
    8. QSslSocketBackendPrivate::ensureInitialized: unable to resolve all symbols
    9. QSslSocket: cannot find ssleay32 library: QLibrary::load_sys: Cannot load ssleay32 (Le module spécifié est introuvable.).
    10. QSslSocketBackendPrivate::ensureInitialized: unable to resolve all symbols
    To copy to clipboard, switch view to plain text mode 

    It seems that I should make a link between my app (and more generally Qt, because I would like to recompile it in -release -static modes) and the openSSL library... But I can't achieve to do that.

    I suppose I shoul modifiy my .pro file, so did I, adding the following lines :
    Qt Code:
    1. INCLUDEPATH += /openssl/include
    2. LIBS += -L/openssl/lib ssleay32.lib libeay32.lib
    To copy to clipboard, switch view to plain text mode 
    But the console returns me :
    Qt Code:
    1. C:\Qt\4.3.0\Workspace\Veilleur\SRC\MC_NB_mails>make
    2. mingw32-make -f Makefile.Release
    3. mingw32-make[1]: Entering directory `C:/Qt/4.3.0/Workspace/Veilleur/SRC/MC_NB_ma
    4. ils'
    5. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
    6. oc -Wl,-s -Wl,-subsystem,console -mthreads -Wl -o "release\MC_NB_mails.exe" tmp\
    7. obj\release_shared\Gestion_comptes.o tmp\obj\release_shared\Gestion_liste_noire.
    8. o tmp\obj\release_shared\MailChecker.o tmp\obj\release_shared\main.o tmp\obj\rel
    9. ease_shared\MC_Logs.o tmp\obj\release_shared\moc_MailChecker.o -L"c:\Qt\4.3.0\l
    10. ib" -L"c:\Qt\4.3.0\lib" ssleay32.lib -leay32.lib -lQtGui4 -lQtNetwork4 -lQtCore4
    11.  
    12. g++: ssleay32.lib: No such file or directory
    13. mingw32-make[1]: *** [release\MC_NB_mails.exe] Error 1
    14. mingw32-make[1]: Leaving directory `C:/Qt/4.3.0/Workspace/Veilleur/SRC/MC_NB_mai
    15. ls'
    16. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 
    I get the same error with openSSL installed in "C:\" or "C:\Program Files\".
    I've tried to create a new OPENSSLDIR environment variable, without success.



    .
    Last edited by Nyphel; 26th June 2007 at 14:59.

  5. #4
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket : Having troubles

    I've installed OpenSSL like this :

    - C:\OpenSSL : the OpenSSL application directory
    - C:\OpenSSL\lib\MinGW : the directory that contains the libs (ssleay32.a, ssleay32.def, libeay32.a and libeay32.def)
    - C:\OpenSSL\include\openssl : the directory that contains the files to include, I suppose...

    My MinGW compiler is in C:\MinGW.

    Has someone an idea about linking the openSSL libs from my application, please ?

Similar Threads

  1. makefile troubles
    By Walsi in forum Qt Programming
    Replies: 6
    Last Post: 12th April 2007, 15:12
  2. libqjpeg troubles
    By TheRonin in forum Installation and Deployment
    Replies: 6
    Last Post: 25th August 2006, 15:48
  3. lupdate *.pro troubles
    By jeff_s in forum Qt Programming
    Replies: 1
    Last Post: 28th July 2006, 10:07
  4. QTextEdit troubles?!
    By Jojo in forum Qt Programming
    Replies: 2
    Last Post: 21st February 2006, 16:54

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.