If this is your first visit, be sure to
check out the
FAQ
by clicking the
link above. You may have to
register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
Welcome to
Qt Centre
.
Qt Centre
is a community site devoted to programming in C++ using the
Qt framework
. Over 90 percent of questions asked here gets answered. If you are looking for information about Qt related issue —
register
and post your question.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our
free
community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please,
join our community today
!
If you have any problems with the registration process or your account login, please
contact us
.
Hi everybody,
I've got the probvlem that if I want to read the to my QSslSocket transmitted https-data, the call of QSslSocket->CanReadLine seems to return false. I don't haver any idea whrer this comes from, but it worked how it should and soddenly it didn't without changing anything and changing anything now brings no success.
Here is my code (CSSLConnection inherits QThread and is created from a QTCPServer in its' incommingConnection-function):
Qt Code:
Switch view
// Verbindung verschlüsseln
MSResult CMSSSLConnection::startSocketencryption()
{
m_pSSLSocket->setLocalCertificate("/home/niklas/Dokumente/MySchool/Debug_Ubuntu_x86_Desktop/MSHTTPSServer/myschool.crt");
m_pSSLSocket->setPrivateKey("/home/niklas/Dokumente/MySchool/Debug_Ubuntu_x86_Desktop/MSHTTPSServer/myschool.key.insecure");
m_pSSLSocket->startServerEncryption();
if(m_pSSLSocket->waitForEncrypted())
{
m_pSSLSocket->write("HTTP/1.1 200 OK\r\n"
"Content-type: text/plain\r\n"
"Content-length: 12\r\n"
"\r\n"
"Hello World!");
return MSR_OK;
}
else
{
Log
->Error
(QString("Cannot encrypt connection to %1: %2").
arg(m_pSSLSocket
->peerAddress
().
toString(),
m_pSSLSocket->errorString()));
m_pSSLSocket->disconnectFromHost();
return MSR_ENCRYPTION_ERROR;
}
}
// Neue Verbindung wurde aufgebaut
void CMSSSLConnection::acceptClient()
{
}
// Daten verarbeiten
void CMSSSLConnection::readData()
{
if(m_pSSLSocket->canReadLine())
{
// Anfrage zerlegen
// Um welchen Anfragetypen handelt es sich?
if(request[0] == "GET")
{
// Einfache GET-ANfrage
out.setAutoDetectUnicode(true);
out << "HTTP/1.0 200 Ok\r\n"
"Content-Type: text/html;\r\n"
"\r\n"
"<h1>Nothing to see here</h1>\n";
}
}
else
{
Log
->Error
(QString("Cannot read line from %1").
arg(m_pSSLSocket
->peerAddress
().
toString()));
return;
}
}
// Verbindung verschlüsseln
MSResult CMSSSLConnection::startSocketencryption()
m_pSSLSocket->setLocalCertificate("/home/niklas/Dokumente/MySchool/Debug_Ubuntu_x86_Desktop/MSHTTPSServer/myschool.crt");
m_pSSLSocket->setPrivateKey("/home/niklas/Dokumente/MySchool/Debug_Ubuntu_x86_Desktop/MSHTTPSServer/myschool.key.insecure");
m_pSSLSocket->startServerEncryption();
if(m_pSSLSocket->waitForEncrypted())
m_pSSLSocket->write("HTTP/1.1 200 OK\r\n"
"Content-type: text/plain\r\n"
"Content-length: 12\r\n"
"\r\n"
"Hello World!");
return MSR_OK;
Log->Error(QString("Cannot encrypt connection to %1: %2").arg(m_pSSLSocket->peerAddress().toString(),
m_pSSLSocket->errorString()));
m_pSSLSocket->disconnectFromHost();
return MSR_ENCRYPTION_ERROR;
// Neue Verbindung wurde aufgebaut
void CMSSSLConnection::acceptClient()
// Daten verarbeiten
void CMSSSLConnection::readData()
if(m_pSSLSocket->canReadLine())
// Anfrage zerlegen
QStringList request = QString(m_pSSLSocket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
// Um welchen Anfragetypen handelt es sich?
if(request[0] == "GET")
// Einfache GET-ANfrage
QTextStream out(m_pSSLSocket);
out.setAutoDetectUnicode(true);
out << "HTTP/1.0 200 Ok\r\n"
"Content-Type: text/html;\r\n"
"\r\n"
"<h1>Nothing to see here</h1>\n";
Log->Error(QString("Cannot read line from %1").arg(m_pSSLSocket->peerAddress().toString()));
return;
To copy to clipboard, switch view to plain text mode
So in fact, if I connect via firefox (https://localhost) the first message (Hello World) is transmitted, but the second one isn't. Instead of this, in my logfile it says "cannot read line form 127.0.0.1", but there is no exact error given.
The certificates are created like here: http://quickmediasolutions.com/blog/...ations-with-qt, but I used only a length of 2048 for the key and the program should run on linux (ubuntu).
I hope you can help me.
QStringList request = QString(m_pSSLSocket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
To copy to clipboard, switch view to plain text mode
As in my language it says "read one line and split it on the 'new line' character". If you read one line how can it have any newline characters?
Analyze your code. Think whether it may happen that you receive the request in different chunks that you sent it, e.g.:
chunk 1:
chunk 2:
T /index.html HTTP/1.
chunk 3:
1\r\nHost: mywonder
chunk 4:
fulhost.com\r\n
chunk 5:
If you come to a conclusion that it might happen (I'll give you a hint: yes, it might) then look at your code again and see if it is able to handle that situation.
I can see this is some kind of school project so we're not allowed to give you complete solutions but such hint should be useful too.
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.