Skip to content
Decrypt and parse Web Push Notifications sent by Mastodon
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
.gitignore
.travis.yml
LICENSE
README.md
compat.go
crypto.go
go.mod
go.sum
helper.go
mastopush.go

README.md

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+

You can’t perform that action at this time.