Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci_static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Upgrade setuptools
run: python -m pip install "setuptools<81"
Comment thread
lucasmcdonald3 marked this conversation as resolved.
Outdated
- name: not-grep
uses: mattsb42-meta/not-grep@1.0.0
1 change: 0 additions & 1 deletion modules/web-crypto-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"license": "Apache-2.0",
"dependencies": {
"@aws-crypto/ie11-detection": "4.0.0",
"@aws-crypto/supports-web-crypto": "5.2.0",
"@aws-sdk/util-locate-window": "3.310.0",
"tslib": "^2.2.0"
Expand Down
3 changes: 0 additions & 3 deletions modules/web-crypto-backend/src/backend-factory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { isMsWindow } from '@aws-crypto/ie11-detection'
import {
supportsWebCrypto,
supportsSubtleCrypto,
supportsZeroByteGCM,
} from '@aws-crypto/supports-web-crypto'
import { generateSynchronousRandomValues } from './synchronous_random_values'
import promisifyMsSubtleCrypto from './promisify-ms-crypto'

type MaybeSubtleCrypto = SubtleCrypto | false
export type WebCryptoBackend =
Expand Down Expand Up @@ -140,7 +138,6 @@ export function pluckSubtleCrypto(window: Window): MaybeSubtleCrypto {
// if needed webkitSubtle check should be added here
// see: https://webkit.org/blog/7790/update-on-web-cryptography/
if (supportsWebCrypto(window)) return window.crypto.subtle
if (isMsWindow(window)) return promisifyMsSubtleCrypto(window.msCrypto.subtle)
return false
}

Expand Down
38 changes: 0 additions & 38 deletions modules/web-crypto-backend/src/promisify-ms-crypto.ts

This file was deleted.

5 changes: 0 additions & 5 deletions modules/web-crypto-backend/src/synchronous_random_values.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { isMsWindow } from '@aws-crypto/ie11-detection'
import { supportsSecureRandom } from '@aws-crypto/supports-web-crypto'
import { locateWindow } from '@aws-sdk/util-locate-window'

Expand All @@ -19,10 +18,6 @@ export function generateSynchronousRandomValues(
return function synchronousRandomValues(byteLength: number): Uint8Array {
if (supportsSecureRandom(globalScope)) {
return globalScope.crypto.getRandomValues(new Uint8Array(byteLength))
} else if (isMsWindow(globalScope)) {
const values = new Uint8Array(byteLength)
globalScope.msCrypto.getRandomValues(values)
return values
}

throw new Error(`Unable to locate a secure random source.`)
Expand Down
149 changes: 6 additions & 143 deletions modules/web-crypto-backend/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

export const fakeWindowWebCryptoSupportsZeroByteGCM: Window = {
crypto: {
getRandomValues: () => {},
getRandomValues: (array: Uint8Array) => {
for (let i = 0; i < array.length; i++) {
array[i] = Math.floor(Math.random() * 256)
}
return array
},
subtle: {
async decrypt() {
return {} as any
Expand Down Expand Up @@ -142,145 +147,3 @@ export const subtleFallbackZeroByteEncryptFail = {
} as any

export const subtleFallbackNoWebCrypto = {} as any

export const fakeWindowIE11OnComplete = {
msCrypto: {
getRandomValues: (values: Uint8Array) => {
return values.fill(1)
},
subtle: {
decrypt() {
const obj = {} as any
setTimeout(() => {
obj.result = true
obj.oncomplete()
})
return obj
},
digest() {
const obj = {} as any
setTimeout(() => {
obj.result = true
obj.oncomplete()
})
return obj
},
encrypt() {
const obj = {} as any
setTimeout(() => {
obj.result = true
obj.oncomplete()
})
return obj
},
exportKey() {
const obj = {} as any
setTimeout(() => {
obj.result = true
obj.oncomplete()
})
return obj
},
generateKey() {
const obj = {} as any
setTimeout(() => {
obj.result = true
obj.oncomplete()
})
return obj
},
importKey() {
const obj = {} as any
setTimeout(() => {
obj.result = true
obj.oncomplete()
})
return obj
},
sign() {
const obj = {} as any
setTimeout(() => {
obj.result = true
obj.oncomplete()
})
return obj
},
verify() {
const obj = {} as any
setTimeout(() => {
obj.result = true
obj.oncomplete()
})
return obj
},
},
},
MSInputMethodContext: {} as any,
} as any

export const fakeWindowIE11OnError = {
msCrypto: {
getRandomValues: (values: Uint8Array) => {
return values.fill(1)
},
subtle: {
decrypt() {
const obj = {} as any
setTimeout(() => {
obj.onerror(new Error('stub error'))
})
return obj
},
digest() {
const obj = {} as any
setTimeout(() => {
obj.onerror(new Error('stub error'))
})
return obj
},
encrypt() {
const obj = {} as any
setTimeout(() => {
obj.onerror(new Error('stub error'))
})
return obj
},
exportKey() {
const obj = {} as any
setTimeout(() => {
obj.onerror(new Error('stub error'))
})
return obj
},
generateKey() {
const obj = {} as any
setTimeout(() => {
obj.onerror(new Error('stub error'))
})
return obj
},
importKey() {
const obj = {} as any
setTimeout(() => {
obj.onerror(new Error('stub error'))
})
return obj
},
sign() {
const obj = {} as any
setTimeout(() => {
obj.onerror(new Error('stub error'))
})
return obj
},
verify() {
const obj = {} as any
setTimeout(() => {
obj.onerror(new Error('stub error'))
})
return obj
},
},
},
MSInputMethodContext: {} as any,
} as any
36 changes: 0 additions & 36 deletions modules/web-crypto-backend/test/promisify-ms-crypto.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,15 @@

import { expect } from 'chai'
import { generateSynchronousRandomValues } from '../src/synchronous_random_values'
import { synchronousRandomValues } from '../src/index'
import * as fixtures from './fixtures'

describe('synchronousRandomValues', () => {
it('should return random values', () => {
const test = synchronousRandomValues(5)
expect(test).to.be.instanceOf(Uint8Array)
expect(test).lengthOf(5)
})

it('should return msCrypto random values', () => {
const synchronousRandomValues = generateSynchronousRandomValues(
fixtures.fakeWindowIE11OnComplete
fixtures.fakeWindowWebCryptoSupportsZeroByteGCM
)

const test = synchronousRandomValues(5)
expect(test).to.be.instanceOf(Uint8Array)
expect(test).lengthOf(5)
// The random is a stub, so I know the value
expect(test).to.deep.equal(new Uint8Array(5).fill(1))
})
})
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.