e2e

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: GPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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:"
)
View Source
const DetailsMember = "readers"

DetailsMember is the member of a card's details that holds its Details.

Variables

View Source
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

func Detect(body []byte) (suite string, ok bool)

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

func GenerateKey() (pub, secret string, err error)

GenerateKey makes a new key pair and returns its text forms.

func Open

func Open(env []byte, secret string) ([]byte, error)

Open decrypts an envelope with secret. A failure wraps ErrMalformed, ErrNotRecipient or ErrDecrypt.

func ParsePublic

func ParsePublic(s string) (hpke.PublicKey, error)

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.

func Seal

func Seal(plain []byte, pubs []string) ([]byte, error)

Seal encrypts plain to every key in pubs and returns the envelope, which is the message body. A fresh content key encrypts plain, so the all-zero body nonce is used once per key.

Types

type Details

type Details struct {
	V     int      `json:"v"`
	Suite string   `json:"suite"`
	Keys  []string `json:"keys"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL