-
Notifications
You must be signed in to change notification settings - Fork 34
Bug 1689547 - First attempt at providing a ping encryption plugin #96
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
243d970
First attempt at providing a ping encrypiton plugin
ad5cbbd
Add tests and fix(?) issues
5c2f984
Change alg and keys used
58812e3
Attend to review comments
5aa303c
Make testing a bit more comprehensive
f3d9b72
Update glean/src/plugins/encryption.ts
brizental d95c2fe
BONUS: Use descriptive app id for tests
405022d
Attend to review comments
b8c1976
Fix identation and add method to get registered plugin name in events
141b080
Catch plugin errors on afterPingCollection event
fd541f9
Add extra test to encryption plugin and fix kid
7e2f338
Add more context to alg and enc comment
07ab598
Bundle plugins code in the final package
4a3cd1b
Update CHANGELOG.md
da52189
Fix errors that surfaced after rebase
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,60 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import CompactEncrypt from "jose/jwe/compact/encrypt"; | ||
| import parseJwk from "jose/jwk/parse"; | ||
| import calculateThumbprint from "jose/jwk/thumbprint"; | ||
| import { JWK } from "jose/types"; | ||
|
|
||
| import Plugin from "./index"; | ||
| import { PingPayload } from "../core/pings/database"; | ||
| import { JSONObject } from "../core/utils"; | ||
| import CoreEvents from "../core/events"; | ||
|
|
||
| // These are the chosen defaults, because they are the ones expected by Glean's data pipeline. | ||
| // | ||
| // That is the case because they are the only algorithm and content encoding pair supported | ||
| // by Firefox's hand-rolled JWE implementation. | ||
| // See: https://searchfox.org/mozilla-central/rev/eeb8cf278192d68b3977d0adb4d43f1463439269/services/crypto/modules/jwcrypto.jsm#58-74 | ||
| const JWE_ALGORITHM = "ECDH-ES"; | ||
| const JWE_CONTENT_ENCODING = "A256GCM"; | ||
|
|
||
| /** | ||
| * A plugin that listens for the `afterPingCollection` event and encrypts **all** outgoing pings | ||
| * with the JWK provided upon initialization. | ||
brizental marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * This plugin will modify the schema of outgoing pings to: | ||
| * | ||
| * ```json | ||
| * { | ||
| * payload: "<encrypted-payload>" | ||
| * } | ||
| * ``` | ||
| */ | ||
| class PingEncryptionPlugin extends Plugin<typeof CoreEvents["afterPingCollection"]> { | ||
| /** | ||
| * Creates a new PingEncryptionPlugin instance. | ||
| * | ||
| * @param jwk The JWK that will be used to encode outgoing ping payloads. | ||
| */ | ||
| constructor(private jwk: JWK) { | ||
| super(CoreEvents["afterPingCollection"].name, "pingEncryptionPlugin"); | ||
| } | ||
|
|
||
| async action(payload: PingPayload): Promise<JSONObject> { | ||
| const key = await parseJwk(this.jwk, JWE_ALGORITHM); | ||
brizental marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const encoder = new TextEncoder(); | ||
| const encodedPayload = await new CompactEncrypt(encoder.encode(JSON.stringify(payload))) | ||
| .setProtectedHeader({ | ||
| kid: await calculateThumbprint(this.jwk), | ||
| alg: JWE_ALGORITHM, | ||
| enc: JWE_CONTENT_ENCODING, | ||
| typ: "JWE", | ||
| }) | ||
| .encrypt(key); | ||
| return { payload: encodedPayload }; | ||
brizental marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| export default PingEncryptionPlugin; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.