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"
}
go get -u github.com/buckket/go-mastopush
Here’s a simple example project. Check GoDoc for the full documentation.
- Only supports
aesgcm
and notaes128gcm
. 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.
- 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.
GNU GPLv3+