diff options
Diffstat (limited to 'vmime')
28 files changed, 1418 insertions, 147 deletions
diff --git a/vmime/exception.hpp b/vmime/exception.hpp index ed104fba..d686ab1f 100644 --- a/vmime/exception.hpp +++ b/vmime/exception.hpp @@ -77,11 +77,15 @@ public: */ virtual const char* name() const throw(); + /** Clone this object. + * + * @return a new copy of this object + */ + virtual exception* clone() const; + protected: static const exception NO_EXCEPTION; - - virtual exception* clone() const; }; @@ -818,7 +822,7 @@ public: #if VMIME_HAVE_SASL_SUPPORT -/** Base class for exceptions throw by SASL module. +/** Base class for exceptions thrown by SASL module. */ class sasl_exception : public vmime::exception @@ -866,6 +870,63 @@ public: #endif // VMIME_HAVE_SASL_SUPPORT +#if VMIME_HAVE_TLS_SUPPORT + + +/** Base class for exceptions thrown by TLS module. + */ + +class tls_exception : public vmime::exception +{ +public: + + tls_exception(const string& what, const exception& other = NO_EXCEPTION); + ~tls_exception() throw(); + + exception* clone() const; + const char* name() const throw(); +}; + + +class certificate_exception : public tls_exception +{ +public: + + certificate_exception(const string& what, const exception& other = NO_EXCEPTION); + ~certificate_exception() throw(); + + exception* clone() const; + const char* name() const throw(); +}; + + +class certificate_verification_exception : public certificate_exception +{ +public: + + certificate_verification_exception(const string& what, const exception& other = NO_EXCEPTION); + ~certificate_verification_exception() throw (); + + exception* clone() const; + const char* name() const throw (); +}; + + +class unsupported_certificate_type : public certificate_exception +{ +public: + + unsupported_certificate_type(const string& type, const exception& other = NO_EXCEPTION); + ~unsupported_certificate_type() throw (); + + exception* clone() const; + const char* name() const throw (); +}; + + +#endif // VMIME_HAVE_TLS_SUPPORT + + } // exceptions diff --git a/vmime/net/imap/IMAPConnection.hpp b/vmime/net/imap/IMAPConnection.hpp index f51e97e2..f01236f2 100644 --- a/vmime/net/imap/IMAPConnection.hpp +++ b/vmime/net/imap/IMAPConnection.hpp @@ -99,6 +99,10 @@ private: void authenticateSASL(); #endif // VMIME_HAVE_SASL_SUPPORT +#if VMIME_HAVE_TLS_SUPPORT + void startTLS(); +#endif // VMIME_HAVE_TLS_SUPPORT + weak_ref <IMAPStore> m_store; diff --git a/vmime/net/imap/IMAPParser.hpp b/vmime/net/imap/IMAPParser.hpp index d88fcf6e..5b267ac8 100644 --- a/vmime/net/imap/IMAPParser.hpp +++ b/vmime/net/imap/IMAPParser.hpp @@ -94,6 +94,11 @@ public: return (m_tag); } + void setSocket(weak_ref <socket> sok) + { + m_socket = sok; + } + const string lastLine() const { diff --git a/vmime/net/authHelper.hpp b/vmime/net/imap/IMAPSStore.hpp index 54487fbe..a99aff6e 100644 --- a/vmime/net/authHelper.hpp +++ b/vmime/net/imap/IMAPSStore.hpp @@ -21,22 +21,43 @@ // the GNU General Public License cover the whole combination. // -#ifndef VMIME_NET_AUTHHELPER_HPP_INCLUDED -#define VMIME_NET_AUTHHELPER_HPP_INCLUDED +#ifndef VMIME_NET_IMAP_IMAPSSTORE_HPP_INCLUDED +#define VMIME_NET_IMAP_IMAPSSTORE_HPP_INCLUDED -#include "vmime/types.hpp" +#include "vmime/net/imap/IMAPStore.hpp" namespace vmime { namespace net { +namespace imap { -void hmac_md5(const string& text, const string& key, string& hexDigest); +/** IMAPS store service. + */ +class IMAPSStore : public IMAPStore +{ +public: + IMAPSStore(ref <session> sess, ref <security::authenticator> auth); + ~IMAPSStore(); + + const string getProtocolName() const; + + static const serviceInfos& getInfosInstance(); + const serviceInfos& getInfos() const; + +private: + + static IMAPServiceInfos sm_infos; +}; + + +} // imap } // net } // vmime -#endif // VMIME_NET_AUTHHELPER_HPP_INCLUDED +#endif // VMIME_NET_IMAP_IMAPSSTORE_HPP_INCLUDED + diff --git a/vmime/net/imap/IMAPServiceInfos.hpp b/vmime/net/imap/IMAPServiceInfos.hpp new file mode 100644 index 00000000..67ef0980 --- /dev/null +++ b/vmime/net/imap/IMAPServiceInfos.hpp @@ -0,0 +1,87 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_IMAP_IMAPSERVICEINFOS_HPP_INCLUDED +#define VMIME_NET_IMAP_IMAPSERVICEINFOS_HPP_INCLUDED + + +#include "vmime/config.hpp" +#include "vmime/net/serviceInfos.hpp" + + +namespace vmime { +namespace net { +namespace imap { + + +/** Information about IMAP service. + */ + +class IMAPServiceInfos : public serviceInfos +{ +public: + + IMAPServiceInfos(const bool imaps); + + struct props + { + // IMAP-specific options +#if VMIME_HAVE_SASL_SUPPORT + serviceInfos::property PROPERTY_OPTIONS_SASL; + serviceInfos::property PROPERTY_OPTIONS_SASL_FALLBACK; +#endif // VMIME_HAVE_SASL_SUPPORT + + // Common properties + serviceInfos::property PROPERTY_AUTH_USERNAME; + serviceInfos::property PROPERTY_AUTH_PASSWORD; + +#if VMIME_HAVE_TLS_SUPPORT + serviceInfos::property PROPERTY_CONNECTION_TLS; + serviceInfos::property PROPERTY_CONNECTION_TLS_REQUIRED; +#endif // VMIME_HAVE_TLS_SUPPORT + + serviceInfos::property PROPERTY_SERVER_ADDRESS; + serviceInfos::property PROPERTY_SERVER_PORT; + serviceInfos::property PROPERTY_SERVER_SOCKETFACTORY; + + serviceInfos::property PROPERTY_TIMEOUT_FACTORY; + }; + + const props& getProperties() const; + + const string getPropertyPrefix() const; + const std::vector <serviceInfos::property> getAvailableProperties() const; + +private: + + const bool m_imaps; +}; + + +} // imap +} // net +} // vmime + + +#endif // VMIME_NET_IMAP_IMAPSERVICEINFOS_HPP_INCLUDED + diff --git a/vmime/net/imap/IMAPStore.hpp b/vmime/net/imap/IMAPStore.hpp index 0dd748cc..dcd2099b 100644 --- a/vmime/net/imap/IMAPStore.hpp +++ b/vmime/net/imap/IMAPStore.hpp @@ -31,7 +31,7 @@ #include "vmime/net/socket.hpp" #include "vmime/net/folder.hpp" -#include <ostream> +#include "vmime/net/imap/IMAPServiceInfos.hpp" namespace vmime { @@ -56,7 +56,7 @@ class IMAPStore : public store public: - IMAPStore(ref <session> sess, ref <security::authenticator> auth); + IMAPStore(ref <session> sess, ref <security::authenticator> auth, const bool secured = false); ~IMAPStore(); const string getProtocolName() const; @@ -78,7 +78,9 @@ public: const int getCapabilities() const; -private: + const bool isSecuredConnection() const; + +protected: // Connection ref <IMAPConnection> m_connection; @@ -93,39 +95,10 @@ private: std::list <IMAPFolder*> m_folders; + bool m_secured; // Use IMAPS - // Service infos - class _infos : public serviceInfos - { - public: - - struct props - { - // IMAP-specific options -#if VMIME_HAVE_SASL_SUPPORT - serviceInfos::property PROPERTY_OPTIONS_SASL; - serviceInfos::property PROPERTY_OPTIONS_SASL_FALLBACK; -#endif // VMIME_HAVE_SASL_SUPPORT - - // Common properties - serviceInfos::property PROPERTY_AUTH_USERNAME; - serviceInfos::property PROPERTY_AUTH_PASSWORD; - - serviceInfos::property PROPERTY_SERVER_ADDRESS; - serviceInfos::property PROPERTY_SERVER_PORT; - serviceInfos::property PROPERTY_SERVER_SOCKETFACTORY; - - serviceInfos::property PROPERTY_TIMEOUT_FACTORY; - }; - - const props& getProperties() const; - - const string getPropertyPrefix() const; - const std::vector <serviceInfos::property> getAvailableProperties() const; - }; - - static _infos sm_infos; + static IMAPServiceInfos sm_infos; }; diff --git a/vmime/net/maildir/maildirServiceInfos.hpp b/vmime/net/maildir/maildirServiceInfos.hpp new file mode 100644 index 00000000..29ef32b9 --- /dev/null +++ b/vmime/net/maildir/maildirServiceInfos.hpp @@ -0,0 +1,64 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_MAILDIR_MAILDIRSERVICEINFOS_HPP_INCLUDED +#define VMIME_NET_MAILDIR_MAILDIRSERVICEINFOS_HPP_INCLUDED + + +#include "vmime/config.hpp" +#include "vmime/net/serviceInfos.hpp" + + +namespace vmime { +namespace net { +namespace maildir { + + +/** Information about maildir service. + */ + +class maildirServiceInfos : public serviceInfos +{ +public: + + maildirServiceInfos(); + + struct props + { + serviceInfos::property PROPERTY_SERVER_ROOTPATH; + }; + + const props& getProperties() const; + + const string getPropertyPrefix() const; + const std::vector <serviceInfos::property> getAvailableProperties() const; +}; + + +} // maildir +} // net +} // vmime + + +#endif // VMIME_NET_MAILDIR_MAILDIRSERVICEINFOS_HPP_INCLUDED + diff --git a/vmime/net/maildir/maildirStore.hpp b/vmime/net/maildir/maildirStore.hpp index 41807336..f2792403 100644 --- a/vmime/net/maildir/maildirStore.hpp +++ b/vmime/net/maildir/maildirStore.hpp @@ -31,6 +31,8 @@ #include "vmime/net/socket.hpp" #include "vmime/net/folder.hpp" +#include "vmime/net/maildir/maildirServiceInfos.hpp" + #include "vmime/utility/file.hpp" #include <ostream> @@ -91,22 +93,7 @@ private: // Service infos - class _infos : public serviceInfos - { - public: - - struct props - { - serviceInfos::property PROPERTY_SERVER_ROOTPATH; - }; - - const props& getProperties() const; - - const string getPropertyPrefix() const; - const std::vector <serviceInfos::property> getAvailableProperties() const; - }; - - static _infos sm_infos; + static maildirServiceInfos sm_infos; }; diff --git a/vmime/net/pop3/POP3SStore.hpp b/vmime/net/pop3/POP3SStore.hpp new file mode 100644 index 00000000..b1bf08ad --- /dev/null +++ b/vmime/net/pop3/POP3SStore.hpp @@ -0,0 +1,63 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_POP3_POP3SSTORE_HPP_INCLUDED +#define VMIME_NET_POP3_POP3SSTORE_HPP_INCLUDED + + +#include "vmime/net/pop3/POP3Store.hpp" + + +namespace vmime { +namespace net { +namespace pop3 { + + +/** POP3S store service. + */ + +class POP3SStore : public POP3Store +{ +public: + + POP3SStore(ref <session> sess, ref <security::authenticator> auth); + ~POP3SStore(); + + const string getProtocolName() const; + + static const serviceInfos& getInfosInstance(); + const serviceInfos& getInfos() const; + +private: + + static POP3ServiceInfos sm_infos; +}; + + +} // pop3 +} // net +} // vmime + + +#endif // VMIME_NET_POP3_POP3SSTORE_HPP_INCLUDED + diff --git a/vmime/net/pop3/POP3ServiceInfos.hpp b/vmime/net/pop3/POP3ServiceInfos.hpp new file mode 100644 index 00000000..04f14b78 --- /dev/null +++ b/vmime/net/pop3/POP3ServiceInfos.hpp @@ -0,0 +1,89 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_POP3_POP3SERVICEINFOS_HPP_INCLUDED +#define VMIME_NET_POP3_POP3SERVICEINFOS_HPP_INCLUDED + + +#include "vmime/config.hpp" +#include "vmime/net/serviceInfos.hpp" + + +namespace vmime { +namespace net { +namespace pop3 { + + +/** Information about POP3 service. + */ + +class POP3ServiceInfos : public serviceInfos +{ +public: + + POP3ServiceInfos(const bool pop3s); + + struct props + { + // POP3-specific options + serviceInfos::property PROPERTY_OPTIONS_APOP; + serviceInfos::property PROPERTY_OPTIONS_APOP_FALLBACK; +#if VMIME_HAVE_SASL_SUPPORT + serviceInfos::property PROPERTY_OPTIONS_SASL; + serviceInfos::property PROPERTY_OPTIONS_SASL_FALLBACK; +#endif // VMIME_HAVE_SASL_SUPPORT + + // Common properties + serviceInfos::property PROPERTY_AUTH_USERNAME; + serviceInfos::property PROPERTY_AUTH_PASSWORD; + +#if VMIME_HAVE_TLS_SUPPORT + serviceInfos::property PROPERTY_CONNECTION_TLS; + serviceInfos::property PROPERTY_CONNECTION_TLS_REQUIRED; +#endif // VMIME_HAVE_TLS_SUPPORT + + serviceInfos::property PROPERTY_SERVER_ADDRESS; + serviceInfos::property PROPERTY_SERVER_PORT; + serviceInfos::property PROPERTY_SERVER_SOCKETFACTORY; + + serviceInfos::property PROPERTY_TIMEOUT_FACTORY; + }; + + const props& getProperties() const; + + const string getPropertyPrefix() const; + const std::vector <serviceInfos::property> getAvailableProperties() const; + +private: + + const bool m_pop3s; +}; + + +} // pop3 +} // net +} // vmime + + +#endif // VMIME_NET_POP3_POP3SERVICEINFOS_HPP_INCLUDED + diff --git a/vmime/net/pop3/POP3Store.hpp b/vmime/net/pop3/POP3Store.hpp index 461741f8..b19c9790 100644 --- a/vmime/net/pop3/POP3Store.hpp +++ b/vmime/net/pop3/POP3Store.hpp @@ -31,6 +31,8 @@ #include "vmime/net/socket.hpp" #include "vmime/net/timeoutHandler.hpp" +#include "vmime/net/pop3/POP3ServiceInfos.hpp" + #include "vmime/utility/stream.hpp" @@ -52,7 +54,7 @@ class POP3Store : public store public: - POP3Store(ref <session> sess, ref <security::authenticator> auth); + POP3Store(ref <session> sess, ref <security::authenticator> auth, const bool secured = false); ~POP3Store(); const string getProtocolName() const; @@ -88,6 +90,10 @@ private: void authenticateSASL(); #endif // VMIME_HAVE_SASL_SUPPORT +#if VMIME_HAVE_TLS_SUPPORT + void startTLS(); +#endif // VMIME_HAVE_TLS_SUPPORT + const std::vector <string> getCapabilities(); static const bool isSuccessResponse(const string& buffer); @@ -116,40 +122,11 @@ private: ref <timeoutHandler> m_timeoutHandler; + bool m_secured; - // Service infos - class _infos : public serviceInfos - { - public: - - struct props - { - // POP3-specific options - serviceInfos::property PROPERTY_OPTIONS_APOP; - serviceInfos::property PROPERTY_OPTIONS_APOP_FALLBACK; -#if VMIME_HAVE_SASL_SUPPORT - serviceInfos::property PROPERTY_OPTIONS_SASL; - serviceInfos::property PROPERTY_OPTIONS_SASL_FALLBACK; -#endif // VMIME_HAVE_SASL_SUPPORT - - // Common properties - serviceInfos::property PROPERTY_AUTH_USERNAME; - serviceInfos::property PROPERTY_AUTH_PASSWORD; - - serviceInfos::property PROPERTY_SERVER_ADDRESS; - serviceInfos::property PROPERTY_SERVER_PORT; - serviceInfos::property PROPERTY_SERVER_SOCKETFACTORY; - - serviceInfos::property PROPERTY_TIMEOUT_FACTORY; - }; - - const props& getProperties() const; - const string getPropertyPrefix() const; - const std::vector <serviceInfos::property> getAvailableProperties() const; - }; - - static _infos sm_infos; + // Service infos + static POP3ServiceInfos sm_infos; }; diff --git a/vmime/net/sendmail/sendmailServiceInfos.hpp b/vmime/net/sendmail/sendmailServiceInfos.hpp new file mode 100644 index 00000000..7da4b776 --- /dev/null +++ b/vmime/net/sendmail/sendmailServiceInfos.hpp @@ -0,0 +1,64 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_SENDMAIL_SENDMAILSERVICEINFOS_HPP_INCLUDED +#define VMIME_NET_SENDMAIL_SENDMAILSERVICEINFOS_HPP_INCLUDED + + +#include "vmime/config.hpp" +#include "vmime/net/serviceInfos.hpp" + + +namespace vmime { +namespace net { +namespace sendmail { + + +/** Information about sendmail service. + */ + +class sendmailServiceInfos : public serviceInfos +{ +public: + + sendmailServiceInfos(); + + struct props + { + serviceInfos::property PROPERTY_BINPATH; + }; + + const props& getProperties() const; + + const string getPropertyPrefix() const; + const std::vector <serviceInfos::property> getAvailableProperties() const; +}; + + +} // sendmail +} // net +} // vmime + + +#endif // VMIME_NET_SENDMAIL_SENDMAILSERVICEINFOS_HPP_INCLUDED + diff --git a/vmime/net/sendmail/sendmailTransport.hpp b/vmime/net/sendmail/sendmailTransport.hpp index 937aaf1e..39f02b8c 100644 --- a/vmime/net/sendmail/sendmailTransport.hpp +++ b/vmime/net/sendmail/sendmailTransport.hpp @@ -31,6 +31,8 @@ #include "vmime/net/socket.hpp" #include "vmime/net/timeoutHandler.hpp" +#include "vmime/net/sendmail/sendmailServiceInfos.hpp" + #if VMIME_BUILTIN_PLATFORM_POSIX @@ -77,22 +79,7 @@ private: // Service infos - class _infos : public serviceInfos - { - public: - - struct props - { - serviceInfos::property PROPERTY_BINPATH; - }; - - const props& getProperties() const; - - const string getPropertyPrefix() const; - const std::vector <serviceInfos::property> getAvailableProperties() const; - }; - - static _infos sm_infos; + static sendmailServiceInfos sm_infos; }; diff --git a/vmime/net/service.hpp b/vmime/net/service.hpp index c9cc77e4..8025ebd9 100644 --- a/vmime/net/service.hpp +++ b/vmime/net/service.hpp @@ -25,6 +25,7 @@ #define VMIME_NET_SERVICE_HPP_INCLUDED +#include "vmime/config.hpp" #include "vmime/types.hpp" #include "vmime/net/session.hpp" @@ -32,6 +33,10 @@ #include "vmime/net/serviceFactory.hpp" #include "vmime/net/serviceInfos.hpp" +#if VMIME_HAVE_TLS_SUPPORT + #include "vmime/net/tls/certificateVerifier.hpp" +#endif // VMIME_HAVE_TLS_SUPPORT + #include "vmime/utility/progressionListener.hpp" @@ -52,7 +57,7 @@ public: virtual ~service(); - // Possible service types + /** Possible service types. */ enum Type { TYPE_STORE = 0, /**< The service is a message store. */ @@ -127,6 +132,20 @@ public: */ void setAuthenticator(ref <security::authenticator> auth); +#if VMIME_HAVE_TLS_SUPPORT + + /** Set the object responsible for verifying certificates when + * using secured connections (TLS/SSL). + */ + void setCertificateVerifier(ref <tls::certificateVerifier> cv); + + /** Get the object responsible for verifying certificates when + * using secured connections (TLS/SSL). + */ + ref <tls::certificateVerifier> getCertificateVerifier(); + +#endif // VMIME_HAVE_TLS_SUPPORT + /** Set a property for this service (service prefix is added automatically). * * WARNING: this sets the property on the session object, so all service @@ -148,10 +167,10 @@ public: { public: - initializer(const string& protocol) + initializer(const string& protocol, const Type type) { serviceFactory::getInstance()-> - template registerServiceByProtocol <S>(protocol); + template registerServiceByProtocol <S>(protocol, type); } }; #endif // VMIME_BUILDING_DOC @@ -160,6 +179,11 @@ private: ref <session> m_session; ref <security::authenticator> m_auth; + +#if VMIME_HAVE_TLS_SUPPORT + ref <tls::certificateVerifier> m_certVerifier; +#endif // VMIME_HAVE_TLS_SUPPORT + }; diff --git a/vmime/net/serviceFactory.hpp b/vmime/net/serviceFactory.hpp index 71c5cb34..9401e310 100644 --- a/vmime/net/serviceFactory.hpp +++ b/vmime/net/serviceFactory.hpp @@ -45,8 +45,8 @@ namespace vmime { namespace net { -class service; class session; +class service; /** A factory to create 'service' objects for a specified protocol. @@ -78,6 +78,7 @@ public: (ref <session> sess, ref <security::authenticator> auth) const = 0; + virtual const int getType() const = 0; virtual const string& getName() const = 0; virtual const serviceInfos& getInfos() const = 0; }; @@ -92,8 +93,8 @@ private: protected: - registeredServiceImpl(const string& name) - : m_name(name), m_servInfos(S::getInfosInstance()) + registeredServiceImpl(const string& name, const int type) + : m_type(type), m_name(name), m_servInfos(S::getInfosInstance()) { } @@ -116,8 +117,14 @@ private: return (m_name); } + const int getType() const + { + return (m_type); + } + private: + const int m_type; const string m_name; const serviceInfos& m_servInfos; }; @@ -129,12 +136,13 @@ public: /** Register a new service by its protocol name. * * @param protocol protocol name + * @param type service type */ template <class S> - void registerServiceByProtocol(const string& protocol) + void registerServiceByProtocol(const string& protocol, const int type) { const string name = utility::stringUtils::toLower(protocol); - m_services.push_back(vmime::create <registeredServiceImpl <S> >(name)); + m_services.push_back(vmime::create <registeredServiceImpl <S> >(name, type)); } /** Create a new service instance from a protocol name. diff --git a/vmime/net/serviceInfos.hpp b/vmime/net/serviceInfos.hpp index 03fe0a0e..14657b2b 100644 --- a/vmime/net/serviceInfos.hpp +++ b/vmime/net/serviceInfos.hpp @@ -95,6 +95,23 @@ public: * no time-out handler is used. */ static const property TIMEOUT_FACTORY; +#if VMIME_HAVE_TLS_SUPPORT + + /** The common property 'connection.tls': this is used to + * start a secured connection if it is supported by the + * server (STARTTLS extension). + */ + static const property CONNECTION_TLS; + + /** The common property 'connection.tls.required' should be + * set to 'true' to make the connection process fail if the + * server can't start a secured connection (no effect if + * 'connection.tls' is not set to 'true'). + */ + static const property CONNECTION_TLS_REQUIRED; + +#endif // VMIME_HAVE_TLS_SUPPORT + /** Value types. */ diff --git a/vmime/net/smtp/SMTPSTransport.hpp b/vmime/net/smtp/SMTPSTransport.hpp new file mode 100644 index 00000000..87eba159 --- /dev/null +++ b/vmime/net/smtp/SMTPSTransport.hpp @@ -0,0 +1,63 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_SMTP_SMTPSSTORE_HPP_INCLUDED +#define VMIME_NET_SMTP_SMTPSSTORE_HPP_INCLUDED + + +#include "vmime/net/smtp/SMTPTransport.hpp" + + +namespace vmime { +namespace net { +namespace smtp { + + +/** SMTPS transport service. + */ + +class SMTPSTransport : public SMTPTransport +{ +public: + + SMTPSTransport(ref <session> sess, ref <security::authenticator> auth); + ~SMTPSTransport(); + + const string getProtocolName() const; + + static const serviceInfos& getInfosInstance(); + const serviceInfos& getInfos() const; + +private: + + static SMTPServiceInfos sm_infos; +}; + + +} // smtp +} // net +} // vmime + + +#endif // VMIME_NET_SMTP_SMTPSSTORE_HPP_INCLUDED + diff --git a/vmime/net/smtp/SMTPServiceInfos.hpp b/vmime/net/smtp/SMTPServiceInfos.hpp new file mode 100644 index 00000000..ac3ae372 --- /dev/null +++ b/vmime/net/smtp/SMTPServiceInfos.hpp @@ -0,0 +1,88 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_SMTP_SMTPSERVICEINFOS_HPP_INCLUDED +#define VMIME_NET_SMTP_SMTPSERVICEINFOS_HPP_INCLUDED + + +#include "vmime/config.hpp" +#include "vmime/net/serviceInfos.hpp" + + +namespace vmime { +namespace net { +namespace smtp { + + +/** Information about SMTP service. + */ + +class SMTPServiceInfos : public serviceInfos +{ +public: + + SMTPServiceInfos(const bool smtps); + + struct props + { + // SMTP-specific options + serviceInfos::property PROPERTY_OPTIONS_NEEDAUTH; +#if VMIME_HAVE_SASL_SUPPORT + serviceInfos::property PROPERTY_OPTIONS_SASL; + serviceInfos::property PROPERTY_OPTIONS_SASL_FALLBACK; +#endif // VMIME_HAVE_SASL_SUPPORT + + // Common properties + serviceInfos::property PROPERTY_AUTH_USERNAME; + serviceInfos::property PROPERTY_AUTH_PASSWORD; + +#if VMIME_HAVE_TLS_SUPPORT + serviceInfos::property PROPERTY_CONNECTION_TLS; + serviceInfos::property PROPERTY_CONNECTION_TLS_REQUIRED; +#endif // VMIME_HAVE_TLS_SUPPORT + + serviceInfos::property PROPERTY_SERVER_ADDRESS; + serviceInfos::property PROPERTY_SERVER_PORT; + serviceInfos::property PROPERTY_SERVER_SOCKETFACTORY; + + serviceInfos::property PROPERTY_TIMEOUT_FACTORY; + }; + + const props& getProperties() const; + + const string getPropertyPrefix() const; + const std::vector <serviceInfos::property> getAvailableProperties() const; + +private: + + const bool m_smtps; +}; + + +} // smtp +} // net +} // vmime + + +#endif // VMIME_NET_SMTP_SMTPSERVICEINFOS_HPP_INCLUDED + diff --git a/vmime/net/smtp/SMTPTransport.hpp b/vmime/net/smtp/SMTPTransport.hpp index ae22af7f..65d8537b 100644 --- a/vmime/net/smtp/SMTPTransport.hpp +++ b/vmime/net/smtp/SMTPTransport.hpp @@ -31,6 +31,8 @@ #include "vmime/net/socket.hpp" #include "vmime/net/timeoutHandler.hpp" +#include "vmime/net/smtp/SMTPServiceInfos.hpp" + namespace vmime { namespace net { @@ -44,7 +46,7 @@ class SMTPTransport : public transport { public: - SMTPTransport(ref <session> sess, ref <security::authenticator> auth); + SMTPTransport(ref <session> sess, ref <security::authenticator> auth, const bool secured = false); ~SMTPTransport(); const string getProtocolName() const; @@ -77,6 +79,9 @@ private: void authenticateSASL(); #endif // VMIME_HAVE_SASL_SUPPORT +#if VMIME_HAVE_TLS_SUPPORT + void startTLS(); +#endif // VMIME_HAVE_TLS_SUPPORT ref <socket> m_socket; bool m_authentified; @@ -89,39 +94,11 @@ private: ref <timeoutHandler> m_timeoutHandler; + bool m_secured; - // Service infos - class _infos : public serviceInfos - { - public: - - struct props - { - // SMTP-specific options - serviceInfos::property PROPERTY_OPTIONS_NEEDAUTH; -#if VMIME_HAVE_SASL_SUPPORT - serviceInfos::property PROPERTY_OPTIONS_SASL; - serviceInfos::property PROPERTY_OPTIONS_SASL_FALLBACK; -#endif // VMIME_HAVE_SASL_SUPPORT - - // Common properties - serviceInfos::property PROPERTY_AUTH_USERNAME; - serviceInfos::property PROPERTY_AUTH_PASSWORD; - - serviceInfos::property PROPERTY_SERVER_ADDRESS; - serviceInfos::property PROPERTY_SERVER_PORT; - serviceInfos::property PROPERTY_SERVER_SOCKETFACTORY; - - serviceInfos::property PROPERTY_TIMEOUT_FACTORY; - }; - - const props& getProperties() const; - const string getPropertyPrefix() const; - const std::vector <serviceInfos::property> getAvailableProperties() const; - }; - - static _infos sm_infos; + // Service infos + static SMTPServiceInfos sm_infos; }; diff --git a/vmime/net/tls/TLSSession.hpp b/vmime/net/tls/TLSSession.hpp new file mode 100644 index 00000000..e946c102 --- /dev/null +++ b/vmime/net/tls/TLSSession.hpp @@ -0,0 +1,95 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_TLS_TLSSESSION_HPP_INCLUDED +#define VMIME_NET_TLS_TLSSESSION_HPP_INCLUDED + + +#include "vmime/types.hpp" + +#include "vmime/net/tls/TLSSocket.hpp" + +#include "vmime/net/tls/certificateVerifier.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +/** Describe a TLS connection between a client and a server. + */ +class TLSSession : public object +{ + friend class TLSSocket; + +public: + + ~TLSSession(); + + /** Create and initialize a new TLS session. + * + * @param cv object responsible for verifying certificates + * sent by the server + * @return a new TLS session + */ + TLSSession(ref <certificateVerifier> cv); + + /** Create a new socket that adds a TLS security layer around + * an existing socket. You should create only one socket + * per session. + * + * @param sok socket to wrap + * @return TLS socket wrapper + */ + ref <TLSSocket> getSocket(ref <socket> sok); + + /** Get the object responsible for verifying certificates when + * using secured connections (TLS/SSL). + */ + ref <tls::certificateVerifier> getCertificateVerifier(); + +private: + + TLSSession(const TLSSession&); + + static void throwTLSException(const string& fname, const int code); + + +#ifdef LIBGNUTLS_VERSION + gnutls_session* m_gnutlsSession; +#else + void* m_gnutlsSession; +#endif // LIBGNUTLS_VERSION + + ref <certificateVerifier> m_certVerifier; +}; + + +} // tls +} // net +} // vmime + + +#endif // VMIME_NET_TLS_TLSSESSION_HPP_INCLUDED + diff --git a/vmime/net/tls/TLSSocket.hpp b/vmime/net/tls/TLSSocket.hpp new file mode 100644 index 00000000..075a77ef --- /dev/null +++ b/vmime/net/tls/TLSSocket.hpp @@ -0,0 +1,125 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_TLS_TLSSOCKET_HPP_INCLUDED +#define VMIME_NET_TLS_TLSSOCKET_HPP_INCLUDED + + +#include "vmime/exception.hpp" + +#include "vmime/net/socket.hpp" +#include "vmime/net/timeoutHandler.hpp" + +#include "vmime/net/tls/certificateChain.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +class TLSSession; + + +/** Add a TLS security layer to an existing socket. + */ +class TLSSocket : public socket +{ + friend class vmime::creator; + +protected: + + /** Create a new socket object that adds a security layer + * around an existing socket. + * + * @param session TLS session + * @param sok socket to wrap + */ + TLSSocket(ref <TLSSession> session, ref <socket> sok); + +public: + + ~TLSSocket(); + + + /** Starts a TLS handshake on this connection. + * + * @throw exceptions::tls_exception if a fatal error occurs + * during the negociation process, exceptions::operation_timed_out + * if a time-out occurs + */ + void handshake(ref <timeoutHandler> toHandler = NULL); + + /** Return the peer's certificate (chain) as sent by the peer. + * + * @return server certificate chain, or NULL if the handshake + * has not been performed yet + */ + ref <certificateChain> getPeerCertificates(); + + + // Implementation of 'socket' + void connect(const string& address, const port_t port); + void disconnect(); + const bool isConnected() const; + + void receive(string& buffer); + const int receiveRaw(char* buffer, const int count); + + void send(const string& buffer); + void sendRaw(const char* buffer, const int count); + +private: + + void internalThrow(); + +#ifdef LIBGNUTLS_VERSION + static ssize_t gnutlsPushFunc(gnutls_transport_ptr trspt, const void* data, size_t len); + static ssize_t gnutlsPullFunc(gnutls_transport_ptr trspt, void* data, size_t len); +#else + static ssize_t gnutlsPushFunc(void* trspt, const void* data, size_t len); + static ssize_t gnutlsPullFunc(void* trspt, void* data, size_t len); +#endif // LIBGNUTLS_VERSION + + + ref <TLSSession> m_session; + ref <socket> m_wrapped; + + bool m_connected; + + char m_buffer[65536]; + + bool m_handshaking; + ref <timeoutHandler> m_toHandler; + + exception* m_ex; +}; + + +} // tls +} // net +} // vmime + + +#endif // VMIME_NET_TLS_TLSSOCKET_HPP_INCLUDED + diff --git a/vmime/net/tls/X509Certificate.hpp b/vmime/net/tls/X509Certificate.hpp new file mode 100644 index 00000000..5edd4e46 --- /dev/null +++ b/vmime/net/tls/X509Certificate.hpp @@ -0,0 +1,158 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_TLS_X509CERTIFICATE_HPP_INCLUDED +#define VMIME_NET_TLS_X509CERTIFICATE_HPP_INCLUDED + + +#include "vmime/net/tls/certificate.hpp" + +#include "vmime/utility/stream.hpp" + +#include "vmime/base.hpp" +#include "vmime/dateTime.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +/** Identity certificate based on X.509 standard. + */ +class X509Certificate : public certificate +{ + friend class vmime::creator; + +protected: + + X509Certificate(); + X509Certificate(const X509Certificate&); + +public: + + ~X509Certificate(); + + /** Supported encodings for X.509 certificates. */ + enum Format + { + FORMAT_DER, /**< DER encoding */ + FORMAT_PEM /**< PEM encoding */ + }; + + /** Supported digest algorithms (used for fingerprint). */ + enum DigestAlgorithm + { + DIGEST_MD5, /**< MD5 digest */ + DIGEST_SHA1 /**< SHA1 digest */ + }; + + + /** Imports a DER or PEM encoded X.509 certificate. + * + * @param is input stream to read data from + * @return a X.509 certificate, or NULL if the given data does not + * represent a valid certificate + */ + static ref <X509Certificate> import(utility::inputStream& is); + + /** Imports a DER or PEM encoded X.509 certificate. + * + * @param data points to raw data + * @param length size of data + * @return a X.509 certificate, or NULL if the given data does not + * represent a valid certificate + */ + static ref <X509Certificate> import(const byte* data, const unsigned int length); + + /** Exports this X.509 certificate to the specified format. + * + * @param os output stream into which write data + * @param format output format + */ + void write(utility::outputStream& os, const Format format) const; + + /** Returns the X.509 certificate's serial number. This is obtained + * by the X.509 Certificate 'serialNumber' field. Serial is not + * always a 32 or 64bit number. Some CAs use large serial numbers, + * thus it may be wise to handle it as something opaque. + * + * @return serial number of this certificate + */ + const byteArray getSerialNumber() const; + + /** Checks if this certificate has the given issuer. + * + * @param issuer certificate of a possible issuer + * @return true if this certificate was issued by the given issuer, + * false otherwise + */ + const bool checkIssuer(ref <const X509Certificate> issuer) const; + + /** Verifies this certificate against a given trusted one. + * + * @param caCert a certificate that is considered to be trusted one + * @return true if the verification succeeded, false otherwise + */ + const bool verify(ref <const X509Certificate> caCert) const; + + /** Gets the expiration date of this certificate. This is the date + * at which this certificate will not be valid anymore. + * + * @return expiration date of this certificate + */ + const datetime getExpirationDate() const; + + /** Gets the activation date of this certificate. This is the date + * at which this certificate will be valid. + * + * @return activation date of this certificate + */ + const datetime getActivationDate() const; + + /** Returns the fingerprint of this certificate. + * + * @return the fingerprint of this certificate + */ + const byteArray getFingerprint(const DigestAlgorithm algo) const; + + + // Implementation of 'certificate' + const byteArray getEncoded() const; + const string getType() const; + const int getVersion() const; + const bool equals(ref <const certificate> other) const; + +private: + + class X509CertificateInternalData* m_data; +}; + + +} // tls +} // net +} // vmime + + +#endif // VMIME_NET_TLS_X509CERTIFICATE_HPP_INCLUDED + diff --git a/vmime/net/tls/certificate.hpp b/vmime/net/tls/certificate.hpp new file mode 100644 index 00000000..c070484b --- /dev/null +++ b/vmime/net/tls/certificate.hpp @@ -0,0 +1,77 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_TLS_CERTIFICATE_HPP_INCLUDED +#define VMIME_NET_TLS_CERTIFICATE_HPP_INCLUDED + + +#include "vmime/types.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +/** Identity certificate for a peer. + */ +class certificate : public object +{ +public: + + /** Returns the encoded form of this certificate (for example, + * X.509 certificates are encoded as ASN.1 DER). + * + * @return the encoded form of this certificate + */ + virtual const byteArray getEncoded() const = 0; + + /** Return the type of this certificate. + * + * @return the type of this certificate + */ + virtual const string getType() const = 0; + + /** Return the version of this certificate. + * + * @return the version of this certificate + */ + virtual const int getVersion() const = 0; + + /** Checks if two certificates are the same. + * + * @param other certificate to compare with + * @return true if the two certificates are the same, + * false otherwise + */ + virtual const bool equals(ref <const certificate> other) const = 0; +}; + + +} // tls +} // net +} // vmime + + +#endif // VMIME_NET_TLS_CERTIFICATE_HPP_INCLUDED + diff --git a/vmime/net/tls/certificateChain.hpp b/vmime/net/tls/certificateChain.hpp new file mode 100644 index 00000000..332e3f70 --- /dev/null +++ b/vmime/net/tls/certificateChain.hpp @@ -0,0 +1,79 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_TLS_CERTIFICATECHAIN_HPP_INCLUDED +#define VMIME_NET_TLS_CERTIFICATECHAIN_HPP_INCLUDED + + +#include "vmime/types.hpp" + +#include "vmime/net/tls/certificate.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +/** An ordered list of certificates, from the subject certificate to + * the issuer certificate. + */ +class certificateChain : public object +{ +public: + + /** Construct a new certificateChain object given an ordered list + * of certificates. + * + * @param certs chain of certificates + */ + certificateChain(const std::vector <ref <certificate> >& certs); + + /** Return the number of certificates in the chain. + * + * @return number of certificates in the chain + */ + const unsigned int getCount() const; + + /** Return the certificate at the specified position. 0 is the + * subject certificate, 1 is the issuer's certificate, 2 is + * the issuer's issuer, etc. + * + * @param index position at which to retrieve certificate + * @return certificate at the specified position + */ + ref <certificate> getAt(const unsigned int index); + +protected: + + std::vector <ref <certificate> > m_certs; +}; + + +} // tls +} // net +} // vmime + + +#endif // VMIME_NET_TLS_CERTIFICATECHAIN_HPP_INCLUDED + diff --git a/vmime/net/tls/certificateVerifier.hpp b/vmime/net/tls/certificateVerifier.hpp new file mode 100644 index 00000000..fd235b48 --- /dev/null +++ b/vmime/net/tls/certificateVerifier.hpp @@ -0,0 +1,60 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_TLS_CERTIFICATEVERIFIER_HPP_INCLUDED +#define VMIME_NET_TLS_CERTIFICATEVERIFIER_HPP_INCLUDED + + +#include "vmime/types.hpp" + +#include "vmime/net/tls/certificateChain.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +/** Verify that a certificate path issued by a server can be trusted. + */ +class certificateVerifier : public object +{ +public: + + /** Verify that the specified certificate chain is trusted. + * + * @param chain certificate chain + * @throw exceptions::certificate_verification_exception if one + * or more certificates can not be trusted + */ + virtual void verify(ref <certificateChain> chain) = 0; +}; + + +} // tls +} // net +} // vmime + + +#endif // VMIME_NET_TLS_CERTIFICATEVERIFIER_HPP_INCLUDED + diff --git a/vmime/net/tls/defaultCertificateVerifier.hpp b/vmime/net/tls/defaultCertificateVerifier.hpp new file mode 100644 index 00000000..3713fd21 --- /dev/null +++ b/vmime/net/tls/defaultCertificateVerifier.hpp @@ -0,0 +1,88 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard <[email protected]> +// +// 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_TLS_DEFAULTCERTIFICATEVERIFIER_HPP_INCLUDED +#define VMIME_NET_TLS_DEFAULTCERTIFICATEVERIFIER_HPP_INCLUDED + + +#include "vmime/net/tls/certificateVerifier.hpp" + + +namespace vmime { +namespace net { +namespace tls { + + +class X509Certificate; + + +/** Default implementation for certificate verification. + */ +class defaultCertificateVerifier : public certificateVerifier +{ +private: + + defaultCertificateVerifier(const defaultCertificateVerifier&); + +public: + + defaultCertificateVerifier(); + ~defaultCertificateVerifier(); + + /** Sets a list of X.509 certificates that are trusted. + * + * @param trustedCerts list of trusted certificates + */ + void setX509TrustedCerts(const std::vector <ref <X509Certificate> >& trustedCerts); + + /** Sets the X.509 root CAs used for certificate verification. + * + * @param caCerts list of root CAs + */ + void setX509RootCAs(const std::vector <ref <X509Certificate> >& caCerts); + + + // Implementation of 'certificateVerifier' + void verify(ref <certificateChain> chain); + +private: + + /** Verify a chain of X.509 certificates. + * + * @param chain list of X.509 certificates + */ + void verifyX509(ref <certificateChain> chain); + + + std::vector <ref <X509Certificate> > m_x509RootCAs; + std::vector <ref <X509Certificate> > m_x509TrustedCerts; +}; + + +} // tls +} // net +} // vmime + + +#endif // VMIME_NET_TLS_DEFAULTCERTIFICATEVERIFIER_HPP_INCLUDED + diff --git a/vmime/utility/stream.hpp b/vmime/utility/stream.hpp index 4a5bd216..2ebd41c5 100644 --- a/vmime/utility/stream.hpp +++ b/vmime/utility/stream.hpp @@ -229,6 +229,23 @@ private: }; +/** An adapter class for byte array output. + */ + +class outputStreamByteArrayAdapter : public outputStream +{ +public: + + outputStreamByteArrayAdapter(byteArray& array); + + void write(const value_type* const data, const size_type count); + +private: + + byteArray m_array; +}; + + /** An adapter class for C++ standard input streams. */ diff --git a/vmime/vmime.hpp b/vmime/vmime.hpp index b2245917..c7a0b4f6 100644 --- a/vmime/vmime.hpp +++ b/vmime/vmime.hpp @@ -119,5 +119,18 @@ #include "vmime/net/message.hpp" #endif // VMIME_HAVE_MESSAGING_FEATURES +// Net/TLS +#if VMIME_HAVE_TLS_SUPPORT + #include "vmime/net/tls/certificate.hpp" + #include "vmime/net/tls/certificateChain.hpp" + #include "vmime/net/tls/certificateVerifier.hpp" + + #include "vmime/net/tls/X509Certificate.hpp" + + #include "vmime/net/tls/defaultCertificateVerifier.hpp" + + #include "vmime/net/tls/TLSSession.hpp" +#endif // VMIME_HAVE_TLS_SUPPORT + #endif // VMIME_INCLUDED |