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

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