From 6a34b95f02848f75057f5e913e500115643fde5d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 22 Mar 2010 02:46:24 +0100 Subject: First SSL support. checking metadata missing.. --- src/websslinfo.cpp | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 src/websslinfo.cpp (limited to 'src/websslinfo.cpp') diff --git a/src/websslinfo.cpp b/src/websslinfo.cpp new file mode 100644 index 00000000..ffc4918f --- /dev/null +++ b/src/websslinfo.cpp @@ -0,0 +1,211 @@ +/* + * This file is part of the KDE project. + * + * Copyright (C) 2009 Dawit Alemayehu + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "websslinfo.h" + +#include + + +class WebSslInfo::WebSslInfoPrivate +{ +public: + WebSslInfoPrivate() + : usedCipherBits(0), supportedCipherBits(0) {} + + QUrl url; + QString ciphers; + QString protocol; + QString certErrors; + QHostAddress peerAddress; + QHostAddress parentAddress; + QList certificateChain; + + int usedCipherBits; + int supportedCipherBits; +}; + +WebSslInfo::WebSslInfo() + :d(new WebSslInfo::WebSslInfoPrivate) +{ +} + +WebSslInfo::WebSslInfo(const WebSslInfo& other) + :d(new WebSslInfo::WebSslInfoPrivate) +{ + *this = other; +} + +WebSslInfo::~WebSslInfo() +{ + delete d; + d = 0; +} + +bool WebSslInfo::isValid() const +{ + return !d->peerAddress.isNull(); +} + +QUrl WebSslInfo::url() const +{ + return d->url; +} + +QHostAddress WebSslInfo::parentAddress() const +{ + return d->parentAddress; +} + +QHostAddress WebSslInfo::peerAddress() const +{ + return d->peerAddress; +} + +QString WebSslInfo::protocol() const +{ + return d->protocol; +} + +QString WebSslInfo::ciphers() const +{ + return d->ciphers; +} + +QString WebSslInfo::certificateErrors() const +{ + return d->certErrors; +} + +int WebSslInfo::supportedChiperBits () const +{ + return d->supportedCipherBits; +} + +int WebSslInfo::usedChiperBits () const +{ + return d->usedCipherBits; +} + +QList WebSslInfo::certificateChain() const +{ + return d->certificateChain; +} + +WebSslInfo& WebSslInfo::operator=(const WebSslInfo& other) +{ + d->ciphers = other.d->ciphers; + d->protocol = other.d->protocol; + d->certErrors = other.d->certErrors; + d->peerAddress = other.d->peerAddress; + d->parentAddress = other.d->parentAddress; + d->certificateChain = other.d->certificateChain; + + d->usedCipherBits = other.d->usedCipherBits; + d->supportedCipherBits = other.d->supportedCipherBits; + d->url = other.d->url; + + return *this; +} + +QVariant WebSslInfo::toMetaData() const +{ + if (isValid()) { + QMap data; + data.insert("ssl_in_use", true); + data.insert("ssl_peer_ip", d->peerAddress.toString()); + data.insert("ssl_parent_ip", d->parentAddress.toString()); + data.insert("ssl_protocol_version", d->protocol); + data.insert("ssl_cipher", d->ciphers); + data.insert("ssl_cert_errors", d->certErrors); + data.insert("ssl_cipher_used_bits", d->usedCipherBits); + data.insert("ssl_cipher_bits", d->supportedCipherBits); + QByteArray certChain; + Q_FOREACH(const QSslCertificate& cert, d->certificateChain) + certChain += cert.toPem(); + data.insert("ssl_peer_chain", certChain); + return data; + } + + return QVariant(); +} + +void WebSslInfo::fromMetaData(const QVariant& value) +{ + if (value.isValid() && value.type() == QVariant::Map) { + QMap metaData = value.toMap(); + if (metaData.value("ssl_in_use", false).toBool()) { + setCertificateChain(metaData.value("ssl_peer_chain").toByteArray()); + setPeerAddress(metaData.value("ssl_peer_ip").toString()); + setParentAddress(metaData.value("ssl_parent_ip").toString()); + setProtocol(metaData.value("ssl_protocol_version").toString()); + setCiphers(metaData.value("ssl_cipher").toString()); + setCertificateErrors(metaData.value("ssl_cert_errors").toString()); + setUsedCipherBits(metaData.value("ssl_cipher_used_bits").toString()); + setSupportedCipherBits(metaData.value("ssl_cipher_bits").toString()); + } + } +} + +void WebSslInfo::setUrl (const QUrl &url) +{ + d->url = url; +} + +void WebSslInfo::setPeerAddress(const QString& address) +{ + d->peerAddress = address; +} + +void WebSslInfo::setParentAddress(const QString& address) +{ + d->parentAddress = address; +} + +void WebSslInfo::setProtocol(const QString& protocol) +{ + d->protocol = protocol; +} + +void WebSslInfo::setCertificateChain(const QByteArray& chain) +{ + d->certificateChain = QSslCertificate::fromData(chain); +} + +void WebSslInfo::setCiphers(const QString& ciphers) +{ + d->ciphers = ciphers; +} + +void WebSslInfo::setUsedCipherBits(const QString& bits) +{ + d->usedCipherBits = bits.toInt(); +} + +void WebSslInfo::setSupportedCipherBits(const QString& bits) +{ + d->supportedCipherBits = bits.toInt(); +} + +void WebSslInfo::setCertificateErrors(const QString& certErrors) +{ + d->certErrors = certErrors; +} -- cgit v1.2.1