Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
net_ssl.h
Go to the documentation of this file.
1
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2
// All rights reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
6
// * Redistributions of source code must retain the above copyright
7
// notice, this list of conditions and the following disclaimer.
8
// * Redistributions in binary form must reproduce the above copyright
9
// notice, this list of conditions and the following disclaimer in the
10
// documentation and/or other materials provided with the distribution.
11
// * Neither the name of the Andrey N. Sabelnikov nor the
12
// names of its contributors may be used to endorse or promote products
13
// derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
//
26
27
28
29
#ifndef _NET_SSL_H
30
#define _NET_SSL_H
31
32
#include <
stdint.h
>
33
#include <string>
34
#include <vector>
35
#include <boost/utility/string_ref.hpp>
36
#include <boost/asio/ip/tcp.hpp>
37
#include <boost/asio/ssl.hpp>
38
#include <boost/system/error_code.hpp>
39
40
#define SSL_FINGERPRINT_SIZE 32
41
42
namespace
epee
43
{
44
namespace
net_utils
45
{
46
enum class
ssl_support_t
:
uint8_t
{
47
e_ssl_support_disabled
,
48
e_ssl_support_enabled
,
49
e_ssl_support_autodetect
,
50
};
51
52
enum class
ssl_verification_t
:
uint8_t
53
{
54
none
= 0,
55
system_ca
,
56
user_certificates
,
57
user_ca
58
};
59
60
struct
ssl_authentication_t
61
{
62
std::string
private_key_path
;
63
std::string
certificate_path
;
64
66
void
use_ssl_certificate
(boost::asio::ssl::context &ssl_context)
const
;
67
};
68
73
class
ssl_options_t
74
{
75
// force sorted behavior in private
76
std::vector<std::vector<std::uint8_t>> fingerprints_;
77
78
public
:
79
std::string
ca_path
;
80
ssl_authentication_t
auth
;
81
ssl_support_t
support
;
82
ssl_verification_t
verification
;
83
85
ssl_options_t
(
ssl_support_t
support
)
86
: fingerprints_(),
87
ca_path
(),
88
auth
(),
89
support
(
support
),
90
verification
(
support
==
ssl_support_t
::
e_ssl_support_disabled
?
ssl_verification_t
::
none
:
ssl_verification_t
::
system_ca
)
91
{}
92
94
ssl_options_t
(std::vector<std::vector<std::uint8_t>> fingerprints, std::string
ca_path
);
95
96
ssl_options_t
(
const
ssl_options_t
&) =
default
;
97
ssl_options_t
(
ssl_options_t
&&) =
default
;
98
99
ssl_options_t
&
operator=
(
const
ssl_options_t
&) =
default
;
100
ssl_options_t
&
operator=
(
ssl_options_t
&&) =
default
;
101
103
explicit
operator
bool() const noexcept {
return
support
!=
ssl_support_t::e_ssl_support_disabled
; }
104
106
bool
has_strong_verification
(boost::string_ref host)
const
noexcept
;
107
109
bool
has_fingerprint
(boost::asio::ssl::verify_context &ctx)
const
;
110
111
boost::asio::ssl::context
create_context
()
const
;
112
131
bool
handshake
(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &socket, boost::asio::ssl::stream_base::handshake_type type,
const
std::string& host = {})
const
;
132
};
133
134
// https://security.stackexchange.com/questions/34780/checking-client-hello-for-https-classification
135
constexpr
size_t
get_ssl_magic_size
() {
return
9; }
136
bool
is_ssl
(
const
unsigned
char
*data,
size_t
len);
137
bool
ssl_support_from_string
(
ssl_support_t
&ssl, boost::string_ref s);
138
139
bool
create_ec_ssl_certificate
(EVP_PKEY *&pkey, X509 *&cert);
140
bool
create_rsa_ssl_certificate
(EVP_PKEY *&pkey, X509 *&cert);
141
}
142
}
143
144
#endif
//_NET_SSL_H
epee::net_utils::ssl_options_t::support
ssl_support_t support
Definition
net_ssl.h:81
epee::net_utils::ssl_options_t::create_context
boost::asio::ssl::context create_context() const
Definition
net_ssl.cpp:283
epee::net_utils::ssl_options_t::verification
ssl_verification_t verification
Definition
net_ssl.h:82
epee::net_utils::ssl_options_t::ca_path
std::string ca_path
Definition
net_ssl.h:79
epee::net_utils::ssl_options_t::ssl_options_t
ssl_options_t(const ssl_options_t &)=default
epee::net_utils::ssl_options_t::ssl_options_t
ssl_options_t(ssl_support_t support)
Verification is set to system ca unless SSL is disabled.
Definition
net_ssl.h:85
epee::net_utils::ssl_options_t::has_strong_verification
bool has_strong_verification(boost::string_ref host) const noexcept
\retrurn True if host can be verified using this configuration WITHOUT system "root" CAs.
Definition
net_ssl.cpp:402
epee::net_utils::ssl_options_t::operator=
ssl_options_t & operator=(const ssl_options_t &)=default
epee::net_utils::ssl_options_t::auth
ssl_authentication_t auth
Definition
net_ssl.h:80
epee::net_utils::ssl_options_t::ssl_options_t
ssl_options_t(ssl_options_t &&)=default
epee::net_utils::ssl_options_t::handshake
bool handshake(boost::asio::ssl::stream< boost::asio::ip::tcp::socket > &socket, boost::asio::ssl::stream_base::handshake_type type, const std::string &host={}) const
Definition
net_ssl.cpp:459
epee::net_utils::ssl_options_t::has_fingerprint
bool has_fingerprint(boost::asio::ssl::verify_context &ctx) const
Search against internal fingerprints. Always false if behavior() != user_certificate_check.
Definition
net_ssl.cpp:421
epee::net_utils::ssl_options_t::operator=
ssl_options_t & operator=(ssl_options_t &&)=default
epee::net_utils::ssl_verification_t
ssl_verification_t
Definition
net_ssl.h:53
epee::net_utils::ssl_verification_t::user_certificates
@ user_certificates
Verify peer via specific (non-chain) certificate(s) only.
Definition
net_ssl.h:56
epee::net_utils::ssl_verification_t::none
@ none
Do not verify peer.
Definition
net_ssl.h:54
epee::net_utils::ssl_verification_t::system_ca
@ system_ca
Verify peer via system ca only (do not inspect user certificates).
Definition
net_ssl.h:55
epee::net_utils::ssl_verification_t::user_ca
@ user_ca
Verify peer via specific (possibly chain) certificate(s) only.
Definition
net_ssl.h:57
epee::net_utils::is_ssl
bool is_ssl(const unsigned char *data, size_t len)
Definition
net_ssl.cpp:382
epee::net_utils::get_ssl_magic_size
constexpr size_t get_ssl_magic_size()
Definition
net_ssl.h:135
epee::net_utils::ssl_support_from_string
bool ssl_support_from_string(ssl_support_t &ssl, boost::string_ref s)
Definition
net_ssl.cpp:516
epee::net_utils::create_rsa_ssl_certificate
bool create_rsa_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
Definition
net_ssl.cpp:122
epee::net_utils::create_ec_ssl_certificate
bool create_ec_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
epee::net_utils::ssl_support_t
ssl_support_t
Definition
net_ssl.h:46
epee::net_utils::ssl_support_t::e_ssl_support_disabled
@ e_ssl_support_disabled
Definition
net_ssl.h:47
epee::net_utils::ssl_support_t::e_ssl_support_autodetect
@ e_ssl_support_autodetect
Definition
net_ssl.h:49
epee::net_utils::ssl_support_t::e_ssl_support_enabled
@ e_ssl_support_enabled
Definition
net_ssl.h:48
epee
Definition
ado_db_helper.h:67
stdint.h
uint8_t
unsigned char uint8_t
Definition
stdint.h:124
epee::net_utils::ssl_authentication_t
Definition
net_ssl.h:61
epee::net_utils::ssl_authentication_t::certificate_path
std::string certificate_path
Certificate used for authentication to peer.
Definition
net_ssl.h:63
epee::net_utils::ssl_authentication_t::private_key_path
std::string private_key_path
Private key used for authentication.
Definition
net_ssl.h:62
epee::net_utils::ssl_authentication_t::use_ssl_certificate
void use_ssl_certificate(boost::asio::ssl::context &ssl_context) const
Load private_key_path and certificate_path into ssl_context.
Definition
net_ssl.cpp:376
contrib
epee
include
net
net_ssl.h
Generated on
for Electroneum by
1.17.0