فهرست منبع

Fix various OpenSSL version compatibilities.

Since 1.1.0 the library will auto initialize and on 3.x these functions are deprecated.
Use ERR_get_error instead of ERR_get_error_line_data since we don't use the extra options.
Detect if library supports SSL_OP_NO_TLSv1_1 before using.
Doug Nazar 2 سال پیش
والد
کامیت
b391bcdb8f
2فایلهای تغییر یافته به همراه22 افزوده شده و 16 حذف شده
  1. 12 8
      src/check_nrpe.c
  2. 10 8
      src/nrpe.c

+ 12 - 8
src/check_nrpe.c

@@ -855,11 +855,13 @@ void setup_ssl()
 
 	/* initialize SSL */
 	if (use_ssl == TRUE) {
+#if OPENSSL_VERSION_NUMBER < 0x10100000
 		SSL_load_error_strings();
 		SSL_library_init();
 		ENGINE_load_builtin_engines();
 		RAND_set_rand_engine(NULL);
  		ENGINE_register_all_complete();
+#endif
 
 #if OPENSSL_VERSION_NUMBER >= 0x10100000
 
@@ -952,7 +954,9 @@ void setup_ssl()
 #endif
 			case TLSv1_2:
 			case TLSv1_2_plus:
+#ifdef SSL_OP_NO_TLSv1_1
 				ssl_opts |= SSL_OP_NO_TLSv1_1;
+#endif
 			case TLSv1_1:
 			case TLSv1_1_plus:
 				ssl_opts |= SSL_OP_NO_TLSv1;
@@ -972,7 +976,7 @@ void setup_ssl()
 		if (sslprm.cert_file != NULL && sslprm.privatekey_file != NULL) {
 			if (!SSL_CTX_use_certificate_chain_file(ctx, sslprm.cert_file)) {
 				printf("Error: could not use certificate file '%s'.\n", sslprm.cert_file);
-				while ((x = ERR_get_error_line_data(NULL, NULL, NULL, NULL)) != 0) {
+				while ((x = ERR_get_error()) != 0) {
 					printf("Error: could not use certificate file '%s': %s\n", sslprm.cert_file, ERR_reason_error_string(x));
 				}
 				SSL_CTX_free(ctx);
@@ -981,7 +985,7 @@ void setup_ssl()
 			if (!SSL_CTX_use_PrivateKey_file(ctx, sslprm.privatekey_file, SSL_FILETYPE_PEM)) {
 				SSL_CTX_free(ctx);
 				printf("Error: could not use private key file '%s'.\n", sslprm.privatekey_file);
-				while ((x = ERR_get_error_line_data(NULL, NULL, NULL, NULL)) != 0) {
+				while ((x = ERR_get_error()) != 0) {
 					printf("Error: could not use private key file '%s': %s\n", sslprm.privatekey_file, ERR_reason_error_string(x));
 				}
 				SSL_CTX_free(ctx);
@@ -994,8 +998,8 @@ void setup_ssl()
 			SSL_CTX_set_verify(ctx, vrfy, verify_callback);
 			if (!SSL_CTX_load_verify_locations(ctx, sslprm.cacert_file, NULL)) {
 				printf("Error: could not use CA certificate '%s'.\n", sslprm.cacert_file);
-				while ((x = ERR_get_error_line_data(NULL, NULL, NULL, NULL)) != 0) {
-					printf("Error: could not use CA certificate '%s': %s\n", sslprm.privatekey_file, ERR_reason_error_string(x));
+				while ((x = ERR_get_error()) != 0) {
+					printf("Error: could not use CA certificate '%s': %s\n", sslprm.cacert_file, ERR_reason_error_string(x));
 				}
 				SSL_CTX_free(ctx);
 				exit(timeout_return_code);
@@ -1021,7 +1025,7 @@ void setup_ssl()
 
 		if (SSL_CTX_set_cipher_list(ctx, sslprm.cipher_list) == 0) {
 			printf("Error: Could not set SSL/TLS cipher list: %s\n", sslprm.cipher_list);
-			while ((x = ERR_get_error_line_data(NULL, NULL, NULL, NULL)) != 0) {
+			while ((x = ERR_get_error()) != 0) {
 				printf("Could not set SSL/TLS cipher list '%s': %s\n", sslprm.cipher_list, ERR_reason_error_string(x));
 			}
 			SSL_CTX_free(ctx);
@@ -1095,15 +1099,15 @@ int connect_to_remote()
 
 		if (sslprm.log_opts & (SSL_LogCertDetails | SSL_LogIfClientCert)) {
 			rc = 0;
-			while ((x = ERR_get_error_line_data(NULL, NULL, NULL, NULL)) != 0) {
-				logit(LOG_ERR, "Error: (ERR_get_error_line_data = %d), Could not complete SSL handshake with %s: %s", x, rem_host, ERR_reason_error_string(x));
+			while ((x = ERR_get_error()) != 0) {
+				logit(LOG_ERR, "Error: (ERR_get_error = 0x%08x), Could not complete SSL handshake with %s: %s", x, rem_host, ERR_reason_error_string(x));
 				++nerrs;
 			}
 			if (nerrs == 0) {
 				logit(LOG_ERR, "Error: (nerrs = 0) Could not complete SSL handshake with %s: rc=%d SSL-error=%d", rem_host, rc, ssl_err);
 			}
 		} else {
-			while ((x = ERR_get_error_line_data(NULL, NULL, NULL, NULL)) != 0) {
+			while ((x = ERR_get_error()) != 0) {
 				logit(LOG_ERR, "Error: (!log_opts) Could not complete SSL handshake with %s: %s", rem_host, ERR_reason_error_string(x));
 				++nerrs;
 			}

+ 10 - 8
src/nrpe.c

@@ -288,15 +288,14 @@ void init_ssl(void)
 	if (sslprm.log_opts & SSL_LogStartup)
 		log_ssl_startup();
 
+#if OPENSSL_VERSION_NUMBER < 0x10100000
 	/* initialize SSL */
 	SSL_load_error_strings();
 	SSL_library_init();
 	ENGINE_load_builtin_engines();
 	RAND_set_rand_engine(NULL);
  	ENGINE_register_all_complete();
-
-	meth = SSLv23_server_method();
-
+#endif
 	/* use week random seed if necessary */
 	if (allow_weak_random_seed && (RAND_status() == 0)) {
 		if (RAND_file_name(seedfile, sizeof(seedfile) - 1))
@@ -322,6 +321,7 @@ void init_ssl(void)
 
 #else		/* OPENSSL_VERSION_NUMBER >= 0x10100000 */
 
+	meth = SSLv23_server_method();
 # ifndef OPENSSL_NO_SSL2
 	if (sslprm.ssl_proto_ver == SSLv2)
 		meth = SSLv2_server_method();
@@ -410,7 +410,9 @@ void init_ssl(void)
 #endif
 		case TLSv1_2:
 		case TLSv1_2_plus:
+#ifdef SSL_OP_NO_TLSv1_1
 			ssl_opts |= SSL_OP_NO_TLSv1_1;
+#endif
 		case TLSv1_1:
 		case TLSv1_1_plus:
 			ssl_opts |= SSL_OP_NO_TLSv1;
@@ -429,7 +431,7 @@ void init_ssl(void)
 
 	if (sslprm.cacert_file != NULL) {
 		if (!SSL_CTX_load_verify_locations(ctx, sslprm.cacert_file, NULL)) {
-			while ((x = ERR_get_error_line_data(NULL, NULL, NULL, NULL)) != 0) {
+			while ((x = ERR_get_error()) != 0) {
 				logit(LOG_ERR, "Error: could not use CA certificate file '%s': %s\n",
 					   sslprm.cacert_file, ERR_reason_error_string(x));
 			}
@@ -2057,9 +2059,9 @@ int handle_conn_ssl(int sock, void *ssl_ptr)
 		if (sslprm.log_opts & (SSL_LogCertDetails | SSL_LogIfClientCert)) {
 			int nerrs = 0;
 			rc = 0;
-			while ((x = ERR_get_error_line_data(NULL, NULL, NULL, NULL)) != 0) {
+			while ((x = ERR_get_error()) != 0) {
 				errmsg = ERR_reason_error_string(x);
-				logit(LOG_ERR, "Error: (ERR_get_error_line_data = %d), Could not complete SSL handshake with %s: %s", x, remote_host, errmsg);
+				logit(LOG_ERR, "Error: (ERR_get_error = 0x%08x), Could not complete SSL handshake with %s: %s", x, remote_host, errmsg);
 				
 				if (errmsg && !strcmp(errmsg, "no shared cipher") && (sslprm.cert_file == NULL || sslprm.cacert_file == NULL))
 					logit(LOG_ERR, "Error: This could be because you have not specified certificate or ca-certificate files");
@@ -2068,10 +2070,10 @@ int handle_conn_ssl(int sock, void *ssl_ptr)
 			}
 
 			if (nerrs == 0) {
-				logit(LOG_ERR, "Error: (nerrs = 0) Could not complete SSL handshake with %s: %d", remote_host, SSL_get_error(ssl, rc));
+				logit(LOG_ERR, "Error: (nerrs = 0) Could not complete SSL handshake with %s: 0x%08x", remote_host, SSL_get_error(ssl, rc));
 			}
 		} else {
-			logit(LOG_ERR, "Error: (!log_opts) Could not complete SSL handshake with %s: %d", remote_host, SSL_get_error(ssl, rc));
+			logit(LOG_ERR, "Error: (!log_opts) Could not complete SSL handshake with %s: 0x%08x", remote_host, SSL_get_error(ssl, rc));
 		}
 # ifdef DEBUG
 		errfp = fopen("/tmp/err.log", "a");