Qpid Proton C++  0.13.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ssl.hpp
1 #ifndef PROTON_SSL_HPP
2 #define PROTON_SSL_HPP
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include "./internal/export.hpp"
26 #include "./internal/object.hpp"
27 
28 #include <proton/ssl.h>
29 
30 #include <string>
31 
32 namespace proton {
33 
34 class connection_options;
35 
37 class ssl {
39  ssl(pn_ssl_t* s) : object_(s) {}
41 
42  public:
44  ssl() : object_(0) {}
45 
47  enum verify_mode {
49  VERIFY_PEER = PN_SSL_VERIFY_PEER,
51  ANONYMOUS_PEER = PN_SSL_ANONYMOUS_PEER,
53  VERIFY_PEER_NAME = PN_SSL_VERIFY_PEER_NAME
54  };
55 
58  UNKNOWN = PN_SSL_RESUME_UNKNOWN,
59  NEW = PN_SSL_RESUME_NEW,
60  REUSED = PN_SSL_RESUME_REUSED
61  };
62 
64 
67  PN_CPP_EXTERN std::string cipher() const;
68 
71  PN_CPP_EXTERN std::string protocol() const;
72 
74  PN_CPP_EXTERN int ssf() const;
75 
77  PN_CPP_EXTERN void peer_hostname(const std::string &);
78  PN_CPP_EXTERN std::string peer_hostname() const;
79 
81  PN_CPP_EXTERN std::string remote_subject() const;
82 
84  PN_CPP_EXTERN void resume_session_id(const std::string& session_id);
85 
86  PN_CPP_EXTERN enum resume_status resume_status() const;
87 
89 
90  private:
91  pn_ssl_t* object_;
92 
94  friend class internal::factory<ssl>;
96 };
97 
100  public:
102  PN_CPP_EXTERN ssl_certificate(const std::string &certdb_main);
103 
104  // XXX Document the following constructors
105 
107  PN_CPP_EXTERN ssl_certificate(const std::string &certdb_main, const std::string &certdb_extra);
108 
110  PN_CPP_EXTERN ssl_certificate(const std::string &certdb_main, const std::string &certdb_extra, const std::string &passwd);
112 
113  private:
114  std::string certdb_main_;
115  std::string certdb_extra_;
116  std::string passwd_;
117  bool pw_set_;
118 
120  friend class ssl_client_options;
121  friend class ssl_server_options;
123 };
124 
125 class ssl_domain_impl;
126 
127 namespace internal {
128 
129 // Base class for SSL configuration
130 class ssl_domain {
131  public:
132  PN_CPP_EXTERN ssl_domain(const ssl_domain&);
133  PN_CPP_EXTERN ssl_domain& operator=(const ssl_domain&);
134  PN_CPP_EXTERN ~ssl_domain();
135 
136  protected:
137  ssl_domain(bool is_server);
138  pn_ssl_domain_t *pn_domain();
139 
140  private:
141  ssl_domain_impl *impl_;
142  bool server_type_;
143 };
144 
145 }
146 
148 class ssl_server_options : private internal::ssl_domain {
149  public:
152  PN_CPP_EXTERN ssl_server_options(ssl_certificate &cert);
153 
156  PN_CPP_EXTERN ssl_server_options(ssl_certificate &cert, const std::string &trust_db,
157  const std::string &advertise_db = std::string(),
158  enum ssl::verify_mode mode = ssl::VERIFY_PEER);
159 
162  PN_CPP_EXTERN ssl_server_options();
163 
164  private:
165  // Bring pn_domain into scope and allow connection_options to use
166  // it.
167  using internal::ssl_domain::pn_domain;
168 
170  friend class connection_options;
172 };
173 
175 class ssl_client_options : private internal::ssl_domain {
176  public:
178  PN_CPP_EXTERN ssl_client_options(const std::string &trust_db,
180 
182  PN_CPP_EXTERN ssl_client_options(ssl_certificate&, const std::string &trust_db,
184 
187  PN_CPP_EXTERN ssl_client_options();
188 
189  private:
190  // Bring pn_domain into scope and allow connection_options to use
191  // it.
192  using internal::ssl_domain::pn_domain;
193 
195  friend class connection_options;
197 };
198 
199 } // proton
200 
201 #endif // PROTON_SSL_HPP
ssl_server_options()
Server SSL options restricted to available anonymous cipher suites on the platform.
Experimental - SSL configuration for inbound connections.
Definition: ssl.hpp:148
ssl()
Create an empty ssl object.
Definition: ssl.hpp:44
SSL information.
Definition: ssl.hpp:37
Require valid certificate and matching name.
Definition: ssl.hpp:53
Session resume state unknown or not supported.
Definition: ssl.hpp:58
Options for creating a connection.
Definition: connection_options.hpp:67
Experimental - SSL configuration for outbound connections.
Definition: ssl.hpp:175
ssl_certificate(const std::string &certdb_main)
Create an SSL certificate.
resume_status
Outcome specifier for an attempted session resume.
Definition: ssl.hpp:57
ssl_client_options()
SSL connections restricted to available anonymous cipher suites on the platform.
verify_mode
Determines the level of peer validation.
Definition: ssl.hpp:47
Do not require a certificate or cipher authorization.
Definition: ssl.hpp:51
Require peer to provide a valid identifying certificate.
Definition: ssl.hpp:49
Session renegotiated, not resumed.
Definition: ssl.hpp:59
Experimental - An SSL certificate.
Definition: ssl.hpp:99
Session resumed from previous session.
Definition: ssl.hpp:60