From 1539754d5357df5eed7a88cc3f2955c87af9faae Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sun, 29 Jan 2006 17:36:34 +0000 Subject: [PATCH] Added service::isSecuredConnection() and service::getConnectionInfos() to retrieve information about the connection. --- ChangeLog | 5 ++ SConstruct | 4 ++ examples/example6.cpp | 7 ++ src/net/defaultConnectionInfos.cpp | 52 ++++++++++++++ src/net/imap/IMAPConnection.cpp | 34 ++++++++- src/net/imap/IMAPStore.cpp | 32 +++++++-- src/net/maildir/maildirStore.cpp | 14 ++++ src/net/pop3/POP3Store.cpp | 36 +++++++++- src/net/sendmail/sendmailTransport.cpp | 14 ++++ src/net/smtp/SMTPTransport.cpp | 35 +++++++++- src/net/tls/TLSSecuredConnectionInfos.cpp | 63 +++++++++++++++++ vmime/net/connectionInfos.hpp | 60 ++++++++++++++++ vmime/net/defaultConnectionInfos.hpp | 58 ++++++++++++++++ vmime/net/imap/IMAPConnection.hpp | 7 ++ vmime/net/imap/IMAPStore.hpp | 5 +- vmime/net/maildir/maildirStore.hpp | 3 + vmime/net/pop3/POP3Store.hpp | 6 ++ vmime/net/securedConnectionInfos.hpp | 47 +++++++++++++ vmime/net/sendmail/sendmailTransport.hpp | 3 + vmime/net/service.hpp | 13 ++++ vmime/net/smtp/SMTPTransport.hpp | 6 ++ vmime/net/tls/TLSSecuredConnectionInfos.hpp | 76 +++++++++++++++++++++ 22 files changed, 564 insertions(+), 16 deletions(-) create mode 100644 src/net/defaultConnectionInfos.cpp create mode 100644 src/net/tls/TLSSecuredConnectionInfos.cpp create mode 100644 vmime/net/connectionInfos.hpp create mode 100644 vmime/net/defaultConnectionInfos.hpp create mode 100644 vmime/net/securedConnectionInfos.hpp create mode 100644 vmime/net/tls/TLSSecuredConnectionInfos.hpp diff --git a/ChangeLog b/ChangeLog index 54fe8aa3..e8b4c35b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,11 @@ VERSION 0.8.1cvs ================ +2006-01-29 Vincent Richard + + * Added service::isSecuredConnection() and service::getConnectionInfos() + to retrieve information about the connection. + 2006-01-16 Vincent Richard * Added support for attachments of type "message/rfc822". diff --git a/SConstruct b/SConstruct index d2c17549..4b1894d2 100644 --- a/SConstruct +++ b/SConstruct @@ -198,9 +198,12 @@ libvmime_examples_sources = [ libvmime_messaging_sources = [ 'net/builtinServices.inl', + 'net/connectionInfos.hpp', + 'net/defaultConnectionInfos.cpp', 'net/defaultConnectionInfos.hpp', 'net/events.cpp', 'net/events.hpp', 'net/folder.cpp', 'net/folder.hpp', 'net/message.cpp', 'net/message.hpp', + 'net/securedConnectionInfos.hpp', 'net/service.cpp', 'net/service.hpp', 'net/serviceFactory.cpp', 'net/serviceFactory.hpp', 'net/serviceInfos.cpp', 'net/serviceInfos.hpp', @@ -215,6 +218,7 @@ libvmime_messaging_sources = [ libvmime_net_tls_sources = [ 'net/tls/TLSSession.cpp', 'net/tls/TLSSession.hpp', 'net/tls/TLSSocket.cpp', 'net/tls/TLSSocket.hpp', + 'net/tls/TLSSecuredConnectionInfos.cpp', 'net/tls/TLSSecuredConnectionInfos.hpp', 'security/cert/certificateChain.cpp', 'security/cert/certificateChain.hpp', 'security/cert/certificateVerifier.hpp', 'security/cert/defaultCertificateVerifier.cpp', 'security/cert/defaultCertificateVerifier.hpp', diff --git a/examples/example6.cpp b/examples/example6.cpp index 344a4d87..7bd7a82c 100644 --- a/examples/example6.cpp +++ b/examples/example6.cpp @@ -516,6 +516,13 @@ static void connectStore() // Connect to the mail store st->connect(); + // Display some information about the connection + vmime::ref ci = st->getConnectionInfos(); + + std::cout << std::endl; + std::cout << "Connected to '" << ci->getHost() << "' (port " << ci->getPort() << ")" << std::endl; + std::cout << "Connection is " << (st->isSecuredConnection() ? "" : "NOT ") << "secured." << std::endl; + // Open the default folder in this store vmime::ref f = st->getDefaultFolder(); // vmime::ref f = st->getFolder(vmime::utility::path("a")); diff --git a/src/net/defaultConnectionInfos.cpp b/src/net/defaultConnectionInfos.cpp new file mode 100644 index 00000000..e6ecfae0 --- /dev/null +++ b/src/net/defaultConnectionInfos.cpp @@ -0,0 +1,52 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// This program 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#include "vmime/net/defaultConnectionInfos.hpp" + + +namespace vmime { +namespace net { + + +defaultConnectionInfos::defaultConnectionInfos(const string& host, const port_t port) + : m_host(host), m_port(port) +{ +} + + +const string defaultConnectionInfos::getHost() const +{ + return m_host; +} + + +const port_t defaultConnectionInfos::getPort() const +{ + return m_port; +} + + +} // net +} // vmime + + diff --git a/src/net/imap/IMAPConnection.cpp b/src/net/imap/IMAPConnection.cpp index 76c09316..e4a49041 100644 --- a/src/net/imap/IMAPConnection.cpp +++ b/src/net/imap/IMAPConnection.cpp @@ -25,12 +25,15 @@ #include "vmime/exception.hpp" #include "vmime/platformDependant.hpp" +#include "vmime/net/defaultConnectionInfos.hpp" + #if VMIME_HAVE_SASL_SUPPORT #include "vmime/security/sasl/SASLContext.hpp" #endif // VMIME_HAVE_SASL_SUPPORT #if VMIME_HAVE_TLS_SUPPORT #include "vmime/net/tls/TLSSession.hpp" + #include "vmime/net/tls/TLSSecuredConnectionInfos.hpp" #endif // VMIME_HAVE_TLS_SUPPORT #include @@ -52,7 +55,8 @@ namespace imap { IMAPConnection::IMAPConnection(weak_ref store, ref auth) : m_store(store), m_auth(auth), m_socket(NULL), m_parser(NULL), m_tag(NULL), - m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(NULL) + m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(NULL), + m_secured(false) { } @@ -92,7 +96,7 @@ void IMAPConnection::connect() m_socket = m_store->getSocketFactory()->create(); #if VMIME_HAVE_TLS_SUPPORT - if (m_store->isSecuredConnection()) // dedicated port/IMAPS + if (m_store->isIMAPS()) // dedicated port/IMAPS { ref tlsSession = vmime::create (m_store->getCertificateVerifier()); @@ -101,8 +105,15 @@ void IMAPConnection::connect() tlsSession->getSocket(m_socket); m_socket = tlsSocket; + + m_secured = true; + m_cntInfos = vmime::create (address, port, tlsSession, tlsSocket); } #endif // VMIME_HAVE_TLS_SUPPORT + else + { + m_cntInfos = vmime::create (address, port); + } m_socket->connect(address, port); @@ -446,6 +457,10 @@ void IMAPConnection::startTLS() m_socket = tlsSocket; m_parser->setSocket(m_socket); + + m_secured = true; + m_cntInfos = vmime::create + (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket); } catch (exceptions::command_error&) { @@ -517,6 +532,18 @@ const bool IMAPConnection::isConnected() const } +const bool IMAPConnection::isSecuredConnection() const +{ + return m_secured; +} + + +ref IMAPConnection::getConnectionInfos() const +{ + return m_cntInfos; +} + + void IMAPConnection::disconnect() { if (!isConnected()) @@ -539,6 +566,9 @@ void IMAPConnection::internalDisconnect() m_timeoutHandler = NULL; m_state = STATE_LOGOUT; + + m_secured = false; + m_cntInfos = NULL; } diff --git a/src/net/imap/IMAPStore.cpp b/src/net/imap/IMAPStore.cpp index 95f96276..aba36751 100644 --- a/src/net/imap/IMAPStore.cpp +++ b/src/net/imap/IMAPStore.cpp @@ -33,7 +33,7 @@ namespace imap { IMAPStore::IMAPStore(ref sess, ref auth, const bool secured) - : store(sess, getInfosInstance(), auth), m_connection(NULL), m_secured(secured) + : store(sess, getInfosInstance(), auth), m_connection(NULL), m_isIMAPS(secured) { } @@ -91,12 +91,6 @@ const bool IMAPStore::isValidFolderName(const folder::path::component& /* name * } -const bool IMAPStore::isSecuredConnection() const -{ - return m_secured; -} - - void IMAPStore::connect() { if (isConnected()) @@ -123,6 +117,30 @@ const bool IMAPStore::isConnected() const } +const bool IMAPStore::isIMAPS() const +{ + return m_isIMAPS; +} + + +const bool IMAPStore::isSecuredConnection() const +{ + if (m_connection == NULL) + return false; + + return m_connection->isSecuredConnection(); +} + + +ref IMAPStore::getConnectionInfos() const +{ + if (m_connection == NULL) + return NULL; + + return m_connection->getConnectionInfos(); +} + + void IMAPStore::disconnect() { if (!isConnected()) diff --git a/src/net/maildir/maildirStore.cpp b/src/net/maildir/maildirStore.cpp index d1baf8dd..2803b17b 100644 --- a/src/net/maildir/maildirStore.cpp +++ b/src/net/maildir/maildirStore.cpp @@ -26,6 +26,8 @@ #include "vmime/exception.hpp" #include "vmime/platformDependant.hpp" +#include "vmime/net/defaultConnectionInfos.hpp" + // Helpers for service properties #define GET_PROPERTY(type, prop) \ @@ -154,6 +156,18 @@ const bool maildirStore::isConnected() const } +const bool maildirStore::isSecuredConnection() const +{ + return false; +} + + +ref maildirStore::getConnectionInfos() const +{ + return vmime::create ("localhost", 0); +} + + void maildirStore::disconnect() { for (std::list ::iterator it = m_folders.begin() ; diff --git a/src/net/pop3/POP3Store.cpp b/src/net/pop3/POP3Store.cpp index 29a22dcf..5340e50d 100644 --- a/src/net/pop3/POP3Store.cpp +++ b/src/net/pop3/POP3Store.cpp @@ -27,12 +27,15 @@ #include "vmime/utility/filteredStream.hpp" #include "vmime/utility/stringUtils.hpp" +#include "vmime/net/defaultConnectionInfos.hpp" + #if VMIME_HAVE_SASL_SUPPORT #include "vmime/security/sasl/SASLContext.hpp" #endif // VMIME_HAVE_SASL_SUPPORT #if VMIME_HAVE_TLS_SUPPORT #include "vmime/net/tls/TLSSession.hpp" + #include "vmime/net/tls/TLSSecuredConnectionInfos.hpp" #endif // VMIME_HAVE_TLS_SUPPORT #include @@ -54,7 +57,8 @@ namespace pop3 { POP3Store::POP3Store(ref sess, ref auth, const bool secured) : store(sess, getInfosInstance(), auth), m_socket(NULL), - m_authentified(false), m_timeoutHandler(NULL), m_secured(secured) + m_authentified(false), m_timeoutHandler(NULL), + m_isPOP3S(secured), m_secured(false) { } @@ -130,7 +134,7 @@ void POP3Store::connect() m_socket = getSocketFactory()->create(); #if VMIME_HAVE_TLS_SUPPORT - if (m_secured) // dedicated port/POP3S + if (m_isPOP3S) // dedicated port/POP3S { ref tlsSession = vmime::create (getCertificateVerifier()); @@ -139,8 +143,15 @@ void POP3Store::connect() tlsSession->getSocket(m_socket); m_socket = tlsSocket; + + m_secured = true; + m_cntInfos = vmime::create (address, port, tlsSession, tlsSocket); } #endif // VMIME_HAVE_TLS_SUPPORT + else + { + m_cntInfos = vmime::create (address, port); + } m_socket->connect(address, port); @@ -165,7 +176,7 @@ void POP3Store::connect() const bool tlsRequired = HAS_PROPERTY(PROPERTY_CONNECTION_TLS_REQUIRED) && GET_PROPERTY(bool, PROPERTY_CONNECTION_TLS_REQUIRED); - if (!m_secured && tls) // only if not POP3S + if (!m_isPOP3S && tls) // only if not POP3S { try { @@ -533,6 +544,10 @@ void POP3Store::startTLS() tlsSocket->handshake(m_timeoutHandler); m_socket = tlsSocket; + + m_secured = true; + m_cntInfos = vmime::create + (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket); } catch (exceptions::command_error&) { @@ -556,6 +571,18 @@ const bool POP3Store::isConnected() const } +const bool POP3Store::isSecuredConnection() const +{ + return m_secured; +} + + +ref POP3Store::getConnectionInfos() const +{ + return m_cntInfos; +} + + void POP3Store::disconnect() { if (!isConnected()) @@ -590,6 +617,9 @@ void POP3Store::internalDisconnect() m_timeoutHandler = NULL; m_authentified = false; + + m_secured = false; + m_cntInfos = NULL; } diff --git a/src/net/sendmail/sendmailTransport.cpp b/src/net/sendmail/sendmailTransport.cpp index 2b5c4b04..514a66a6 100644 --- a/src/net/sendmail/sendmailTransport.cpp +++ b/src/net/sendmail/sendmailTransport.cpp @@ -28,6 +28,8 @@ #include "vmime/utility/childProcess.hpp" #include "vmime/utility/smartPtr.hpp" +#include "vmime/net/defaultConnectionInfos.hpp" + #include "vmime/config.hpp" @@ -92,6 +94,18 @@ const bool sendmailTransport::isConnected() const } +const bool sendmailTransport::isSecuredConnection() const +{ + return false; +} + + +ref sendmailTransport::getConnectionInfos() const +{ + return vmime::create ("localhost", 0); +} + + void sendmailTransport::disconnect() { if (!isConnected()) diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp index 48ea5cdc..385ebcec 100644 --- a/src/net/smtp/SMTPTransport.cpp +++ b/src/net/smtp/SMTPTransport.cpp @@ -28,12 +28,15 @@ #include "vmime/utility/filteredStream.hpp" #include "vmime/utility/stringUtils.hpp" +#include "vmime/net/defaultConnectionInfos.hpp" + #if VMIME_HAVE_SASL_SUPPORT #include "vmime/security/sasl/SASLContext.hpp" #endif // VMIME_HAVE_SASL_SUPPORT #if VMIME_HAVE_TLS_SUPPORT #include "vmime/net/tls/TLSSession.hpp" + #include "vmime/net/tls/TLSSecuredConnectionInfos.hpp" #endif // VMIME_HAVE_TLS_SUPPORT @@ -54,7 +57,7 @@ namespace smtp { SMTPTransport::SMTPTransport(ref sess, ref auth, const bool secured) : transport(sess, getInfosInstance(), auth), m_socket(NULL), m_authentified(false), m_extendedSMTP(false), m_timeoutHandler(NULL), - m_secured(secured) + m_isSMTPS(secured), m_secured(false) { } @@ -97,7 +100,7 @@ void SMTPTransport::connect() m_socket = getSocketFactory()->create(); #if VMIME_HAVE_TLS_SUPPORT - if (m_secured) // dedicated port/SMTPS + if (m_isSMTPS) // dedicated port/SMTPS { ref tlsSession = vmime::create (getCertificateVerifier()); @@ -106,8 +109,15 @@ void SMTPTransport::connect() tlsSession->getSocket(m_socket); m_socket = tlsSocket; + + m_secured = true; + m_cntInfos = vmime::create (address, port, tlsSession, tlsSocket); } #endif // VMIME_HAVE_TLS_SUPPORT + else + { + m_cntInfos = vmime::create (address, port); + } m_socket->connect(address, port); @@ -163,7 +173,7 @@ void SMTPTransport::connect() const bool tlsRequired = HAS_PROPERTY(PROPERTY_CONNECTION_TLS_REQUIRED) && GET_PROPERTY(bool, PROPERTY_CONNECTION_TLS_REQUIRED); - if (!m_secured && tls) // only if not POP3S + if (!m_isSMTPS && tls) // only if not POP3S { try { @@ -436,6 +446,10 @@ void SMTPTransport::startTLS() tlsSocket->handshake(m_timeoutHandler); m_socket = tlsSocket; + + m_secured = true; + m_cntInfos = vmime::create + (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket); } catch (exceptions::command_error&) { @@ -459,6 +473,18 @@ const bool SMTPTransport::isConnected() const } +const bool SMTPTransport::isSecuredConnection() const +{ + return m_secured; +} + + +ref SMTPTransport::getConnectionInfos() const +{ + return m_cntInfos; +} + + void SMTPTransport::disconnect() { if (!isConnected()) @@ -486,6 +512,9 @@ void SMTPTransport::internalDisconnect() m_authentified = false; m_extendedSMTP = false; + + m_secured = false; + m_cntInfos = NULL; } diff --git a/src/net/tls/TLSSecuredConnectionInfos.cpp b/src/net/tls/TLSSecuredConnectionInfos.cpp new file mode 100644 index 00000000..2670b81b --- /dev/null +++ b/src/net/tls/TLSSecuredConnectionInfos.cpp @@ -0,0 +1,63 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// This program 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#include "vmime/net/tls/TLSSecuredConnectionInfos.hpp" +#include "vmime/net/tls/TLSSession.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +TLSSecuredConnectionInfos::TLSSecuredConnectionInfos + (const string& host, const port_t port, + ref tlsSession, ref tlsSocket) + : m_host(host), m_port(port), + m_tlsSession(tlsSession), m_tlsSocket(tlsSocket) +{ +} + + +const string TLSSecuredConnectionInfos::getHost() const +{ + return m_host; +} + + +const port_t TLSSecuredConnectionInfos::getPort() const +{ + return m_port; +} + + +ref TLSSecuredConnectionInfos::getPeerCertificates() const +{ + return m_tlsSocket->getPeerCertificates(); +} + + +} // tls +} // net +} // vmime + diff --git a/vmime/net/connectionInfos.hpp b/vmime/net/connectionInfos.hpp new file mode 100644 index 00000000..ee02eb16 --- /dev/null +++ b/vmime/net/connectionInfos.hpp @@ -0,0 +1,60 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// This program 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#ifndef VMIME_NET_CONNECTIONINFOS_HPP_INCLUDED +#define VMIME_NET_CONNECTIONINFOS_HPP_INCLUDED + + +#include "vmime/object.hpp" + + +namespace vmime { +namespace net { + + +/** Information about the connection used by a service. + */ +class connectionInfos : public object +{ +public: + + /** Return the host to which the service is connected. + * + * @return server host name or address + */ + virtual const string getHost() const = 0; + + /** Return the port to which the service is connected. + * + * @return server port + */ + virtual const port_t getPort() const = 0; +}; + + +} // net +} // vmime + + +#endif // VMIME_NET_CONNECTIONINFOS_HPP_INCLUDED + diff --git a/vmime/net/defaultConnectionInfos.hpp b/vmime/net/defaultConnectionInfos.hpp new file mode 100644 index 00000000..39530f18 --- /dev/null +++ b/vmime/net/defaultConnectionInfos.hpp @@ -0,0 +1,58 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// This program 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#ifndef VMIME_NET_DEFAULTCONNECTIONINFOS_HPP_INCLUDED +#define VMIME_NET_DEFAULTCONNECTIONINFOS_HPP_INCLUDED + + +#include "vmime/net/connectionInfos.hpp" + + +namespace vmime { +namespace net { + + +/** Information about the connection used by a service. + */ +class defaultConnectionInfos : public connectionInfos +{ +public: + + defaultConnectionInfos(const string& host, const port_t port); + + const string getHost() const; + const port_t getPort() const; + +private: + + string m_host; + port_t m_port; +}; + + +} // net +} // vmime + + +#endif // VMIME_NET_DEFAULTCONNECTIONINFOS_HPP_INCLUDED + diff --git a/vmime/net/imap/IMAPConnection.hpp b/vmime/net/imap/IMAPConnection.hpp index f01236f2..3ca9b007 100644 --- a/vmime/net/imap/IMAPConnection.hpp +++ b/vmime/net/imap/IMAPConnection.hpp @@ -30,6 +30,7 @@ #include "vmime/net/socket.hpp" #include "vmime/net/timeoutHandler.hpp" #include "vmime/net/session.hpp" +#include "vmime/net/connectionInfos.hpp" #include "vmime/net/imap/IMAPParser.hpp" @@ -92,6 +93,9 @@ public: ref getAuthenticator(); + const bool isSecuredConnection() const; + ref getConnectionInfos() const; + private: void authenticate(); @@ -120,6 +124,9 @@ private: ref m_timeoutHandler; + bool m_secured; + ref m_cntInfos; + void internalDisconnect(); diff --git a/vmime/net/imap/IMAPStore.hpp b/vmime/net/imap/IMAPStore.hpp index 26810b9d..ce38190b 100644 --- a/vmime/net/imap/IMAPStore.hpp +++ b/vmime/net/imap/IMAPStore.hpp @@ -78,7 +78,10 @@ public: const int getCapabilities() const; + const bool isIMAPS() const; + const bool isSecuredConnection() const; + ref getConnectionInfos() const; protected: @@ -95,7 +98,7 @@ protected: std::list m_folders; - bool m_secured; // Use IMAPS + const bool m_isIMAPS; // Use IMAPS static IMAPServiceInfos sm_infos; diff --git a/vmime/net/maildir/maildirStore.hpp b/vmime/net/maildir/maildirStore.hpp index f2792403..a229ae8c 100644 --- a/vmime/net/maildir/maildirStore.hpp +++ b/vmime/net/maildir/maildirStore.hpp @@ -79,6 +79,9 @@ public: const int getCapabilities() const; + const bool isSecuredConnection() const; + ref getConnectionInfos() const; + private: void registerFolder(maildirFolder* folder); diff --git a/vmime/net/pop3/POP3Store.hpp b/vmime/net/pop3/POP3Store.hpp index 2839d198..98d2e380 100644 --- a/vmime/net/pop3/POP3Store.hpp +++ b/vmime/net/pop3/POP3Store.hpp @@ -77,6 +77,9 @@ public: const int getCapabilities() const; + const bool isSecuredConnection() const; + ref getConnectionInfos() const; + private: enum ResponseCode @@ -123,7 +126,10 @@ private: ref m_timeoutHandler; + const bool m_isPOP3S; + bool m_secured; + ref m_cntInfos; // Service infos diff --git a/vmime/net/securedConnectionInfos.hpp b/vmime/net/securedConnectionInfos.hpp new file mode 100644 index 00000000..2af7b970 --- /dev/null +++ b/vmime/net/securedConnectionInfos.hpp @@ -0,0 +1,47 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// This program 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#ifndef VMIME_NET_SECUREDCONNECTIONINFOS_HPP_INCLUDED +#define VMIME_NET_SECUREDCONNECTIONINFOS_HPP_INCLUDED + + +#include "vmime/net/connectionInfos.hpp" + + +namespace vmime { +namespace net { + + +/** Information about the secured connection used by a service. + */ +class securedConnectionInfos : public connectionInfos +{ +}; + + +} // net +} // vmime + + +#endif // VMIME_NET_SECUREDCONNECTIONINFOS_HPP_INCLUDED + diff --git a/vmime/net/sendmail/sendmailTransport.hpp b/vmime/net/sendmail/sendmailTransport.hpp index 75a7c704..9a362179 100644 --- a/vmime/net/sendmail/sendmailTransport.hpp +++ b/vmime/net/sendmail/sendmailTransport.hpp @@ -65,6 +65,9 @@ public: void send(const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, const utility::stream::size_type size, utility::progressListener* progress = NULL); + const bool isSecuredConnection() const; + ref getConnectionInfos() const; + private: void internalDisconnect(); diff --git a/vmime/net/service.hpp b/vmime/net/service.hpp index ec165462..8104cd50 100644 --- a/vmime/net/service.hpp +++ b/vmime/net/service.hpp @@ -31,6 +31,7 @@ #include "vmime/net/session.hpp" #include "vmime/net/serviceInfos.hpp" +#include "vmime/net/connectionInfos.hpp" #include "vmime/net/socket.hpp" #include "vmime/net/timeoutHandler.hpp" @@ -191,6 +192,18 @@ public: m_session->getProperties()[getInfos().getPropertyPrefix() + name] = value; } + /** Check whether the connection is secured. + * + * @return true if the connection is secured, false otherwise + */ + virtual const bool isSecuredConnection() const = 0; + + /** Get information about the connection. + * + * @return information about the connection + */ + virtual ref getConnectionInfos() const = 0; + private: ref m_session; diff --git a/vmime/net/smtp/SMTPTransport.hpp b/vmime/net/smtp/SMTPTransport.hpp index d42288b7..8269fe3f 100644 --- a/vmime/net/smtp/SMTPTransport.hpp +++ b/vmime/net/smtp/SMTPTransport.hpp @@ -65,6 +65,9 @@ public: void send(const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, const utility::stream::size_type size, utility::progressListener* progress = NULL); + const bool isSecuredConnection() const; + ref getConnectionInfos() const; + private: void sendRequest(const string& buffer, const bool end = true); @@ -89,7 +92,10 @@ private: ref m_timeoutHandler; + const bool m_isSMTPS; + bool m_secured; + ref m_cntInfos; // Service infos diff --git a/vmime/net/tls/TLSSecuredConnectionInfos.hpp b/vmime/net/tls/TLSSecuredConnectionInfos.hpp new file mode 100644 index 00000000..77fc5ddb --- /dev/null +++ b/vmime/net/tls/TLSSecuredConnectionInfos.hpp @@ -0,0 +1,76 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// This program 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#ifndef VMIME_NET_TLSSECUREDCONNECTIONINFOS_HPP_INCLUDED +#define VMIME_NET_TLSSECUREDCONNECTIONINFOS_HPP_INCLUDED + + +#include "vmime/net/securedConnectionInfos.hpp" + +#include "vmime/security/cert/certificateChain.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +class TLSSession; +class TLSSocket; + + +/** Information about a TLS-secured connection used by a service. + */ +class TLSSecuredConnectionInfos : public securedConnectionInfos +{ +public: + + TLSSecuredConnectionInfos(const string& host, const port_t port, + ref tlsSession, ref tlsSocket); + + const string getHost() const; + const port_t getPort() const; + + /** Return the peer's certificate (chain) as sent by the peer. + * + * @return server certificate chain + */ + ref getPeerCertificates() const; + +private: + + string m_host; + port_t m_port; + + ref m_tlsSession; + ref m_tlsSocket; +}; + + +} // tls +} // net +} // vmime + + +#endif // VMIME_NET_TLSSECUREDCONNECTIONINFOS_HPP_INCLUDED +