Documentation
¶
Overview ¶
Package e2e implements the Peer Protocol message encryption extension, suite peer-e2e-v1: a message body sealed to one or more long-term X25519 keys with RFC 9180 HPKE, so that only the holder of a listed secret key can read it. Seats, relays and hosts carry the envelope and see ciphertext.
The wire format is fixed in docs/protocol.md; the browser renderer worker/reader/index.html implements the same bytes with crypto.subtle.
Index ¶
- Constants
- Variables
- func Detect(body []byte) (suite string, ok bool)
- func GenerateKey() (pub, secret string, err error)
- func Open(env []byte, secret string) ([]byte, error)
- func ParsePublic(s string) (hpke.PublicKey, error)
- func ParseSecret(s string) (hpke.PrivateKey, error)
- func Seal(plain []byte, pubs []string) ([]byte, error)
- type Details
Constants ¶
const ( // Suite is the suite id of this implementation. Suite = "peer-e2e-v1" // Version is the envelope's "e2e" value and the card's details.readers "v". Version = 1 // PublicPrefix and SecretPrefix tag the text form of a key. PublicPrefix = "x25519:" SecretPrefix = "x25519-secret:" )
const DetailsMember = "readers"
DetailsMember is the member of a card's details that holds its Details.
Variables ¶
var ( // ErrMalformed reports an envelope that is not a well-formed peer-e2e-v1 // envelope. ErrMalformed = errors.New("malformed encrypted record") // ErrNotRecipient reports an envelope with no stanza for this key. ErrNotRecipient = errors.New("encrypted to other keys") // ErrDecrypt reports a stanza or body that failed authentication. ErrDecrypt = errors.New("does not open with this key") )
Functions ¶
func Detect ¶
Detect reports whether a message body is an e2e envelope and names its suite: after leading JSON whitespace it starts {"e2e":, parses as an object with "e2e" equal to 1 and "suite" matching [A-Za-z0-9._-]{1,64}. Anything else is plain text.
Members are matched exactly, unlike encoding/json's struct decoding, so Go and a JSON.parse reader classify the same bytes the same way.
func GenerateKey ¶
GenerateKey makes a new key pair and returns its text forms.
func Open ¶
Open decrypts an envelope with secret. A failure wraps ErrMalformed, ErrNotRecipient or ErrDecrypt.
func ParsePublic ¶
ParsePublic decodes a public key string x25519:<43 base64url>.
func ParseSecret ¶
func ParseSecret(s string) (hpke.PrivateKey, error)
ParseSecret decodes a secret key string x25519-secret:<43 base64url>. Its errors never quote the input.
Types ¶
type Details ¶
Details is the card's details.readers object: the keys a party receives on.
func ParseDetails ¶
func ParseDetails(details json.RawMessage) (*Details, error)
ParseDetails reads the readers member of a card's details. It returns nil and no error when the card names no e2e keys, and an error when the member is present and not a usable v1 key list.