summaryrefslogtreecommitdiffstats
path: root/examples/network/securesocketclient
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /examples/network/securesocketclient
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'examples/network/securesocketclient')
-rw-r--r--examples/network/securesocketclient/certificateinfo.cpp99
-rw-r--r--examples/network/securesocketclient/certificateinfo.h68
-rw-r--r--examples/network/securesocketclient/certificateinfo.ui85
-rw-r--r--examples/network/securesocketclient/encrypted.pngbin0 -> 750 bytes
-rw-r--r--examples/network/securesocketclient/main.cpp62
-rw-r--r--examples/network/securesocketclient/securesocketclient.pro21
-rw-r--r--examples/network/securesocketclient/securesocketclient.qrc5
-rw-r--r--examples/network/securesocketclient/sslclient.cpp219
-rw-r--r--examples/network/securesocketclient/sslclient.h80
-rw-r--r--examples/network/securesocketclient/sslclient.ui190
-rw-r--r--examples/network/securesocketclient/sslerrors.ui110
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 0000000000..ff3a4d2f3c
--- /dev/null
+++ b/examples/network/securesocketclient/certificateinfo.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $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 0000000000..6e60ade4f0
--- /dev/null
+++ b/examples/network/securesocketclient/certificateinfo.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $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 0000000000..3761fe8f50
--- /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
new file mode 100644
index 0000000000..04a05c1cb1
--- /dev/null
+++ b/examples/network/securesocketclient/encrypted.png
Binary files differ
diff --git a/examples/network/securesocketclient/main.cpp b/examples/network/securesocketclient/main.cpp
new file mode 100644
index 0000000000..c15534b523
--- /dev/null
+++ b/examples/network/securesocketclient/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $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 0000000000..3bbd9a81df
--- /dev/null
+++ b/examples/network/securesocketclient/securesocketclient.pro
@@ -0,0 +1,21 @@
+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]/qtbase/network/securesocketclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png *.jpg images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/securesocketclient
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000CF67
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/network/securesocketclient/securesocketclient.qrc b/examples/network/securesocketclient/securesocketclient.qrc
new file mode 100644
index 0000000000..83b49c790c
--- /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 0000000000..43b81cd984
--- /dev/null
+++ b/examples/network/securesocketclient/sslclient.cpp
@@ -0,0 +1,219 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $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("&lt;not connected&gt;"));
+
+ 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"));
+#ifndef QT_NO_CURSOR
+ padLock->setCursor(Qt::ArrowCursor);
+#endif
+ 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 0000000000..33a9a882b6
--- /dev/null
+++ b/examples/network/securesocketclient/sslclient.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $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 0000000000..5a24751168
--- /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>&lt;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>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;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;">&lt;/p>&lt;/body>&lt;/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>&amp;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 0000000000..4aac18cddb
--- /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>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-weight:600; color:#ff0000;">Warning&lt;/span>&lt;span style=" color:#ff0000;">:&lt;/span>&lt;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 &lt;/span>&lt;span style=" color:#000000;">Ignore&lt;/span>&lt;span style=" color:#000000;"> to continue, or &lt;/span>&lt;span style=" color:#000000;">Cancel&lt;/span>&lt;span style=" color:#000000;"> to abort the connection.&lt;/span>&lt;/p>&lt;/body>&lt;/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>