mate
15th July 2008, 22:08
hi,
i have a problem with password authentication in a QSslSocket connection.
void encThread::run()
{
serverSocket = new QSslSocket();
connect(serverSocket, SIGNAL(readyRead()), this, SLOT(input()));
while(true)
{
QByteArray pass("password");
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;
}
if(!(file->open(QIODevice::ReadOnly | QIODevice::Text)))
{
exit();
}
syslog = QString::fromUtf8(file->readAll());
file->close();
serverSocket->write(toChar(syslog));
while(serverSocket->waitForDisconnected())
{
serverSocket->disconnectFromHost();
}
}
}
...
void encThread::input()
{
QByteArray line = serverSocket->readAll();
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:
...
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
i have a problem with password authentication in a QSslSocket connection.
void encThread::run()
{
serverSocket = new QSslSocket();
connect(serverSocket, SIGNAL(readyRead()), this, SLOT(input()));
while(true)
{
QByteArray pass("password");
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;
}
if(!(file->open(QIODevice::ReadOnly | QIODevice::Text)))
{
exit();
}
syslog = QString::fromUtf8(file->readAll());
file->close();
serverSocket->write(toChar(syslog));
while(serverSocket->waitForDisconnected())
{
serverSocket->disconnectFromHost();
}
}
}
...
void encThread::input()
{
QByteArray line = serverSocket->readAll();
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:
...
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