Skip to content

Decrypt and parse Web Push Notifications sent by Mastodon

License

Notifications You must be signed in to change notification settings

buckket/go-mastopush

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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+

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages