@@ -40,8 +40,66 @@ using datastax::internal::core::UuidGen;
4040#define DSE_VERSION " 6.7.1"
4141#define DSE_CASSANDRA_VERSION " 4.0.0.671"
4242
43+ #if defined(OPENSSL_VERSION_NUMBER) && \
44+ !defined (LIBRESSL_VERSION_NUMBER) // Required as OPENSSL_VERSION_NUMBER for LibreSSL is defined
45+ // as 2.0.0
46+ #if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
47+ #define SSL_SERVER_METHOD TLS_server_method
48+ #else
49+ #define SSL_SERVER_METHOD SSLv23_server_method
50+ #endif
51+ #else
52+ #if (LIBRESSL_VERSION_NUMBER >= 0x20302000L)
53+ #define SSL_SERVER_METHOD TLS_server_method
54+ #else
55+ #define SSL_SERVER_METHOD SSLv23_server_method
56+ #endif
57+ #endif
58+
4359namespace mockssandra {
4460
61+ /*
62+ * The following function was generated using the libressl utility, using
63+ * the command : "openssl dhparam -dsaparam -C 512"
64+ */
65+ #ifdef LIBRESSL_VERSION_NUMBER
66+ #ifndef HEADER_DH_H
67+ #include < openssl/dh.h>
68+ #endif
69+ DH* get_dh512 () {
70+ static unsigned char dh512_p[] = {
71+ 0xBF , 0xA0 , 0x2D , 0x47 , 0x30 , 0xB2 , 0x81 , 0x13 , 0xEC , 0xC5 , 0xB8 , 0x79 , 0xE1 , 0x16 , 0x6F , 0x2E ,
72+ 0x19 , 0xB5 , 0xC1 , 0xE6 , 0xCE , 0x15 , 0x7E , 0x94 , 0x00 , 0x9D , 0x71 , 0x4D , 0xB9 , 0x73 , 0xC8 , 0x31 ,
73+ 0xE3 , 0xFB , 0xDF , 0x37 , 0x6A , 0x7B , 0xD6 , 0x1D , 0xA8 , 0xB3 , 0x78 , 0x7A , 0x23 , 0xE4 , 0x1D , 0x91 ,
74+ 0x34 , 0x23 , 0x74 , 0x58 , 0x96 , 0xD2 , 0x20 , 0xEC , 0x61 , 0xAC , 0x37 , 0x96 , 0x18 , 0x33 , 0xE6 , 0x05 ,
75+ };
76+ static unsigned char dh512_g[] = {
77+ 0x08 , 0x5E , 0x84 , 0x3B , 0xC2 , 0xD1 , 0xEA , 0xB9 , 0x39 , 0xFA , 0xA4 , 0x2A , 0x91 , 0x79 , 0xA3 , 0x18 ,
78+ 0x1E , 0x24 , 0x7C , 0x4C , 0x0F , 0xFD , 0x2F , 0x5C , 0x38 , 0xFB , 0xC4 , 0xA4 , 0x1B , 0xF3 , 0xE8 , 0xB7 ,
79+ 0x61 , 0x9E , 0xA1 , 0x4F , 0x8E , 0xE3 , 0xF8 , 0x4B , 0x9C , 0xA7 , 0xDD , 0xA5 , 0x72 , 0x01 , 0x17 , 0xF0 ,
80+ 0xBF , 0x65 , 0x53 , 0xAB , 0x07 , 0xFB , 0x07 , 0xF4 , 0xD8 , 0xFA , 0x4D , 0xEB , 0x1A , 0x0E , 0x29 , 0x0A ,
81+ };
82+ DH* dh;
83+
84+ if ((dh = DH_new ()) == NULL ) return (NULL );
85+ dh->p = BN_bin2bn (dh512_p, sizeof (dh512_p), NULL );
86+ dh->g = BN_bin2bn (dh512_g, sizeof (dh512_g), NULL );
87+ if ((dh->p == NULL ) || (dh->g == NULL )) {
88+ DH_free (dh);
89+ return (NULL );
90+ }
91+ dh->length = 160 ;
92+ return (dh);
93+ }
94+ /*
95+ -----BEGIN DH PARAMETERS-----
96+ MIGJAkEAv6AtRzCygRPsxbh54RZvLhm1webOFX6UAJ1xTblzyDHj+983anvWHaiz
97+ eHoj5B2RNCN0WJbSIOxhrDeWGDPmBQJACF6EO8LR6rk5+qQqkXmjGB4kfEwP/S9c
98+ OPvEpBvz6LdhnqFPjuP4S5yn3aVyARfwv2VTqwf7B/TY+k3rGg4pCgICAKA=
99+ -----END DH PARAMETERS-----
100+ */
101+ #endif
102+
45103String Ssl::generate_key () {
46104 EVP_PKEY* pkey = NULL ;
47105 EVP_PKEY_CTX* pctx = EVP_PKEY_CTX_new_id (EVP_PKEY_RSA, NULL );
@@ -374,10 +432,13 @@ bool ServerConnection::use_ssl(const String& key, const String& cert, const Stri
374432 SSL_CTX_free (ssl_context_);
375433 }
376434
377- if ((ssl_context_ = SSL_CTX_new (SSLv23_server_method ())) == NULL ) {
435+ if ((ssl_context_ = SSL_CTX_new (SSL_SERVER_METHOD ())) == NULL ) {
378436 print_ssl_error ();
379437 return false ;
380438 }
439+ #ifdef SSL_OP_NO_TLSv1_3
440+ SSL_CTX_set_options (ssl_context_, SSL_OP_NO_TLSv1_3);
441+ #endif
381442
382443 SSL_CTX_set_default_passwd_cb_userdata (ssl_context_, (void *)password.c_str ());
383444 SSL_CTX_set_default_passwd_cb (ssl_context_, on_password);
@@ -418,9 +479,28 @@ bool ServerConnection::use_ssl(const String& key, const String& cert, const Stri
418479 }
419480 EVP_PKEY_free (pkey);
420481
421- RSA* rsa = RSA_generate_key (512 , RSA_F4, NULL , NULL );
422- SSL_CTX_set_tmp_rsa (ssl_context_, rsa);
482+ #ifdef LIBRESSL_VERSION_NUMBER // SSL_CTX_set_tmp_rsa is a no-op on LibreSSL
483+ DH* dh512 = get_dh512 ();
484+ if (!SSL_CTX_set_tmp_dh (ssl_context_, dh512)) {
485+ print_ssl_error ();
486+ DH_free (dh512);
487+ return false ;
488+ }
489+ DH_free (dh512);
490+ #else
491+ BIGNUM* factor = BN_new ();
492+ BN_set_word (factor, RSA_F4);
493+ RSA* rsa = RSA_new ();
494+ RSA_generate_key_ex (rsa, 512 , factor, NULL );
495+ if (!SSL_CTX_set_tmp_rsa (ssl_context_, rsa)) {
496+ print_ssl_error ();
497+ BN_free (factor);
498+ RSA_free (rsa);
499+ return false ;
500+ }
501+ BN_free (factor);
423502 RSA_free (rsa);
503+ #endif
424504
425505 SSL_CTX_set_verify (ssl_context_, SSL_VERIFY_NONE, 0 );
426506
@@ -777,7 +857,7 @@ const char* decode_query_params_v1(const char* input, const char* end, bool is_e
777857}
778858
779859const char * decode_query_params_v2 (const char * input, const char * end, QueryParameters* params) {
780- int8_t flags;
860+ int8_t flags = 0 ;
781861 const char * pos = input;
782862 pos = decode_uint16 (pos, end, ¶ms->consistency );
783863 pos = decode_int8 (pos, end, &flags);
@@ -798,7 +878,7 @@ const char* decode_query_params_v2(const char* input, const char* end, QueryPara
798878}
799879
800880const char * decode_query_params_v3v4 (const char * input, const char * end, QueryParameters* params) {
801- int8_t flags;
881+ int8_t flags = 0 ;
802882 const char * pos = input;
803883 pos = decode_uint16 (pos, end, ¶ms->consistency );
804884 pos = decode_int8 (pos, end, &flags);
0 commit comments