Results 1 to 10 of 10

Thread: QSslSocket problem client-server

  1. #1
    Join Date
    Mar 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default QSslSocket problem client-server

    Hi all, I'm writing a client and server using Qt 4.8.0 and OpenSsl 0.9.8.
    I have problem that i can't get encrypted signal from client.
    Server was tested using OpenSsl > s_client and i got that output:
    Qt Code:
    1. >s_client -connect 127.0.0.1:803 -CAfile "C:\serwer\server2.crt"
    2.  
    3. CONNECTED(00000100)
    4. ---
    5. Certificate chain
    6. 0 s:/C=PL/ST=Warminsko-Mazurskie/L=Olsztyn/O=3SAT/OU=IT/CN=stlserver/emailAddress=ksybek@gmail.com
    7. i:/C=PL/ST=Warminsko-Mazurskie/L=Olsztyn/O=3SAT/OU=IT/CN=stlserver/emailAddress=ksybek@gmail.com
    8. ---
    9. Server certificate
    10. -----BEGIN CERTIFICATE-----
    11. MIIC7DCCAlWgAwIBAgIJALzzyQK1Lyt2MA0GCSqGSIb3DQEBBQUAMIGOMQswCQYD
    12. VQQGEwJQTDEcMBoGA1UECAwTV2FybWluc2tvLU1henVyc2tpZTEQMA4GA1UEBwwH
    13. T2xzenR5bjENMAsGA1UECgwEM1NBVDELMAkGA1UECwwCSVQxEjAQBgNVBAMMCXN0
    14. bHNlcnZlcjEfMB0GCSqGSIb3DQEJARYQa3N5YmVrQGdtYWlsLmNvbTAeFw0xMjA2
    15. MTkxMDUyMjdaFw0xMzA2MTkxMDUyMjdaMIGOMQswCQYDVQQGEwJQTDEcMBoGA1UE
    16. CAwTV2FybWluc2tvLU1henVyc2tpZTEQMA4GA1UEBwwHT2xzenR5bjENMAsGA1UE
    17. CgwEM1NBVDELMAkGA1UECwwCSVQxEjAQBgNVBAMMCXN0bHNlcnZlcjEfMB0GCSqG
    18. SIb3DQEJARYQa3N5YmVrQGdtYWlsLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
    19. gYkCgYEAr2YjfwNDJahYvAmXHdzklZKE2UBwZXRTHlOpiwICa3IkLcW4kIO4g0sC
    20. 9MD/IRBw4ghtT24oGI7y79K5TN9hwTkBMpTsFdM/6m1+P7dOqYBa+V8MZrgYZrBO
    21. YsbkFiaTHhxM8UNaLDsfvD+i5WymCV3l0L8OLZ42BF0FXwqym4MCAwEAAaNQME4w
    22. HQYDVR0OBBYEFDEfymESS2ucUmX9/7ZvXfjVRml5MB8GA1UdIwQYMBaAFDEfymES
    23. S2ucUmX9/7ZvXfjVRml5MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEA
    24. nmn4sFnEqyx2/CMchUfFhZgqRUrxTbcFxIKfZCBz4LVF2IF4LDhXk0g30zB2HftN
    25. TewDGCygsTosUBUaHaykKXMCrJ/GPyERTbfA0FrMFn7Ij4913I6MBT6t1VZ1ZZy7
    26. euNz82aKmQpmDwLLVu33dJOBG/oqEKTM+zzcwNU53wc=
    27. -----END CERTIFICATE-----
    28. subject=/C=PL/ST=Warminsko-Mazurskie/L=Olsztyn/O=3SAT/OU=IT/CN=stlserver/emailAddress=ksybek@gmail.com
    29. issuer=/C=PL/ST=Warminsko-Mazurskie/L=Olsztyn/O=3SAT/OU=IT/CN=stlserver/emailAddress=ksybek@gmail.com
    30. ---
    31. No client certificate CA names sent
    32. ---
    33. SSL handshake has read 1109 bytes and written 523 bytes
    34. ---
    35. New, TLSv1/SSLv3, Cipher is AES256-GCM-SHA384
    36. Server public key is 1024 bit
    37. Secure Renegotiation IS supported
    38. Compression: NONE
    39. Expansion: NONE
    40. SSL-Session:
    41. Protocol : TLSv1.2
    42. Cipher : AES256-GCM-SHA384
    43. Session-ID: F075F17CFB5774F22DC6DF579F5E9A7E6EB3C529018910186553CE1D5868125C
    44. Session-ID-ctx:
    45. Master-Key: BD0C01DA7D5E09406AB1789E29D6A1B4CEABFE0856AF58C4B707C0D956EA1FED1AE140C72656CFB8E8A8BBB576F7783E
    46. Key-Arg : None
    47. PSK identity: None
    48. PSK identity hint: None
    49. SRP username: None
    50. TLS session ticket lifetime hint: 300 (seconds)
    51. TLS session ticket:
    52. 0000 - bc 8a 45 64 82 2b 26 7f-9f a3 c1 8c 50 b8 1e 30 ..Ed.+&.....P..0
    53. 0010 - df 3a 51 02 e1 58 af 2e-9e 4c 74 89 dc b7 15 d7 .:Q..X...Lt.....
    54. 0020 - fa 3a ca 1a 8e e0 63 9c-a3 44 5d ec 38 14 e5 f0 .:....c..D].8...
    55. 0030 - 8a 9b 12 7f 17 56 f5 48-47 ab 28 78 c3 61 9a 5a .....V.HG.(x.a.Z
    56. 0040 - b8 a6 48 81 f4 eb 7d 91-02 d6 46 1d c2 72 98 d2 ..H...}...F..r..
    57. 0050 - f0 bb 4a 56 a0 ac c2 e2-71 3f 17 30 9f 33 58 ca ..JV....q?.0.3X.
    58. 0060 - 4c 71 20 e6 97 68 80 6d-80 4a 1c 17 e1 1c 6b db Lq ..h.m.J....k.
    59. 0070 - d6 8c 5c eb 70 71 82 89-88 e5 7c e4 9f a3 c1 cc ..\.pq....|.....
    60. 0080 - 28 a4 b7 db 17 ae 21 85-fd ad 03 45 41 ca a8 c1 (.....!....EA...
    61. 0090 - 59 79 57 14 a8 72 09 86-d8 5f 0a d0 56 f0 54 78 YyW..r..._..V.Tx
    62.  
    63. Start Time: 1340208337
    64. Timeout : 300 (sec)
    65. Verify return code: 0 (ok)
    66. ---
    To copy to clipboard, switch view to plain text mode 

    This is client code:
    Qt Code:
    1. socket = new QSslSocket(this);
    2. socket->setProtocol(QSsl::TlsV1);
    3.  
    4. socket->setLocalCertificate("C:\\serwer\\server2.crt");
    5.  
    6. connect(socket, SIGNAL(encrypted()), this, SLOT(ready()));
    7. connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)),
    8. this, SLOT(sslError(const QList<QSslError> &)));
    9.  
    10. socket->connectToHost("127.0.0.1", 803);
    11. if(socket->waitForConnected())
    12. {
    13. socket->startClientEncryption();
    14. }
    To copy to clipboard, switch view to plain text mode 

    Also some output from server:
    Qt Code:
    1. Private key: true
    2. Certificate: true
    3. Descryptor: 968
    4. Mode: 2
    5. Connection state: QAbstractSocket::ConnectedState
    6. Connection mode: 2
    To copy to clipboard, switch view to plain text mode 

    Thats all...
    I dont get any errors, or encrypted signal. If I delete LocalCertificate from client i get an encypted signal on server and after that:
    Qt Code:
    1. Encrypted
    2. Error: QAbstractSocket::RemoteHostClosedError
    3. State: QAbstractSocket::ClosingState
    4. State: QAbstractSocket::UnconnectedState
    5. Disconnected
    To copy to clipboard, switch view to plain text mode 

    I read somewhere that I should get CACertificate from server but this should be done after encypted signal. So... any ideas why I can't get this signal?

  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 problem client-server

    Do you get any ssl 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.


  3. #3
    Join Date
    Mar 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket problem client-server

    None, while program is working there is no sslErrors signal. When i delete loading LocalCertificate there is error: No Error

  4. #4
    Join Date
    Mar 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket problem client-server

    I'm trying to get certificate from peer (on client and on server) by socket->peerCertificate(), but all the time i get Null value, is it normal? (I tried to get certificate after connection and after startEncryption)

  5. #5
    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 problem client-server

    If the encryption handshake didn't complete, there is no peer certificate.
    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.


  6. #6
    Join Date
    Mar 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket problem client-server

    Any ideas why process stays in connection mode all the time without encryption? If i use wait for encyption then i get just timeout error.

  7. #7
    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 problem client-server

    No idea, maybe the server doesn't initiate the handshake.
    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.


  8. #8
    Join Date
    Mar 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket problem client-server

    Yes it does
    Qt Code:
    1. void SslServer::incomingConnection(int socketDescriptor)
    2. {
    3. socket = new QSslSocket(this);
    4. qDebug() << "Nowe polaczenie nadchodzi";
    5. socket->setPrivateKey("C:\\serwer\\serverkey.pem");
    6. if(socket->privateKey().isNull())
    7. qDebug() << "Private key: false";
    8. else
    9. qDebug() << "Private key: true";
    10.  
    11. socket->setLocalCertificate("C:\\serwer\\taserver.cer");
    12. if(socket->localCertificate().isNull())
    13. qDebug() << "Certificate: false";
    14. else
    15. qDebug() << "Certificate: true";
    16.  
    17. if(socket->setSocketDescriptor(socketDescriptor))
    18. {
    19. qDebug() << "Descryptor: " << socket->socketDescriptor();
    20. socket->setProtocol(QSsl::AnyProtocol);
    21. connect(socket,SIGNAL(encrypted()),this,SLOT(ready()));
    22. connect(socket,SIGNAL(disconnected()),this,SLOT(Disconnected()));
    23. connect(socket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
    24. connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
    25. connect(socket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
    26. connect(socket,SIGNAL(modeChanged(QSslSocket::SslMode)),this,SLOT(mode(QSslSocket::SslMode)));
    27. connect(socket,SIGNAL(peerVerifyError(QSslError)),this,SLOT(bladPeer(QSslError)));
    28.  
    29. socket->startServerEncryption();
    30. qDebug() << socket->errorString();
    31.  
    32. qDebug() << "Connection state: " << socket->state();
    33. qDebug() << "Connection mode: " << socket->mode();
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    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 problem client-server

    What is supposed to happen is one thing. What actually happens is another.
    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.


  10. #10
    Join Date
    Mar 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSslSocket problem client-server

    So mayby someone have working example of client/server whit qsslsocket?

Similar Threads

  1. problem in client and server model of tcp in qt
    By shakthi in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2011, 15:18
  2. QSslSocket - problem with connecting to the server
    By kremuwa in forum Qt Programming
    Replies: 9
    Last Post: 26th August 2010, 14:40
  3. server-client problem
    By sksingh73 in forum Newbie
    Replies: 2
    Last Post: 3rd July 2010, 07:18
  4. TCP server-client app problem
    By pogostick in forum Newbie
    Replies: 6
    Last Post: 25th January 2010, 08:13
  5. Qt-- Client Server communication problem
    By thisismyuname in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2010, 01: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.