HTTPS for PSP homebrew — download over TLS 1.3 from a PSP, with the certificate checks and the randomness a PSP does not bring by itself. → Download
Stick and buttons make the seed for wolfSSL's random number generator.
- Secure downloads: HTTPS with TLS 1.3, built on wolfSSL
- Trusts what Firefox trusts: Mozilla's list of root certificates, checked for updates every week
- Copes with a wrong clock: a PSP's date is usually off, so certificates are checked against the day the library was built; an expired or unknown one asks the player instead of failing
- Makes its own randomness: once, the player steers the stick or smashes buttons for about 18 seconds; the result is saved, later starts skip it
Tested in PPSSPP so far. demo/ is a complete example.
Measured in PPSSPP, best case ChaCha20-Poly1305 with X25519:
| Parsing the 121 roots, once per run | 38 ms |
| TLS 1.3 handshake, local server | 166–171 ms |
| TLS 1.3 handshake, GitHub Pages | 187–307 ms |
| 5 MB with ChaCha20-Poly1305 | 1.3 s |
| 5 MB with AES-128-GCM | 4.8 s |
The emulator runs on a PC's CPU; on a real PSP the 802.11b radio sets the pace, and ChaCha is the cipher that keeps the CPU out of the way.
1. Download the zip from the
latest release
and unpack it into your homebrew, say into lib/. It holds the headers and
the prebuilt libraries, wolfSSL included.
2. Include it in your Makefile, before build.mak:
include lib/pspkit-https-0.2.2/module.mk3. Make a seed, then download. The first start shows the sweep; every later start loads the saved seed.
#include "pspkit-https/entropy.h"
#include "pspkit-https/https.h"
#include "pspkit-https/sweep.h"
/* Called with each piece of the download. */
static int on_data(void *ctx, const void *data, size_t len) {
return 0; /* 0 = keep going */
}
int main(void) {
entropy_set_seed_file("ms0:/PSP/GAME/MYAPP/seed.bin");
entropy_init();
if (!entropy_load())
sweep_ascii_run(); /* the screen above */
entropy_save(0);
struct https_result result;
https_net_connect(); /* Wi-Fi profile 1 */
https_get("https://example.org/", on_data, NULL, NULL, NULL, &result);
}For a PSP system connection dialog, call https_net_init() on the main
thread before opening sceUtilityNetconf. After the dialog succeeds,
https_net_connect() adopts that connection. Once this mode is selected,
it never connects to profile 1 automatically, including after cancellation
or a later disconnect; reopen the dialog to reconnect. Initialize or show
the dialog only while network workers are stopped.
Connections · speed, requests, limits
- ChaCha20-Poly1305 is used first: the PSP has no AES hardware, and 5 MB take 1.3 s with ChaCha against 4.8 s with AES-GCM
- X25519 for the key exchange, about seven times faster than P-256 on a PSP
- Redirects are followed (up to 5), but never from
https://down tohttp:// - A password for one host,
https_set_basic(host, user, password), goes with every request to that host as HTTP Basic, and to no other, a redirect's included http://works too, for a server somebody hosts at home: no TLS, so nothing about it is checked, and a download from it is only as good as the hash the caller holds it to- Sockets explicitly enable PSPSDK
SO_NONBLOCK; timeout checks must remain reachable after a dropped WLAN connection - Progress callbacks also run periodically while waiting for response data, with unchanged byte counts, so a UI can still cancel a stalled download
- Timeouts: 10 s to connect, 20 s for the handshake, 30 s for the whole response head, then 30 s without a byte of body. A slow body is never cut off for being slow, so a big download on 802.11b can finish
https_set_time_limit(seconds)gives a wholehttps_geta bound, redirects included:FAILEDif it runs out before the body,TRUNCATEDafter. Off by default- Up to six idle connections are kept for 60 seconds
https_abort()stops a download from any threadhttps_set_accept_gzip(1)asks for gzip; the body reaches your sink as sent,content_encodingin the result names it, and inflating is yours (zlib'sinflateInit2with16 + MAX_WBITS). Off by default, and best left off for files that are already compressed- Chunked responses are streamed to the sink with framing removed;
content_lengthstays zero. Chunk headers are bounded to 1023 bytes and trailers to 8 KiB. Unsupported transfer codings and ambiguous Transfer-Encoding plus Content-Length are refused - Concurrent requests have separate buffers; TLS handshakes are serialized
- Not supported: POST, IPv6
Certificates · roots, dates, asking the player
- 118 root certificates from Mozilla, taken from curl; a workflow checks for a newer list every Monday and, when the roots changed, releases it as the next patch version
- Server name and certificate chain are always checked; a forged signature or the wrong name always fails
- Dates: a PSP's clock resets to 2000 when the battery runs flat. So a certificate only counts as expired if it had already expired on the day the library was built. Anything that expired later still passes; only updating the app closes that gap
- wolfSSL is never shown the console's clock: its date is the build day, its timers count from boot. A clock that was never set reads as 0, and a connection must not fail on that
- Why not ask the internet for the time? A hostile Wi-Fi can fake the answer, and setting the PSP's clock needs a kernel module
- Asking the player: after a refused connection,
https_doubt_take()tells you the server and why (expired or unknown issuer); if the player agrees, callhttps_doubt_accept()and try again. To keep an answer across runs, store the host yourself and hand it back withhttps_doubt_trust()at start
The seed · why a sweep, what counts
- A PSP has no random number generator an app can use, and TLS needs 128 bits nobody can guess. So the player makes them
- Only what nobody could predict counts: a turn in a new direction at an unexpected moment, a button nobody expected. Circles, turbo buttons, holding a button count nothing
- Honest players need about 18 seconds, by stick or by buttons
- The seed is saved in a 32-byte file and replaced on every start
- Your own sweep screen: call
sweep_step()every frame with the pad, drawstruct sweep, showsweep_get_percent(); PSPDX draws water with it
Threads · who may call what
- Downloads:
https_net_connect,https_getand the settings from one thread at a time - Anytime, from anywhere:
https_abort,https_get_phase,https_get_last_info - The sweep and
entropy_initfrom your main thread - Every function in
include/pspkit-https/says this at its declaration
From source · submodule, own wolfSSL build
To change the library or build it yourself, pin a release tag as a submodule instead of the zip:
git submodule add https://github.com/chriopter/pspkit-https lib/pspkit-https
git -C lib/pspkit-https checkout v0.2.2
git submodule update --init --recursive
cd lib/pspkit-https
docker run --rm -v "$PWD:/src" -w /src \
pspdev/pspdev:latest sh tools/build-wolfsslinclude lib/pspkit-https/module.mkUpdating is git -C lib/pspkit-https checkout v0.2.2 and a commit; build
wolfSSL again when its version or tools/build-wolfssl changed.
Development · build, demo, tests
| Command | What it does |
|---|---|
tools/build-wolfssl |
Builds wolfSSL 5.9.2 for the PSP |
tools/package/build VERSION |
Builds the release zip; a v* tag does it on GitHub |
demo/run |
Builds the demo and starts it in PPSSPP (--fresh starts with a sweep) |
tests/nettest/run |
Measures download speed over a local connection |
tests/request/run |
Checks the request and the response head on the PC, against a scripted server |
tests/clock/run |
Checks, with wolfSSL built for the PC, that a clock reading 0 stops no connection |
tests/certificates/run |
Checks legacy serial-zero certificate chains and rejects forged chains, unknown issuers, wrong hostnames and malformed ASN.1 |
make -C tests/corpus |
Builds a PSP download auditor: reads jobs.tsv, retains ZIPs and records sizes, SHA-256, HTTP/TLS failures and progress; run each emulator with its own Memory Stick |
ca/update |
Fetches the newest root certificates |
tools/entropy-sim |
Tests the seed counting against lazy input on the PC |
Credits
- wolfSSL, GPL-2.0; its PSP build started from pspdev's psp-packages
- Root certificates: Mozilla, via curl
- pspkit-https is GPL-2.0
