File tree Expand file tree Collapse file tree 8 files changed +8
-249
lines changed
modules/web-crypto-backend Expand file tree Collapse file tree 8 files changed +8
-249
lines changed Original file line number Diff line number Diff line change 1919 },
2020 "license" : " Apache-2.0" ,
2121 "dependencies" : {
22- "@aws-crypto/ie11-detection" : " 4.0.0" ,
2322 "@aws-crypto/supports-web-crypto" : " 5.2.0" ,
2423 "@aws-sdk/util-locate-window" : " 3.310.0" ,
2524 "tslib" : " ^2.2.0"
Original file line number Diff line number Diff line change 11// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- import { isMsWindow } from '@aws-crypto/ie11-detection'
54import {
65 supportsWebCrypto ,
76 supportsSubtleCrypto ,
87 supportsZeroByteGCM ,
98} from '@aws-crypto/supports-web-crypto'
109import { generateSynchronousRandomValues } from './synchronous_random_values'
11- import promisifyMsSubtleCrypto from './promisify-ms-crypto'
1210
1311type MaybeSubtleCrypto = SubtleCrypto | false
1412export type WebCryptoBackend =
@@ -140,7 +138,6 @@ export function pluckSubtleCrypto(window: Window): MaybeSubtleCrypto {
140138 // if needed webkitSubtle check should be added here
141139 // see: https://webkit.org/blog/7790/update-on-web-cryptography/
142140 if ( supportsWebCrypto ( window ) ) return window . crypto . subtle
143- if ( isMsWindow ( window ) ) return promisifyMsSubtleCrypto ( window . msCrypto . subtle )
144141 return false
145142}
146143
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- import { isMsWindow } from '@aws-crypto/ie11-detection'
54import { supportsSecureRandom } from '@aws-crypto/supports-web-crypto'
65import { locateWindow } from '@aws-sdk/util-locate-window'
76
@@ -19,10 +18,6 @@ export function generateSynchronousRandomValues(
1918 return function synchronousRandomValues ( byteLength : number ) : Uint8Array {
2019 if ( supportsSecureRandom ( globalScope ) ) {
2120 return globalScope . crypto . getRandomValues ( new Uint8Array ( byteLength ) )
22- } else if ( isMsWindow ( globalScope ) ) {
23- const values = new Uint8Array ( byteLength )
24- globalScope . msCrypto . getRandomValues ( values )
25- return values
2621 }
2722
2823 throw new Error ( `Unable to locate a secure random source.` )
Original file line number Diff line number Diff line change 33
44export const fakeWindowWebCryptoSupportsZeroByteGCM : Window = {
55 crypto : {
6- getRandomValues : ( ) => { } ,
6+ getRandomValues : ( array : Uint8Array ) => {
7+ for ( let i = 0 ; i < array . length ; i ++ ) {
8+ array [ i ] = Math . floor ( Math . random ( ) * 256 )
9+ }
10+ return array
11+ } ,
712 subtle : {
813 async decrypt ( ) {
914 return { } as any
@@ -142,145 +147,3 @@ export const subtleFallbackZeroByteEncryptFail = {
142147} as any
143148
144149export const subtleFallbackNoWebCrypto = { } as any
145-
146- export const fakeWindowIE11OnComplete = {
147- msCrypto : {
148- getRandomValues : ( values : Uint8Array ) => {
149- return values . fill ( 1 )
150- } ,
151- subtle : {
152- decrypt ( ) {
153- const obj = { } as any
154- setTimeout ( ( ) => {
155- obj . result = true
156- obj . oncomplete ( )
157- } )
158- return obj
159- } ,
160- digest ( ) {
161- const obj = { } as any
162- setTimeout ( ( ) => {
163- obj . result = true
164- obj . oncomplete ( )
165- } )
166- return obj
167- } ,
168- encrypt ( ) {
169- const obj = { } as any
170- setTimeout ( ( ) => {
171- obj . result = true
172- obj . oncomplete ( )
173- } )
174- return obj
175- } ,
176- exportKey ( ) {
177- const obj = { } as any
178- setTimeout ( ( ) => {
179- obj . result = true
180- obj . oncomplete ( )
181- } )
182- return obj
183- } ,
184- generateKey ( ) {
185- const obj = { } as any
186- setTimeout ( ( ) => {
187- obj . result = true
188- obj . oncomplete ( )
189- } )
190- return obj
191- } ,
192- importKey ( ) {
193- const obj = { } as any
194- setTimeout ( ( ) => {
195- obj . result = true
196- obj . oncomplete ( )
197- } )
198- return obj
199- } ,
200- sign ( ) {
201- const obj = { } as any
202- setTimeout ( ( ) => {
203- obj . result = true
204- obj . oncomplete ( )
205- } )
206- return obj
207- } ,
208- verify ( ) {
209- const obj = { } as any
210- setTimeout ( ( ) => {
211- obj . result = true
212- obj . oncomplete ( )
213- } )
214- return obj
215- } ,
216- } ,
217- } ,
218- MSInputMethodContext : { } as any ,
219- } as any
220-
221- export const fakeWindowIE11OnError = {
222- msCrypto : {
223- getRandomValues : ( values : Uint8Array ) => {
224- return values . fill ( 1 )
225- } ,
226- subtle : {
227- decrypt ( ) {
228- const obj = { } as any
229- setTimeout ( ( ) => {
230- obj . onerror ( new Error ( 'stub error' ) )
231- } )
232- return obj
233- } ,
234- digest ( ) {
235- const obj = { } as any
236- setTimeout ( ( ) => {
237- obj . onerror ( new Error ( 'stub error' ) )
238- } )
239- return obj
240- } ,
241- encrypt ( ) {
242- const obj = { } as any
243- setTimeout ( ( ) => {
244- obj . onerror ( new Error ( 'stub error' ) )
245- } )
246- return obj
247- } ,
248- exportKey ( ) {
249- const obj = { } as any
250- setTimeout ( ( ) => {
251- obj . onerror ( new Error ( 'stub error' ) )
252- } )
253- return obj
254- } ,
255- generateKey ( ) {
256- const obj = { } as any
257- setTimeout ( ( ) => {
258- obj . onerror ( new Error ( 'stub error' ) )
259- } )
260- return obj
261- } ,
262- importKey ( ) {
263- const obj = { } as any
264- setTimeout ( ( ) => {
265- obj . onerror ( new Error ( 'stub error' ) )
266- } )
267- return obj
268- } ,
269- sign ( ) {
270- const obj = { } as any
271- setTimeout ( ( ) => {
272- obj . onerror ( new Error ( 'stub error' ) )
273- } )
274- return obj
275- } ,
276- verify ( ) {
277- const obj = { } as any
278- setTimeout ( ( ) => {
279- obj . onerror ( new Error ( 'stub error' ) )
280- } )
281- return obj
282- } ,
283- } ,
284- } ,
285- MSInputMethodContext : { } as any ,
286- } as any
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 55
66import { expect } from 'chai'
77import { generateSynchronousRandomValues } from '../src/synchronous_random_values'
8- import { synchronousRandomValues } from '../src/index'
98import * as fixtures from './fixtures'
109
1110describe ( 'synchronousRandomValues' , ( ) => {
1211 it ( 'should return random values' , ( ) => {
13- const test = synchronousRandomValues ( 5 )
14- expect ( test ) . to . be . instanceOf ( Uint8Array )
15- expect ( test ) . lengthOf ( 5 )
16- } )
17-
18- it ( 'should return msCrypto random values' , ( ) => {
1912 const synchronousRandomValues = generateSynchronousRandomValues (
20- fixtures . fakeWindowIE11OnComplete
13+ fixtures . fakeWindowWebCryptoSupportsZeroByteGCM
2114 )
22-
2315 const test = synchronousRandomValues ( 5 )
2416 expect ( test ) . to . be . instanceOf ( Uint8Array )
2517 expect ( test ) . lengthOf ( 5 )
26- // The random is a stub, so I know the value
27- expect ( test ) . to . deep . equal ( new Uint8Array ( 5 ) . fill ( 1 ) )
2818 } )
2919} )
You can’t perform that action at this time.
0 commit comments