Results 1 to 3 of 3

Thread: QSslSocket, certificate and error

  1. #1
    Join Date
    Nov 2009
    Location
    Częstochowa, Poland
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSslSocket, certificate and error

    I have to secure my data sharing program (i use QTcpServer i QTcpSocket). I decided to use QSslSocket and began from the simple examples from the internet. At the beginning I encountered the problem that I can not solve. I downloaded Win32OpenSSL_Light-1_0_0d and generated a key and certificate in accordance with Guide to SSL certificates and certificate authorities

    Next I created a server and client. When trying to connect my server throws an error. Similarly, when trying to connect to server via the client securesocketclient example from the documentation.
    Qt Code:
    1. Error during SSL handshake: error:1408A0C1:SSL routines:SSL3_GET_CLIENT_HELLO:no shared cipher
    To copy to clipboard, switch view to plain text mode 
    Certificates are in server directory, paths is correct.

    Please help in resolve the problem.

    Qt Code:
    1. class SslServer : public QTcpServer
    2. {
    3. Q_OBJECT
    4. QSslSocket *serverSocket;
    5.  
    6. public:
    7. SslServer(QObject *parent = 0);
    8.  
    9. void start(quint16 port);
    10. void incomingConnection(int socketDescr);
    11.  
    12. public slots:
    13. void readyToRead();
    14. void sslErrors(QAbstractSocket::SocketError error);
    15.  
    16. };
    17.  
    18. SslServer::SslServer(QObject *parent) :
    19. QTcpServer(parent)
    20. {
    21. }
    22.  
    23. void SslServer::start(quint16 port)
    24. {
    25. listen(QHostAddress::Any, port);
    26. }
    27.  
    28. void SslServer::readyToRead()
    29. {
    30. //qDebug() << this->serverSocket->readAll();
    31. }
    32.  
    33. void SslServer::sslErrors(QAbstractSocket::SocketError error)
    34. {
    35. qDebug() << serverSocket->errorString();
    36. }
    37.  
    38. void SslServer::incomingConnection(int socketDescr)
    39. {
    40. serverSocket = new QSslSocket;
    41. if(serverSocket->setSocketDescriptor(socketDescr))
    42. {
    43. connect(serverSocket, SIGNAL(readyRead()), this, SLOT(readyToRead()));
    44. connect(serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sslErrors(QAbstractSocket::SocketError)));
    45. serverSocket->setProtocol(QSsl::SslV3);
    46. serverSocket->setPrivateKey("ca.key");
    47. serverSocket->setLocalCertificate("ca.cer");
    48. serverSocket->startServerEncryption();
    49. }
    50. else
    51. {
    52. delete serverSocket;
    53. }
    54. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSslSocket, certificate and error

    Make sure the socket is able to load the files you mention. See what QFile::exists() returns for "ca.key" and "ca.cer".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    ithanoss (26th May 2011)

  4. #3
    Join Date
    Nov 2009
    Location
    Częstochowa, Poland
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket, certificate and error

    I don't know what it was but QFile:: exist () returned true.
    I tried to load the files manually and server began to work correctly.
    Thanks wysota for directing
    Modified function incommingConnection

    Qt Code:
    1. void SslServer::incomingConnection(int socketDescr)
    2. {
    3. serverSocket = new QSslSocket;
    4. if(serverSocket->setSocketDescriptor(socketDescr))
    5. {
    6. connect(serverSocket, SIGNAL(readyRead()), this, SLOT(readyToRead()));
    7. connect(serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sslErrors(QAbstractSocket::SocketError)));
    8. serverSocket->setProtocol(QSsl::SslV3);
    9.  
    10. QByteArray cert;
    11.  
    12. QFile fileKey("ca.key");
    13. if(fileKey.open(QIODevice::ReadOnly))
    14. {
    15. key = fileKey.readAll();
    16. fileKey.close();
    17. }
    18. else
    19. {
    20. qDebug() << fileKey.errorString();
    21. }
    22.  
    23. QFile fileCert("ca.crt");
    24. if(fileCert.open(QIODevice::ReadOnly))
    25. {
    26. cert = fileCert.readAll();
    27. fileCert.close();
    28. }
    29. else
    30. {
    31. qDebug() << fileCert.errorString();
    32. }
    33.  
    34. qDebug() << key + "\n" + cert;
    35.  
    36. QSslKey sslKey(key, QSsl::Rsa);
    37. QSslCertificate sslCert(cert);
    38.  
    39. serverSocket->setPrivateKey(sslKey);
    40. serverSocket->setLocalCertificate(sslCert);
    41. serverSocket->startServerEncryption();
    42. }
    43. else
    44. {
    45. delete serverSocket;
    46. }
    47. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Generating key and certificate for QSslSocket
    By dawwin in forum Qt Programming
    Replies: 7
    Last Post: 27th March 2011, 15:12
  2. Qt 4.7 SSL error : "The certificate has expired”
    By Joshy Abraham in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2011, 07:06
  3. QSslsocket and Unknown error
    By szarek in forum Qt Programming
    Replies: 21
    Last Post: 14th October 2010, 15:20
  4. App Trk installation failed (Nokia E65)- Certificate error
    By baluk in forum Installation and Deployment
    Replies: 0
    Last Post: 2nd October 2010, 20:52
  5. Mysterious QSslSocket error causes installation to fail on Ubuntu 64-bit.
    By spitfirejunky in forum Installation and Deployment
    Replies: 2
    Last Post: 2nd April 2010, 00:04

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.