Documentation
¶
Overview ¶
Package pageserver puts the desktop page in front of the service: Proxy forwards the page's API calls to the service's socket (the desktop app's web view and a Server both use it), and a Server serves the page itself to a browser, on a loopback port only whoever holds its link can use.
The service never listens on a network port; a Server does, for the page, so it lets in only requests that carry its cookie, which a one-time link (OpenURL) hands out. Requests must also name the Server's own address as their host (no DNS rebinding) and, when they say where they come from, come from the page (no other site, not even another port on 127.0.0.1, whose requests a browser would send the cookie with).
A Server speaks only HTTP/2, over TLS: a browser keeps at most six HTTP/1.1 connections to a host, and each of the page's open streams (a turn, its watches) held one, so a seventh request waited for one to end and the window froze. HTTP/2 carries them all on one connection. The certificate is the Server's own, made in memory as it starts and never written down; the window that shows the page trusts that one certificate by its fingerprint (Fingerprint), so a program that took the port after the Server stopped couldn't pose as it.
Index ¶
Constants ¶
const CertLifetime = 30 * 24 * time.Hour
CertLifetime is how long a Server's certificate is valid. The window trusts it by its fingerprint, not by its dates; a Server lives as long as the app that started it.
const HostPrefix = "/host/"
HostPrefix is where Options.Host answers: what the page asks of the program serving it (opening folders, the service's controls).
const TicketTTL = time.Minute
TicketTTL is how long a link from OpenURL lasts unused.
Variables ¶
This section is empty.
Functions ¶
func Fingerprint ¶ added in v0.8.0
Fingerprint is a certificate's SHA-256 as upper-case hex pairs joined by colons, as Node's X509Certificate.fingerprint256 writes it.
Types ¶
type Options ¶
type Options struct {
// Page is the page's files, index.html at the root.
Page fs.FS
// Socket is the service's socket, for Proxy.
Socket string
// Host answers under HostPrefix (nil: not found).
Host http.Handler
// Addr is where to listen: 127.0.0.1:0 (any free port) by default.
// Only a loopback address is allowed.
Addr string
}
Options are what a Server serves.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the page on a loopback port. Close it when done.
func (*Server) Fingerprint ¶ added in v0.8.0
Fingerprint is the SHA-256 fingerprint of the Server's certificate, the one the window showing the page trusts (pageserver's Fingerprint).
func (*Server) OpenURL ¶
OpenURL is a link that opens the page once: it lets the browser in (a cookie) and then goes to the page, so the link in the address bar and the history is the page's, not one that would let anyone in again.
func (*Server) Origin ¶
Origin is the page's origin: https://127.0.0.1:port.