Skip to content

Add authenticated HTTPS to the existing target 6 HTTP interface - #1

Draft
araxis wants to merge 638 commits into
masterfrom
feature/https-client
Draft

araxis wants to merge 638 commits into
masterfrom
feature/https-client

Conversation

@araxis

@araxis araxis commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Upstream review: GideonZ#936

Problem

Target 6 lets C64 programs send HTTP requests, but cannot authenticate an
https:// endpoint. Applications need HTTPS without a second request/response API.

Change

An https:// URL uses the existing request, header/body handle and continuation
commands. The controller validates the hostname, certificate chain and dates.
TLS or transport failure returns the existing empty 503 SERVICE UNAVAILABLE;
there is no plaintext fallback. The change includes bounded TLS/UART sessions,
response-framing checks, correlated failure diagnostics and regression tests.
Usage examples are in doc/https-usage.md.

Hardware suites are now in tests/e2e/io/command_interface; repetition and timed
tests are in tests/soak/io/command_interface. Each is registered in run-tests
and uses the shared CLI/reporting. The build recipe remains in tools/c64u_https.

Validation

Device / environment Tests actually run Result
Commodore 64 Ultimate, Slimline BASIC Beige, pinned retail v14 candidate Native target-6 smoke: paired HTTP/HTTPS binary and typed JSON responses, 895/896/2048-byte bodies and continuations 10/10 exchanges passed
Same retail device and v14 candidate Two-hour native HTTP/HTTPS repetition, configuration/boot continuity and memory measurements 2,966/2,966 exchanges; 7,202.503 seconds; unchanged configuration/boot, no new diagnostic failures
Linux host, ESP-IDF 5.3.1 and 5.3.6 Mbed TLS Production framing, TLS/UCI, compatibility and sanitizer tests Passed in the current-head hosted run at fc149893
Linux host, upstream toolchain versions ESP-IDF 5.3.1 controller and U64-II management software compilation; both application-space limits Passed in the same hosted run; not a full FPGA/multi-board build
Linux host, test-layout follow-up 31 harness regressions, 16 retail recipe tests, six native-agent CPU cases; registry, transport, lint and generated-doc checks Passed locally and in both hosted TLS jobs; no hardware contacted

The retail hardware result belongs to the exact package/source manifest in
doc/https-source-provenance.json. It predates the upstream merge and this test
layout change, so it does not qualify a rebuilt current-head image or the
newly registered suites. Detailed dated evidence is in doc/https-device-validation.md.

Not covered

  • Ultimate 64: no physical E2E run yet. The retail Commodore 64 Ultimate
    results above are not Ultimate 64 coverage.
  • Ultimate II cartridge: no physical E2E run yet.
  • No complete upstream standard E2E profile or full multi-board/FPGA Build pass.
  • Physical Wi-Fi loss overlapping an active TLS request, independent processor
    restart, sustained UART pressure, clock faults and power-loss cases remain open.
  • An older v9 experiment returned one unexpected empty HTTPS 503. Its cause is
    unresolved; it did not recur in the recorded v14 run and is not an established
    TLS defect.

This remains a draft pending the missing hardware coverage and review.

chrisgleissner pushed a commit that referenced this pull request Oct 7, 2026
GideonZ#968)

HVSC's SID_file_format.txt: "If bits 6-7 are set to Unknown then the second
SID will be set to the same SID model as the first SID", and the same for
bits 8-9 and the third SID. ConfigSIDs() maps the chips that way, and the
info screen means to show it too: its comment says "unknown SID model for
second SID so use the info of first SID".

The test for an open model compared the whole byte with zero. For SID GideonZ#3
that is the high flags byte, whose other bits are reserved, so the fallback
worked there. For SID GideonZ#2 it is the low flags byte rotated three times, which
still holds the clock and SID #1's model, so for nearly every tune the
fallback never ran and the SID GideonZ#2 line said UNKNOWN. Both now mask the two
model bits first, at the same size. A tune that leaves SID #1 open too still
shows UNKNOWN.

sidcrt.bin: 8101 of 8192 bytes, muscrt.bin: 7561, both unchanged in size.
araxis and others added 29 commits October 25, 2026 10:45
The firmware keeps the sectors of a 1571 MFM track decoded inside a
G64/G71 track, marked by bit 15 of the length word. Denise reads and
writes the same layout, but it was never written down, so a third
implementation had to read the source of both.

The note describes the container, the length word, the 162-byte
sector list in front of the data and the error byte, as both programs
handle them today, and where they differ: track placement, the length
word as Denise's revolution size, and error byte bit 2. The firmware
side was checked on an Ultimate II+L (3.15a) with the 1571's own
burst format, inquire and read on crafted images.

Refs GideonZ#920

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of 8 October:

- The refusal on arrival goes: no check failed without it, as the
  completion already refuses a track the image has no space for, and it
  could reach a 1581 with lost data, which hung the bus in GideonZ#938.
- The FIXME on decode_write_track() is back, as its error is still
  ignored.
- The refusal's log line now gives the space the track has, not only
  what the format needed. Like every printf in this file, it is compiled
  out unless the define near the top is removed.

The suite gains a check for what it could not see before: the refused
sectors written over another track of the drive's copy of the image. A
burst READ that leaves out the data transfer puts the sector into the
1571's buffer, and M-R fetches it, so a C64 can read MFM sectors back.
On a second image, a program reads sector 1 of cylinder 0, formats
cylinder 35, which is too small, and reads sector 1 again. On 3.15a the
second read finds the refused format's fill byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Release pending HTTP responses and handles on reset
…s in the U64 WiFi bridge

ConnectCommand_t.ssid was char[32], so a 32-character SSID had no terminator and was later read with %s and strcmp. Make it char[33] and terminate it after the two copies into it. The NVS slot lookup read the stored SSID into 32 bytes, so a 32-character SSID (33 with the NUL) failed with ESP_ERR_NVS_INVALID_LENGTH, looked like a free slot, and was stored again on every connect; read into 33 bytes. The reconnect read into last_connect.ssid now uses sizeof.

The password has the same flaw: cmd_wifi_connect copied 64 bytes into pw[68] of an uninitialised stack ConnectCommand_t, so a 64-character passphrase or hex PSK had no terminator. Terminate it (ev.pw[64] = 0), and read the stored password with the size of last_connect.pw instead of 64 (wifi_find_password callers and the recent-AP read), since a 64-character password is 65 bytes in NVS.

Bump the module version to 1.7 (IDENT_MINOR, with a changelog line in rpc_dispatch.h), so that the updater installs the fixed module on a device that already runs the current one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s in the U64 control module

ConnectCommand_t.ssid was char[32], so a 32-character SSID had no terminator and was later read with %s and strcmp. Make it char[33] and terminate it after the two copies into it. The NVS slot lookup read the stored SSID into 32 bytes, so a 32-character SSID (33 with the NUL) failed with ESP_ERR_NVS_INVALID_LENGTH, looked like a free slot, and was stored again on every connect; read into 33 bytes. The reconnect read into last_connect.ssid now uses sizeof.

The password has the same flaw: cmd_wifi_connect copied 64 bytes into pw[68] of an uninitialised stack ConnectCommand_t, so a 64-character passphrase or hex PSK had no terminator. Terminate it (ev.pw[64] = 0), and read the stored password with the size of last_connect.pw instead of 64 (wifi_find_password callers and the recent-AP read), since a 64-character password is 65 bytes in NVS.

The recovery hotspot copies in wifi_connect_to_hotspot already use sizeof(last_connect.ssid) and sizeof(last_connect.pw) after a memset, so they follow the new size and need no change.

Bump the module version to 1.20 (IDENT_MINOR, with a changelog line in rpc_dispatch.h), so that the updater installs the fixed module on a device that already runs the current one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s in the C3 WiFi bridge

ConnectCommand_t.ssid was char[32], so a 32-character SSID had no terminator and was later read with %s and strcmp. Make it char[33] and terminate it after the two copies into it. The NVS slot lookup read the stored SSID into 32 bytes, so a 32-character SSID (33 with the NUL) failed with ESP_ERR_NVS_INVALID_LENGTH, looked like a free slot, and was stored again on every connect; read into 33 bytes. The reconnect read into last_connect.ssid now uses sizeof.

The password has the same flaw: cmd_wifi_connect copied 64 bytes into pw[68] of an uninitialised stack ConnectCommand_t, so a 64-character passphrase or hex PSK had no terminator. Terminate it (ev.pw[64] = 0), and read the stored password with the size of last_connect.pw instead of 64 (wifi_find_password callers and the recent-AP read), since a 64-character password is 65 bytes in NVS.

