| 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 |
|
| 27 |
#include <proton/ssl.h> |
| 28 |
|
| 29 |
#include <string> |
| 30 |
|
| 31 |
/// @file |
| 32 |
/// @copybrief proton::ssl |
| 33 |
|
| 34 |
namespace proton { |
| 35 |
|
| 36 |
/// SSL information. |
| 37 |
class ssl { |
| 38 |
/// @cond INTERNAL |
| 39 |
ssl(pn_ssl_t* s) : object_(s) {} |
| 40 |
/// @endcond |
| 41 |
|
| 42 |
ssl() = delete; |
| 43 |
|
| 44 |
public: |
| 45 |
/// Determines the level of peer validation. |
| 46 |
enum verify_mode { |
| 47 |
/// Require peer to provide a valid identifying certificate |
| 48 |
VERIFY_PEER = PN_SSL_VERIFY_PEER, |
| 49 |
/// Do not require a certificate or cipher authorization |
| 50 |
ANONYMOUS_PEER = PN_SSL_ANONYMOUS_PEER, |
| 51 |
/// Require valid certificate and matching name |
| 52 |
VERIFY_PEER_NAME = PN_SSL_VERIFY_PEER_NAME |
| 53 |
}; |
| 54 |
|
| 55 |
/// Outcome specifier for an attempted session resume. |
| 56 |
enum resume_status { |
| 57 |
UNKNOWN = PN_SSL_RESUME_UNKNOWN, ///< Session resume state unknown or not supported |
| 58 |
NEW = PN_SSL_RESUME_NEW, ///< Session renegotiated, not resumed |
| 59 |
REUSED = PN_SSL_RESUME_REUSED ///< Session resumed from previous session |
| 60 |
}; |
| 61 |
|
| 62 |
/// @cond INTERNAL |
| 63 |
|
| 64 |
/// XXX C API uses cipher_name |
| 65 |
/// Get the cipher name. |
| 66 |
PN_CPP_EXTERN std::string cipher() const; |
| 67 |
|
| 68 |
/// XXX C API uses protocol_name |
| 69 |
/// Get the protocol name. |
| 70 |
PN_CPP_EXTERN std::string protocol() const; |
| 71 |
|
| 72 |
/// Get the security strength factor. |
| 73 |
PN_CPP_EXTERN int ssf() const; |
| 74 |
|
| 75 |
/// XXX discuss, what's the meaning of "remote" here? |
| 76 |
PN_CPP_EXTERN std::string remote_subject() const; |
| 77 |
|
| 78 |
/// XXX setters? versus connection options |
| 79 |
PN_CPP_EXTERN void resume_session_id(const std::string& session_id); |
| 80 |
|
| 81 |
PN_CPP_EXTERN enum resume_status resume_status() const; |
| 82 |
|
| 83 |
/// @endcond |
| 84 |
|
| 85 |
private: |
| 86 |
pn_ssl_t* const object_; |
| 87 |
|
| 88 |
/// @cond INTERNAL |
| 89 |
friend class transport; |
| 90 |
/// @endcond |
| 91 |
}; |
| 92 |
|
| 93 |
/// **Unsettled API** - An SSL certificate. |
| 94 |
class ssl_certificate { |
| 95 |
public: |
| 96 |
/// Create an SSL certificate. |
| 97 |
PN_CPP_EXTERN ssl_certificate(const std::string &certdb_main); |
| 98 |
|
| 99 |
// XXX Document the following constructors |
| 100 |
|
| 101 |
/// @copydoc ssl_certificate |
| 102 |
PN_CPP_EXTERN ssl_certificate(const std::string &certdb_main, const std::string &certdb_extra); |
| 103 |
|
| 104 |
/// @copydoc ssl_certificate |
| 105 |
PN_CPP_EXTERN ssl_certificate(const std::string &certdb_main, const std::string &certdb_extra, const std::string &passwd); |
| 106 |
/// @endcond |
| 107 |
|
| 108 |
private: |
| 109 |
std::string certdb_main_; |
| 110 |
std::string certdb_extra_; |
| 111 |
std::string passwd_; |
| 112 |
bool pw_set_; |
| 113 |
|
| 114 |
/// @cond INTERNAL |
| 115 |
friend class ssl_client_options; |
| 116 |
friend class ssl_server_options; |
| 117 |
/// @endcond |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
/// **Unsettled API** - SSL configuration for inbound connections. |
| 123 |
class ssl_server_options { |
| 124 |
public: |
| 125 |
/// Server SSL options based on the supplied X.509 certificate |
| 126 |
/// specifier. |
| 127 |
PN_CPP_EXTERN ssl_server_options(const ssl_certificate &cert); |
| 128 |
|
| 129 |
/// Server SSL options requiring connecting clients to provide a |
| 130 |
/// client certificate. |
| 131 |
PN_CPP_EXTERN ssl_server_options(const ssl_certificate &cert, const std::string &trust_db, |
| 132 |
const std::string &advertise_db = std::string(), |
| 133 |
enum ssl::verify_mode mode = ssl::VERIFY_PEER); |
| 134 |
|
| 135 |
/// Server SSL options restricted to available anonymous cipher |
| 136 |
/// suites on the platform. |
| 137 |
PN_CPP_EXTERN ssl_server_options(); |
| 138 |
|
| 139 |
PN_CPP_EXTERN ~ssl_server_options(); |
| 140 |
PN_CPP_EXTERN ssl_server_options(const ssl_server_options&); |
| 141 |
PN_CPP_EXTERN ssl_server_options& operator=(const ssl_server_options&); |
| 142 |
|
| 143 |
private: |
| 144 |
class impl; |
| 145 |
impl* impl_; |
| 146 |
|
| 147 |
/// @cond INTERNAL |
| 148 |
friend class connection_options; |
| 149 |
/// @endcond |
| 150 |
}; |
| 151 |
|
| 152 |
/// **Unsettled API** - SSL configuration for outbound connections. |
| 153 |
class ssl_client_options { |
| 154 |
public: |
| 155 |
/// Create SSL client with defaults (use system certificate trust database and require name verification) |
| 156 |
PN_CPP_EXTERN ssl_client_options(); |
| 157 |
|
| 158 |
/// Create SSL client with unusual verification policy (but default certificate trust database) |
| 159 |
PN_CPP_EXTERN ssl_client_options(enum ssl::verify_mode); |
| 160 |
|
| 161 |
/// Create SSL client specifying the certificate trust database. |
| 162 |
PN_CPP_EXTERN ssl_client_options(const std::string &trust_db, |
| 163 |
enum ssl::verify_mode = ssl::VERIFY_PEER_NAME); |
| 164 |
|
| 165 |
/// Create SSL client with a client certificate. |
| 166 |
PN_CPP_EXTERN ssl_client_options(const ssl_certificate&, const std::string &trust_db, |
| 167 |
enum ssl::verify_mode = ssl::VERIFY_PEER_NAME); |
| 168 |
|
| 169 |
PN_CPP_EXTERN ~ssl_client_options(); |
| 170 |
PN_CPP_EXTERN ssl_client_options(const ssl_client_options&); |
| 171 |
PN_CPP_EXTERN ssl_client_options& operator=(const ssl_client_options&); |
| 172 |
|
| 173 |
private: |
| 174 |
class impl; |
| 175 |
impl* impl_; |
| 176 |
|
| 177 |
/// @cond INTERNAL |
| 178 |
friend class connection_options; |
| 179 |
/// @endcond |
| 180 |
}; |
| 181 |
|
| 182 |
} // proton |
| 183 |
|
| 184 |
#endif // PROTON_SSL_HPP |