diff --git a/netbox_utilities/__init__.py b/netbox_utilities/__init__.py index 76aafda..a1a0dac 100644 --- a/netbox_utilities/__init__.py +++ b/netbox_utilities/__init__.py @@ -1,6 +1,6 @@ from netbox.plugins import PluginConfig, get_plugin_config -__version__ = "0.32.0" +__version__ = "0.32.1" class NetBoxUtilitiesConfig(PluginConfig): diff --git a/netbox_utilities/software_latest.py b/netbox_utilities/software_latest.py index 67d1bd8..337df41 100644 --- a/netbox_utilities/software_latest.py +++ b/netbox_utilities/software_latest.py @@ -13,6 +13,7 @@ dependency; lookup() adds HTTP, NetBox's HTTP_PROXIES and the Django cache. import hashlib import json import re +import ssl import threading import time import urllib.error @@ -169,8 +170,20 @@ def user_agent(): return f"netbox-utilities/{__version__} (software version check)" +def ssl_context(): + """ + Certificates are verified against the system CA store, like curl and requests do. + + Python 3.13 turned on VERIFY_X509_STRICT, which rejects CA certificates of many TLS-inspecting + firewalls ("Basic Constraints of CA cert not marked critical") that the rest of the system accepts. + """ + context = ssl.create_default_context() + context.verify_flags &= ~getattr(ssl, "VERIFY_X509_STRICT", 0) + return context + + def opener(): - handlers = [] + handlers = [urllib.request.HTTPSHandler(context=ssl_context())] try: from django.conf import settings diff --git a/netbox_utilities/tests/test_software_latest.py b/netbox_utilities/tests/test_software_latest.py index 2080fed..aecd4ef 100644 --- a/netbox_utilities/tests/test_software_latest.py +++ b/netbox_utilities/tests/test_software_latest.py @@ -108,3 +108,14 @@ class FindLatestTest(SimpleTestCase): self.assertIsNone(result["latest"]) self.assertIn("endoflife.date: timeout", result["errors"]) + + +class SslContextTest(SimpleTestCase): + def test_verifies_certificates_without_strict_x509_checks(self): + import ssl + + context = latest.ssl_context() + + self.assertEqual(context.verify_mode, ssl.CERT_REQUIRED) + self.assertTrue(context.check_hostname) + self.assertFalse(context.verify_flags & getattr(ssl, "VERIFY_X509_STRICT", 0)) diff --git a/pyproject.toml b/pyproject.toml index 63aa701..7fad344 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "netbox-utilities" -version = "0.32.0" +version = "0.32.1" description = "Navigation, tenant utilities, connection VLANs, partial-width racks, disks, CPU & RAM, switch port export and bulk operations for NetBox 4.6/4.7" readme = "README.md" requires-python = ">=3.12"