Skip to content

Commit cf7e389

Browse files
committed
fix: for MSRCrypto 1.6.0
Since MSRCrypto is a viable option for a falback, it must be usable. These differ from the WebCrypto API * The algorithm argument in importKey is passed through to the imported key. * The algorithm is normalize to lower case microsoft/MSR-JavaScript-Crypto#1
1 parent 6100d1d commit cf7e389

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

modules/material-management-browser/src/material_helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ export async function _importCryptoKey<T extends WebCryptoMaterial<T>> (
262262
* with browsers that need a zero byte gcm fallback.
263263
*/
264264
const format = 'raw'
265-
const algorithm = suite.kdf
265+
const algorithm = { name: suite.kdf, length: suite.keyLength }
266266
return subtle.importKey(format, udk, algorithm, extractable, keyUsages)
267267
} else {
268268
const format = 'jwk'
269-
const algorithm = suite.encryption
269+
const algorithm = { name: suite.encryption, length: suite.keyLength }
270270
const jwk = bytes2JWK(udk)
271271
return subtle.importKey(format, jwk, algorithm, extractable, keyUsages)
272272
}

modules/material-management/src/cryptographic_material.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,18 @@ export function isValidCryptoKey<T extends WebCryptoMaterial<T>> (
608608
// @ts-ignore length is an optional value...
609609
const { name, length } = algorithm
610610

611+
/* MSRCrypto, for legacy reasons,
612+
* normalizes the algorithm name
613+
* to lower case.
614+
* https://github.com/microsoft/MSR-JavaScript-Crypto/issues/1
615+
* For now, I'm going to upper case the name.
616+
*/
617+
611618
// Only symmetric algorithms
612619
return type === 'secret' &&
613620
// Must match the suite
614-
((kdf && name === kdf) ||
615-
(name === encryption && length === keyLength)) &&
621+
((kdf && name.toUpperCase() === kdf) ||
622+
(name.toUpperCase() === encryption && length === keyLength)) &&
616623
/* Only valid usage are: encrypt|decrypt|deriveKey
617624
* The complexity between deriveKey and suite.kdf should be handled in the Material class.
618625
*/

0 commit comments

Comments
 (0)