Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dm/net/nextendo-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"provider": {
"server": "51.178.29.194",
"nat": "164.132.111.120",
"caURL": "https://git.nextendo.network/NextendoNetwork/Prelude-Nextendo/raw/commit/482c182917228d69ebbbabfea44fffa4a44051be/romfs/sd/rootCA.pem",
"caURL": "https://git.nextendo.network/api/v1/repos/NextendoNetwork/Prelude-Nextendo/raw/romfs/sd/rootCA.pem?ref=482c182917228d69ebbbabfea44fffa4a44051be",
"caSHA256": "a654c0eff8aa20a72280ea0ef2b5c2a17392922dd78ffbb113862e1ad2c66d49"
},
"base": [
Expand Down
12 changes: 9 additions & 3 deletions dm/tools/nextendo_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@ def contract(repository):
return value


class _NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
return None


def provider_ca(value):
cache = Path.home() / 'Library/Application Support/nxnative/nextendo/public-provider-ca.der'
if cache.is_file() and not cache.is_symlink() and cache.stat().st_size <= 65536:
data = cache.read_bytes()
if hashlib.sha256(data).hexdigest() == value['provider']['caSHA256']: return data
url = value['provider']['caURL']
# Nextendo's own Git server, where Prelude-Nextendo moved from GitHub (the old raw.githubusercontent.com address is 404); the SHA-256 below is the trust, not the host
if not url.startswith('https://git.nextendo.network/NextendoNetwork/Prelude-Nextendo/raw/commit/'):
# The web UI's raw link can return 403; the API serves the same file at the pinned revision. The SHA-256 below is the trust, not the host.
if not re.fullmatch(r'https://git\.nextendo\.network/api/v1/repos/NextendoNetwork/Prelude-Nextendo/raw/'
r'romfs/sd/rootCA\.pem\?ref=[0-9a-f]{40}', url):
raise ValueError('The provider CA must come from its official source')
request = urllib.request.Request(url, headers={'User-Agent': 'nxnative'})
with urllib.request.urlopen(request, timeout=15) as response: encoded = response.read(65537)
with urllib.request.build_opener(_NoRedirect).open(request, timeout=15) as response: encoded = response.read(65537)
if len(encoded) > 65536: raise ValueError('Provider CA exceeds its bounds')
match = re.fullmatch(rb'\s*-----BEGIN CERTIFICATE-----\s*([A-Za-z0-9+/=\r\n]+)\s*-----END CERTIFICATE-----\s*', encoded)
if not match: raise ValueError('Expected exactly one public provider certificate')
Expand Down
41 changes: 41 additions & 0 deletions dm/tools/tests/test_nextendo_services.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""Public Nextendo service profiles (dm/tools/nextendo_services.py), after NX-Port-Studio's test (MIT); no account state, no network."""
import base64
from email.message import Message
import hashlib
import importlib.util
import io
import json
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
from urllib.error import HTTPError

REPO = Path(__file__).resolve().parents[3]
spec = importlib.util.spec_from_file_location('nextendo_services', REPO / 'dm/tools/nextendo_services.py')
Expand All @@ -15,6 +19,43 @@


class NextendoServicesTests(unittest.TestCase):
def test_empty_cache_uses_the_pinned_raw_api(self):
value = n.contract(REPO)
self.assertEqual(value['provider']['caSHA256'], 'a654c0eff8aa20a72280ea0ef2b5c2a17392922dd78ffbb113862e1ad2c66d49')
url = ('https://git.nextendo.network/api/v1/repos/NextendoNetwork/Prelude-Nextendo/raw/'
'romfs/sd/rootCA.pem?ref=482c182917228d69ebbbabfea44fffa4a44051be')
der = b'synthetic public CA bytes'
encoded = b'-----BEGIN CERTIFICATE-----\n' + base64.b64encode(der) + b'\n-----END CERTIFICATE-----\n'

def fetch(request, timeout):
if request.full_url != url:
with HTTPError(request.full_url, 403, 'Forbidden', Message(), io.BytesIO()) as error:
raise error
self.assertEqual(timeout, 15)
return io.BytesIO(encoded)

with tempfile.TemporaryDirectory() as folder, patch.object(n.Path, 'home', return_value=Path(folder)):
with (patch.object(n.urllib.request, 'urlopen', side_effect=fetch),
patch.object(n.urllib.request.OpenerDirector, 'open', side_effect=fetch) as opened):
with self.assertRaisesRegex(ValueError, 'integrity check failed'): n.provider_ca(value)
value['provider']['caSHA256'] = hashlib.sha256(der).hexdigest()
self.assertEqual(n.provider_ca(value), der)
self.assertEqual(n.provider_ca(value), der)
self.assertEqual(opened.call_count, 2)

def test_ca_redirect_is_not_followed(self):
value = n.contract(REPO)
headers = Message()
headers['Location'] = 'https://outside.invalid/other.pem'
with HTTPError(value['provider']['caURL'], 302, 'Found', headers, io.BytesIO()) as redirect:
with (tempfile.TemporaryDirectory() as folder, patch.object(n.Path, 'home', return_value=Path(folder)),
patch.object(n.urllib.request.HTTPSHandler, 'https_open', return_value=redirect) as opened,
self.assertRaises(HTTPError) as failure):
n.provider_ca(value)
self.assertEqual(failure.exception.code, 302)
failure.exception.close()
self.assertEqual(opened.call_count, 1)

def test_shared_families_and_title_scoped_services(self):
value = n.contract(REPO)
self.assertIn('suffix\tdemonware.net\t', n.rules(value, '01001b300b9be000'))
Expand Down
1 change: 1 addition & 0 deletions docs/agents/symptoms.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
- the JPEG icon in a NUP is written as `control.nacp` and the display version is written as `icon.jpg`. A wrong-size NACP can also supply incorrect application and DLC IDs during scanning. → [A NUP icon is written as control data](../reference/packing.md#a-nup-icon-is-written-as-control-data)
- `[RED] <file>.nup: 2 base packages`, `base program ID 040015100B514001 is not a base title ID`, or `010015100B515001 is not a DLC of 040015100B514001`, from a NUP of a Switch 1 game's Nintendo Switch 2 Edition (PR #2692). Packed by hand on its own RomFS, the Switch 2 program crashed within a second of `nnMain` on a null `this` in a constructor: with no heap sizes the engine's heaps were never made. With an add-on older than the program: `[RED] game asks to show an error: its upgrade add-on content is older than this program needs`, then `CRASH sig=4` at the game's own trap (before the hook, a crash in `sdk` under `nn::applet::StartLibraryAppletImmediately`). → [A Switch 2 Edition NUP stops at "2 base packages" or "is not a base title ID"](../reference/packing.md#a-switch-2-edition-nup-stops-at-2-base-packages-or-is-not-a-base-title-id)
- the survey of a Switch 2 game says `SDK: ?` and `no SDK version string found`, and its provisional profile has `app_pool 0xCD500000`. → [A provisional profile of a Switch 2 game shows no SDK and a Switch 1 memory pool](../reference/packing.md#a-provisional-profile-of-a-switch-2-game-shows-no-sdk-and-a-switch-1-memory-pool)
- a Nextendo build with no cached provider CA stops while preparing its service profile with `HTTP Error 403: Forbidden`. → [An uncached Nextendo CA download returns HTTP 403](../reference/packing.md#an-uncached-nextendo-ca-download-returns-http-403)
- after the NSP script was stopped in Spyder (its interrupt), or by a front end's SIGTERM, the tool it was running went on: a shader build or `build_ipa.sh`'s `xcodebuild` kept the CPU busy and wrote into the build folder that the next build reads, and the script could wait for it with no end. A regression run (`regress.py`) stopped during a shader build whose direct child ignored SIGTERM for 10 s left the build's workers running. A tool's child still writing after the tool's own exit was taken for a finished step. → [Stopping a build left its tools running](../reference/packing.md#stopping-a-build-left-its-tools-running)
- after the terminal running the NSP script or `regress.py` was closed, the tool the script was running (a shader build, `xcodebuild`, a game under the harness) went on running with no parent, writing into the build folder; the script itself had gone without its cleanup. → [Closing the terminal left a build's tools running](../reference/packing.md#closing-the-terminal-left-a-builds-tools-running)
- none seen on a game. An interrupt, a SIGTERM or a failed delete while the NSP script replaced one of its outputs (an extraction, the rewritten modules, the NROs, a DLC folder, a shader capture, the shader package) could leave that output half deleted at its real path, and a reuse check that looks for a few files (`extract`'s: `ExeFS/main`, `RomFS.img`, the RomFS marker) could take it for a finished output on the next run. → [Stopping a build while it replaced an output left that output half deleted](../reference/packing.md#stopping-a-build-while-it-replaced-an-output-left-that-output-half-deleted)
Expand Down
7 changes: 7 additions & 0 deletions docs/reference/packing.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@

## Build tools

### An uncached Nextendo CA download returns HTTP 403

- **Symptom:** a Nextendo build with no cached provider CA stops while preparing its service profile with `HTTP Error 403: Forbidden`.
- **Cause:** the Git server's web raw link refuses the download.
- **Fix:** fetch the same file and commit through Forgejo's raw API without following redirects. The DER SHA-256 check and per-route trust still apply.
- **Found on:** an uncached public CA fetch and a network-free service profile fixture.

### Stopping a build left its tools running

- **Symptom:** after the NSP script was stopped in Spyder (its interrupt), or by a front end's SIGTERM, the tool it was running went on: a shader build or `build_ipa.sh`'s `xcodebuild` kept the CPU busy and wrote into the build folder that the next build reads, and the script could wait for it with no end. A regression run (`regress.py`) stopped during a shader build whose direct child ignored SIGTERM for 10 s left the build's workers running. A tool's child still writing after the tool's own exit was taken for a finished step.
Expand Down