7
SSL_CTX *netdata_srv_ctx=NULL;
8
const char *security_key=NULL;
9
const char *security_cert=NULL;
10
+const char *tls_version=NULL;
11
+const char *tls_ciphers=NULL;
12
int netdata_validate_server = NETDATA_SSL_VALID_CERTIFICATE;
13
14
/**
34
*/
35
void security_openssl_library()
36
{
35
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
36
-# if (SSLEAY_VERSION_NUMBER >= 0x0907000L)
37
+#if OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_110
38
+# if (SSLEAY_VERSION_NUMBER >= OPENSSL_VERSION_097)
39
OPENSSL_config(NULL);
40
# endif
41
40
-# if OPENSSL_API_COMPAT < 0x10100000L
42
SSL_load_error_strings();
42
-# endif
43
44
SSL_library_init();
45
#else
49
#endif
50
}
51
52
+#if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_110
53
+/**
54
+ * TLS version
55
+ *
56
+ * Returns the TLS version depending of the user input.
57
+ *
58
+ * @param lversion is the user input.
59
+ *
60
+ * @return it returns the version number.
61
+ */
62
+int tls_select_version(const char *lversion) {
63
+ if (!strcmp(lversion, "1") || !strcmp(lversion, "1.0"))
64
+ return TLS1_VERSION;
65
+ else if (!strcmp(lversion, "1.1"))
66
+ return TLS1_1_VERSION;
67
+ else if (!strcmp(lversion, "1.2"))
68
+ return TLS1_2_VERSION;
69
+#if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_111
70
+ else if (!strcmp(lversion, "1.3"))
71
+ return TLS1_3_VERSION;
72
+#endif
73
+
74
+ return TLS_MAX_VERSION;
75
+}
76
+#endif
77
+
78
/**
79
* OpenSSL common options
80
*
81
* Clients and SERVER have common options, this function is responsible to set them in the context.
82
*
57
- * @param ctx
83
+ * @param ctx the initialized SSL context.
84
+ * @param side 0 means server, and 1 client.
85
*/
59
-void security_openssl_common_options(SSL_CTX *ctx) {
60
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
61
- static char *ciphers = {"ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA"};
86
+void security_openssl_common_options(SSL_CTX *ctx, int side) {
87
+#if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_110
88
+ if (!side) {
89
+ int version = tls_select_version(tls_version) ;
90
#endif
63
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
64
- SSL_CTX_set_options (ctx,SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_COMPRESSION);
91
+#if OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_110
92
+ SSL_CTX_set_options (ctx,SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_COMPRESSION);
93
#else
66
- SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
67
- //We are avoiding the TLS v1.3 for while, because Google Chrome
68
- //is giving the message net::ERR_SSL_VERSION_INTERFERENCE with it.
69
- SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION);
70
-#endif
71
- SSL_CTX_set_mode(ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
94
+ SSL_CTX_set_min_proto_version(ctx, TLS1_VERSION);
95
+ SSL_CTX_set_max_proto_version(ctx, version);
96
73
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
74
- if (!SSL_CTX_set_cipher_list(ctx, ciphers)) {
75
- error("SSL error. cannot set the cipher list");
97
+ if(tls_ciphers && strcmp(tls_ciphers, "none") != 0) {
98
+ if (!SSL_CTX_set_cipher_list(ctx, tls_ciphers)) {
99
+ error("SSL error. cannot set the cipher list");
100
+ }
101
+ }
102
}
103
#endif
104
+
105
+ SSL_CTX_set_mode(ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
106
}
107
108
/**
114
*/
115
SSL_CTX * security_initialize_openssl_client() {
116
SSL_CTX *ctx;
89
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
117
+#if OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_110
118
ctx = SSL_CTX_new(SSLv23_client_method());
119
#else
120
ctx = SSL_CTX_new(TLS_client_method());
121
#endif
122
if(ctx) {
95
- security_openssl_common_options(ctx);
123
+ security_openssl_common_options(ctx, 1);
124
}
125
126
return ctx;
139
static int netdata_id_context = 1;
140
141
//TO DO: Confirm the necessity to check return for other OPENSSL function
114
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
142
+#if OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_110
143
ctx = SSL_CTX_new(SSLv23_server_method());
144
if (!ctx) {
145
error("Cannot create a new SSL context, netdata won't encrypt communication");
156
157
SSL_CTX_use_certificate_chain_file(ctx, security_cert);
158
#endif
131
- security_openssl_common_options(ctx);
159
+ security_openssl_common_options(ctx, 0);
160
161
SSL_CTX_use_PrivateKey_file(ctx,security_key,SSL_FILETYPE_PEM);
162
170
SSL_CTX_set_session_id_context(ctx,(void*)&netdata_id_context,(unsigned int)sizeof(netdata_id_context));
171
SSL_CTX_set_info_callback(ctx,security_info_callback);
172
145
-#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
173
+#if (OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_095)
174
SSL_CTX_set_verify_depth(ctx,1);
175
#endif
176
debug(D_WEB_CLIENT,"SSL GLOBAL CONTEXT STARTED\n");
235
SSL_CTX_free(netdata_opentsdb_ctx);
236
}
237
210
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
238
+#if OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_110
239
ERR_free_strings();
240
#endif
241
}