PDA

View Full Version : examples and Ssl



szarek
12th July 2010, 18:17
I want to learn how to use encryption using QSslsocket but it is to hard to me with out example. I know about Secure socket client but it is only client. I want to ask for write complet code changing: http://doc.qt.nokia.com/4.6/network-fortuneclient.html and http://doc.qt.nokia.com/4.6/network-fortuneserver.html

squidge
12th July 2010, 18:31
Have you tried reading the documentation? (http://doc.trolltech.com/qq/qq10-sslfilter.html)

szarek
12th July 2010, 19:23
Have you tried reading the documentation? (http://doc.trolltech.com/qq/qq10-sslfilter.html)
Thank you for your respond. It is perfect example for client but where is code for server?

wysota
12th July 2010, 22:43
Create a QTcpServer and use setSocketDescriptor to pass it a socket from QSslSocket.

szarek
18th July 2010, 10:18
Create a QTcpServer and use setSocketDescriptor to pass it a socket from QSslSocket.
I do not understand where should I set:

tcpServer->ignoreSslErrors();
QFile *file = new QFile("server.key");
QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server" );
tcpServer->setPrivateKey(key);
tcpServer->setLocalCertificate("server.csr");
where should I set and what for it is:

QSslSocket *serverSocket = new QSslSocket;
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(zmien()));
serverSocket->startServerEncryption();
} else {
delete serverSocket;
} Could someone write complete code? It will be faster to learn for me.

squidge
18th July 2010, 12:17
There are various complete examples out there, try the Qt-interest Archive for example, or doc.trolltech.com, both of which have SSL Server examples.

szarek
18th July 2010, 13:14
There are various complete examples out there, try the Qt-interest Archive for example, or doc.trolltech.com, both of which have SSL Server examples. You have right but example( http://doc.trolltech.com/solutions/4/qtsslsocket/server-example.html ) does not want compile because I have Qt 4.6.3, what should I do?

squidge
18th July 2010, 14:36
Alter the code so it does want compile?

If you don't understand the error messages, post them here. Perhaps someone can help.

szarek
20th July 2010, 17:03
I modified http://doc.trolltech.com/solutions/4/qtsslsocket/server-example.html (see attachments)

I am compaling typing: "qmake && make" and I see:

sslserver.cpp: In constructor ‘SSLServerConnection::SSLServerConnection(qu int16, QObject*)’:
sslserver.cpp:22:33: error: ‘Server’ is not a member of ‘QSslSocket’
sslserver.cpp:23:17: error: ‘class QSslSocket’ has no member named ‘socket’
sslserver.cpp:24:17: error: ‘class QSslSocket’ has no member named ‘setPathToCertificate’
sslserver.cpp:25:17: error: ‘class QSslSocket’ has no member named ‘setPathToPrivateKey’
sslserver.cpp:29:17: error: ‘class QSslSocket’ has no member named ‘setPathToCACertDir’
sslserver.cpp:41:17: error: ‘class QSslSocket’ has no member named ‘sslAccept’
sslserver.cpp: In member function ‘void SSLServerConnection::connectionClosed()’:
sslserver.cpp:152:21: error: ‘class QSslSocket’ has no member named ‘socket’
sslserver.cpp:153:29: error: ‘class QSslSocket’ has no member named ‘socket’
make: *** [sslserver.o] BÅ‚Ä…d 1 What have to I correct?

wysota
20th July 2010, 22:06
I would start with using method calls that actually exist. I have no idea where did you take that code from but it makes no sense - you are calling non-existing enums methods and even if they existed, they wouldn't work as you expect them to.

szarek
21st July 2010, 08:09
It is not my code. I try compile example. I could not understand why compiler do not see "socket".

wysota
21st July 2010, 08:59
I try compile example.
What example? Please point me to an example that claims QSslSocket has a constructor like the one you are calling in your code.

szarek
21st July 2010, 19:36
Maybe I do something wrong, I will start from original code. When I compile this: http://doc.trolltech.com/solutions/4/qtsslsocket/server-example.html I have:

WARNING: /home/szarek/praca_inzynierska/temp/sslserver/sslserver.pro:5: Unable to find file for inclusion ../../src/qtsslsocket.pri
sslserver.h:24:28: fatal error: qtcpserver.h: Nie ma takiego pliku ani katalogu(There is no such file or directory)
compilation terminated.
make: *** [main.o] BÅ‚Ä…d 1

wysota
21st July 2010, 22:33
This example is not compatible with current Qt releases, it uses an outdated addition to Qt that since several months is incorporated into Qt. I suggest you turn to a "what I want to achieve" approach instead of "where do I find an example and how do I modify it to do what I want" one.