diff options
author | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
commit | 8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch) | |
tree | a17e1a767a89542ab59907462206d7dcf2e504b2 /examples/network/securesocketclient | |
download | Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.zip Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.gz Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.bz2 |
Long live Qt for S60!
Diffstat (limited to 'examples/network/securesocketclient')
-rw-r--r-- | examples/network/securesocketclient/certificateinfo.cpp | 100 | ||||
-rw-r--r-- | examples/network/securesocketclient/certificateinfo.h | 69 | ||||
-rw-r--r-- | examples/network/securesocketclient/certificateinfo.ui | 85 | ||||
-rw-r--r-- | examples/network/securesocketclient/encrypted.png | bin | 0 -> 750 bytes | |||
-rw-r--r-- | examples/network/securesocketclient/main.cpp | 63 | ||||
-rw-r--r-- | examples/network/securesocketclient/securesocketclient.pro | 18 | ||||
-rw-r--r-- | examples/network/securesocketclient/securesocketclient.qrc | 5 | ||||
-rw-r--r-- | examples/network/securesocketclient/sslclient.cpp | 218 | ||||
-rw-r--r-- | examples/network/securesocketclient/sslclient.h | 81 | ||||
-rw-r--r-- | examples/network/securesocketclient/sslclient.ui | 190 | ||||
-rw-r--r-- | examples/network/securesocketclient/sslerrors.ui | 110 |
11 files changed, 939 insertions, 0 deletions
diff --git a/examples/network/securesocketclient/certificateinfo.cpp b/examples/network/securesocketclient/certificateinfo.cpp new file mode 100644 index 0000000..d9be2e3 --- /dev/null +++ b/examples/network/securesocketclient/certificateinfo.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "certificateinfo.h" +#include "ui_certificateinfo.h" + +CertificateInfo::CertificateInfo(QWidget *parent) + : QDialog(parent) +{ + form = new Ui_CertificateInfo; + form->setupUi(this); + + connect(form->certificationPathView, SIGNAL(currentRowChanged(int)), + this, SLOT(updateCertificateInfo(int))); +} + +CertificateInfo::~CertificateInfo() +{ + delete form; +} + +void CertificateInfo::setCertificateChain(const QList<QSslCertificate> &chain) +{ + this->chain = chain; + + form->certificationPathView->clear(); + + for (int i = 0; i < chain.size(); ++i) { + const QSslCertificate &cert = chain.at(i); + form->certificationPathView->addItem(tr("%1%2 (%3)").arg(!i ? QString() : tr("Issued by: ")) + .arg(cert.subjectInfo(QSslCertificate::Organization)) + .arg(cert.subjectInfo(QSslCertificate::CommonName))); + } + + form->certificationPathView->setCurrentRow(0); +} + +void CertificateInfo::updateCertificateInfo(int index) +{ + form->certificateInfoView->clear(); + if (index >= 0 && index < chain.size()) { + const QSslCertificate &cert = chain.at(index); + QStringList lines; + lines << tr("Organization: %1").arg(cert.subjectInfo(QSslCertificate::Organization)) + << tr("Subunit: %1").arg(cert.subjectInfo(QSslCertificate::OrganizationalUnitName)) + << tr("Country: %1").arg(cert.subjectInfo(QSslCertificate::CountryName)) + << tr("Locality: %1").arg(cert.subjectInfo(QSslCertificate::LocalityName)) + << tr("State/Province: %1").arg(cert.subjectInfo(QSslCertificate::StateOrProvinceName)) + << tr("Common Name: %1").arg(cert.subjectInfo(QSslCertificate::CommonName)) + << QString() + << tr("Issuer Organization: %1").arg(cert.issuerInfo(QSslCertificate::Organization)) + << tr("Issuer Unit Name: %1").arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName)) + << tr("Issuer Country: %1").arg(cert.issuerInfo(QSslCertificate::CountryName)) + << tr("Issuer Locality: %1").arg(cert.issuerInfo(QSslCertificate::LocalityName)) + << tr("Issuer State/Province: %1").arg(cert.issuerInfo(QSslCertificate::StateOrProvinceName)) + << tr("Issuer Common Name: %1").arg(cert.issuerInfo(QSslCertificate::CommonName)); + foreach (QString line, lines) + form->certificateInfoView->addItem(line); + } else { + form->certificateInfoView->clear(); + } +} diff --git a/examples/network/securesocketclient/certificateinfo.h b/examples/network/securesocketclient/certificateinfo.h new file mode 100644 index 0000000..dc6a200 --- /dev/null +++ b/examples/network/securesocketclient/certificateinfo.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CERTIFICATEINFO_H +#define CERTIFICATEINFO_H + +#include <QtGui/QDialog> +#include <QtNetwork/QSslCertificate> + +QT_BEGIN_NAMESPACE +class Ui_CertificateInfo; +QT_END_NAMESPACE + +class CertificateInfo : public QDialog +{ + Q_OBJECT +public: + CertificateInfo(QWidget *parent = 0); + ~CertificateInfo(); + + void setCertificateChain(const QList<QSslCertificate> &chain); + +private slots: + void updateCertificateInfo(int index); + +private: + Ui_CertificateInfo *form; + QList<QSslCertificate> chain; +}; + +#endif diff --git a/examples/network/securesocketclient/certificateinfo.ui b/examples/network/securesocketclient/certificateinfo.ui new file mode 100644 index 0000000..3761fe8 --- /dev/null +++ b/examples/network/securesocketclient/certificateinfo.ui @@ -0,0 +1,85 @@ +<ui version="4.0" > + <class>CertificateInfo</class> + <widget class="QDialog" name="CertificateInfo" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>397</height> + </rect> + </property> + <property name="windowTitle" > + <string>Display Certificate Information</string> + </property> + <layout class="QVBoxLayout" > + <item> + <widget class="QGroupBox" name="groupBox" > + <property name="title" > + <string>Certification Path</string> + </property> + <layout class="QHBoxLayout" > + <item> + <widget class="QListWidget" name="certificationPathView" /> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2" > + <property name="title" > + <string>Certificate Information</string> + </property> + <layout class="QHBoxLayout" > + <item> + <widget class="QListWidget" name="certificateInfoView" /> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QHBoxLayout" > + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="standardButtons" > + <set>QDialogButtonBox::Close</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>clicked(QAbstractButton*)</signal> + <receiver>CertificateInfo</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel" > + <x>343</x> + <y>374</y> + </hint> + <hint type="destinationlabel" > + <x>352</x> + <y>422</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/examples/network/securesocketclient/encrypted.png b/examples/network/securesocketclient/encrypted.png Binary files differnew file mode 100644 index 0000000..04a05c1 --- /dev/null +++ b/examples/network/securesocketclient/encrypted.png diff --git a/examples/network/securesocketclient/main.cpp b/examples/network/securesocketclient/main.cpp new file mode 100644 index 0000000..200aa26 --- /dev/null +++ b/examples/network/securesocketclient/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QMessageBox> + +#include "sslclient.h" + +int main(int argc, char **argv) +{ + Q_INIT_RESOURCE(securesocketclient); + + QApplication app(argc, argv); + + if (!QSslSocket::supportsSsl()) { + QMessageBox::information(0, "Secure Socket Client", + "This system does not support OpenSSL."); + return -1; + } + + SslClient client; + client.show(); + + return app.exec(); +} diff --git a/examples/network/securesocketclient/securesocketclient.pro b/examples/network/securesocketclient/securesocketclient.pro new file mode 100644 index 0000000..166d7ad --- /dev/null +++ b/examples/network/securesocketclient/securesocketclient.pro @@ -0,0 +1,18 @@ +HEADERS += certificateinfo.h \ + sslclient.h +SOURCES += certificateinfo.cpp \ + main.cpp \ + sslclient.cpp +RESOURCES += securesocketclient.qrc +FORMS += certificateinfo.ui \ + sslclient.ui \ + sslerrors.ui +QT += network + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/network/securesocketclient +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png *.jpg images +sources.path = $$[QT_INSTALL_EXAMPLES]/network/securesocketclient +INSTALLS += target sources + +include($$QT_SOURCE_TREE/examples/examplebase.pri) diff --git a/examples/network/securesocketclient/securesocketclient.qrc b/examples/network/securesocketclient/securesocketclient.qrc new file mode 100644 index 0000000..83b49c7 --- /dev/null +++ b/examples/network/securesocketclient/securesocketclient.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>encrypted.png</file> +</qresource> +</RCC> diff --git a/examples/network/securesocketclient/sslclient.cpp b/examples/network/securesocketclient/sslclient.cpp new file mode 100644 index 0000000..bf8443d --- /dev/null +++ b/examples/network/securesocketclient/sslclient.cpp @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "certificateinfo.h" +#include "sslclient.h" +#include "ui_sslclient.h" +#include "ui_sslerrors.h" + +#include <QtGui/QScrollBar> +#include <QtGui/QStyle> +#include <QtGui/QToolButton> +#include <QtNetwork/QSslCipher> + +SslClient::SslClient(QWidget *parent) + : QWidget(parent), socket(0), padLock(0), executingDialog(false) +{ + form = new Ui_Form; + form->setupUi(this); + form->hostNameEdit->setSelection(0, form->hostNameEdit->text().size()); + form->sessionOutput->setHtml(tr("<not connected>")); + + connect(form->hostNameEdit, SIGNAL(textChanged(QString)), + this, SLOT(updateEnabledState())); + connect(form->connectButton, SIGNAL(clicked()), + this, SLOT(secureConnect())); + connect(form->sendButton, SIGNAL(clicked()), + this, SLOT(sendData())); +} + +SslClient::~SslClient() +{ + delete form; +} + +void SslClient::updateEnabledState() +{ + bool unconnected = !socket || socket->state() == QAbstractSocket::UnconnectedState; + + form->hostNameEdit->setReadOnly(!unconnected); + form->hostNameEdit->setFocusPolicy(unconnected ? Qt::StrongFocus : Qt::NoFocus); + + form->hostNameLabel->setEnabled(unconnected); + form->portBox->setEnabled(unconnected); + form->portLabel->setEnabled(unconnected); + form->connectButton->setEnabled(unconnected && !form->hostNameEdit->text().isEmpty()); + + bool connected = socket && socket->state() == QAbstractSocket::ConnectedState; + form->sessionBox->setEnabled(connected); + form->sessionOutput->setEnabled(connected); + form->sessionInput->setEnabled(connected); + form->sessionInputLabel->setEnabled(connected); + form->sendButton->setEnabled(connected); +} + +void SslClient::secureConnect() +{ + if (!socket) { + socket = new QSslSocket(this); + connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), + this, SLOT(socketStateChanged(QAbstractSocket::SocketState))); + connect(socket, SIGNAL(encrypted()), + this, SLOT(socketEncrypted())); + connect(socket, SIGNAL(sslErrors(QList<QSslError>)), + this, SLOT(sslErrors(QList<QSslError>))); + connect(socket, SIGNAL(readyRead()), + this, SLOT(socketReadyRead())); + } + + socket->connectToHostEncrypted(form->hostNameEdit->text(), form->portBox->value()); + updateEnabledState(); +} + +void SslClient::socketStateChanged(QAbstractSocket::SocketState state) +{ + if (executingDialog) + return; + + updateEnabledState(); + if (state == QAbstractSocket::UnconnectedState) { + form->hostNameEdit->setPalette(QPalette()); + form->hostNameEdit->setFocus(); + form->cipherLabel->setText(tr("<none>")); + if (padLock) + padLock->hide(); + socket->deleteLater(); + socket = 0; + } +} + +void SslClient::socketEncrypted() +{ + if (!socket) + return; // might have disconnected already + + form->sessionOutput->clear(); + form->sessionInput->setFocus(); + + QPalette palette; + palette.setColor(QPalette::Base, QColor(255, 255, 192)); + form->hostNameEdit->setPalette(palette); + + QSslCipher ciph = socket->sessionCipher(); + QString cipher = QString("%1, %2 (%3/%4)").arg(ciph.authenticationMethod()) + .arg(ciph.name()).arg(ciph.usedBits()).arg(ciph.supportedBits());; + form->cipherLabel->setText(cipher); + + if (!padLock) { + padLock = new QToolButton; + padLock->setIcon(QIcon(":/encrypted.png")); + padLock->setCursor(Qt::ArrowCursor); + padLock->setToolTip(tr("Display encryption details.")); + + int extent = form->hostNameEdit->height() - 2; + padLock->resize(extent, extent); + padLock->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); + + QHBoxLayout *layout = new QHBoxLayout(form->hostNameEdit); + layout->setMargin(form->hostNameEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth)); + layout->setSpacing(0); + layout->addStretch(); + layout->addWidget(padLock); + + form->hostNameEdit->setLayout(layout); + + connect(padLock, SIGNAL(clicked()), + this, SLOT(displayCertificateInfo())); + } else { + padLock->show(); + } +} + +void SslClient::socketReadyRead() +{ + appendString(QString::fromUtf8(socket->readAll())); +} + +void SslClient::sendData() +{ + QString input = form->sessionInput->text(); + appendString(input + "\n"); + socket->write(input.toUtf8() + "\r\n"); + form->sessionInput->clear(); +} + +void SslClient::sslErrors(const QList<QSslError> &errors) +{ + QDialog errorDialog(this); + Ui_SslErrors ui; + ui.setupUi(&errorDialog); + connect(ui.certificateChainButton, SIGNAL(clicked()), + this, SLOT(displayCertificateInfo())); + + foreach (const QSslError &error, errors) + ui.sslErrorList->addItem(error.errorString()); + + executingDialog = true; + if (errorDialog.exec() == QDialog::Accepted) + socket->ignoreSslErrors(); + executingDialog = false; + + // did the socket state change? + if (socket->state() != QAbstractSocket::ConnectedState) + socketStateChanged(socket->state()); +} + +void SslClient::displayCertificateInfo() +{ + CertificateInfo *info = new CertificateInfo(this); + info->setCertificateChain(socket->peerCertificateChain()); + info->exec(); + info->deleteLater(); +} + +void SslClient::appendString(const QString &line) +{ + QTextCursor cursor(form->sessionOutput->textCursor()); + cursor.movePosition(QTextCursor::End); + cursor.insertText(line); + form->sessionOutput->verticalScrollBar()->setValue(form->sessionOutput->verticalScrollBar()->maximum()); +} diff --git a/examples/network/securesocketclient/sslclient.h b/examples/network/securesocketclient/sslclient.h new file mode 100644 index 0000000..ae208bb --- /dev/null +++ b/examples/network/securesocketclient/sslclient.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SSLCLIENT_H +#define SSLCLIENT_H + +#include <QtGui/QWidget> +#include <QtNetwork/QAbstractSocket> +#include <QtNetwork/QSslSocket> + +QT_BEGIN_NAMESPACE +class QSslSocket; +class QToolButton; +class Ui_Form; +QT_END_NAMESPACE + +class SslClient : public QWidget +{ + Q_OBJECT +public: + SslClient(QWidget *parent = 0); + ~SslClient(); + +private slots: + void updateEnabledState(); + void secureConnect(); + void socketStateChanged(QAbstractSocket::SocketState state); + void socketEncrypted(); + void socketReadyRead(); + void sendData(); + void sslErrors(const QList<QSslError> &errors); + void displayCertificateInfo(); + +private: + void appendString(const QString &line); + + QSslSocket *socket; + QToolButton *padLock; + Ui_Form *form; + bool executingDialog; +}; + +#endif diff --git a/examples/network/securesocketclient/sslclient.ui b/examples/network/securesocketclient/sslclient.ui new file mode 100644 index 0000000..5a24751 --- /dev/null +++ b/examples/network/securesocketclient/sslclient.ui @@ -0,0 +1,190 @@ +<ui version="4.0" > + <class>Form</class> + <widget class="QWidget" name="Form" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>343</width> + <height>320</height> + </rect> + </property> + <property name="windowTitle" > + <string>Secure Socket Client</string> + </property> + <layout class="QVBoxLayout" > + <item> + <layout class="QGridLayout" > + <item row="0" column="0" > + <widget class="QLabel" name="hostNameLabel" > + <property name="text" > + <string>Host name:</string> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QLineEdit" name="hostNameEdit" > + <property name="text" > + <string>imap.example.com</string> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="portLabel" > + <property name="text" > + <string>Port:</string> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QSpinBox" name="portBox" > + <property name="minimum" > + <number>1</number> + </property> + <property name="maximum" > + <number>65535</number> + </property> + <property name="value" > + <number>993</number> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QPushButton" name="connectButton" > + <property name="enabled" > + <bool>true</bool> + </property> + <property name="text" > + <string>Connect to host</string> + </property> + <property name="default" > + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QGroupBox" name="sessionBox" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="title" > + <string>Active session</string> + </property> + <layout class="QVBoxLayout" > + <item> + <layout class="QHBoxLayout" > + <item> + <widget class="QLabel" name="cipherText" > + <property name="text" > + <string>Cryptographic Cipher:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="cipherLabel" > + <property name="text" > + <string><none></string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QTextEdit" name="sessionOutput" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="focusPolicy" > + <enum>Qt::NoFocus</enum> + </property> + <property name="readOnly" > + <bool>true</bool> + </property> + <property name="html" > + <string><html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" > + <item> + <widget class="QLabel" name="sessionInputLabel" > + <property name="text" > + <string>Input:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="sessionInput" > + <property name="enabled" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="sendButton" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="focusPolicy" > + <enum>Qt::TabFocus</enum> + </property> + <property name="text" > + <string>&Send</string> + </property> + <property name="default" > + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>hostNameEdit</sender> + <signal>returnPressed()</signal> + <receiver>connectButton</receiver> + <slot>animateClick()</slot> + <hints> + <hint type="sourcelabel" > + <x>126</x> + <y>20</y> + </hint> + <hint type="destinationlabel" > + <x>142</x> + <y>78</y> + </hint> + </hints> + </connection> + <connection> + <sender>sessionInput</sender> + <signal>returnPressed()</signal> + <receiver>sendButton</receiver> + <slot>animateClick()</slot> + <hints> + <hint type="sourcelabel" > + <x>142</x> + <y>241</y> + </hint> + <hint type="destinationlabel" > + <x>297</x> + <y>234</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/examples/network/securesocketclient/sslerrors.ui b/examples/network/securesocketclient/sslerrors.ui new file mode 100644 index 0000000..4aac18c --- /dev/null +++ b/examples/network/securesocketclient/sslerrors.ui @@ -0,0 +1,110 @@ +<ui version="4.0" > + <class>SslErrors</class> + <widget class="QDialog" name="SslErrors" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>371</width> + <height>216</height> + </rect> + </property> + <property name="windowTitle" > + <string>Unable To Validate The Connection</string> + </property> + <layout class="QVBoxLayout" > + <item> + <widget class="QLabel" name="label" > + <property name="text" > + <string><html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600; color:#ff0000;">Warning</span><span style=" color:#ff0000;">:</span><span style=" color:#000000;"> One or more errors with this connection prevent validating the authenticity of the host you are connecting to. Please review the following list of errors, and click </span><span style=" color:#000000;">Ignore</span><span style=" color:#000000;"> to continue, or </span><span style=" color:#000000;">Cancel</span><span style=" color:#000000;"> to abort the connection.</span></p></body></html></string> + </property> + <property name="wordWrap" > + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QListWidget" name="sslErrorList" /> + </item> + <item> + <layout class="QHBoxLayout" > + <item> + <widget class="QPushButton" name="certificateChainButton" > + <property name="text" > + <string>View Certificate Chain</string> + </property> + <property name="autoDefault" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="pushButton" > + <property name="text" > + <string>Ignore</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_2" > + <property name="text" > + <string>Cancel</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>pushButton</sender> + <signal>clicked()</signal> + <receiver>SslErrors</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel" > + <x>235</x> + <y>185</y> + </hint> + <hint type="destinationlabel" > + <x>228</x> + <y>287</y> + </hint> + </hints> + </connection> + <connection> + <sender>pushButton_2</sender> + <signal>clicked()</signal> + <receiver>SslErrors</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel" > + <x>325</x> + <y>192</y> + </hint> + <hint type="destinationlabel" > + <x>333</x> + <y>231</y> + </hint> + </hints> + </connection> + </connections> +</ui> |