Documentation
¶
Overview ¶
Package push provides push notification drivers.
Index ¶
- Constants
- Variables
- func KeyID(publicKey []byte) string
- func MarshalEnvelope(e Envelope) ([]byte, error)
- func Open(privateKey, sealed []byte) ([]byte, error)
- func Seal(publicKey, plaintext []byte) ([]byte, error)
- func SignatureBase(timestamp string, body []byte) []byte
- type Envelope
- type FCMDriver
- type SealedDriver
- func (d *SealedDriver) Channel() string
- func (d *SealedDriver) Fields() []driver.Field
- func (d *SealedDriver) Name() string
- func (d *SealedDriver) Send(ctx context.Context, msg *driver.OutboundMessage) (*driver.DeliveryResult, error)
- func (d *SealedDriver) Validate(credentials, settings map[string]string) error
- type SendBody
Constants ¶
const ( // HeaderKey carries the server's Ed25519 public key, standard base64. HeaderKey = "X-Herald-Key" // HeaderTimestamp carries the Unix seconds the request was signed at. HeaderTimestamp = "X-Herald-Timestamp" // HeaderSignature carries the standard base64 Ed25519 signature of SignatureBase. HeaderSignature = "X-Herald-Signature" )
Headers the sealed driver sets on a gateway request. The gateway reads the same names, so both sides import them from here.
const MaxEnvelopeBytes = 2560
MaxEnvelopeBytes is the largest envelope JSON, in bytes, accepted before sealing.
const SealInfo = "herald push v1"
SealInfo is the HPKE info string every sealed push envelope is bound to.
const SealOverhead = 48
SealOverhead is what sealing adds to a plaintext: a 32-byte enc and a 16-byte tag.
Variables ¶
var ( // ErrPayloadTooLarge reports an envelope over MaxEnvelopeBytes. ErrPayloadTooLarge = errors.New("herald: push payload too large") // ErrMissingCollapseID reports a withdraw with no collapse ID: a withdraw // names the notification to remove by that ID. ErrMissingCollapseID = errors.New("herald: push withdraw needs a collapse id") // ErrMissingPublicKey reports a device without a usable X25519 public key. ErrMissingPublicKey = errors.New("herald: push device has no public key") )
Functions ¶
func MarshalEnvelope ¶
MarshalEnvelope encodes e as JSON with V forced to 1.
func Seal ¶
Seal encrypts plaintext to a raw 32-byte X25519 public key with HPKE base mode. The result is the 32-byte enc followed by the ciphertext.
func SignatureBase ¶
SignatureBase returns the bytes a request signature covers: the timestamp, a dot, then the raw body.
Types ¶
type Envelope ¶
type Envelope struct {
V int `json:"v"`
Title string `json:"title"`
Body string `json:"body"`
Category string `json:"category,omitempty"`
Thread string `json:"thread,omitempty"`
Data map[string]string `json:"data,omitempty"`
}
Envelope is the plaintext a device opens after unsealing a push.
type FCMDriver ¶
type FCMDriver struct {
// contains filtered or unexported fields
}
FCMDriver delivers push notifications via Firebase Cloud Messaging HTTP v1 API.
The zero value is ready to use. It caches minted access tokens per service account key, so share one instance rather than creating one per send.
func (*FCMDriver) Fields ¶
Fields describes what the FCM driver reads. It needs one of service_account, access_token or server_key; the schema can't express "one of", so neither is required here and Validate enforces it.
func (*FCMDriver) Send ¶
func (d *FCMDriver) Send(ctx context.Context, msg *driver.OutboundMessage) (*driver.DeliveryResult, error)
type SealedDriver ¶
type SealedDriver struct {
// Now supplies the signing time. Nil means time.Now.
Now func() time.Time
}
SealedDriver delivers a push through a gateway without letting it read the content. It seals the notification to the device's public key, then asks the gateway to relay the sealed bytes, signing the request with an Ed25519 key.
The zero value is ready to use.
func (*SealedDriver) Channel ¶
func (d *SealedDriver) Channel() string
Channel returns the channel the driver serves.
func (*SealedDriver) Fields ¶
func (d *SealedDriver) Fields() []driver.Field
Fields describes what the sealed gateway driver reads.
func (*SealedDriver) Send ¶
func (d *SealedDriver) Send(ctx context.Context, msg *driver.OutboundMessage) (*driver.DeliveryResult, error)
Send seals msg to the device key and posts it to the gateway.
type SendBody ¶
type SendBody struct {
Handle string `json:"handle"`
Sealed string `json:"sealed,omitempty"`
KeyID string `json:"key_id"`
Urgency string `json:"urgency"`
Kind string `json:"kind"`
CollapseID string `json:"collapse_id,omitempty"`
TTLSeconds int64 `json:"ttl_seconds,omitempty"`
}
SendBody is the JSON body of POST /v1/send on a push gateway.