Blame SOURCES/bz1963163-fence_zvmip-add-ssl-tls-support.patch

021bc5
From 81be3c529ec1165f3135b4f14fbec2a19403cfbe Mon Sep 17 00:00:00 2001
021bc5
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
021bc5
Date: Fri, 27 Aug 2021 08:53:36 +0200
021bc5
Subject: [PATCH] fence_zvmip: add ssl/tls support
021bc5
021bc5
---
021bc5
 agents/zvm/fence_zvmip.py           | 20 ++++++++++++++++----
021bc5
 tests/data/metadata/fence_zvmip.xml | 19 +++++++++++++++++++
021bc5
 2 files changed, 35 insertions(+), 4 deletions(-)
021bc5
021bc5
diff --git a/agents/zvm/fence_zvmip.py b/agents/zvm/fence_zvmip.py
021bc5
index 001106a44..874eb699f 100644
021bc5
--- a/agents/zvm/fence_zvmip.py
021bc5
+++ b/agents/zvm/fence_zvmip.py
021bc5
@@ -26,12 +26,22 @@ def open_socket(options):
021bc5
 	except socket.gaierror:
021bc5
 		fail(EC_LOGIN_DENIED)
021bc5
 
021bc5
-	conn = socket.socket()
021bc5
+	if "--ssl" in options:
021bc5
+		import ssl
021bc5
+		sock = socket.socket()
021bc5
+		sslcx = ssl.create_default_context()
021bc5
+		if "--ssl-insecure" in options:
021bc5
+			sslcx.check_hostname = False
021bc5
+			sslcx.verify_mode = ssl.CERT_NONE
021bc5
+		conn = sslcx.wrap_socket(sock, server_hostname=options["--ip"])
021bc5
+	else:
021bc5
+		conn = socket.socket()
021bc5
 	conn.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
021bc5
 	conn.settimeout(float(options["--shell-timeout"]) or None)
021bc5
 	try:
021bc5
 		conn.connect(addr)
021bc5
-	except socket.error:
021bc5
+	except socket.error as e:
021bc5
+		logging.debug(e)
021bc5
 		fail(EC_LOGIN_DENIED)
021bc5
 
021bc5
 	return conn
021bc5
@@ -122,11 +132,12 @@ def get_list_of_images(options, command, data_as_plug):
021bc5
 	images = set()
021bc5
 
021bc5
 	if output_len > 3*INT4:
021bc5
+		recvflag = socket.MSG_WAITALL if "--ssl" not in options else 0
021bc5
 		array_len = struct.unpack("!i", conn.recv(INT4))[0]
021bc5
 		data = ""
021bc5
 
021bc5
 		while True:
021bc5
-			read_data = conn.recv(1024, socket.MSG_WAITALL).decode("UTF-8")
021bc5
+			read_data = conn.recv(1024, recvflag).decode("UTF-8")
021bc5
 			data += read_data
021bc5
 			if array_len == len(data):
021bc5
 				break
021bc5
@@ -146,7 +157,8 @@ def get_list_of_images(options, command, data_as_plug):
021bc5
 	return (return_code, reason_code, images)
021bc5
 
021bc5
 def main():
021bc5
-	device_opt = ["ipaddr", "login", "passwd", "port", "method", "missing_as_off", "inet4_only", "inet6_only"]
021bc5
+	device_opt = ["ipaddr", "login", "passwd", "port", "method", "missing_as_off",
021bc5
+		      "inet4_only", "inet6_only", "ssl"]
021bc5
 
021bc5
 	atexit.register(atexit_handler)
021bc5
 
021bc5
diff --git a/tests/data/metadata/fence_zvmip.xml b/tests/data/metadata/fence_zvmip.xml
021bc5
index f84115c08..d91192946 100644
021bc5
--- a/tests/data/metadata/fence_zvmip.xml
021bc5
+++ b/tests/data/metadata/fence_zvmip.xml
021bc5
@@ -91,6 +91,21 @@ to access the system's directory manager.
021bc5
 		<content type="string"  />
021bc5
 		<shortdesc lang="en">Physical plug number on device, UUID or identification of machine</shortdesc>
021bc5
 	</parameter>
021bc5
+	<parameter name="ssl" unique="0" required="0">
021bc5
+		<getopt mixed="-z, --ssl" />
021bc5
+		<content type="boolean"  />
021bc5
+		<shortdesc lang="en">Use SSL connection with verifying certificate</shortdesc>
021bc5
+	</parameter>
021bc5
+	<parameter name="ssl_insecure" unique="0" required="0">
021bc5
+		<getopt mixed="--ssl-insecure" />
021bc5
+		<content type="boolean"  />
021bc5
+		<shortdesc lang="en">Use SSL connection without verifying certificate</shortdesc>
021bc5
+	</parameter>
021bc5
+	<parameter name="ssl_secure" unique="0" required="0">
021bc5
+		<getopt mixed="--ssl-secure" />
021bc5
+		<content type="boolean"  />
021bc5
+		<shortdesc lang="en">Use SSL connection with verifying certificate</shortdesc>
021bc5
+	</parameter>
021bc5
 	<parameter name="username" unique="0" required="1" obsoletes="login">
021bc5
 		<getopt mixed="-l, --username=[name]" />
021bc5
 		<content type="string"  />
021bc5
@@ -181,6 +196,10 @@ to access the system's directory manager.
021bc5
 		<content type="integer" default="1"  />
021bc5
 		<shortdesc lang="en">Count of attempts to retry power on</shortdesc>
021bc5
 	</parameter>
021bc5
+	<parameter name="gnutlscli_path" unique="0" required="0">
021bc5
+		<getopt mixed="--gnutlscli-path=[path]" />
021bc5
+		<shortdesc lang="en">Path to gnutls-cli binary</shortdesc>
021bc5
+	</parameter>
021bc5
 </parameters>
021bc5
 <actions>
021bc5
 	<action name="on" automatic="0"/>