mastopush

package module
v0.0.0-...-60954b1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

README

go-mastopush Build Status Go Report Card codecov GoDoc

go-mastopush implements the decryption portion of the Web Push standard (RFC8030, RFC8291), as well as additional helper functions, which allow for easy decryption and parsing of Push Notifications sent by Mastodon.

Here’s the output of the included example project:

[buckket@uncloaked go-mastopush]$ ./go-mastopush 
2019/05/19 16:52:33 Added new push subscription (ID: 1, Endpoint: https://example.org/go-mastopush/)
2019/05/19 16:52:33 Mastodon ServerKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX="
2019/05/19 16:52:46 Incoming request from [::1]:39306
2019/05/19 16:52:46 JWT Header: &{Algorithm:ES256 KeyID: Type:JWT ContentType:}
2019/05/19 16:52:46 JWT Payload: &{Issuer: Subject:mailto:no-reply@example.org Audience:[https://example.org] ExpirationTime:1558363966 NotBefore:0 IssuedAt:0 JWTID:}
2019/05/19 16:52:46 New push notification: 
{
	"access_token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"preferred_locale": "en",
	"notification_id": "701",
	"notification_type": "mention",
	"icon": "https://social.buckket.org/avatars/original/missing.png",
	"title": "You were mentioned by mirror",
	"body": "@buckket Hello. Testing 123"
}

Installation

From source
go get -u github.com/buckket/go-mastopush

Usage

Here’s a simple example project. Check GoDoc for the full documentation.

Limitations

  • Only supports aesgcm and not aes128gcm. Which is fine, because Mastodon only uses the former. But implementing the later should be straight forward as well, as parsing the HTTP request headers is no longer necessary.
  • Documentation is still lacking.

Notes

  • A remotely similar project which forwards notifications (to APN in this case) instead of decrypting them can be found here: https://github.com/DagAgren/toot-relay
  • Your HTTP handler should resepct Section 6.2 when it comes to returning HTTP status codes.

License

GNU GPLv3+

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseHeader

func ParseHeader(header *http.Header) (dh, salt, token []byte, err error)

Types

type Config

type Config struct {
	PrivateKey   ecdsa.PrivateKey
	ServerKey    ecdsa.PublicKey
	SharedSecret []byte
}

func (*Config) ExportPrivateKey

func (c *Config) ExportPrivateKey() string

func (*Config) ExportServerKey

func (c *Config) ExportServerKey() string

func (*Config) ExportSharedSecret

func (c *Config) ExportSharedSecret() string

func (*Config) GenerateNewKeys

func (c *Config) GenerateNewKeys() error

func (*Config) ImportPrivateKey

func (c *Config) ImportPrivateKey(privateKeyStr string) error

func (*Config) ImportServerKey

func (c *Config) ImportServerKey(serverKeyStr string) error

func (*Config) ImportSharedSecret

func (c *Config) ImportSharedSecret(sharedSecretStr string) error

type ID

type ID string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

type MastoPush

type MastoPush struct {
	*Config
}

func NewMastoPush

func NewMastoPush(config *Config) *MastoPush

func (*MastoPush) Decrypt

func (m *MastoPush) Decrypt(dh, salt, data []byte) (payload []byte, err error)

func (*MastoPush) VerifyJWT

func (m *MastoPush) VerifyJWT(token []byte) (*jwt.Header, *jwt.Payload, error)

type Payload

type Payload struct {
	AccessToken      string `json:"access_token"`
	PreferredLocale  string `json:"preferred_locale"`
	NotificationID   ID     `json:"notification_id"`
	NotificationType string `json:"notification_type"`
	Icon             string `json:"icon"`
	Title            string `json:"title"`
	Body             string `json:"body"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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