-
Notifications
You must be signed in to change notification settings - Fork 209
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
Demonstrating Proof of Possession #1361
Closed
Closed
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
dd5adc6
Add initial DPoPService to create proofs when exchanging a secret
4bc0be5
Expose method on User class to access dpop proof after dpop bound acc…
460da52
Persist dpop CryptoKeyPair to indexeddb
d8d9ad6
refactor dpop service
542faa0
add DPoPService tests and setup jsdom to handle TextEncoder, TextDeco…
5d832fb
add optional dpop boolean to OidcClientSettings
9c5dd61
add test for ClientSettingsStore.dpop
ba16e05
Correct DPoP header name
ae148e5
Throw error if dpop keys are not found in the store, add tests
162ce9f
Remove dpop keys from storage on signout if dpop enabled
34a6407
add test from removing dpop keys when removing user
1f4320a
rename dpop setting to dpopEnabled
8838369
add test for invalid CryptoKeyPair in indexeddb, add failing test for…
1dbb762
rename dpop setting to dpopEnabled in oidcClientSettings
323aa5c
Add first cut support for bind DPoP key to auth code
d8840fa
Refactor dpopservice
fbe0b32
make DPoPService static
c9c3ee1
add DPoPSettings interface
9e4f76e
Include dpop key thumbprint if dpop enabled and bind_authorization_co…
7d7c7e8
Minor clean up
13cb759
Fix merge conflicts with main
9b2d100
remove jose jwt creation and base64url encode
47d7d40
remove jose entirely for DPoPService
9036ad0
Move functions into relevant util module and fix jwk serialisation error
50900fd
Move jose to dev deps for now
7085388
Move jwkthumbprint code and add test
4c5d727
Create IndexedDbStore class
fe84f3c
remove idb-keyval dep entirely
78891f0
add more tests for IndexedDbCryptoKeyPairStore
45302fb
change indexeddb db and store names
d78885f
Move dpopEnabdle out of json service and extend postFormOpts with ext…
92f5458
Store dpop nonce in session storage when received from authz server
d5067a6
remove nonce support for now, will do this separately in another PR
e71ddc5
Merge branch 'main' into DPoP
88af397
Use Opts interface for generateDPoPProof parameters
04b1a97
pull up DPoP into UserManager
284b6ca
Pull up DPoP settings out of OidcClientSettings and into UserManagerS…
1e019ea
refactor JsonService extraHeaders test
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 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 |
---|---|---|
|
@@ -22,3 +22,4 @@ node_modules/ | |
.vscode/ | ||
temp/ | ||
.history/ | ||
.idea/ |
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,28 @@ | ||
'use strict'; | ||
|
||
const { TextEncoder, TextDecoder } = require('util'); | ||
const { default: $JSDOMEnvironment, TestEnvironment } = require('jest-environment-jsdom'); | ||
const crypto = require("crypto"); | ||
|
||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
|
||
class JSDOMEnvironment extends $JSDOMEnvironment { | ||
constructor(...args) { | ||
const { global } = super(...args); | ||
// see https://github.com/jsdom/jsdom/issues/2524 | ||
global.TextEncoder = TextEncoder; | ||
global.TextDecoder = TextDecoder; | ||
// see https://github.com/jestjs/jest/issues/9983 | ||
global.Uint8Array = Uint8Array; | ||
global.crypto.subtle = crypto.subtle; | ||
global.crypto.randomUUID = crypto.randomUUID; | ||
// see https://github.com/dumbmatter/fakeIndexedDB#jsdom-often-used-with-jest | ||
global.structuredClone = structuredClone; | ||
} | ||
} | ||
|
||
exports.default = JSDOMEnvironment; | ||
exports.TestEnvironment = TestEnvironment === $JSDOMEnvironment ? | ||
JSDOMEnvironment : TestEnvironment; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
import { DPoPService } from "./DPoPService"; | ||
import { jwtVerify, decodeProtectedHeader, importJWK, type JWK } from "jose"; | ||
import { IndexedDbCryptoKeyPairStore as idb } from "./IndexedDbCryptoKeyPairStore"; | ||
|
||
describe("DPoPService", () => { | ||
|
||
beforeEach(async () => { | ||
await idb.remove("oidc.dpop"); | ||
}); | ||
|
||
describe("generateDPoPProof", () => { | ||
it("should generate a valid proof without an access token", async () => { | ||
const proof = await DPoPService.generateDPoPProof({ url: "http://example.com" }); | ||
const protectedHeader = decodeProtectedHeader(proof); | ||
const publicKey = await importJWK(<JWK>protectedHeader.jwk); | ||
const verifiedResult = await jwtVerify(proof, publicKey); | ||
|
||
expect(verifiedResult.payload).toHaveProperty("htu"); | ||
expect(verifiedResult.payload).toHaveProperty("htm"); | ||
}); | ||
|
||
it("should generate a valid proof with an access token", async () => { | ||
await DPoPService.generateDPoPProof({ url: "http://example.com" }); | ||
const proof = await DPoPService.generateDPoPProof({ url: "http://example.com", accessToken: "some_access_token" }); | ||
|
||
const protectedHeader = decodeProtectedHeader(proof); | ||
const publicKey = await importJWK(<JWK>protectedHeader.jwk); | ||
const verifiedResult = await jwtVerify(proof, publicKey); | ||
|
||
expect(verifiedResult.payload).toHaveProperty("htu"); | ||
expect(verifiedResult.payload).toHaveProperty("htm"); | ||
expect(verifiedResult.payload).toHaveProperty("ath"); | ||
expect(verifiedResult.payload["htu"]).toEqual("http://example.com"); | ||
}); | ||
}); | ||
|
||
describe("dpopJkt", () => { | ||
it("should generate crypto keys when generating a dpop thumbprint if no keys exists in the store", async () => { | ||
const setMock = jest.spyOn(idb, "set"); | ||
await DPoPService.generateDPoPJkt(); | ||
expect(setMock).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jsdom doesn't support some apis so I had to work around that.
jsdom/jsdom#2524
Also some issues with jest and esm modules...
https://stackoverflow.com/questions/76608600/jest-tests-are-failing-because-of-an-unknown-unexpected-token-export