Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: QSslsocket and Unknown error

  1. #1
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSslsocket and Unknown error

    I wrote that code:
    Server:
    Qt Code:
    1. //H
    2.  
    3. #ifndef POLACZENIESSL_H
    4. #define POLACZENIESSL_H
    5. #include <QTcpServer>
    6. #include <QTcpSocket>
    7. #include <QSslSocket>
    8. #include <QFile>
    9. #include <QSslKey>
    10. #include <QAbstractSocket>
    11. class PolaczenieSSL : public QTcpServer
    12. {
    13. Q_OBJECT
    14. public:
    15. PolaczenieSSL(QWidget *parent = 0);
    16. ~PolaczenieSSL();
    17. private:
    18. void incomingConnection(int port);
    19. private slots:
    20. void gotowy();
    21. };
    22.  
    23. #endif // POLACZENIESSL_H
    24.  
    25. //CPP
    26.  
    27. #include "polaczeniessl.h"
    28.  
    29. PolaczenieSSL::PolaczenieSSL(QWidget *parent)
    30. {
    31.  
    32. }
    33. PolaczenieSSL::~PolaczenieSSL()
    34. {
    35.  
    36. }
    37. void PolaczenieSSL::incomingConnection(int port)
    38. {
    39. qDebug()<<"incomingConnection";
    40. QSslSocket *serverSocket = new QSslSocket;
    41. serverSocket->setProtocol(QSsl::AnyProtocol);
    42. serverSocket->ignoreSslErrors();
    43. QFile *file = new QFile("server.key");
    44. QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
    45. serverSocket->setPrivateKey(key);
    46. serverSocket->setLocalCertificate("server.csr");
    47. serverSocket->addCaCertificates("/etc/ssl/certs");
    48. if (serverSocket->setSocketDescriptor(port))
    49. {
    50. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
    51. serverSocket->startServerEncryption();
    52. qDebug()<<serverSocket->errorString();
    53.  
    54. }
    55. else
    56. {
    57. delete serverSocket;
    58. }
    59. }
    60.  
    61. void PolaczenieSSL::gotowy()
    62. {
    63. qDebug()<<"gotowy";
    64. }
    To copy to clipboard, switch view to plain text mode 
    On console, when client started connection:
    Qt Code:
    1. incomingConnection
    2. "Unknown error"
    To copy to clipboard, switch view to plain text mode 

    What is it wrong?

  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 and Unknown error

    Please provide a minimal compilable example reproducing the problem. By the way, I suggest you don't call client socket as "serverSocket" and socket as "port", it leads to confusion.
    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. #3
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    In attachments are code. Next time, I will better use name for variables :-)
    Attached Files Attached Files

  4. #4
    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 and Unknown error

    The project is missing some files. And based on the code I see I don't think that's a minimal example meant to reproduce a problem but rather your complete project.
    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.


  5. #5
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    I do not understand what is for you "minimal example". File "Polaczenie" I have but a can not publish him on forum because is limit 5 attachments in one post. Can you help me with what I published?

  6. #6
    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 and Unknown error

    Quote Originally Posted by szarek View Post
    I do not understand what is for you "minimal example".
    A minimal amount of code unrelated to your project that suffers from the same problem as your project. It is usually assembled by stripping down everything unrelated to the problem from your project and then eliminating pieces of code until the code starts working. Then you'll have your minimal example.

    File "Polaczenie" I have but a can not publish him on forum because is limit 5 attachments in one post.
    Then compress everything into single archive (zip or tar.gz).

    Can you help me with what I published?
    How can I help if I can't reproduce the problem?
    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.


  7. #7
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    I think it will all to reproduce problem. It will run on QtCreator 2.0,on Linux
    Attached Files Attached Files

  8. #8
    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 and Unknown error

    You are using ignoreSslErrors() incorrectly, that's for sure but the real problem is elsewhere.

    You are calling:
    Qt Code:
    1. qDebug()<<serverSocket->errorString();
    To copy to clipboard, switch view to plain text mode 
    And my question is, what would you expect to get as a result of this method for a connection without errors? I can tell you errorString() returns a textual description of QAbstractSocket::SocketError, so the real question is what value of QAbstractSocket::SocketError would you like to receive for a connection without errors?
    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.


  9. #9
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    I did not think it "ignore" = "do not inform". When I comment line: "serverSocket->ignoreSslErrors();" I get that same result: "Unknown error".

  10. #10
    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 and Unknown error

    Quote Originally Posted by szarek View Post
    I did not think it "ignore" = "do not inform". When I comment line: "serverSocket->ignoreSslErrors();"
    This is unrelated to your original "problem", I just say you are using the method incorrectly (it's a no-op in your case). This method should be used as a result of emitting an sslErrors() signal to clear the errors (i.e. untrusted certificate error) and allow the connection to continue.

    I get that same result: "Unknown error".
    Please answer my question. What result would you expect to get?
    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.


  11. #11
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    Please, Can we talk about problem? I want to encrypt connection but signal "encrypted" is not working and I do not know why. Is this emit necessary? If yes, how this write?

  12. #12
    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 and Unknown error

    Quote Originally Posted by szarek View Post
    Please, Can we talk about problem?
    We are talking about the problem. You think you have a problem and I'm telling you that your problem is not there.

    I want to encrypt connection but signal "encrypted" is not working and I do not know why. Is this emit necessary? If yes, how this write?
    Thanks for stating the problem, so far you just said you didn't undestand why you were getting the "unknown error" message.

    First of all monitor state changes of sockets so that you know in what part of connection establishment your sockets currently are.
    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.


  13. #13
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    Qt Code:
    1. #include "polaczeniessl.h"
    2.  
    3. PolaczenieSSL::PolaczenieSSL(QWidget *parent)
    4. {
    5.  
    6. }
    7. PolaczenieSSL::~PolaczenieSSL()
    8. {
    9.  
    10. }
    11. void PolaczenieSSL::incomingConnection(int port)
    12. {
    13. qDebug()<<"incomingConnection";
    14. QSslSocket *serverSocket = new QSslSocket;
    15. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
    16. connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
    17. connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
    18. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
    19. serverSocket->setProtocol(QSsl::AnyProtocol);
    20. //serverSocket->ignoreSslErrors();
    21. QFile *file = new QFile("server.key");
    22. QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
    23. serverSocket->setPrivateKey(key);
    24. serverSocket->setLocalCertificate("server.csr");
    25. serverSocket->addCaCertificates("/etc/ssl/certs");
    26. if (serverSocket->setSocketDescriptor(port))
    27. {
    28. serverSocket->startServerEncryption();
    29. }
    30. else
    31. {
    32. delete serverSocket;
    33. }
    34. }
    35.  
    36. void PolaczenieSSL::gotowy()
    37. {
    38. qDebug()<<"gotowy";
    39. }
    40. void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
    41. {
    42. qDebug()<<"Stan: "<<state;
    43. }
    44. void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
    45. {
    46. qDebug()<<"Blad: "<<err;
    47. }
    48. void PolaczenieSSL::bledySSL(QList<QSslError> l)
    49. {
    50. for(int i=0;i<l.size();++i)
    51. qDebug()<<"BladSSL: "<<l.at(i);
    52. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. incomingConnection
    2. Stan: QAbstractSocket::ConnectedState
    3. Blad: QAbstractSocket::SocketError( 13 ) // The SSL/TLS handshake failed, so the connection was closed (only used in QSslSocket)
    4. Stan: QAbstractSocket::UnconnectedState
    To copy to clipboard, switch view to plain text mode 
    I do not know why QList<QSslError> l is empty.

  14. #14
    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 and Unknown error

    Quote Originally Posted by szarek View Post
    Blad: QAbstractSocket::SocketError( 13 ) // The SSL/TLS handshake failed, so the connection was closed (only used in QSslSocket)
    As stated few posts earlier...

    Qt Code:
    1. connect(serverSocket, SIGNAL(sslErrors(QList<SslError>()), serverSocket, SLOT(ignoreSslErrors()));
    To copy to clipboard, switch view to plain text mode 
    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.


  15. #15
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    I was wrong, I want to encrypt connection but I want to ignore verify by CACertificate. How to do that?

  16. #16
    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 and Unknown error

    Please just add the code from my previous post to your project.
    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.


  17. #17
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    Qt Code:
    1. #include "polaczeniessl.h"
    2.  
    3. PolaczenieSSL::PolaczenieSSL(QWidget *parent)
    4. {
    5.  
    6. }
    7. PolaczenieSSL::~PolaczenieSSL()
    8. {
    9.  
    10. }
    11. void PolaczenieSSL::incomingConnection(int port)
    12. {
    13. qDebug()<<"incomingConnection";
    14. QSslSocket *serverSocket = new QSslSocket;
    15. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
    16. connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
    17. connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
    18. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
    19. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)), serverSocket, SLOT(ignoreSslErrors()));
    20. serverSocket->setProtocol(QSsl::AnyProtocol);
    21. //serverSocket->ignoreSslErrors();
    22. QFile *file = new QFile("server.key");
    23. QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
    24. serverSocket->setPrivateKey(key);
    25. serverSocket->setLocalCertificate("server.csr");
    26. serverSocket->addCaCertificates("/etc/ssl/certs");
    27. if (serverSocket->setSocketDescriptor(port))
    28. {
    29. serverSocket->startServerEncryption();
    30. }
    31. else
    32. {
    33. delete serverSocket;
    34. }
    35. }
    36.  
    37. void PolaczenieSSL::gotowy()
    38. {
    39. qDebug()<<"gotowy";
    40. }
    41. void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
    42. {
    43. qDebug()<<"Stan: "<<state;
    44. }
    45. void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
    46. {
    47. qDebug()<<"Blad: "<<err;
    48. }
    49. void PolaczenieSSL::bledySSL(QList<QSslError> l)
    50. {
    51. for(int i=0;i<l.size();++i)
    52. qDebug()<<"BladSSL: "<<l.at(i);
    53. }
    To copy to clipboard, switch view to plain text mode 
    It is not working.

  18. #18
    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 and Unknown error

    What if you remove lines #22-#26?
    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.


  19. #19
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    Qt Code:
    1. #include "polaczeniessl.h"
    2.  
    3. PolaczenieSSL::PolaczenieSSL(QWidget *parent)
    4. {
    5.  
    6. }
    7. PolaczenieSSL::~PolaczenieSSL()
    8. {
    9.  
    10. }
    11. void PolaczenieSSL::incomingConnection(int port)
    12. {
    13. qDebug()<<"incomingConnection";
    14. QSslSocket *serverSocket = new QSslSocket;
    15. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
    16. connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
    17. connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
    18. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
    19. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)), serverSocket, SLOT(ignoreSslErrors()));
    20. serverSocket->setProtocol(QSsl::AnyProtocol);
    21. /*
    22.   QFile *file = new QFile("server.key");
    23.   QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
    24.   serverSocket->setPrivateKey(key);
    25.   serverSocket->setLocalCertificate("server.csr");
    26.   serverSocket->addCaCertificates("/etc/ssl/certs");
    27.   */
    28. if (serverSocket->setSocketDescriptor(port))
    29. {
    30. serverSocket->startServerEncryption();
    31. }
    32. else
    33. {
    34. delete serverSocket;
    35. }
    36. }
    37.  
    38. void PolaczenieSSL::gotowy()
    39. {
    40. qDebug()<<"gotowy";
    41. }
    42. void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
    43. {
    44. qDebug()<<"Stan: "<<state;
    45. }
    46. void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
    47. {
    48. qDebug()<<"Blad: "<<err;
    49. }
    50. void PolaczenieSSL::bledySSL(QList<QSslError> l)
    51. {
    52. for(int i=0;i<l.size();++i)
    53. qDebug()<<"BladSSL: "<<l.at(i);
    54. }
    To copy to clipboard, switch view to plain text mode 
    It is not working.
    Qt Code:
    1. incomingConnection
    2. Stan: QAbstractSocket::ConnectedState
    3. Blad: QAbstractSocket::SocketError( 13 )
    4. Stan: QAbstractSocket::UnconnectedState
    To copy to clipboard, switch view to plain text mode 

  20. #20
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslsocket and Unknown error

    result in client is:
    Qt Code:
    1. Stan: QAbstractSocket::HostLookupState
    2. Stan: QAbstractSocket::ConnectingState
    3. Stan: QAbstractSocket::ConnectedState
    4. Mode: 1
    5. Blad: QAbstractSocket::RemoteHostClosedError
    6. Stan: QAbstractSocket::ClosingState
    7. Stan: QAbstractSocket::UnconnectedState
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Unknown problem
    By theMVP in forum Newbie
    Replies: 3
    Last Post: 2nd July 2010, 05:50
  2. QimageReader Unknown Error
    By bhaskar in forum Newbie
    Replies: 1
    Last Post: 2nd June 2010, 09:24
  3. 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
  4. Replies: 2
    Last Post: 15th February 2010, 07:42
  5. "unknown test function error" with MAc
    By tommy in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd August 2008, 19:25

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.