-
Notifications
You must be signed in to change notification settings - Fork 10
feat: implement new keypackage api [WPB-19574] #1598
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
57 commits
Select commit
Hold shift + click to select a range
feffab9
refactor: `StoredCredential` stores `ciphersuite` not `signature_scheme`
coriolinus ce87314
chore: add `v7` wasm migration
coriolinus 9ae3871
build: add dev-dependencies to keystore for a new test
coriolinus f3334b5
chore: add a sqlite migration test
coriolinus 20c9501
chore: add `v18`, `v19` sqlite migrations + meta-migration
coriolinus 2429a0d
chore: add `KeyPackage::make_ref`
coriolinus 26f333d
feat: add ciphersuite to credential
coriolinus c85259b
chore: adjust tests for ciphersuite in credential
coriolinus 7606b08
feat: add `generate_keypackage` according to new api
coriolinus a682a73
feat: add `getKeypackages()`
coriolinus 49a4f64
chore: add `Session::load_keypackage`
coriolinus be15355
feat: add `TransactionContext::remove_keypackage`
coriolinus 0a29434
feat: add `TransactionContext::remove_keypackages_for`
coriolinus e5f5429
chore: use new api in `Session::remove_credential`
coriolinus 10a4936
chore(ffi): adjust usage to new CC api
coriolinus f777f26
chore(ffi): push new APIs to the FFI layer
coriolinus d6ff28c
chore: ensure everything builds
coriolinus 43161ab
chore: ensure there is no unreachable pub item
coriolinus 06a52a1
chore: make `KEYPACKAGE_DEFAULT_LIFETIME` public
coriolinus d696666
refactor: `Keypackage` is a struct of its own
coriolinus c0cf846
chore: cause to build cleanly on all targets
coriolinus dfb8790
chore: rm intra-doc links from ffi docs
coriolinus a001433
chore: reduce visibility to eliminate unreachable public item
coriolinus bbb3088
chore(ts): propagate new keypackage api
coriolinus 7dafa5e
test(ts): add tests for new keypackage api
coriolinus 166c056
chore(ffi): expose `SignatureScheme` over FFI
coriolinus f664fa9
chore(ffi): make certain conversions safely infallible
coriolinus 0bc6114
chore: use correct procedure for identifying keypackages for a creden…
coriolinus e097e08
chore: cause uniffi to use a default when keypackage lifetime unspeci…
coriolinus 8887842
test(jvm): add tests for new keypackage api
coriolinus 76b6bb1
test(swift): add tests for new keypackage api
coriolinus b742863
chore: add some tsdoc `@param` notations
coriolinus fc25147
chore: reexport some more ts types for documentation
coriolinus 7c94503
feat: add utility methods to `KeyPackageExt`
coriolinus 9ea95b7
feat: make keypackage refs fat
coriolinus 83e5704
chore: rm old `client_keypackages` method
coriolinus 98053e2
chore: rm old `deleteStaleKeypackages` method
coriolinus d909bd7
chore: rm old `client_valid_keypackages_count` method
coriolinus 937af61
chore: rm old `prune_keypackages` method
coriolinus 569845f
chore: rm old `generate_one_keypackage_from_credential` method
coriolinus 07c8cf9
chore: transaction context uses proper keypackage, ref structs
coriolinus ead8fa1
chore: CC tests compile with new keypackage api
coriolinus 75aacba
chore(ffi): update to new keypackage api
coriolinus a39d68f
chore(interop): update to new keypackage api
coriolinus b38a15b
chore(docs): ensure intra-doc links work
coriolinus dcb24f5
chore: fix clippy lints
coriolinus 2c66c3f
chore(benches): refactor initialization for better credential handling
coriolinus c6928f6
chore: fix a test which was failing due to changed semantics
coriolinus d47e27b
chore: fix a test which was failing due to changed semantics
coriolinus 44f5f2e
chore(ts): remove removed methods
coriolinus c4d03ff
chore(ts): adjust tests to use only new keypackage api
coriolinus e8aedee
chore(ts): update docs to not mention removed methods
coriolinus 007a941
chore(jvm): adapt tests to new keypackage api
coriolinus cf89d42
chore(swift): adjust tests to the new api
coriolinus 366969e
chore(interop/js): adjust to new api
coriolinus beab6cd
chore: `cargo +nightly fmt`
coriolinus 326ba95
chore(js): copy bun tests into browser context
coriolinus 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import { ccInit, setup, teardown } from "./utils"; | ||
coriolinus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import { afterEach, test, beforeEach, describe, expect } from "bun:test"; | ||
| import { ciphersuiteDefault, ClientId } from "../../src/CoreCrypto"; | ||
| import { | ||
| Ciphersuite, | ||
| credentialBasic, | ||
| Keypackage, | ||
| } from "../../src/autogenerated/core_crypto_ffi"; | ||
|
|
||
| beforeEach(async () => { | ||
| await setup(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await teardown(); | ||
| }); | ||
|
|
||
| describe("key package", () => { | ||
| test("can be created", async () => { | ||
| const clientId = new ClientId( | ||
| Buffer.from("any random client id here").buffer | ||
| ); | ||
| const credential = credentialBasic(ciphersuiteDefault(), clientId); | ||
|
|
||
| const cc = await ccInit(clientId); | ||
|
|
||
| const credentialRef = await cc.transaction(async (ctx) => { | ||
| return await ctx.addCredential(credential); | ||
| }); | ||
|
|
||
| const keyPackage = await cc.transaction(async (ctx) => { | ||
| return await ctx.generateKeypackage(credentialRef); | ||
| }); | ||
|
|
||
| expect(keyPackage).toBeDefined(); | ||
| }); | ||
|
|
||
| test("can be serialized", async () => { | ||
| const clientId = new ClientId( | ||
| Buffer.from("any random client id here").buffer | ||
| ); | ||
| const credential = credentialBasic(ciphersuiteDefault(), clientId); | ||
|
|
||
| const cc = await ccInit(clientId); | ||
|
|
||
| const credentialRef = await cc.transaction(async (ctx) => { | ||
| return await ctx.addCredential(credential); | ||
| }); | ||
|
|
||
| const keyPackage = await cc.transaction(async (ctx) => { | ||
| return await ctx.generateKeypackage(credentialRef); | ||
| }); | ||
|
|
||
| const bytes = new Uint8Array(keyPackage.serialize()); | ||
|
|
||
| expect(bytes).toBeDefined(); | ||
| expect(bytes).not.toBeEmpty(); | ||
|
|
||
| // roundtrip | ||
| const kp2 = new Keypackage(bytes.buffer); | ||
| const bytes2 = new Uint8Array(kp2.serialize()); | ||
|
|
||
| expect(bytes2).toEqual(bytes); | ||
| }); | ||
|
|
||
| test("can be retrieved in bulk", async () => { | ||
| const clientId = new ClientId( | ||
| Buffer.from("any random client id here").buffer | ||
| ); | ||
| const credential = credentialBasic(ciphersuiteDefault(), clientId); | ||
|
|
||
| const cc = await ccInit(clientId); | ||
|
|
||
| const credentialRef = await cc.transaction(async (ctx) => { | ||
| return await ctx.addCredential(credential); | ||
| }); | ||
|
|
||
| await cc.transaction(async (ctx) => { | ||
| await ctx.generateKeypackage(credentialRef); | ||
| }); | ||
|
|
||
| const keyPackages = await cc.transaction(async (ctx) => { | ||
| return await ctx.getKeypackages(); | ||
| }); | ||
|
|
||
| expect(keyPackages).toBeDefined(); | ||
| expect(keyPackages).toBeArrayOfSize(1); | ||
| expect(keyPackages[0]).toBeDefined(); | ||
| }); | ||
|
|
||
| test("can be removed", async () => { | ||
| const clientId = new ClientId( | ||
| Buffer.from("any random client id here").buffer | ||
| ); | ||
| const credential = credentialBasic(ciphersuiteDefault(), clientId); | ||
|
|
||
| const cc = await ccInit(clientId); | ||
|
|
||
| const credentialRef = await cc.transaction(async (ctx) => { | ||
| return await ctx.addCredential(credential); | ||
| }); | ||
|
|
||
| // add a kp which will not be removed, so we have one left over | ||
| await cc.transaction(async (ctx) => { | ||
| await ctx.generateKeypackage(credentialRef); | ||
| }); | ||
|
|
||
| // add a kp which will be removed | ||
| const keyPackage = await cc.transaction(async (ctx) => { | ||
| return await ctx.generateKeypackage(credentialRef); | ||
| }); | ||
|
|
||
| // now remove the keypackage | ||
| await cc.transaction(async (ctx) => { | ||
| await ctx.removeKeypackage(keyPackage.ref()); | ||
| }); | ||
|
|
||
| const keyPackages = await cc.transaction(async (ctx) => { | ||
| return await ctx.getKeypackages(); | ||
| }); | ||
|
|
||
| expect(keyPackages).toBeDefined(); | ||
| expect(keyPackages).toBeArrayOfSize(1); | ||
| }); | ||
|
|
||
| test("can be removed by credentialref", async () => { | ||
| const clientId = new ClientId( | ||
| Buffer.from("any random client id here").buffer | ||
| ); | ||
| const credential1 = credentialBasic( | ||
| Ciphersuite.Mls128Dhkemx25519Aes128gcmSha256Ed25519, | ||
| clientId | ||
| ); | ||
| const credential2 = credentialBasic( | ||
| Ciphersuite.Mls128Dhkemp256Aes128gcmSha256P256, | ||
| clientId | ||
| ); | ||
| const cc = await ccInit(clientId); | ||
|
|
||
| await cc.transaction(async (ctx) => { | ||
| const cref1 = await ctx.addCredential(credential1); | ||
| const cref2 = await ctx.addCredential(credential2); | ||
|
|
||
| // we're going to generate keypackages for both credentials, | ||
| // then remove those packages for credential 2, leaving behind those for credential 1 | ||
| const KEYPACKAGES_PER_CREDENTIAL = 2; | ||
| for (const cref of [cref1, cref2]) { | ||
| for (let i = 0; i < KEYPACKAGES_PER_CREDENTIAL; i++) { | ||
| await ctx.generateKeypackage(cref); | ||
| } | ||
| } | ||
|
|
||
| const kpsBeforeRemoval = await ctx.getKeypackages(); | ||
| // 2 credentials with the same n keypackages each | ||
| expect(kpsBeforeRemoval).toBeArrayOfSize( | ||
| KEYPACKAGES_PER_CREDENTIAL * 2 | ||
| ); | ||
|
|
||
| // now remove all keypackages for one of the credentials | ||
| await ctx.removeKeypackagesFor(cref1); | ||
|
|
||
| const kps = await ctx.getKeypackages(); | ||
| expect(kps).toBeArrayOfSize(KEYPACKAGES_PER_CREDENTIAL); | ||
| }); | ||
| }); | ||
| }); | ||
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
Oops, something went wrong.
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.