Documentation
¶
Overview ¶
Package pair is how a new device gets its own revocable token: a one-time code shown on a device already logged in, claimed by the new one. Tokens are kept only as hashes; codes only in memory.
Index ¶
- Constants
- Variables
- func CheckURL(raw string) (string, error)
- func Fingerprint(c *x509.Certificate) string
- func ParseCerts(b []byte) []*x509.Certificate
- func SVG(text string) (string, error)
- func Served(base string) []*x509.Certificate
- func Signs(anchor *x509.Certificate, chain []*x509.Certificate) bool
- func TLS(pems ...string) *tls.Config
- func Terminal(text string) (string, error)
- func Transport(pems ...string) http.RoundTripper
- func Trusted(chain []*x509.Certificate) bool
- type Device
- type Limiter
- type Mismatch
- type Payload
- type Redeemed
- type Store
- func (s *Store) Check(token string) (string, bool)
- func (s *Store) Claim(code, name string) (string, Device, error)
- func (s *Store) List() []Device
- func (s *Store) NewCode() (string, time.Time)
- func (s *Store) Revoke(id string) (bool, error)
- func (s *Store) Watch(id string, stop func()) (done func())
Constants ¶
const ClaimPath = "/api/pair/claim"
const (
CodeLife = 10 * time.Minute
)
Variables ¶
var ErrCode = errors.New("invalid or expired code")
Functions ¶
func CheckURL ¶
CheckURL accepts only a plain http(s) server address and returns it without a trailing slash.
func Fingerprint ¶
func Fingerprint(c *x509.Certificate) string
func ParseCerts ¶
func ParseCerts(b []byte) []*x509.Certificate
ParseCerts reads every certificate in PEM data.
func Served ¶
func Served(base string) []*x509.Certificate
Served returns the certificates an https server presents, unchecked: callers only compare them.
func Signs ¶
func Signs(anchor *x509.Certificate, chain []*x509.Certificate) bool
Signs says whether anchor is, or signs, the served chain. The host name is checked when connecting.
func TLS ¶
TLS trusts the system's authorities and the given PEM ones; nil when there are none to add.
func Terminal ¶
Terminal draws a QR code in half blocks, two modules to a character, with explicit colours so a dark and a light terminal print the same thing.
func Transport ¶
func Transport(pems ...string) http.RoundTripper
Transport is the default one with TLS(pems...) when that adds anything, otherwise nil, which an http.Client reads as the default.
func Trusted ¶
func Trusted(chain []*x509.Certificate) bool
Trusted says whether the system's own authorities accept the served chain.
Types ¶
type Limiter ¶
type Limiter struct {
Window time.Duration
PerAddr, All int
// contains filtered or unexported fields
}
Limiter counts attempts per address and overall in fixed windows.
type Mismatch ¶
type Mismatch struct{ URL, Want, Got string }
Mismatch is a server whose certificate is not the one the pairing names.
type Payload ¶
type Payload struct {
URL, Code, CA string
}
Payload is what a QR code or a pasted line carries: atc://pair?url=&code=&ca=
type Redeemed ¶
type Redeemed struct {
Token string `json:"token"`
ID string `json:"id"`
Host string `json:"host"`
CA string `json:"-"`
}
Redeemed is what claiming a pairing brings back. CA is the pinned certificate as PEM, for the caller to keep trusting; empty when the pairing pins none.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) Claim ¶
Claim spends a code on a new device and returns its token, which exists nowhere after this.