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
37namespace Pt {
38
39namespace Ssl {
40
41class Certificate;
42class ContextImpl;
43
45static struct PT_SSL_API SSLInit
46{
47 SSLInit();
48 ~SSLInit();
49} ssl_init;
50
56{
57 Connect = 1,
58 Accept = 2
59};
60
66{
67 SSLv2 = 0,
69 SSLv3 = 2,
71 TLSv1 = 3,
72 TLSv1_1 = 4,
74};
75
86
112class PT_SSL_API Context : public NonCopyable
113{
114 public:
118
122
126
129 void assign(const Context& ctx);
130
134
138
141 void setVerifyDepth(int n);
142
146
150
155 void addCACertificate(const Certificate& trustedCert);
156
164 void setIdentity(const Certificate& cert);
165
170 void addCertificate(const Certificate& cert);
171
173 ContextImpl* impl();
174
176 const ContextImpl* impl() const;
177
178 private:
179 ContextImpl* _impl;
180};
181
182} // namespace Ssl
183
184} // namespace Pt
185
186#endif // PT_SSL_CONTEXT_H
NonCopyable()
Default constructor.
Definition NonCopyable.h:63
X509 certificate.
Definition Certificate.h:56
void setVerifyDepth(int n)
Limits how many certificates are checked in the peer chain.
void addCACertificate(const Certificate &trustedCert)
Adds trustedCert to the trusted CA certificates.
void setIdentity(const Certificate &cert)
Sets the certificate presented to the peer.
void addCertificate(const Certificate &cert)
Adds cert to the chain presented with the identity.
Context()
Creates a context for the highest available TLS protocol.
Context(Protocol protocol)
Creates a context for protocol.
void assign(const Context &ctx)
Copies protocol, verify settings and certificates from ctx.
void setVerifyMode(VerifyMode mode)
Sets the verification mode.
Protocol protocol() const
Returns the protocol.
~Context()
Destructor.
void setProtocol(Protocol protocol)
Sets the protocol.
VerifyMode verifyMode() const
Returns the verification mode.
Protocol
SSL/TLS protocol version.
Definition Context.h:66
VerifyMode
How the peer certificate is verified.
Definition Context.h:81
@ TLSv1
TLS version 1.0.
Definition Context.h:71
@ SSLv3or2
Highest available protocol version.
Definition Context.h:68
@ SSLv3
SSL version 3.
Definition Context.h:69
@ TLSv1_2
TLS version 1.2.
Definition Context.h:73
@ TLS
Highest available TLS protocol version.
Definition Context.h:70
@ SSLv2
SSL version 2.
Definition Context.h:67
@ TLSv1_1
TLS version 1.1.
Definition Context.h:72
@ TryVerify
Verify a certificate when the peer presents one.
Definition Context.h:83
@ AlwaysVerify
Require a peer certificate.
Definition Context.h:84
@ NoVerify
Do not verify the peer.
Definition Context.h:82
OpenMode
Open mode for an SSL stream.
Definition Context.h:56
@ Accept
Server handshake.
Definition Context.h:58
@ Connect
Client handshake.
Definition Context.h:57
SSL/TLS streams, certificates and contexts.
Definition Client.h:50
Core module.
Definition Allocator.h:33