Skip to content

Commit

Permalink
fix: Get correct version of IE11 crypto (#274)
Browse files Browse the repository at this point in the history
Users on Windows 7 and IE11 sometimes trigger a bind error because the
crypto object exists but getRandomValues is undefined. Using
openpgpjs/openpgpjs#207 as a reference, I've
added a more robust check for the necessary crypto properties in IE 11.
  • Loading branch information
robwierzbowski authored and broofa committed Apr 25, 2018
1 parent df40e54 commit 153d331
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/rng-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// and inconsistent support for the `crypto` API. We do the best we can via
// feature-detection

// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues.bind(crypto)) ||
(typeof(msCrypto) != 'undefined' && msCrypto.getRandomValues.bind(msCrypto));
// getRandomValues needs to be invoked in a context where "this" is a Crypto
// implementation. Also, find the complete implementation of crypto on IE11.
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||
(typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));

if (getRandomValues) {
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
Expand Down

0 comments on commit 153d331

Please sign in to comment.