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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ IP65_BUILD := ip65-build
IP65_BIN := $(IP65_BUILD)/ip65-c64.bin

CA65FLAGS := -I src -I src/inc -I src/crypto/shared -I src/net/$(BACKEND) -I build --debug-info
# Optional HTTPS target-port override (src/boot.s defaults to 443).
# `make HTTPS_PORT=4433` lets a test rig's TLS listener bind unprivileged.
ifdef HTTPS_PORT
CA65FLAGS += -D HTTPS_PORT=$(HTTPS_PORT)
endif
# Lazy (=) so the USE_NISTCURVES_ONCHIP_COMB block below can retarget
# CFG to the cfg variant after this line.
LD65FLAGS = -C $(CFG) -Ln build/labels.txt -m build/c64-https.map --dbgfile build/c64-https.dbg
Expand Down
18 changes: 13 additions & 5 deletions src/boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

.include "constants.inc"

; HTTPS target port. Overridable at build time for test rigs
; whose TLS listener cannot bind the privileged default (e.g.
; `make HTTPS_PORT=4433` for the unprivileged macOS/VICE e2e).
; The default MUST stay 443 and the default build byte-identical.
.ifndef HTTPS_PORT
HTTPS_PORT = 443
.endif

; ---- exports: entry + print helpers ----
.export start
.export main_loop
Expand Down Expand Up @@ -521,9 +529,9 @@ do_https_get:
lda #1
sta http_path_len

lda #<443
lda #<HTTPS_PORT
sta http_port
lda #>443
lda #>HTTPS_PORT
sta http_port+1

; --- copy hostname into tls_hostname for SNI ---
Expand Down Expand Up @@ -556,9 +564,9 @@ do_https_get:
ldy #>dns_ok_msg
jsr print_string

; --- TCP connect port 443 ---
lda #<443 ; port low byte
ldx #>443 ; port high byte
; --- TCP connect on HTTPS_PORT (default 443) ---
lda #<HTTPS_PORT ; port low byte
ldx #>HTTPS_PORT ; port high byte
jsr net_tcp_connect
bcc @tcp_ok

Expand Down
33 changes: 33 additions & 0 deletions src/tls13.s
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,39 @@ tls_recv_server_hello:
lda #$05
sta tls_recv_progress

; Drain frames already at the NIC and ACK them BEFORE the
; multi-minute ECDHE stall. The server's post-SH flight is on
; the wire/in the chip by now (it splits at the 512 B default
; MSS because ip65's SYN carries no MSS option); without this
; drain the tail sits unACKed while we compute, and impatient
; peers drop the connection (macOS: hard drop after 13
; retransmits ≈ 54 s on a LAN — the C64 then verifies the whole
; buffered flight offline and dies SENDING client Finished into
; an RST'd socket). Draining here leaves zero unACKed data
; across every later crypto stall; idle connections survive.
; Safe: SH is fully parsed above, and net_poll only appends to
; the TCP ring — it never touches tls_rec_buf. Bounded 8x250
; polls (~10-20 s at 1 MHz — trivial vs the 20 min verify, and
; long enough to cover the peer's first retransmission of the
; flight tail if it wasn't at the NIC yet when we got here).
ldy #8
@sh_drain_outer:
ldx #250
@sh_drain:
tya
pha
txa
pha
jsr net_poll
pla
tax
pla
tay
dex
bne @sh_drain
dey
bne @sh_drain_outer

; compute ECDH shared secret now that tls_server_pubkey is populated
jsr tls_ecdh_compute_shared
clc
Expand Down
Loading