-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ability to track messages based on known VAPID keys (#739)
_*Note*_: This introduces a new setting for autoendpoint: `tracking_keys` This is a JSON formatted list of the "raw"/x962 formatted VAPID public keys that should be monitored for Push tracking and follows the same format as other key data fields. The newly added `script/convert_pem_to_x962.py` script aids by reading a VAPID public key PEM file and outputing a x962 formatted string. Closes: [SYNC-4349](https://mozilla-hub.atlassian.net/browse/SYNC-4349) [SYNC-4349]: https://mozilla-hub.atlassian.net/browse/SYNC-4349?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
Showing
5 changed files
with
160 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Convert a EC Public key in PEM format into an b64 x962 string. | ||
Autopush will try to scan for known VAPID public keys to track. These keys | ||
are specified in the header as x962 formatted strings. X962 is effectively | ||
"raw" format and contains the two longs that are the coordinates for the | ||
public key. | ||
""" | ||
import base64 | ||
import sys | ||
|
||
from typing import cast | ||
from cryptography.hazmat.primitives.asymmetric import ec | ||
from cryptography.hazmat.primitives import serialization | ||
|
||
try: | ||
with open(sys.argv[1], "rb") as fp: | ||
content = fp.read() | ||
pubkey = serialization.load_pem_public_key(content) | ||
except IndexError: | ||
print ("Please specify a public key PEM file to convert.") | ||
exit() | ||
|
||
pk_string = cast(ec.EllipticCurvePublicKey, pubkey).public_bytes( | ||
serialization.Encoding.X962, | ||
serialization.PublicFormat.UncompressedPoint | ||
) | ||
|
||
pk_string = base64.urlsafe_b64encode(pk_string).strip(b'=') | ||
|
||
print(f"{pk_string.decode()}") |