Results 1 to 3 of 3

Thread: password authentication with QsslSocket

  1. #1
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default password authentication with QsslSocket

    hi,

    i have a problem with password authentication in a QSslSocket connection.
    Qt Code:
    1. void encThread::run()
    2. {
    3. serverSocket = new QSslSocket();
    4. connect(serverSocket, SIGNAL(readyRead()), this, SLOT(input()));
    5. while(true)
    6. {
    7. QByteArray pass("password");
    8. serverSocket->setLocalCertificate("server.cert.crt");
    9. serverSocket->setPrivateKey("privkey.pem",QSsl::Rsa,QSsl::Pem,pass);
    10.  
    11. if(serverSocket->setSocketDescriptor(socketDescriptor))
    12. {
    13. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready()));
    14. serverSocket->startServerEncryption();
    15. }
    16. else
    17. {
    18. emit error(serverSocket->error());
    19. delete serverSocket;
    20. return;
    21. }
    22. if(!(file->open(QIODevice::ReadOnly | QIODevice::Text)))
    23. {
    24. exit();
    25. }
    26. syslog = QString::fromUtf8(file->readAll());
    27. file->close();
    28.  
    29. serverSocket->write(toChar(syslog));
    30.  
    31. while(serverSocket->waitForDisconnected())
    32. {
    33. serverSocket->disconnectFromHost();
    34. }
    35.  
    36. }
    37. }
    38. ...
    39. void encThread::input()
    40. {
    41. QByteArray line = serverSocket->readAll();
    42.  
    43. qDebug() << line;
    44.  
    45. if(line.startsWith(':'))
    46. {
    47. qDebug() << "password: " << line;
    48. if(line != test_password)
    49. {
    50. serverSocket->abort;
    51.  
    52. }
    53. }
    To copy to clipboard, switch view to plain text mode 
    when i start a connection from the client with a wrong password, first the server sends with
    serverSocket->write(toChar(syslog));
    to the client, and than he cut the connection.

    other versions with bool values dont' send any data's with good or bad password - like this:
    Qt Code:
    1. ...
    2. bool test;
    3. ...
    4. if(test)
    5. serverSocket->write(toChar(syslog));
    6. ...
    To copy to clipboard, switch view to plain text mode 
    i cant't find a solution that test the passord first, and send the data if the password ist valid.

    regards
    mate

  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: password authentication with QsslSocket

    I'm not sure if I understand your problem but writing data to the socket doesn't mean it has been send to the remote side of the connection. You have to wait until that happens before terminating the connection.

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

    mate (16th July 2008)

  4. #3
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: password authentication with QsslSocket

    hi,
    sorry, i try to explain it better.
    my problem is, that data was send to the remote host before the password is checked. it seems that the readyRead() signal reaches the server after the data is send to the remote host (client). the passwordcheck is to late. i don't want that any data will sent from the server to the host until the password is checked.
    Qt Code:
    1. void encThread::run()
    2. {
    3. ...
    4. connect(serverSocket, SIGNAL(readyRead()), this, SLOT(input()));
    5. ...
    6. }
    7. while(true)
    8. {
    9. ...
    10. {
    11. // this code dosent doesn't work.
    12. if(passwordtest == true)
    13. {
    14. serverSocket->write(toChar(syslog));
    15. }
    16. ...
    17. ...
    18. void encThread::input()
    19. {
    20. if(line.startsWith(':'))
    21. {
    22. QByteArray line = serverSocket->readAll();
    23. if(line != test_password)
    24. {
    25. passwordtest = false; // bool
    26. serverSocket->abort;
    27. }
    28. ...
    To copy to clipboard, switch view to plain text mode 
    i hope this shows the problem.

    thanks
    mate

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.