Context.h
1 /*
2  * Copyright (C) 2010-2010 by Aloysius Indrayanto
3  * Copyright (C) 2010-2013 by Marc Duerner
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * As a special exception, you may use this file as part of a free
11  * software library without restriction. Specifically, if other files
12  * instantiate templates or use macros or inline functions from this
13  * file, or you compile this file and link it with other files to
14  * produce an executable, this file does not by itself cause the
15  * resulting executable to be covered by the GNU General Public
16  * License. This exception does not however invalidate any other
17  * reasons why the executable file might be covered by the GNU Library
18  * General Public License.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this library; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28  */
29 
30 #ifndef PT_SSL_CONTEXT_H
31 #define PT_SSL_CONTEXT_H
32 
33 #include <Pt/Ssl/Api.h>
34 #include <Pt/NonCopyable.h>
35 #include <string>
36 
37 namespace Pt {
38 
39 namespace Ssl {
40 
41 class Certificate;
42 class ContextImpl;
43 
45 static struct PT_SSL_API SSLInit
46 {
47  SSLInit();
48  ~SSLInit();
49 } ssl_init;
50 
53 {
54  Connect = 1,
55  Accept = 2
56 };
57 
59 enum Protocol
60 {
65 };
66 
69 {
70  NoVerify = 0,
71  TryVerify = 1,
73 };
74 
76 class PT_SSL_API Context : public NonCopyable
77 {
78  public:
80  Context();
81 
83  Context(Protocol protocol);
84 
86  ~Context();
87 
89  void assign(const Context& ctx);
90 
92  Protocol protocol() const;
93 
95  void setProtocol(Protocol protocol);
96 
98  void setVerifyDepth(int n);
99 
101  VerifyMode verifyMode() const;
102 
104  void setVerifyMode(VerifyMode mode);
105 
112  void addCACertificate(const Certificate& trustedCert);
113 
119  void setIdentity(const Certificate& cert);
120 
126  void addCertificate(const Certificate& cert);
127 
129  ContextImpl* impl();
130 
132  const ContextImpl* impl() const;
133 
134  private:
135  ContextImpl* _impl;
136 };
137 
138 } // namespace Ssl
139 
140 } // namespace Pt
141 
142 #endif // PT_SSL_CONTEXT_H
Connect to server.
Definition: Context.h:54
Verify if certificate is presented.
Definition: Context.h:71
Protects derived classes from being copied.
Definition: NonCopyable.h:54
X509 certificate.
Definition: Certificate.h:44
SSL version 3.
Definition: Context.h:63
Context for SSL connections.
Definition: Context.h:76
Require tp present certificate.
Definition: Context.h:72
VerifyMode
Verification mode.
Definition: Context.h:68
Accept client.
Definition: Context.h:55
SSL version 2.
Definition: Context.h:61
No verification.
Definition: Context.h:70
OpenMode
Open mode for ssl I/O.
Definition: Context.h:52
SSL version 2 or 3.
Definition: Context.h:62
TLS version 1.
Definition: Context.h:64
Protocol
Communication protocol.
Definition: Context.h:59