Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Devoogdt <thomas@devoogdt.com>
To: buildroot@buildroot.org
Cc: Thomas Perale <thomas.perale@mind.be>,
	Thomas Devoogdt <thomas.devoogdt@barco.com>
Subject: [Buildroot] [PATCH] utils/generate-cyclonedx: add support for certifi ssl context
Date: Wed,  5 Mar 2025 09:56:17 +0100	[thread overview]
Message-ID: <20250305085617.911367-1-thomas.devoogdt@barco.com> (raw)

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)>

Allow to fix this by e.g. using `make host-python-certifi`.

Signed-off-by: Thomas Devoogdt <thomas.devoogdt@barco.com>
---
 utils/generate-cyclonedx | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/utils/generate-cyclonedx b/utils/generate-cyclonedx
index 33e06ea86aa..183ddf60fbd 100755
--- a/utils/generate-cyclonedx
+++ b/utils/generate-cyclonedx
@@ -18,6 +18,14 @@ import urllib.request
 import subprocess
 import sys
 
+try:
+    import certifi
+    import ssl
+
+    ssl_context = ssl.create_default_context(cafile=certifi.where())
+except ModuleNotFoundError:
+    ssl_context = None
+
 CYCLONEDX_VERSION = "1.6"
 SPDX_SCHEMA_URL = f"https://raw.githubusercontent.com/CycloneDX/specification/{CYCLONEDX_VERSION}/schema/spdx.schema.json"
 
@@ -39,7 +47,9 @@ SPDX_LICENSES = []
 if not SPDX_SCHEMA_PATH.exists():
     # Download the CycloneDX SPDX schema JSON, and cache it locally
     cyclonedxpath.mkdir(parents=True, exist_ok=True)
-    urllib.request.urlretrieve(SPDX_SCHEMA_URL, SPDX_SCHEMA_PATH)
+    with (urllib.request.urlopen(SPDX_SCHEMA_URL, context=ssl_context) as resp,
+          open(SPDX_SCHEMA_PATH, "wb") as fp):
+        fp.write(resp.read())
 
 try:
     with SPDX_SCHEMA_PATH.open() as f:
-- 
2.43.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

             reply	other threads:[~2025-03-05  8:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-05  8:56 Thomas Devoogdt [this message]
2025-03-13  9:41 ` [Buildroot] [PATCH] utils/generate-cyclonedx: add support for certifi ssl context Peter Korsgaard
2025-03-13 10:01   ` Thomas Devoogdt
2025-03-13 11:03     ` Peter Korsgaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250305085617.911367-1-thomas.devoogdt@barco.com \
    --to=thomas@devoogdt.com \
    --cc=buildroot@buildroot.org \
    --cc=thomas.devoogdt@barco.com \
    --cc=thomas.perale@mind.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox