-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add system metadata assertion #630
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 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
09a917a
feat: add system metadata assertion
strantalis 44a4aec
remove unused helper
strantalis 78040bf
update tests to check values
strantalis 366573d
fix version reference
strantalis 9670fa9
fix test assert
strantalis 3608b6f
fix tests
strantalis 8c7194c
Merge branch 'main' into dspx-817/add-system-assertions
mkleene 654fada
Update assertions.ts
mkleene 2c9aee3
Update encrypt-decrypt.spec.ts
mkleene 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
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 |
---|---|---|
|
@@ -6,7 +6,12 @@ import { KasPublicKeyAlgorithm } from '../../src/access.js'; | |
import { AuthProvider, HttpRequest } from '../../src/auth/auth.js'; | ||
import { AesGcmCipher, KeyInfo, SplitKey, WebCryptoService } from '../../tdf3/index.js'; | ||
import { Client } from '../../tdf3/src/index.js'; | ||
import { AssertionConfig, AssertionVerificationKeys } from '../../tdf3/src/assertions.js'; | ||
import { | ||
AssertionConfig, | ||
AssertionVerificationKeys, | ||
getSystemMetadataAssertionConfig, | ||
Assertion, | ||
} from '../../tdf3/src/assertions.js'; | ||
import { Scope } from '../../tdf3/src/client/builders.js'; | ||
import { NetworkError } from '../../src/errors.js'; | ||
|
||
|
@@ -365,4 +370,70 @@ describe('encrypt decrypt test', async function () { | |
}); | ||
} | ||
} | ||
|
||
it('encrypt-decrypt with system metadata assertion', async function () { | ||
const cipher = new AesGcmCipher(WebCryptoService); | ||
const encryptionInformation = new SplitKey(cipher); | ||
const key1 = await encryptionInformation.generateKey(); | ||
const keyMiddleware = async () => ({ keyForEncryption: key1, keyForManifest: key1 }); | ||
|
||
const client = new Client.Client({ | ||
kasEndpoint: kasUrl, | ||
platformUrl: kasUrl, | ||
dpopKeys: Mocks.entityKeyPair(), | ||
clientId: 'id', | ||
authProvider, | ||
}); | ||
|
||
const scope: Scope = { | ||
dissem: ['[email protected]'], | ||
attributes: [], | ||
}; | ||
|
||
const encryptedStream = await client.encrypt({ | ||
metadata: Mocks.getMetadataObject(), | ||
wrappingKeyAlgorithm: 'rsa:2048', | ||
offline: true, | ||
scope, | ||
keyMiddleware, | ||
source: new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(new TextEncoder().encode(expectedVal)); | ||
controller.close(); | ||
}, | ||
}), | ||
systemMetadataAssertion: true, // Enable the system metadata assertion | ||
}); | ||
|
||
// Verify the manifest for the system metadata assertion | ||
const manifest = encryptedStream.manifest; | ||
expect(Array.isArray(manifest.assertions)).toBe(true); | ||
expect(manifest.assertions).toHaveLength(1); // Assuming only system metadata assertion for this test | ||
|
||
const systemAssertion = manifest.assertions.find( | ||
(assertion: Assertion) => assertion.id === 'system-metadata' | ||
); | ||
expect(systemAssertion).not.toBeUndefined(); | ||
if (systemAssertion) { | ||
expect(systemAssertion.type).toBe('other'); | ||
expect(systemAssertion.scope).toBe('tdo'); | ||
expect(systemAssertion.statement.format).toBe('json'); | ||
expect(systemAssertion.statement.schema).toBe('system-metadata-v1'); | ||
|
||
const metadataValue = JSON.parse(systemAssertion.statement.value); | ||
expect(metadataValue).toHaveProperty('tdfSpecVersion'); | ||
expect(metadataValue).toHaveProperty('creationDate'); | ||
expect(metadataValue).toHaveProperty('os'); | ||
expect(metadataValue).toHaveProperty('sdkVersion'); | ||
expect(metadataValue).toHaveProperty('browserUserAgent'); | ||
expect(metadataValue).toHaveProperty('platform'); | ||
} | ||
|
||
const decryptStream = await client.decrypt({ | ||
source: { type: 'stream', location: encryptedStream.stream }, | ||
}); | ||
|
||
const { value: decryptedText } = await decryptStream.stream.getReader().read(); | ||
assert.equal(new TextDecoder().decode(decryptedText), expectedVal); | ||
}); | ||
}); |
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.