1 //
2 // VMime library (http://www.vmime.org)
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Linking this library statically or dynamically with other modules is making
20 // a combined work based on this library.  Thus, the terms and conditions of
21 // the GNU General Public License cover the whole combination.
22 //
23 
24 #ifndef VMIME_NET_TLS_TLSSESSION_OPENSSL_HPP_INCLUDED
25 #define VMIME_NET_TLS_TLSSESSION_OPENSSL_HPP_INCLUDED
26 
27 
28 #ifndef VMIME_BUILDING_DOC
29 
30 
31 #include "vmime/config.hpp"
32 
33 
34 #if VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_TLS_SUPPORT && VMIME_TLS_SUPPORT_LIB_IS_OPENSSL
35 
36 
37 #include "vmime/types.hpp"
38 
39 #include "vmime/net/tls/TLSSession.hpp"
40 #include "vmime/net/tls/TLSSocket.hpp"
41 #include "vmime/net/tls/TLSProperties.hpp"
42 
43 
44 #include <openssl/ssl.h>
45 
46 
47 namespace vmime {
48 namespace net {
49 namespace tls {
50 
51 
52 class TLSSession_OpenSSL : public TLSSession
53 {
54 	friend class TLSSocket_OpenSSL;
55 
56 public:
57 
58 	TLSSession_OpenSSL(const shared_ptr <security::cert::certificateVerifier> cv, shared_ptr <TLSProperties> props);
59 	~TLSSession_OpenSSL();
60 
61 
62 	shared_ptr <TLSSocket> getSocket(shared_ptr <socket> sok);
63 
64 	shared_ptr <security::cert::certificateVerifier> getCertificateVerifier();
65 
66 
67 	/** Set the private key to use if server requires a client certificate.
68 	 *
69 	 * @param	keyfile         Path to the private key in PEM format
70 	 * @param passwd_callback If the private key is stored encrypted the
71 	*/
72 	void usePrivateKeyFile(const vmime::string& keyfile);
73 
74 	/** Supply the certificate chain to present if requested by
75 	 *  server.
76 	 *
77 	 * @param chainFile	File in PEM format holding certificate chain
78 	 */
79 	void useCertificateChainFile(const vmime::string& chainFile);
80 
81 	/** Get a pointer to the SSL_CTX used for this session.
82 	 *
83 	 * @return the SSL_CTX used for all connections created with this session
84 	 */
85 	SSL_CTX* getContext() const;
86 
87 private:
88 
89 	TLSSession_OpenSSL(const TLSSession_OpenSSL&);
90 
91 	SSL_CTX* m_sslctx;
92 
93 	shared_ptr <security::cert::certificateVerifier> m_certVerifier;
94 	shared_ptr <TLSProperties> m_props;
95 };
96 
97 
98 } // tls
99 } // net
100 } // vmime
101 
102 
103 #endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_TLS_SUPPORT && VMIME_TLS_SUPPORT_LIB_IS_OPENSSL
104 
105 #endif // VMIME_BUILDING_DOC
106 
107 #endif // VMIME_NET_TLS_TLSSESSION_OPENSSL_HPP_INCLUDED
108 
109