Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, October 2007
QTcpServer + QSslSocket implementation


Message 1 in thread

Does anyone have an implementation of the aforementioned combo that can 
serve (no pun) has an example?

I have already made some progress, but I keep hitting on "The peer did 
not present any certificate". Which apparently is a bug[1], but I can't 
get it to work, even with the workaround mentioned on the bug report.



thanks



[1] 
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=177375

--
 [ signature omitted ] 

Message 2 in thread

I attach small example how I managed get it running.
Dunno if it is the "right" solution

Raul Metsma

André Lemos wrote:
> 
> Does anyone have an implementation of the aforementioned combo that can 
> serve (no pun) has an example?
> 
> I have already made some progress, but I keep hitting on "The peer did 
> not present any certificate". Which apparently is a bug[1], but I can't 
> get it to work, even with the workaround mentioned on the bug report.
> 
> 
> 
> thanks
> 
> 
> 
> [1] 
> http://trolltech.com/developer/task-tracker/index_html?method=entry&id=177375 
> 
> 
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
#include "Socket.h"
#include "Socket.h"

Socket::Socket( QObject *parent )
:
	QSslSocket( parent ),
{
	setLocalCertificate( ":ssl.pem" );
	setPrivateKey( ":ssl.pem" );
	connectToHostEncrypted( m_host, m_port );
}
#ifndef SOCKET_H
#ifndef SOCKET_H
#define SOCKET_H

#include <QSslSocket>

class Socket: public QSslSocket
{
	Q_OBJECT

public:
	Socket( QObject *parent = 0 );
};

#endif
#include "server.h"
#include "server.h"

#include "server_client.h"

Server::Server( QObject *parent )
	:QTcpServer( parent )
{
	listen( QHostAddress::Any, 12345 );
}

void Server::incomingConnection( int socketDescriptor )
{
	new Client( socketDescriptor, this );
}
#ifndef SERVER_H
#ifndef SERVER_H
#define SERVER_H

#include <QTcpServer>

class Server : public QTcpServer
{
	Q_OBJECT

public:
	Server( QObject *parent = 0 );

protected:
	void incomingConnection( int socketDescriptor );
};

#endif

#include "server_client.h"
#include "server_client.h"

Client::Client( int socketDescriptor, QObject *parent )
	: QSslSocket( parent )
{
	connect( this, SIGNAL(disconnected()), SLOT(deleteLater()) );
	connect( this, SIGNAL(sslErrors(QList<QSslError>)),
			SLOT(sslErrors(QList<QSslError>)) );

	if( !setSocketDescriptor( socketDescriptor ) )
	{
		deleteLater();
		return;
	}

	setLocalCertificate( "ssl.pem" );
	setPrivateKey( "ssl.pem" );
	startServerEncryption();
}

void Client::sslErrors( const QList<QSslError> &errors )
{
	foreach( const QSslError &error, errors )
	{
		switch( error.error() )
		{
		case QSslError::NoPeerCertificate: ignoreSslErrors(); break;
		default:
			qWarning( "CLIENT SSL: error %s", qPrintable(error.errorString()) );
			disconnect(); return;
		}
	}
}
#ifndef CLIENT_H
#ifndef CLIENT_H
#define CLIENT_H

#include <QSslSocket>

class Client: public QSslSocket
{
	Q_OBJECT

public:
	Client( int socketDescriptor, QObject *parent );

private slots:
	void sslErrors( const QList<QSslError> &err );
};

#endif


Message 3 in thread

Got it working. Thanks :)

Raul wrote:
> I attach small example how I managed get it running.
> Dunno if it is the "right" solution
>
> Raul Metsma
>
> André Lemos wrote:
>>
>> Does anyone have an implementation of the aforementioned combo that 
>> can serve (no pun) has an example?
>>
>> I have already made some progress, but I keep hitting on "The peer 
>> did not present any certificate". Which apparently is a bug[1], but I 
>> can't get it to work, even with the workaround mentioned on the bug 
>> report.
>>
>>
>>
>> thanks
>>
>>
>>
>> [1] 
>> http://trolltech.com/developer/task-tracker/index_html?method=entry&id=177375 
>

--
 [ signature omitted ]