Bump the module version to 1.7 (IDENT_MINOR, with a changelog line in rpc_dispatch.h), so that the updater installs the fixed module on a device that already runs the current one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BrowsableWifiAP::connect_ap declared char password[64] and passed 64 to string_box, which takes that many characters plus the terminator, so a 64-character key wrote its NUL one byte past the buffer. Make the buffer 65 bytes. This is the only user interface path that can enter a 64-character key.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Match WiFi module replies by slot and sequence, bound the wait
chrisgleissner and others added 30 commits November 12, 2026 20:09
Size the lwIP timeout pool for the timers that can be active at once
…ddress() for a new device number

GideonZ#1083 stores the enable value before configure() and calls configure() on every
settings write. configure() holds the IEC processor in reset: on hardware a settings
change in the middle of a job then makes the C64 see 'device not present' and the rest
of the job is lost (the same on plain master). Keep GideonZ#1083's ordering and comment, and
call configure() only when the enable value changes; a new device number alone is
written with readdress(). The host test fails if a mid-job settings write configures
the bus.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…menu-poll-interval

rest-latency: pause between menu_screen polls while awaiting a toggle
…ency-cartridge-target

rest-path-latency: measure the device of a cartridge target
Virtual printer: spool print data so the IEC bus and REST no longer wait for page renders
…fps-mode

Observability test: extract stills with -fps_mode, which ffmpeg 9 requires
…onZ#1107)

* Printer: draw the Flush/Eject progress bar in the GUI task only

The printer task called update_progress through a UI pointer that the GUI
task could free (hide_progress) before or while it was used: the progress box
is deleted when the wait of the menu ends, and the 'still printing' popup
follows. The printer task now only counts deflate blocks; flush_and_wait waits
in 100 ms slices and the GUI task draws the new blocks between them.
hide_progress also clears status_box and update_progress ignores a missing box.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Printer test: Flush/Eject while page 1 renders and page 2 is spooled

The 11-17 report (two form-feed pages, Flush/Eject during the first). The
printer task counts deflate blocks of both pages from the first moment of the
menu command; no screen work may come from it. Red on master (cmd_ui is set
before the progress box exists), green with the GUI-task drawing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
The startup test drives the native owner to Active, drops and restores the
Wi-Fi link, and requires the factory to become available again with a fresh
lifetime. It fails today: the owner task exits after the first link loss and
the one-shot start paths never create another.
A Wi-Fi disconnect cancels the provider lifetime. The owner treated the
resulting runner failure as final, published Failed and let its task exit.
Both start paths are one-shot, so HTTPS stayed unavailable until reboot.

When the failure follows a cancelled provider lifetime, the task now retires
the old negotiation, fails pending requests and waits for the next provider
snapshot, then negotiates again. Every other failure is still final, and the
bootstrap timeout still bounds only the first identity wait.
…open

Add startup cases for a connection that is open at the drop, a data reply
for a pre-drop request that arrives while the owner is disconnected, and a
second drop between the provider snapshot and the offer. Each must end with
the owner serving again, and none does yet. The reconnect case no longer
calls provider_journal_start_owner again: only module start calls it.
Three ways a link loss still ended the owner for good:

- A connection open at the drop submitted a Close that the waiting owner
  refused, and the failed Close retired the owner. Skip the Close once the
  data lifetime is cancelled, and do not retire on a Close that fails
  because the link was lost under it.
- A data reply to a request from before the drop could arrive while the
  owner waited, because the data channel was open again. Drain the channel
  when the renegotiated session first becomes Active, before admitting
  requests; the UART is ordered, so every stale frame precedes the Offer
  reply.
- A second drop between the provider snapshot and the offer made the failed
  offer final. Wait for the next snapshot when the lifetime just taken is
  already cancelled.

The contract row now lists what stays terminal.
* Apply the syslog server setting at runtime

Syslog::init read "Log to Syslog Server" once at startup, so a value set
later (REST, menu, telnet) did nothing until the next firmware start, and
that start reloads flash, so an unsaved value never took effect.

Syslog is now a ConfigurableObject. effectuate_settings() parses the
setting and publishes the wanted state; the syslog task opens, retargets
and closes its own socket, as lwIP sockets must not be closed from another
task. Empty or invalid stops sending, a valid ip[:port] starts it or
retargets it, and an unrelated Network Settings change leaves the socket
alone. The task and the 16 KB buffer are created on first use and kept, so
repeated toggles leak neither. charout() ignores input while syslog is off,
so ultimate.cc can always route output through it.

Host test (target/pc/linux/syslog, part of make host_tests) drives the real
syslog.cc over loopback UDP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Syslog: review fixes for runtime apply

