Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to v2 API #1

Merged
merged 20 commits into from
Jan 5, 2025
Merged

update to v2 API #1

merged 20 commits into from
Jan 5, 2025

Conversation

slingamn
Copy link
Member

@slingamn slingamn commented Dec 29, 2024

  • Pull in unmerged PRs from upstream, notably updates to use crypto/ecdh
  • Breaking API changes that reflect the current split between crypto/ecdh and crypto/ecdsa
  • Upgrade to JWT v5
  • Some refactoring and optimizations (nothing that made a big difference, ECC operations are over half the total CPU cost in my profiling)

emersion and others added 19 commits November 1, 2023 00:22
The RFC says:

> The "sub" claim SHOULD include a contact URI for the application
> server as either a "mailto:" (email) [RFC6068] or an "https:"
> [RFC2818] URI.

However the library assumes the passed in subscribed is always an
e-mail address, without leaving a way to pass an HTTPS URL.
This new test mocks both the user agent (e.g. browser) and the push service
(e.g. Firestore) to verify that encryption and decryption works properly.

I used the RFCs as reference (RFC8291, RFC8292 & RFC 8188), but didn't follow
them to the letter. The result can successfully check all the signatures and
decrypt the content, so it seems to be working.

Instead of the deprecated crypto/elliptic functions, this makes heavy use of
crypto/ecdh, which require Go 1.20. But this is only a test dependency, library
users should not be impacted.
crypto/elliptic is subject for removal soon, use of crypto/ecdh is advised
instead.

This has a number of side-effects:

- the required Go version increases to Go 1.20
- the configured VAPID keys get verified now, and invalid keys are rejected
  - this necessitated changes to some tests
  - VAPID is effectively mandatory now (but all push services I know require it
    anyway)

go.mod has been updated to reflect the new requirement, and I ran `go mod tidy`
to clean up go.sum.

I also added additional error context by wrapping errors with fmt.Errorf's %w
verb. This was introduced in Go 1.13.
* New key types for Keys and VAPIDKeys
* VAPID key serializes to a JSON string of the PEM-encoded PKCS8
The passed value was wrong, but net/http ignores it anyway (it does a type
assertion for bytes.Buffer and uses Len() on success).
@slingamn
Copy link
Member Author

cc @mrwonko ; this is an attempt at a v2 API for webpush-go that reflects the current split between crypto/ecdsa and crypto/ecdh.

Also sorry if you got a GitHub email from me last week claiming that your code was wrong!

@slingamn slingamn merged commit 20acb10 into master Jan 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants