forked from mariadb-corporation/MaxScale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssl.hh
125 lines (107 loc) · 2.73 KB
/
ssl.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (c) 2018 MariaDB Corporation Ab
* Copyright (c) 2023 MariaDB plc, Finnish Branch
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2025-09-12
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#pragma once
/**
* @file ssl.hh
*
* The SSL definitions for MaxScale
*/
#include <maxscale/ccdefs.hh>
#include <memory>
#include <openssl/crypto.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/dh.h>
#include <maxbase/ssl.hh>
#include <maxscale/modinfo.hh>
class DCB;
namespace maxscale
{
class ConfigParameters;
}
/**
* Return codes for SSL authentication checks
*/
#define SSL_AUTH_CHECKS_OK 0
#define SSL_ERROR_CLIENT_NOT_SSL 1
#define SSL_ERROR_ACCEPT_FAILED 2
namespace maxscale
{
/**
* Verify a private key and certificate
*
* @param cert_file Public certificate
* @param key_file Private key
*
* @return True if the keys are valid can can be loaded into OpenSSL
*/
bool verify_key_pair(const std::string& cert_file, const std::string& key_file);
/**
* The SSLContext is used to aggregate the SSL configuration and data for a particular object.
*/
class SSLContext
{
public:
SSLContext() = default;
SSLContext(SSLContext&&) noexcept;
SSLContext& operator=(SSLContext&& rhs) noexcept;
SSLContext& operator=(SSLContext&) = delete;
SSLContext(SSLContext&) = delete;
~SSLContext();
/**
* Create a new SSL context
*
* @param params SSL configuration from which the SSLContext is created from
*
* @return A new SSL context or nullptr on error
*/
static std::unique_ptr<SSLContext> create(const mxb::SSLConfig& config);
/**
* Opens a new OpenSSL session for this configuration context
*/
SSL* open() const
{
return SSL_new(m_ctx);
}
// SSL configuration
const mxb::SSLConfig& config() const
{
return m_cfg;
}
bool valid() const
{
return m_ctx;
}
/**
* Configure the SSLContext
*
* @param params Configuration parameters
*
* @return True on success
*/
bool configure(const mxb::SSLConfig& config);
void set_usage(mxb::KeyUsage usage)
{
m_usage = usage;
}
private:
void reset();
bool init();
SSL_CTX* m_ctx {nullptr};
SSL_METHOD* m_method {nullptr}; /**< SSLv3 or TLS1.0/1.1/1.2 methods
* see: https://www.openssl.org/docs/ssl/SSL_CTX_new.html */
mxb::SSLConfig m_cfg;
mxb::KeyUsage m_usage {mxb::KeyUsage::NONE};
};
}