Say an invalid server value every time the setting is applied, including
at boot and when logging was already off. Serialize concurrent
effectuate_settings() calls so two tasks cannot create two syslog tasks or
buffers. Recheck the setting inside the safe section before dropping the
pending buffer on disable. Add host cases for a server saved at boot and an
invalid saved value, and build the test with -Wall.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… menu opens (GideonZ#1109)

* Serialise freeze/unfreeze against REST memory access and reset

freeze() sets Ultimax in stop() well before isFrozen is set, and a REST
readmem/writemem that landed in between took the plain memcpy with nothing
mapped: all $FF reads and dropped writes, with HTTP 200 (GideonZ#1106). Add a
recursive C64-owned lock held across freeze()/unfreeze() (and the
take/release_ownership wrappers), taken by dma_load_raw_buffer and by the
machine:reset path, so they only see a running or a fully frozen machine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add E2E for REST memory access racing the menu freeze (GideonZ#1106)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Hold the ownership lock for every command that stops, resumes or restarts the machine

Lock before the client check in MENU_C64_RESET and C64_UNFREEZE, and around
pause/resume, clearmem, reboot, start-cart, the DMA loads, measure_timing and
the SID socket access, so none of them runs inside freeze()'s window. REST and
UCI callers wait at most 2 s and get an error back; the freeze and unfreeze
themselves wait on, logging once. The save dialogs, which wait for a person,
are not under the lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Register menu-freeze-dma; check the menu really opened, recover on failure, check the jiffy clock

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Correct the ownership lock comment; keep sampling after the last press

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* menu_freeze_dma_test: 5 ms gap between operations so the menu can open

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* tests: regenerate README profile matrix for the current registry

Ran tools/docs/update_test_docs.py so the profile-matrix block in
tests/README.md matches the registry. This fills in the rows for
menu-freeze-dma, g71-mfm-format-refused and u64ctrl-ca, which were missing,
and refreshes the suite/suite-run totals. The documentation check
(update_test_docs.py --check) now passes; registry_test.py is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The probe passed Linux's -w 3, which macOS ping rejects, so every ping
probe failed on a Mac host. macOS spells the same thing -o -t 3.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… overflow (GideonZ#1118)

Four defects in filemanager/dos.cc, all reachable from a C64 program
through UCI commands:

1. DOS_CMD_OPEN_FILE while a file is already open overwrote the `file`
   member (FileManager::fopen NULLs it first), dropping the old handle:
   about 4.3 KB leaked per command and the file stays open and locked.
   Dos also had no c64_reset(), so a reset left the handle open. OPEN now
   closes the previous file, and a new c64_reset() closes it and releases
   the directory list.
2. CTRL_CMD_LOAD_INTO_RAMDISK allocated a FileInfo with new and freed it
   only on the error exits, never on the what-if or success exits. It is
   a stack object now.
3. CTRL_CMD_SAVE_RAMDISK did `delete ffi` on the function-scope pointer,
   which that command never assigns, whenever the RAM drive type does not
   match the file extension: a delete of an uninitialised pointer, i.e.
   heap corruption from one command. The delete is removed.
4. The same command filled `char extension[3]` through get_extension(),
   which writes four bytes: a one byte stack overflow. It is [4] now.

Test: software/test/uci_targets/dos_resource_test.cc (ucitargets suite).
Before the fix, plain `make test`: the OPEN and reset cases fail on
open_file_count() (LOAD then fails on the handle they leave open) and the
save case crashes in the bad delete. A whole-suite `make SAN=1` (new,
AddressSanitizer with leak detection) stops at the stack overflow
(pattern.cc:343 via dos.cc:696); per case it reports the leaked handle,
the leaked FileInfos at dos.cc:597 and the bad delete at dos.cc:715. After
the fix all four cases pass, plain and under SAN=1. `make host_tests`
does not enable SAN=1.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
* Tell the C64 when a streamed file read fails

When the next block of a file could not be read while the file was
streaming, the channel went to its error state and the interface ended
the talk with a terminate, but nothing set the drive error. The error
channel kept reading "00, OK,00,00", so a program that stopped on the
short file and asked why was told everything was fine.

read_block now sets the drive error from the failed read, so a disk or
not-ready failure reads "74,DRIVE NOT READY,00,00" as on a Commodore
drive. This covers the single byte talk and the bulk talk.

The test makes the sector reads of the FAT file fail after the open and
checks the status for both talk forms; it reads "00, OK" without the fix.

Related to GideonZ#1100.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Keep a failed streamed read off error 69

The error set for a failed block read went through set_error_fres, which
answers 69,FILESYSTEM ERROR for FR_INT_ERR (a sector chain that loops or
has a bad link in a disk image) and FR_INVALID_OBJECT. SI-036 says 69 must
not reach a user when CBM DOS names the condition. Map them first, as the
other read paths do: FR_INT_ERR answers 20,READ ERROR and
FR_INVALID_OBJECT answers 74,DRIVE NOT READY.

The new test loops a D64 file's sector chain back on itself and checks
for 20,READ ERROR after the file has started streaming. The comment of
the first test no longer claims that the C64 sees no EOI.

Related to GideonZ#1100.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Delete the image of the chain loop test

The 16 MB FAT file has room for the images the suites make and not for one
more, so the next suite could not create its image. Delete it at the end.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
…ils (GideonZ#1117)

postMessage() hands a heap mstring to a 4-slot queue with a zero timeout
and ignored the result. When the queue is full the send fails, nobody
else owns the string, and it was leaked. The queue is drained only by a
menu with focus (TreeBrowser::poll), so once four messages are waiting,
every further post leaks about 55 bytes.

Trigger: several callers post from tasks that have no menu open. The
reachable one without a login is the REST config hook for the U64-II and
C64U Recovery Server value (u64_config.cc setRecoveryUrl): the control
module refuses a URL that is not http(s), the hook posts "Recovery server
not stored.", and the hook runs on every write even with an unchanged
value, so a repeated `PUT /v1/configs/.../Recovery%20Server?value=x`
leaks one string per request (unbounded; with no network password set).

Fix: delete the message when xQueueSend does not return pdTRUE.

Test: software/userinterface/tests (new suite). postMessage and
getMessage are cut out of userinterface.cc as they are and run against a
real bounded queue; the stand-in in io/wifi/tests ignores the send result
and so hid this. Before the fix 100 posts to a full queue leave 100 live
strings (assertion fails) and `make leak` (AddressSanitizer, leak
detection) reports 2900 bytes in 200 allocations; after, both pass. The
suite is added to `make host_tests`; `make leak` is the sanitizer variant.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
When file->read() failed in Dos::get_more_data, the file system's message
was copied into status_message but *status was never pointed at it. The
command interface then copied whatever the caller's uninitialised status
pointer held, so the C64 got a garbage status for a failed READ_DATA.
Point *status at the message, as every other failing DOS command does.
The Ultimate DOS document promises this: "When something goes wrong, this
will be reported through the status channel."

The host test makes File::read fail (new read_result knob in the fakes)
and checks the status on the first and a later block; it fails without
the fix and passes with it.

Related to GideonZ#1100.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
convert() builds an object for every token. jsmn gives each top-level
value parent -1, so a value at index > 0 skips the `if (parent)` block,
does not set invalidJson, and is never attached to anything. Callers keep
only objects[0] and delete only that one, so every further top-level
value (and its children) was lost.

Trigger: any body with more than one top-level value, e.g. `{}{}{}...`.
With no network password set this is reachable without authentication
via POST /v1/configs (up to 1024 tokens, roughly 150 KB per request),
and via POST /v1/machine:input and the remote-JSON readers.

Fix: a second top-level value makes the document invalid; free it right
away. Later children of a freed root find a NULL parent object and are
freed by the existing checks.

Test: software/api/tests/json_multiroot_test.cpp. Without the fix the
parse returns the first root (assertion fails) and, built with
-fsanitize=address and detect_leaks=1 (`make json-leak`), LeakSanitizer
reports 561 bytes in 16 allocations. The plain test already
runs in CI and fails without the fix; `make json-leak` is the sanitizer
variant.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
curl builds cacert.pem from Mozilla's release branch, which lags NSS master.
Roots master has deleted (Buypass Class 2 and 3), no longer trusts for
websites (QuoVadis Root CA 1 G3 and 3 G3, Certigna Root CA) or distrusts
after a date that has made all their certificates expire (Izenpe.com) stayed
in the store. refresh.py now cuts the roots named in REMOVED out of curl's
file and pins the result; the rest stays curl's, byte for byte.

Roots with a distrust-after date that mbedTLS cannot apply (Firmaprofesional,
emSign Root CA - G1, DigiCert Trusted Root G4) stay, listed in DISTRUST_AFTER.
The test fails once the date plus 200 days has passed, when the line moves to
REMOVED.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants