Skip to content

Commit

Permalink
Update the AppleTrustStoreFetcher to support Apple's November 2024 si…
Browse files Browse the repository at this point in the history
…te changes.

* New index page url.
* Changed section headers.
* Support relative urls.
  • Loading branch information
rajiv committed Nov 18, 2024
1 parent 068c8db commit dd93b02
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions trust_stores_observatory/store_fetcher/apple_store_fetcher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from typing import Tuple, List
from urllib.request import urlopen
from urllib.parse import urljoin
from bs4 import BeautifulSoup
from datetime import datetime

Expand All @@ -18,7 +19,7 @@

class AppleTrustStoreFetcher(StoreFetcherInterface):

_INDEX_PAGE_URL = "https://support.apple.com/en-us/HT209143"
_INDEX_PAGE_URL = "https://support.apple.com/en-us/103272"

def fetch(self, certs_repo: RootCertificatesRepository, should_update_repo: bool = True) -> TrustStore:
# First find the latest page with the list of root certificates
Expand All @@ -34,7 +35,7 @@ def fetch(self, certs_repo: RootCertificatesRepository, should_update_repo: bool
parsed_trusted_certs: List[ScrapedRootCertificateRecord] = []
parsed_blocked_certs: List[ScrapedRootCertificateRecord] = []
for h2_section in parsed_page.find_all("h2"):
if "Trusted certificates" in h2_section:
if "Included Root CA Certificates" in h2_section:
parsed_trusted_certs = self._parse_root_records_in_div(h2_section.parent)
elif "Blocked certificates" in h2_section:
parsed_blocked_certs = self._parse_root_records_in_div(h2_section.parent)
Expand Down Expand Up @@ -81,11 +82,12 @@ def _find_latest_root_certificates_page(cls) -> Tuple[str, str]:
parsed_page = BeautifulSoup(page_content, "html.parser")

# The page contains links to the root certificates page for each version of iOS/macOS - find the latest one
section_current = parsed_page.find("h2", text="Current Trust Store").parent
section_current = parsed_page.find("h2", text="Current Root Store").parent
for p_tag in section_current.find_all("p"):
if "List of available trusted root certificates in" in p_tag.text:
os_and_version = p_tag.text.split("List of available trusted root certificates in")[1].strip()
trust_store_url = p_tag.a["href"]
if "List of available root certificates in" in p_tag.text:
os_and_version = p_tag.text.split("List of available root certificates in")[1].strip()
trust_store_path = p_tag.a["href"]
trust_store_url = urljoin(cls._INDEX_PAGE_URL, trust_store_path)
return os_and_version, trust_store_url

raise ValueError(f"Could not find the store URL at {cls._INDEX_PAGE_URL}")

0 comments on commit dd93b02

Please sign in to comment.