Skip to content

Commit c80d13a

Browse files
authoredFeb 15, 2024··
Fetch all Git certs and prefer them (#545)
1 parent be45c87 commit c80d13a

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed
 

‎matter_server/server/helpers/paa_certificates.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
from matter_server.server.const import PAA_ROOT_CERTS_DIR
2020

21+
# Git repo details
22+
OWNER = "project-chip"
23+
REPO = "connectedhomeip"
24+
PATH = "credentials/development/paa-root-certs"
25+
2126
LOGGER = logging.getLogger(__name__)
2227
PRODUCTION_URL = "https://on.dcl.csa-iot.org"
2328
TEST_URL = "https://on.test-net.dcl.csa-iot.org"
24-
GIT_URL = "https://github.com/project-chip/connectedhomeip/raw/master/credentials/development/paa-root-certs" # pylint: disable=line-too-long
25-
GIT_CERTS = [
26-
"Chip-Test-PAA-FFF1-Cert",
27-
"Chip-Test-PAA-NoVID-Cert",
28-
]
29+
GIT_URL = f"https://raw.githubusercontent.com/{OWNER}/{REPO}/master/{PATH}"
30+
31+
2932
LAST_CERT_IDS: set[str] = set()
3033

3134

@@ -66,13 +69,13 @@ async def fetch_dcl_certificates(
6669
base_urls = set()
6770
# determine which url's need to be queried.
6871
# if we're going to fetch both prod and test, do test first
69-
# so any duplicates will be overwritten/preferred by the production version
72+
# so any duplicates will be overwritten/preferred by the production version.
73+
7074
# NOTE: While Matter is in BETA we fetch the test certificates by default
7175
if fetch_test_certificates:
7276
base_urls.add(TEST_URL)
7377
if fetch_production_certificates:
7478
base_urls.add(PRODUCTION_URL)
75-
7679
try:
7780
async with ClientSession(raise_for_status=True) as http_session:
7881
for url_base in base_urls:
@@ -113,16 +116,27 @@ async def fetch_dcl_certificates(
113116
return fetch_count
114117

115118

119+
# Manufacturers release test certificates through the SDK (Git) as a part
120+
# of their standard product release workflow. This will ensure those certs
121+
# are correctly captured
122+
123+
116124
async def fetch_git_certificates() -> int:
117125
"""Fetch Git PAA Certificates."""
118126
fetch_count = 0
119127
LOGGER.info("Fetching the latest PAA root certificates from Git.")
128+
120129
try:
121130
async with ClientSession(raise_for_status=True) as http_session:
122-
for cert in GIT_CERTS:
131+
# Fetch directory contents and filter out extension
132+
api_url = f"https://api.github.com/repos/{OWNER}/{REPO}/contents/{PATH}"
133+
async with http_session.get(api_url, timeout=20) as response:
134+
contents = await response.json()
135+
git_certs = {item["name"].split(".")[0] for item in contents}
136+
# Fetch certificates
137+
for cert in git_certs:
123138
if cert in LAST_CERT_IDS:
124139
continue
125-
126140
async with http_session.get(f"{GIT_URL}/{cert}.pem") as response:
127141
certificate = await response.text()
128142
await write_paa_root_cert(certificate, cert)

0 commit comments

Comments
 (0)
Please sign in to comment.