Client-server application
-
I did enough efforts but I have never worked with SSL. Example would help me.
http://qt-project.org/forums/viewthread/21401 this is server example. But I don't know how can I make it working.This attempt does not work.
[CODE]
#include <QApplication>
#include <QtNetwork/QSslSocket>
#include <QDebug>class Server : public QObject
{
public:
void f()
{
m_socket = new QSslSocket(this);
m_socket->setSocketDescriptor(handle);
m_socket->setProtocol(QSsl::SslV3);QByteArray key; QByteArray cert; QFile file_key("../ssl/server.key"); if(file_key.open(QIODevice::ReadOnly)) { key = file_key.readAll(); file_key.close(); } else { qDebug() << file_key.errorString(); } QFile file_cert("../ssl/server.crt"); if(file_cert.open(QIODevice::ReadOnly)) { cert = file_cert.readAll(); file_cert.close(); } else { qDebug() << file_cert.errorString(); } //qDebug() << key + "\n" + cert; QSslKey ssl_key(key, QSsl::Rsa); QSslCertificate ssl_cert(cert); m_socket->setPrivateKey(ssl_key); m_socket->setLocalCertificate(ssl_cert); m_socket->startServerEncryption(); }
private:
QSslSocket m_socket;
};int main( int argc, char **argv )
{
Server server;
server.f();
}
[/CODE] -
In addition to what Andre said: Are sure that "../ssl/server.crt" is the right path ?
-
I created an application object but code is still not compiling as I expected.
main.cpp:10: error: no match for 'operator=' in '((Server*)this)->Server::m_socket = (operator new(8u), (<statement>, ((QSslSocket*)<anonymous>)))'
[code]
#include <QApplication>
#include <QtNetwork/QSslSocket>
#include <QDebug>class Server : public QObject
{
public:
void f()
{
m_socket = new QSslSocket(this);
m_socket->setSocketDescriptor(handle);
m_socket->setProtocol(QSsl::SslV3);QByteArray key; QByteArray cert; QFile file_key("../ssl/server.key"); if(file_key.open(QIODevice::ReadOnly)) { key = file_key.readAll(); file_key.close(); } else { qDebug() << file_key.errorString(); } QFile file_cert("../ssl/server.crt"); if(file_cert.open(QIODevice::ReadOnly)) { cert = file_cert.readAll(); file_cert.close(); } else { qDebug() << file_cert.errorString(); } //qDebug() << key + "\n" + cert; QSslKey ssl_key(key, QSsl::Rsa); QSslCertificate ssl_cert(cert); m_socket->setPrivateKey(ssl_key); m_socket->setLocalCertificate(ssl_cert); m_socket->startServerEncryption(); }
private:
QSslSocket m_socket;
};int main( int argc, char **argv )
{
QApplication app(argc, argv);if (!QSslSocket::supportsSsl()) { QMessageBox::information(0, "Secure Socket Server", "This system does not support OpenSSL."); return -1; } Server server; server.f(); return app.exec();
}
[/code] -
Have a look at the declaration of m_socket
-
That's not all for m_socket.
Please, search the documentation a bit "Other libraries":http://qt-project.org/doc/qt-4.8/qmake-project-files.html#declaring-other-libraries
-
Thanks but unfortunately it does not help me.
main.cpp:13: error: undefined reference to
_imp___ZN10QSslSocketC1EP7QObject' main.cpp:15: error: undefined reference to
_imp___ZN10QSslSocket11setProtocolEN4QSsl11SslProtocolE'
main.cpp:45: error: undefined reference to_imp___ZN7QSslKeyC1ERK10QByteArrayN4QSsl12KeyAlgorithmENS3_14EncodingFormatENS3_7KeyTypeES2_' main.cpp:47: error: undefined reference to
_imp___ZN15QSslCertificateC1ERK10QByteArrayN4QSsl14EncodingFormatE'
main.cpp:49: error: undefined reference to_imp___ZN10QSslSocket13setPrivateKeyERK7QSslKey' main.cpp:50: error: undefined reference to
_imp___ZN10QSslSocket19setLocalCertificateERK15QSslCertificate'
main.cpp:51: error: undefined reference to_imp___ZN10QSslSocket21startServerEncryptionEv' main.cpp:51: error: undefined reference to
_imp___ZN15QSslCertificateD1Ev'
main.cpp:51: error: undefined reference to_imp___ZN7QSslKeyD1Ev' main.cpp:45: error: undefined reference to
_imp___ZN7QSslKeyD1Ev'
main.cpp:51: error: undefined reference to_imp___ZN15QSslCertificateD1Ev' main.cpp:51: error: undefined reference to
_imp___ZN7QSslKeyD1Ev' -
Sure it helps, that's a new error. Did you build Qt with ssl support ?
-
You are ship your commercial applications under LGPL license? Those are of course compatible with LGPL Qt.