Documentation
¶
Overview ¶
Package mtls is magpie's own certificate authority for mutual TLS (hhdaxia on X: "希望能支持 mtls,避免暴露端口到公网被 compromise"; #5596). With it on (settings' MTLS, `magpie mtls on`), the gateway and `magpie web`'s page serve other computers over HTTPS with a server certificate this CA signs (or the user's own, --tls-cert), and a connection from another computer is let in only with a client certificate this CA issued and nobody revoked. Client certificates are issued for a device by name (`magpie mtls issue <name>`, Settings → Network and sharing) and exported as PEM files beside the CA's own certificate, which the device trusts the server by: Remote magpie takes all three (provider.ClientCert, ClientKey and ServerCA), as curl does (--cert, --key, --cacert).
The CA's key never leaves this computer: it is kept in magpie's folder (0600) and is neither synced nor backed up, as the files here are no part of those.
Index ¶
- func Export(iss Issued, dir string) (string, error)
- func WriteFile(path string, b []byte, mode os.FileMode) error
- type Client
- type Issued
- type Store
- func (s Store) Admits(cert *x509.Certificate) error
- func (s Store) CA() (*x509.Certificate, crypto.Signer, error)
- func (s Store) CAFile() string
- func (s Store) HasCA() bool
- func (s Store) Issue(name string) (Issued, error)
- func (s Store) List() ([]Client, error)
- func (s Store) Pool() (*x509.CertPool, error)
- func (s Store) Revoke(name string) (int, error)
- func (s Store) ServerCert(names []string, ips []net.IP) (tls.Certificate, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
Name string `json:"name"`
Serial string `json:"serial"`
Issued time.Time `json:"issued"`
Expires time.Time `json:"expires"`
Revoked time.Time `json:"revoked,omitzero"`
}
Client is a client certificate issued: Name the device's, as the user gave it; Serial the certificate's, in hex; Revoked when it was taken back, zero while it is good.
type Issued ¶
Issued is a client certificate as it was issued, with its key: the only time the key is seen, as the store keeps none.
type Store ¶
type Store struct{ Dir string }
Store is the CA kept in Dir: ca.pem, ca-key.pem and clients.json, the certificates issued.
func (Store) Admits ¶
func (s Store) Admits(cert *x509.Certificate) error
Admits says whether cert, a client certificate the CA's pool verified, is let in: issued here and not revoked. One the list doesn't hold (its file lost, or edited) is refused, as is any when the list can't be read.
func (Store) Issue ¶
Issue signs a client certificate for the device name. One issued before under the same name, still good, is revoked: the name is the device's, and a device issued again (a lost or new one) has the one certificate.
func (Store) Revoke ¶
Revoke takes back the good certificates of the device name, or the one whose serial name is. A connection already made with one ends with its next request: the gateway asks Admits on each handshake and each request.
func (Store) ServerCert ¶
ServerCert is a server certificate the CA signs for names and ips, with its key: made in memory each time the gateway starts serving, never written.