From f426283e103b2b799722f36ae49003bc71e929f1 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 27 Nov 2026 11:29:44 +0100 Subject: [PATCH] fix: accept firewall CA certificates in the online version check Python 3.13 enables VERIFY_X509_STRICT, which rejects CA certificates of TLS-inspecting firewalls ("Basic Constraints of CA cert not marked critical") that curl and requests accept. The version check still verifies certificates and host names against the system CA store, only without the strict X.509 checks. Co-Authored-By: Claude Opus 5.5 --- netbox_utilities/__init__.py | 2 +- netbox_utilities/software_latest.py | 15 ++++++++++++++- netbox_utilities/tests/test_software_latest.py | 11 +++++++++++ pyproject.toml | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) 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"