Results 1 to 4 of 4

Thread: SSL server: disconnects using QSslSocket::startServerEncryption

  1. #1
    Join Date
    Aug 2008
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default SSL server: disconnects using QSslSocket::startServerEncryption

    Hello, I have sifted through lots of documentation and google pages to try and get a working example of a SSL server. The issue I'm having is only with SSL and using QSslSocket; non-SSL through just QTcpSocket works just fine.

    A client (which I did write a sample program for) connects to my server (through QSslSocket::connectToHostEncrypted() ) and I get the connection, but my server always disconnects the socket before it can read the data, or signal encrypted(). Here's my sample server code.

    HttpServer.h
    Qt Code:
    1. #ifndef HTTPSERVER_H
    2. #define HTTPSERVER_H
    3.  
    4. #include <QtNetwork>
    5.  
    6. class QTcpServer;
    7.  
    8. class HttpServer : public QTcpServer
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. HttpServer();
    14. ~HttpServer();
    15.  
    16. protected:
    17. void incomingConnection (int socket);
    18.  
    19. protected slots:
    20. void gotHeaderData();
    21. void ready();
    22. void sslErrors( const QList<QSslError> &errors );
    23. void gotDisconnected();
    24.  
    25. private:
    26. bool mySSLFlag;
    27. };
    28.  
    29. #endif
    To copy to clipboard, switch view to plain text mode 

    HttpServer.cpp
    Qt Code:
    1. #include <stdlib.h>
    2. //My Include
    3. #include "HttpServer.h"
    4.  
    5. HttpServer::HttpServer()
    6. {
    7. mySSLFlag = true;
    8.  
    9. //Create a new server, and have it listen for any http requests on port 7072
    10. if (!listen(QHostAddress::Any, 7072))
    11. {
    12. fprintf(stderr, "Unable to start the server %s", this->errorString().toLatin1());
    13. return;
    14. }
    15.  
    16. printf("The server is running on port %d\n", this->serverPort());
    17. }
    18.  
    19. HttpServer::~HttpServer()
    20. {
    21. }
    22.  
    23. void HttpServer::incomingConnection(int socketDescriptor)
    24. {
    25. QSslSocket *serverSocket = new QSslSocket(this);
    26. if (serverSocket->setSocketDescriptor(socketDescriptor))
    27. {
    28. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready()));
    29. connect(serverSocket, SIGNAL(disconnected()),
    30. this, SLOT(gotDisconnected()));
    31. connect(serverSocket, SIGNAL(readyRead()),
    32. this, SLOT(gotHeaderData()));
    33. connect( serverSocket, SIGNAL(sslErrors(QList<QSslError>)),
    34. this, SLOT(sslErrors(QList<QSslError>)) );
    35. serverSocket->setLocalCertificate( "ssl.pem" );
    36. serverSocket->setPrivateKey( "ssl.pem" );
    37. serverSocket->startServerEncryption();
    38. }
    39. else
    40. {
    41. delete serverSocket;
    42. }
    43. }
    44.  
    45. void HttpServer::gotDisconnected()
    46. {
    47. qDebug("Ooops...\n");
    48. sender()->deleteLater();
    49. }
    50.  
    51. void HttpServer::ready()
    52. {
    53. qDebug("READY! \n");
    54. }
    55.  
    56. void HttpServer::sslErrors( const QList<QSslError> &errors )
    57. {
    58. foreach( const QSslError &error, errors )
    59. {
    60. switch( error.error() )
    61. {
    62. case QSslError::NoPeerCertificate: dynamic_cast<QSslSocket *>(sender())->ignoreSslErrors(); break;
    63. default:
    64. qWarning( "CLIENT SSL: error %s", qPrintable(error.errorString()) );
    65. disconnect(); return;
    66. }
    67. }
    68. }
    69.  
    70. void HttpServer::gotHeaderData()
    71. {
    72. /*code*/
    73. }
    To copy to clipboard, switch view to plain text mode 

    The signals encrypted, readyRead, and sslErrors never gets called. On my client, I'm also setting a private cert and key of ":ssl.pem" before calling connectToHostEncrypted(). The only hint I get of what the error could be is that in QSslSocketBackendPrivate::testConnection(), an error string comes out as SSL3_GET_CLIENT_HELLO:no shared cipher. This happens right before the disconnect signal is called. The ciphers on both ends are the qt defaults, and they both match. The server disconnects right after it finishes IncomingConnection(), and only after I call startServerEncryption().

    Any ideas on why the server keeps disconnecting? Thank you for your time.

    - Adam
    Last edited by jpn; 20th August 2008 at 22:40. Reason: missing [code] tags

  2. #2
    Join Date
    Aug 2008
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: SSL server: disconnects using QSslSocket::startServerEncryption

    Anyone with knowledge of QSslSocket server side with any insight on this issue?

    Oh yes, I'm using Qt 4.3.5 if that helps.

  3. #3
    Join Date
    Aug 2008
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: SSL server: disconnects using QSslSocket::startServerEncryption

    Well no wonder nobody has replied to this:

    Qt has recognized the bug and is now on Task Tracker #225038.
    http://trolltech.com/developer/task-...ntry&id=225038

    This should help others who are trying to set up an SSL server through Qt; this verifies that Qt is unable to run a successful SSL server as of yet, until this bug is resolved.

  4. #4
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SSL server: disconnects using QSslSocket::startServerEncryption

    I am having this problem as well.

    But I looked at the bug you linked to, and verified that that is not my problem.

    Is there any resolution on this?

Similar Threads

  1. How to download any file through ftp server
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2007, 02:23
  2. How to ping a server ?
    By Nyphel in forum Newbie
    Replies: 2
    Last Post: 23rd April 2007, 12:27
  3. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 15:22
  4. How a server can write "Hello" to a browser ?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 1st December 2006, 15:43
  5. synching client readings to server output
    By OnionRingOfDoom in forum Qt Programming
    Replies: 14
    Last Post: 28th January 2006, 19:15

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.