diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-03-23 11:54:03 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-03-23 11:54:03 (GMT) |
commit | 846c4b9d2e7ec3214a3b13bdbbce77f70fede515 (patch) | |
tree | 579bf6be3e266c8e28a7469e7547ac88fa9af3fc | |
parent | 8ccdfd958ba1e7afbeb8c5893c12f09046cb8892 (diff) | |
download | swift-contrib-846c4b9d2e7ec3214a3b13bdbbce77f70fede515.zip swift-contrib-846c4b9d2e7ec3214a3b13bdbbce77f70fede515.tar.bz2 |
Allow TLS errors to bubble further up the stackks/tlserrors
-rw-r--r-- | Swift/Controllers/MainController.cpp | 4 | ||||
-rw-r--r-- | Swiften/Client/ClientError.h | 3 | ||||
-rw-r--r-- | Swiften/Client/CoreClient.cpp | 23 | ||||
-rw-r--r-- | Swiften/Client/UnitTest/ClientSessionTest.cpp | 4 | ||||
-rw-r--r-- | Swiften/Component/CoreComponent.cpp | 12 | ||||
-rw-r--r-- | Swiften/Component/UnitTest/ComponentSessionTest.cpp | 2 | ||||
-rw-r--r-- | Swiften/Network/BOSHConnection.h | 4 | ||||
-rw-r--r-- | Swiften/Session/BOSHSessionStream.cpp | 2 | ||||
-rw-r--r-- | Swiften/Session/BasicSessionStream.cpp | 16 | ||||
-rw-r--r-- | Swiften/Session/BasicSessionStream.h | 3 | ||||
-rw-r--r-- | Swiften/Session/SessionStream.h | 4 | ||||
-rw-r--r-- | Swiften/StreamStack/TLSLayer.h | 3 | ||||
-rw-r--r-- | Swiften/TLS/OpenSSL/OpenSSLContext.cpp | 6 | ||||
-rw-r--r-- | Swiften/TLS/Schannel/SchannelContext.cpp | 2 | ||||
-rw-r--r-- | Swiften/TLS/TLSContext.h | 3 |
15 files changed, 55 insertions, 36 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index e923cff..b0a1778 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -512,36 +512,38 @@ void MainController::handleDisconnected(const boost::optional<ClientError>& erro purgeCachedCredentials(); } if (quitRequested_) { resetClient(); loginWindow_->quit(); } else if (error) { std::string message; std::string certificateErrorMessage; + bool forceSignout = false; switch(error->getType()) { case ClientError::UnknownError: message = QT_TRANSLATE_NOOP("", "Unknown Error"); break; case ClientError::DomainNameResolveError: message = QT_TRANSLATE_NOOP("", "Unable to find server"); break; case ClientError::ConnectionError: message = QT_TRANSLATE_NOOP("", "Error connecting to server"); break; case ClientError::ConnectionReadError: message = QT_TRANSLATE_NOOP("", "Error while receiving server data"); break; case ClientError::ConnectionWriteError: message = QT_TRANSLATE_NOOP("", "Error while sending data to the server"); break; case ClientError::XMLError: message = QT_TRANSLATE_NOOP("", "Error parsing server data"); break; case ClientError::AuthenticationFailedError: message = QT_TRANSLATE_NOOP("", "Login/password invalid"); break; case ClientError::CompressionFailedError: message = QT_TRANSLATE_NOOP("", "Error while compressing stream"); break; case ClientError::ServerVerificationFailedError: message = QT_TRANSLATE_NOOP("", "Server verification failed"); break; case ClientError::NoSupportedAuthMechanismsError: message = QT_TRANSLATE_NOOP("", "Authentication mechanisms not supported"); break; case ClientError::UnexpectedElementError: message = QT_TRANSLATE_NOOP("", "Unexpected response"); break; case ClientError::ResourceBindError: message = QT_TRANSLATE_NOOP("", "Error binding resource"); break; case ClientError::SessionStartError: message = QT_TRANSLATE_NOOP("", "Error starting session"); break; case ClientError::StreamError: message = QT_TRANSLATE_NOOP("", "Stream error"); break; case ClientError::TLSError: message = QT_TRANSLATE_NOOP("", "Encryption error"); break; case ClientError::ClientCertificateLoadError: message = QT_TRANSLATE_NOOP("", "Error loading certificate (Invalid password?)"); break; case ClientError::ClientCertificateError: message = QT_TRANSLATE_NOOP("", "Certificate not authorized"); break; + case ClientError::CertificateCardRemoved: message = QT_TRANSLATE_NOOP("", "Certificate card removed"); forceSignout = true; break; case ClientError::UnknownCertificateError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unknown certificate"); break; case ClientError::CertificateExpiredError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has expired"); break; case ClientError::CertificateNotYetValidError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not yet valid"); break; case ClientError::CertificateSelfSignedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is self-signed"); break; case ClientError::CertificateRejectedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been rejected"); break; case ClientError::CertificateUntrustedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not trusted"); break; case ClientError::InvalidCertificatePurposeError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate cannot be used for encrypting your connection"); break; case ClientError::CertificatePathLengthExceededError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate path length constraint exceeded"); break; @@ -558,19 +560,19 @@ void MainController::handleDisconnected(const boost::optional<ClientError>& erro } else { message = QT_TRANSLATE_NOOP("", "Certificate error"); } } if (forceReconnectAfterCertificateTrust) { performLoginFromCachedCredentials(); } - else if (!rosterController_) { //hasn't been logged in yet + else if (forceSignout || !rosterController_) { //hasn't been logged in yet or permanent error signOut(); loginWindow_->setMessage(message); loginWindow_->setIsLoggingIn(false); } else { logout(); if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%. To reconnect, Sign Out and provide your password again.")) % jid_.getDomain() % message); } else { if (!offlineRequested_) { diff --git a/Swiften/Client/ClientError.h b/Swiften/Client/ClientError.h index 2f2d2af..a4dc040 100644 --- a/Swiften/Client/ClientError.h +++ b/Swiften/Client/ClientError.h @@ -22,18 +22,21 @@ namespace Swift { NoSupportedAuthMechanismsError, UnexpectedElementError, ResourceBindError, SessionStartError, StreamError, TLSError, ClientCertificateLoadError, ClientCertificateError, + // Certifate on smartcard was removed + CertificateCardRemoved, + // Certificate verification errors UnknownCertificateError, CertificateExpiredError, CertificateNotYetValidError, CertificateSelfSignedError, CertificateRejectedError, CertificateUntrustedError, InvalidCertificatePurposeError, CertificatePathLengthExceededError, diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index 14481c6..45d80aa 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -9,18 +9,19 @@ #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/IDGenerator.h> #include <Swiften/Base/Log.h> #include <Swiften/Base/foreach.h> #include <Swiften/Base/Algorithm.h> #include <Swiften/Client/ClientSession.h> #include <Swiften/TLS/CertificateVerificationError.h> +#include <Swiften/TLS/TLSError.h> #include <Swiften/Network/ChainedConnector.h> #include <Swiften/Network/NetworkFactories.h> #include <Swiften/Network/ProxyProvider.h> #include <Swiften/Network/DomainNameResolveError.h> #include <Swiften/TLS/PKCS12Certificate.h> #include <Swiften/Session/BasicSessionStream.h> #include <Swiften/Session/BOSHSessionStream.h> #include <Swiften/Queries/IQRouter.h> #include <Swiften/Client/ClientSessionStanzaChannel.h> @@ -211,33 +212,43 @@ void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) { break; case ClientSession::Error::TLSClientCertificateError: clientError = ClientError(ClientError::ClientCertificateError); break; case ClientSession::Error::StreamError: clientError = ClientError(ClientError::StreamError); break; } } - else if (boost::shared_ptr<SessionStream::Error> actualError = boost::dynamic_pointer_cast<SessionStream::Error>(error)) { + else if (boost::shared_ptr<TLSError> actualError = boost::dynamic_pointer_cast<TLSError>(error)) { + switch(actualError->getType()) { + case TLSError::CertificateCardRemoved: + clientError = ClientError(ClientError::CertificateCardRemoved); + break; + default: + clientError = ClientError(ClientError::TLSError); + break; + } + } + else if (boost::shared_ptr<SessionStream::SessionStreamError> actualError = boost::dynamic_pointer_cast<SessionStream::SessionStreamError>(error)) { switch(actualError->type) { - case SessionStream::Error::ParseError: + case SessionStream::SessionStreamError::ParseError: clientError = ClientError(ClientError::XMLError); break; - case SessionStream::Error::TLSError: + case SessionStream::SessionStreamError::TLSError: clientError = ClientError(ClientError::TLSError); break; - case SessionStream::Error::InvalidTLSCertificateError: + case SessionStream::SessionStreamError::InvalidTLSCertificateError: clientError = ClientError(ClientError::ClientCertificateLoadError); break; - case SessionStream::Error::ConnectionReadError: + case SessionStream::SessionStreamError::ConnectionReadError: clientError = ClientError(ClientError::ConnectionReadError); break; - case SessionStream::Error::ConnectionWriteError: + case SessionStream::SessionStreamError::ConnectionWriteError: clientError = ClientError(ClientError::ConnectionWriteError); break; } } else if (boost::shared_ptr<CertificateVerificationError> verificationError = boost::dynamic_pointer_cast<CertificateVerificationError>(error)) { switch(verificationError->getType()) { case CertificateVerificationError::UnknownError: clientError = ClientError(ClientError::UnknownCertificateError); break; diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp index a6d5a3a..6793643 100644 --- a/Swiften/Client/UnitTest/ClientSessionTest.cpp +++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp @@ -414,23 +414,23 @@ class ClientSessionTest : public CppUnit::TestFixture { virtual void setWhitespacePingEnabled(bool enabled) { whitespacePingEnabled = enabled; } virtual void resetXMPPParser() { resetCount++; } void breakConnection() { - onClosed(boost::make_shared<SessionStream::Error>(SessionStream::Error::ConnectionReadError)); + onClosed(boost::make_shared<SessionStream::SessionStreamError>(SessionStream::SessionStreamError::ConnectionReadError)); } void breakTLS() { - onClosed(boost::make_shared<SessionStream::Error>(SessionStream::Error::TLSError)); + onClosed(boost::make_shared<SessionStream::SessionStreamError>(SessionStream::SessionStreamError::TLSError)); } void sendStreamStart() { ProtocolHeader header; header.setTo("foo.com"); return onStreamStartReceived(header); } diff --git a/Swiften/Component/CoreComponent.cpp b/Swiften/Component/CoreComponent.cpp index e630ddf..e11d2b0 100644 --- a/Swiften/Component/CoreComponent.cpp +++ b/Swiften/Component/CoreComponent.cpp @@ -108,35 +108,35 @@ void CoreComponent::handleSessionFinished(boost::shared_ptr<Error> error) { switch(actualError->type) { case ComponentSession::Error::AuthenticationFailedError: componentError = ComponentError(ComponentError::AuthenticationFailedError); break; case ComponentSession::Error::UnexpectedElementError: componentError = ComponentError(ComponentError::UnexpectedElementError); break; } } - else if (boost::shared_ptr<SessionStream::Error> actualError = boost::dynamic_pointer_cast<SessionStream::Error>(error)) { + else if (boost::shared_ptr<SessionStream::SessionStreamError> actualError = boost::dynamic_pointer_cast<SessionStream::SessionStreamError>(error)) { switch(actualError->type) { - case SessionStream::Error::ParseError: + case SessionStream::SessionStreamError::ParseError: componentError = ComponentError(ComponentError::XMLError); break; - case SessionStream::Error::TLSError: + case SessionStream::SessionStreamError::TLSError: assert(false); componentError = ComponentError(ComponentError::UnknownError); break; - case SessionStream::Error::InvalidTLSCertificateError: + case SessionStream::SessionStreamError::InvalidTLSCertificateError: assert(false); componentError = ComponentError(ComponentError::UnknownError); break; - case SessionStream::Error::ConnectionReadError: + case SessionStream::SessionStreamError::ConnectionReadError: componentError = ComponentError(ComponentError::ConnectionReadError); break; - case SessionStream::Error::ConnectionWriteError: + case SessionStream::SessionStreamError::ConnectionWriteError: componentError = ComponentError(ComponentError::ConnectionWriteError); break; } } onError(componentError); } } void CoreComponent::handleDataRead(const SafeByteArray& data) { diff --git a/Swiften/Component/UnitTest/ComponentSessionTest.cpp b/Swiften/Component/UnitTest/ComponentSessionTest.cpp index 9763c7f..da9ca7d 100644 --- a/Swiften/Component/UnitTest/ComponentSessionTest.cpp +++ b/Swiften/Component/UnitTest/ComponentSessionTest.cpp @@ -153,19 +153,19 @@ class ComponentSessionTest : public CppUnit::TestFixture { virtual void setWhitespacePingEnabled(bool enabled) { whitespacePingEnabled = enabled; } virtual void resetXMPPParser() { resetCount++; } void breakConnection() { - onClosed(boost::make_shared<SessionStream::Error>(SessionStream::Error::ConnectionReadError)); + onClosed(boost::make_shared<SessionStream::SessionStreamError>(SessionStream::SessionStreamError::ConnectionReadError)); } void sendStreamStart() { ProtocolHeader header; header.setFrom("service.foo.com"); return onStreamStartReceived(header); } void sendHandshakeResponse() { diff --git a/Swiften/Network/BOSHConnection.h b/Swiften/Network/BOSHConnection.h index d9fa016..a2abfcd 100644 --- a/Swiften/Network/BOSHConnection.h +++ b/Swiften/Network/BOSHConnection.h @@ -30,25 +30,25 @@ namespace boost { } } class BOSHConnectionTest; namespace Swift { class XMLParserFactory; class TLSContextFactory; - class BOSHError : public SessionStream::Error { + class BOSHError : public SessionStream::SessionStreamError { public: enum Type {BadRequest, HostGone, HostUnknown, ImproperAddressing, InternalServerError, ItemNotFound, OtherRequest, PolicyViolation, RemoteConnectionFailed, RemoteStreamError, SeeOtherURI, SystemShutdown, UndefinedCondition, NoError}; - BOSHError(Type type) : SessionStream::Error(SessionStream::Error::ConnectionReadError), type(type) {} + BOSHError(Type type) : SessionStream::SessionStreamError(SessionStream::SessionStreamError::ConnectionReadError), type(type) {} Type getType() {return type;} typedef boost::shared_ptr<BOSHError> ref; private: Type type; }; class BOSHConnection : public boost::enable_shared_from_this<BOSHConnection> { diff --git a/Swiften/Session/BOSHSessionStream.cpp b/Swiften/Session/BOSHSessionStream.cpp index ce5df35..237a394 100644 --- a/Swiften/Session/BOSHSessionStream.cpp +++ b/Swiften/Session/BOSHSessionStream.cpp @@ -157,19 +157,19 @@ void BOSHSessionStream::handleStreamStartReceived(const ProtocolHeader& header) onStreamStartReceived(header); } void BOSHSessionStream::handleElementReceived(boost::shared_ptr<Element> element) { onElementReceived(element); } void BOSHSessionStream::handleXMPPError() { available = false; - onClosed(boost::make_shared<Error>(Error::ParseError)); + onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ParseError)); } void BOSHSessionStream::handlePoolSessionStarted() { fakeStreamHeaderReceipt(); } void BOSHSessionStream::handlePoolSessionTerminated(BOSHError::ref error) { eventLoop->postEvent(boost::bind(&BOSHSessionStream::fakeStreamFooterReceipt, this, error), shared_from_this()); } diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index f50c5d5..b49ffc9 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp @@ -105,23 +105,23 @@ bool BasicSessionStream::isOpen() { bool BasicSessionStream::supportsTLSEncryption() { return tlsContextFactory && tlsContextFactory->canCreate(); } void BasicSessionStream::addTLSEncryption() { assert(available); tlsLayer = new TLSLayer(tlsContextFactory); if (hasTLSCertificate() && !tlsLayer->setClientCertificate(getTLSCertificate())) { - onClosed(boost::make_shared<Error>(Error::InvalidTLSCertificateError)); + onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::InvalidTLSCertificateError)); } else { streamStack->addLayer(tlsLayer); - tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this)); + tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this, _1)); tlsLayer->onConnected.connect(boost::bind(&BasicSessionStream::handleTLSConnected, this)); tlsLayer->connect(); } } bool BasicSessionStream::isTLSEncrypted() { return tlsLayer; } @@ -167,40 +167,40 @@ void BasicSessionStream::handleStreamStartReceived(const ProtocolHeader& header) onStreamStartReceived(header); } void BasicSessionStream::handleElementReceived(boost::shared_ptr<Element> element) { onElementReceived(element); } void BasicSessionStream::handleXMPPError() { available = false; - onClosed(boost::make_shared<Error>(Error::ParseError)); + onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ParseError)); } void BasicSessionStream::handleTLSConnected() { onTLSEncrypted(); } -void BasicSessionStream::handleTLSError() { +void BasicSessionStream::handleTLSError(boost::shared_ptr<TLSError> error) { available = false; - onClosed(boost::make_shared<Error>(Error::TLSError)); + onClosed(error); } void BasicSessionStream::handleConnectionFinished(const boost::optional<Connection::Error>& error) { available = false; if (error == Connection::ReadError) { - onClosed(boost::make_shared<Error>(Error::ConnectionReadError)); + onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ConnectionReadError)); } else if (error) { - onClosed(boost::make_shared<Error>(Error::ConnectionWriteError)); + onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ConnectionWriteError)); } else { - onClosed(boost::shared_ptr<Error>()); + onClosed(boost::shared_ptr<SessionStreamError>()); } } void BasicSessionStream::handleDataRead(const SafeByteArray& data) { onDataRead(data); } void BasicSessionStream::handleDataWritten(const SafeByteArray& data) { onDataWritten(data); diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h index b0c4331..e1f32f4 100644 --- a/Swiften/Session/BasicSessionStream.h +++ b/Swiften/Session/BasicSessionStream.h @@ -6,18 +6,19 @@ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/Network/Connection.h> #include <Swiften/Session/SessionStream.h> #include <Swiften/Elements/StreamType.h> +#include <Swiften/TLS/TLSError.h> namespace Swift { class TLSContextFactory; class TLSLayer; class TimerFactory; class WhitespacePingLayer; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class StreamStack; @@ -59,19 +60,19 @@ namespace Swift { virtual void setWhitespacePingEnabled(bool); virtual void resetXMPPParser(); private: void handleConnectionFinished(const boost::optional<Connection::Error>& error); void handleXMPPError(); void handleTLSConnected(); - void handleTLSError(); + void handleTLSError(boost::shared_ptr<TLSError>); void handleStreamStartReceived(const ProtocolHeader&); void handleElementReceived(boost::shared_ptr<Element>); void handleDataRead(const SafeByteArray& data); void handleDataWritten(const SafeByteArray& data); private: bool available; boost::shared_ptr<Connection> connection; PayloadParserFactoryCollection* payloadParserFactories; diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h index 2ff2a56..32cb6b6 100644 --- a/Swiften/Session/SessionStream.h +++ b/Swiften/Session/SessionStream.h @@ -15,29 +15,29 @@ #include <Swiften/Base/Error.h> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/TLS/CertificateWithKey.h> #include <Swiften/TLS/Certificate.h> #include <Swiften/TLS/CertificateVerificationError.h> namespace Swift { class SessionStream { public: - class Error : public Swift::Error { + class SessionStreamError : public Swift::Error { public: enum Type { ParseError, TLSError, InvalidTLSCertificateError, ConnectionReadError, ConnectionWriteError }; - Error(Type type) : type(type) {} + SessionStreamError(Type type) : type(type) {} Type type; }; SessionStream(): certificate() {} virtual ~SessionStream(); virtual void close() = 0; diff --git a/Swiften/StreamStack/TLSLayer.h b/Swiften/StreamStack/TLSLayer.h index 5aab26a..ce0c89b 100644 --- a/Swiften/StreamStack/TLSLayer.h +++ b/Swiften/StreamStack/TLSLayer.h @@ -5,18 +5,19 @@ */ #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/StreamStack/StreamLayer.h> #include <Swiften/TLS/Certificate.h> #include <Swiften/TLS/CertificateWithKey.h> #include <Swiften/TLS/CertificateVerificationError.h> +#include <Swiften/TLS/TLSError.h> namespace Swift { class TLSContext; class TLSContextFactory; class TLSLayer : public StreamLayer { public: TLSLayer(TLSContextFactory*); ~TLSLayer(); @@ -29,16 +30,16 @@ namespace Swift { void writeData(const SafeByteArray& data); void handleDataRead(const SafeByteArray& data); TLSContext* getContext() const { return context; } public: - boost::signal<void ()> onError; + boost::signal<void (boost::shared_ptr<TLSError>)> onError; boost::signal<void ()> onConnected; private: TLSContext* context; }; } diff --git a/Swiften/TLS/OpenSSL/OpenSSLContext.cpp b/Swiften/TLS/OpenSSL/OpenSSLContext.cpp index 54addef..8c03052 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLContext.cpp +++ b/Swiften/TLS/OpenSSL/OpenSSLContext.cpp @@ -126,19 +126,19 @@ void OpenSSLContext::doConnect() { //std::cout << "Compression: " << SSL_COMP_get_name(comp) << std::endl; onConnected(); break; } case SSL_ERROR_WANT_READ: sendPendingDataToNetwork(); break; default: state_ = Error; - onError(); + onError(boost::make_shared<TLSError>()); } } void OpenSSLContext::sendPendingDataToNetwork() { int size = BIO_pending(writeBIO_); if (size > 0) { SafeByteArray data; data.resize(size); BIO_read(writeBIO_, vecptr(data), size); @@ -160,35 +160,35 @@ void OpenSSLContext::handleDataFromNetwork(const SafeByteArray& data) { } } void OpenSSLContext::handleDataFromApplication(const SafeByteArray& data) { if (SSL_write(handle_, vecptr(data), data.size()) >= 0) { sendPendingDataToNetwork(); } else { state_ = Error; - onError(); + onError(boost::make_shared<TLSError>()); } } void OpenSSLContext::sendPendingDataToApplication() { SafeByteArray data; data.resize(SSL_READ_BUFFERSIZE); int ret = SSL_read(handle_, vecptr(data), data.size()); while (ret > 0) { data.resize(ret); onDataForApplication(data); data.resize(SSL_READ_BUFFERSIZE); ret = SSL_read(handle_, vecptr(data), data.size()); } if (ret < 0 && SSL_get_error(handle_, ret) != SSL_ERROR_WANT_READ) { state_ = Error; - onError(); + onError(boost::make_shared<TLSError>()); } } bool OpenSSLContext::setClientCertificate(CertificateWithKey::ref certificate) { boost::shared_ptr<PKCS12Certificate> pkcs12Certificate = boost::dynamic_pointer_cast<PKCS12Certificate>(certificate); if (!pkcs12Certificate || pkcs12Certificate->isNull()) { return false; } diff --git a/Swiften/TLS/Schannel/SchannelContext.cpp b/Swiften/TLS/Schannel/SchannelContext.cpp index 9be1ded..4f8f36f 100644 --- a/Swiften/TLS/Schannel/SchannelContext.cpp +++ b/Swiften/TLS/Schannel/SchannelContext.cpp @@ -467,19 +467,19 @@ void SchannelContext::handleDataFromNetwork(const SafeByteArray& data) } } //------------------------------------------------------------------------ void SchannelContext::indicateError() { m_state = Error; m_receivedData.clear(); - onError(); + onError(boost::make_shared<TLSError>()); } //------------------------------------------------------------------------ void SchannelContext::decryptAndProcessData(const SafeByteArray& data) { SecBuffer inBuffers[4] = {0}; appendNewData(data); diff --git a/Swiften/TLS/TLSContext.h b/Swiften/TLS/TLSContext.h index 9dee902..5640fe1 100644 --- a/Swiften/TLS/TLSContext.h +++ b/Swiften/TLS/TLSContext.h @@ -7,18 +7,19 @@ #pragma once #include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/TLS/Certificate.h> #include <Swiften/TLS/CertificateWithKey.h> #include <Swiften/TLS/CertificateVerificationError.h> +#include <Swiften/TLS/TLSError.h> namespace Swift { class TLSContext { public: virtual ~TLSContext(); virtual void connect() = 0; @@ -29,13 +30,13 @@ namespace Swift { virtual Certificate::ref getPeerCertificate() const = 0; virtual CertificateVerificationError::ref getPeerCertificateVerificationError() const = 0; virtual ByteArray getFinishMessage() const = 0; public: boost::signal<void (const SafeByteArray&)> onDataForNetwork; boost::signal<void (const SafeByteArray&)> onDataForApplication; - boost::signal<void ()> onError; + boost::signal<void (boost::shared_ptr<TLSError>)> onError; boost::signal<void ()> onConnected; }; } |