Skip to content
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

Merged
merged 4 commits into from
Jan 26, 2018
Merged

Fix IE10 crypto #453

merged 4 commits into from
Jan 26, 2018

Conversation

funkyboy
Copy link
Contributor

In particular this makes the following tests pass also on IE10:

2.generateRandomKey0 (2, 0, 2)
3.generateRandomKey1 (2, 0, 2)
4.getDefaultParams_wordArray_key (2, 0, 2)
5.getDefaultParams_base64_key (2, 0, 2)
6.getDefaultParams_check_keylength (2, 0, 2)
7.getDefaultParams_preserves_custom_algorithms (2, 0, 2)
15.single_send_128_with_web_socket_binary_transport (2, 0, 2)
16.single_send_128_with_web_socket_text_transport (2, 0, 2)
17.single_send_128_with_xhr_streaming_binary_transport (2, 0, 2)
18.single_send_128_with_xhr_streaming_text_transport (2, 0, 2)
19.single_send_128_with_xhr_polling_binary_transport (2, 0, 2)
20.single_send_128_with_xhr_polling_text_transport (2, 0, 2)
21.single_send_128_with_binary_transport (2, 0, 2)
22.single_send_128_with_text_transport (2, 0, 2)
23.single_send_256_with_web_socket_binary_transport (2, 0, 2)
24.single_send_256_with_web_socket_text_transport (2, 0, 2)
25.single_send_256_with_xhr_streaming_binary_transport (2, 0, 2)
26.single_send_256_with_xhr_streaming_text_transport (2, 0, 2)
27.single_send_256_with_xhr_polling_binary_transport (2, 0, 2)
28.single_send_256_with_xhr_polling_text_transport (2, 0, 2)
29.single_send_256_with_binary_transport (2, 0, 2)
30.single_send_256_with_text_transport (2, 0, 2)
31.multiple_send_binary_2_200 (2, 0, 2)
32.multiple_send_text_2_200 (2, 0, 2)
33.multiple_send_binary_20_100 (2, 0, 2)

@funkyboy
Copy link
Contributor Author

screen shot 2018-01-25 at 09 48 40

@funkyboy
Copy link
Contributor Author

Also IE9. I am surprised!
screen shot 2018-01-25 at 09 51 52

@@ -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) {
Copy link
Member

@SimonWoolf SimonWoolf Jan 25, 2018

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) {
Copy link
Member

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

Copy link
Contributor Author

@funkyboy funkyboy Jan 25, 2018

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 :(

Copy link
Contributor Author

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);
});

Copy link
Member

@SimonWoolf SimonWoolf Jan 25, 2018

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) {
Copy link
Contributor Author

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?

Copy link
Member

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.?

Copy link
Contributor Author

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.

ie

chrome.pdf

ff.pdf

@SimonWoolf SimonWoolf merged commit fb25a18 into master Jan 26, 2018
@SimonWoolf SimonWoolf deleted the fix-IE-tests branch January 26, 2018 07:59
@SimonWoolf
Copy link
Member

Thanks @funkyboy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants