-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix IE10 crypto #453
Fix IE10 crypto #453
Conversation
browser/lib/util/crypto.js
Outdated
@@ -14,7 +14,7 @@ var Crypto = (function() { | |||
* @param callback | |||
*/ | |||
var generateRandom; | |||
if(typeof Uint32Array !== 'undefined' && Platform.getRandomValues) { | |||
if(typeof Uint32Array !== 'undefined' && Platform.getRandomValues && window.crypto) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the sort of check that needs to be encapsulated in the Platform object. As it stands, the effect of this change will be to force weak random numbers for nativescript, react-native, and IE11 (which uses window.mscrypto
rather than window.crypto
), all of which do support strong random numbers via Platform.getRandomValues
. (Or just crash in the case of platforms with no window
object!)
To put it another way, the code already checks that Platform.getRandomValues
is defined; the bug is that it shouldn't be defined if in a browser context where you have neither window.crypto
nor window.mscrypto
.
@@ -76,7 +76,7 @@ define(['globals', 'browser-base64', 'ably'], function(ablyGlobals, base64, ably | |||
}).then(function (results) { | |||
callback(null, results.content.toString()); | |||
}) | |||
.catch(function(err) { | |||
['catch'](function(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the parsing issue is just that they don't like the newline before the method call with the dot syntax, would be clearer to just move it up to the previous line, avoid having to remember the rules of ASI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using
}).then(function (results) {
callback(null, results.content.toString());
}).catch(function(err) {
callback(err);
});
but no luck :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimonWoolf Is this preferable?
}).then(function (results) {
callback(null, results.content.toString());
})['catch'](function(err) {
callback(err);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so they're confused by catch being a keyword. Yup, I'd prefer that latter one to the original, as then it makes it clearer that it's a property access rather than an array literal, thanks
@@ -21,10 +21,12 @@ var Platform = { | |||
addEventListener: window.addEventListener, | |||
inspect: JSON.stringify, | |||
getRandomValues: (function(crypto) { | |||
if (crypto === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimonWoolf did you mean something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that should work. can you confirm it works as expected in IE10 etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimonWoolf Yup.
Tests keep on passing on Firefox and Chrome.
And with this also on IE10.
Attaching some screenshots for reference.
Thanks @funkyboy |
In particular this makes the following tests pass also on IE10: