Skip to content

Commit

Permalink
use aws sdk crypto implementation (#11320)
Browse files Browse the repository at this point in the history
Co-authored-by: Will McVay <[email protected]>
Co-authored-by: Ashleigh Simonelli <[email protected]>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent 6ef5bc3 commit 515edd2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 2 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions packages/connect-session/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"commit": "yarn test --coverage --no-cache --silent --forceExit --detectOpenHandles --runInBand --watch=false && jest-coverage-badges --input src/tests/coverage/coverage-summary.json --output src/tests/badges && yarn lint --fix && yarn check"
},
"dependencies": {
"@aws-crypto/sha256-browser": "^5.2.0",
"axios": "^1.6.8",
"base-64": "^1.0.0",
"idtoken-verifier": "^2.2.4",
Expand Down
5 changes: 4 additions & 1 deletion packages/connect-session/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import decode from 'jwt-decode'
import { DecodedToken } from '../utils'
import { v4 as uuid } from 'uuid'
import { TextEncoder } from 'text-encoding'
import { Sha256 } from '@aws-crypto/sha256-browser'

type BasePayload = {
redirect_uri: string
Expand Down Expand Up @@ -126,7 +127,9 @@ export class ReapitConnectBrowserSession {
private async encryptCodeVerifier(code_verifier: string): Promise<string> {
const encoder = new TextEncoder()
const data = encoder.encode(code_verifier)
const digest = await window.crypto.subtle.digest('SHA-256', data)
const hash = new Sha256()
hash.update(data)
const digest = await hash.digest()

return btoa(String.fromCharCode.apply(null, [...new Uint8Array(digest)]))
.replace(/\+/g, '-')
Expand Down
49 changes: 48 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ __metadata:
languageName: node
linkType: hard

"@aws-crypto/sha256-browser@npm:^5.2.0":
version: 5.2.0
resolution: "@aws-crypto/sha256-browser@npm:5.2.0"
dependencies:
"@aws-crypto/sha256-js": "npm:^5.2.0"
"@aws-crypto/supports-web-crypto": "npm:^5.2.0"
"@aws-crypto/util": "npm:^5.2.0"
"@aws-sdk/types": "npm:^3.222.0"
"@aws-sdk/util-locate-window": "npm:^3.0.0"
"@smithy/util-utf8": "npm:^2.0.0"
tslib: "npm:^2.6.2"
checksum: 2b1b701ca6caa876333b4eb2b96e5187d71ebb51ebf8e2d632690dbcdedeff038202d23adcc97e023437ed42bb1963b7b463e343687edf0635fd4b98b2edad1a
languageName: node
linkType: hard

"@aws-crypto/sha256-js@npm:1.2.2":
version: 1.2.2
resolution: "@aws-crypto/sha256-js@npm:1.2.2"
Expand All @@ -400,6 +415,17 @@ __metadata:
languageName: node
linkType: hard

"@aws-crypto/sha256-js@npm:^5.2.0":
version: 5.2.0
resolution: "@aws-crypto/sha256-js@npm:5.2.0"
dependencies:
"@aws-crypto/util": "npm:^5.2.0"
"@aws-sdk/types": "npm:^3.222.0"
tslib: "npm:^2.6.2"
checksum: f46aace7b873c615be4e787ab0efd0148ef7de48f9f12c7d043e05c52e52b75bb0bf6dbcb9b2852d940d7724fab7b6d5ff1469160a3dd024efe7a68b5f70df8c
languageName: node
linkType: hard

"@aws-crypto/supports-web-crypto@npm:^3.0.0":
version: 3.0.0
resolution: "@aws-crypto/supports-web-crypto@npm:3.0.0"
Expand All @@ -409,6 +435,15 @@ __metadata:
languageName: node
linkType: hard

"@aws-crypto/supports-web-crypto@npm:^5.2.0":
version: 5.2.0
resolution: "@aws-crypto/supports-web-crypto@npm:5.2.0"
dependencies:
tslib: "npm:^2.6.2"
checksum: 6ed0c7e17f4f6663d057630805c45edb35d5693380c24ab52d4c453ece303c6c8a6ade9ee93c97dda77d9f6cae376ffbb44467057161c513dffa3422250edaf5
languageName: node
linkType: hard

"@aws-crypto/util@npm:^1.2.2":
version: 1.2.2
resolution: "@aws-crypto/util@npm:1.2.2"
Expand All @@ -431,6 +466,17 @@ __metadata:
languageName: node
linkType: hard

"@aws-crypto/util@npm:^5.2.0":
version: 5.2.0
resolution: "@aws-crypto/util@npm:5.2.0"
dependencies:
"@aws-sdk/types": "npm:^3.222.0"
"@smithy/util-utf8": "npm:^2.0.0"
tslib: "npm:^2.6.2"
checksum: f80a174c404e1ad4364741c942f440e75f834c08278fa754349fe23a6edc679d480ea9ced5820774aee58091ed270067022d8059ecf1a7ef452d58134ac7e9e1
languageName: node
linkType: hard

"@aws-sdk/client-cloudformation@npm:^3.410.0":
version: 3.537.0
resolution: "@aws-sdk/client-cloudformation@npm:3.537.0"
Expand Down Expand Up @@ -5890,6 +5936,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@reapit/connect-session@workspace:packages/connect-session"
dependencies:
"@aws-crypto/sha256-browser": "npm:^5.2.0"
"@reapit/config-manager": "workspace:packages/config-manager"
"@reapit/ts-scripts": "workspace:packages/ts-scripts"
"@reapit/ts-types": "workspace:packages/ts-types"
Expand Down Expand Up @@ -7610,7 +7657,7 @@ __metadata:
languageName: node
linkType: hard

"@smithy/util-utf8@npm:^2.3.0":
"@smithy/util-utf8@npm:^2.0.0, @smithy/util-utf8@npm:^2.3.0":
version: 2.3.0
resolution: "@smithy/util-utf8@npm:2.3.0"
dependencies:
Expand Down

0 comments on commit 515edd2

Please sign in to comment.