From d6a13e183be29a0ef5677d4715418d6d3637eb12 Mon Sep 17 00:00:00 2001 From: edenbr Date: Sun, 17 Apr 2022 16:22:44 +0300 Subject: [PATCH 1/3] Add sg file --- examples_python2/add_simple_gateway.py | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples_python2/add_simple_gateway.py diff --git a/examples_python2/add_simple_gateway.py b/examples_python2/add_simple_gateway.py new file mode 100644 index 0000000..1e9c0f9 --- /dev/null +++ b/examples_python2/add_simple_gateway.py @@ -0,0 +1,57 @@ +from __future__ import print_function + +# A package for reading passwords without displaying them on the console. +import argparse +import getpass + +import sys, os +import time + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +# cpapi is a library that handles the communication with the Check Point management server. +from cpapi import APIClient, APIClientArgs, APIResponse + + +def main(usera="python-api-wrapper"): + + client_args = APIClientArgs(server="172.23.3.10", port=443, user_agent=usera) + + with APIClient(client_args) as client: + + if client.check_fingerprint() is False: + print("Could not get the server's fingerprint - Check connectivity with the server.") + exit(1) + + # login to server: + login_res = client.login_as_root() + + if login_res.success is False: + print("Login failed:\n{}".format(login_res.error_message)) + exit(1) + else: + print("Logged in kululu") + start = time.time() + res = client.api_call("show-session") + end = time.time() - start + if res.success is True: + + print("The script has been executed successfully in "+ str(end)+"seconds") + + # publish the result + publish_res = client.api_call("publish", {}) + if publish_res.success: + for call in client_args.api_calls: + print(call) + else: + print("Failed to publish the changes.") + else: + print("Failed to run: Error:\n{}".format(res.error_message)) + + +if __name__ == "__main__": + if len(sys.argv)>1: + usera = sys.argv[1] + main(usera) + else: + main() From 212697f900c634ed09efff0f5c64300e4a35b170 Mon Sep 17 00:00:00 2001 From: edenbr Date: Mon, 25 Apr 2022 16:12:24 +0300 Subject: [PATCH 2/3] Revert "Add sg file" This reverts commit 726298c13acc2f51fccda85035d2b56c23ef4f4f. --- examples_python2/add_simple_gateway.py | 57 -------------------------- 1 file changed, 57 deletions(-) delete mode 100644 examples_python2/add_simple_gateway.py diff --git a/examples_python2/add_simple_gateway.py b/examples_python2/add_simple_gateway.py deleted file mode 100644 index 1e9c0f9..0000000 --- a/examples_python2/add_simple_gateway.py +++ /dev/null @@ -1,57 +0,0 @@ -from __future__ import print_function - -# A package for reading passwords without displaying them on the console. -import argparse -import getpass - -import sys, os -import time - -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) - -# cpapi is a library that handles the communication with the Check Point management server. -from cpapi import APIClient, APIClientArgs, APIResponse - - -def main(usera="python-api-wrapper"): - - client_args = APIClientArgs(server="172.23.3.10", port=443, user_agent=usera) - - with APIClient(client_args) as client: - - if client.check_fingerprint() is False: - print("Could not get the server's fingerprint - Check connectivity with the server.") - exit(1) - - # login to server: - login_res = client.login_as_root() - - if login_res.success is False: - print("Login failed:\n{}".format(login_res.error_message)) - exit(1) - else: - print("Logged in kululu") - start = time.time() - res = client.api_call("show-session") - end = time.time() - start - if res.success is True: - - print("The script has been executed successfully in "+ str(end)+"seconds") - - # publish the result - publish_res = client.api_call("publish", {}) - if publish_res.success: - for call in client_args.api_calls: - print(call) - else: - print("Failed to publish the changes.") - else: - print("Failed to run: Error:\n{}".format(res.error_message)) - - -if __name__ == "__main__": - if len(sys.argv)>1: - usera = sys.argv[1] - main(usera) - else: - main() From ef1dbfaac5e83a863ea32fc36e629502986f5b93 Mon Sep 17 00:00:00 2001 From: edenbr Date: Mon, 27 Nov 2023 14:13:59 +0200 Subject: [PATCH 3/3] Python 3.12 ssl compatibility fix --- cpapi/mgmt_api.py | 6 +++--- setup.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpapi/mgmt_api.py b/cpapi/mgmt_api.py index 9a6a834..83d2396 100644 --- a/cpapi/mgmt_api.py +++ b/cpapi/mgmt_api.py @@ -748,8 +748,8 @@ def read_fingerprint_from_file(server, filename="fingerprints.txt"): return "" def create_https_connection(self): - context = ssl.create_default_context() - context.check_hostname = True + context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS) + context.verify_mode = ssl.CERT_NONE # create https connection if self.proxy_host and self.proxy_port: conn = HTTPSConnection(self.proxy_host, self.proxy_port, context=context) @@ -784,7 +784,7 @@ class HTTPSConnection(http_client.HTTPSConnection): """ def connect(self): http_client.HTTPConnection.connect(self) - self.sock = ssl.wrap_socket(self.sock, self.key_file, self.cert_file, cert_reqs=ssl.CERT_NONE) + self.sock = self._context.wrap_socket(self.sock, server_hostname=self.host) def get_fingerprint_hash(self): if self.sock is None: diff --git a/setup.py b/setup.py index b274b14..9b5a5b1 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="cp-mgmt-api-sdk", - version="1.7.0", + version="1.8.0", author="API team", author_email="api_team@checkpoint.com", license='Apache 2.0',