password authentication with QsslSocket
hi,
i have a problem with password authentication in a QSslSocket connection.
Code:
void encThread::run()
{
serverSocket = new QSslSocket();
connect(serverSocket, SIGNAL(readyRead()), this, SLOT(input()));
while(true)
{
serverSocket->setLocalCertificate("server.cert.crt");
serverSocket->setPrivateKey("privkey.pem",QSsl::Rsa,QSsl::Pem,pass);
if(serverSocket->setSocketDescriptor(socketDescriptor))
{
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready()));
serverSocket->startServerEncryption();
}
else
{
emit error(serverSocket->error());
delete serverSocket;
return;
}
{
exit();
}
syslog
= QString::fromUtf8(file
->readAll
());
file->close();
serverSocket->write(toChar(syslog));
while(serverSocket->waitForDisconnected())
{
serverSocket->disconnectFromHost();
}
}
}
...
void encThread::input()
{
qDebug() << line;
if(line.startsWith(':'))
{
qDebug() << "password: " << line;
if(line != test_password)
{
serverSocket->abort;
}
}
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:
Code:
...
bool test;
...
if(test)
serverSocket->write(toChar(syslog));
...
i cant't find a solution that test the passord first, and send the data if the password ist valid.
regards
mate
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.
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.
Code:
void encThread::run()
{
...
connect(serverSocket, SIGNAL(readyRead()), this, SLOT(input()));
...
}
while(true)
{
...
{
// this code dosent doesn't work.
if(passwordtest == true)
{
serverSocket->write(toChar(syslog));
}
...
...
void encThread::input()
{
if(line.startsWith(':'))
{
if(line != test_password)
{
passwordtest = false; // bool
serverSocket->abort;
}
...
i hope this shows the problem.
thanks
mate