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 Safari 11 PKCS bug #11396

Merged
merged 1 commit into from Sep 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/service/crypto-impl.js
Expand Up @@ -30,11 +30,22 @@ export class Crypto {
/** @private {!Window} */
this.win_ = win;

let subtle = null;
let isLegacyWebkit = false;
if (win.crypto) {
if (win.crypto.subtle) {
subtle = win.crypto.subtle;
} else if (win.crypto.webkitSubtle) {
subtle = win.crypto.webkitSubtle;
isLegacyWebkit = true;
}
}

/** @private @const {?webCrypto.SubtleCrypto} */
this.subtle_ = getSubtle(win);
this.subtle_ = subtle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Any reason to not just use this.subtle_ on lines 37, 39?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it couldn't be @const anymore.


/** @private @const {boolean} */
this.isWebkit_ = this.subtle_ && win.crypto && 'webkitSubtle' in win.crypto;
this.isLegacyWebkit_ = isLegacyWebkit;

/** @private {?Promise<{sha384: function((string|Uint8Array))}>} */
this.polyfillPromise_ = null;
Expand Down Expand Up @@ -149,8 +160,8 @@ export class Crypto {
return /** @type {!Promise<!webCrypto.CryptoKey>} */ (
this.subtle_.importKey(
'jwk',
this.isWebkit_ ?
// WebKit wants this as an ArrayBufferView.
this.isLegacyWebkit_ ?
// Safari 10 and earlier want this as an ArrayBufferView.
utf8EncodeSync(JSON.stringify(
/** @type {!JsonObject} */ (jwk))) :
/** @type {!webCrypto.JsonWebKey} */ (jwk),
Expand Down Expand Up @@ -190,13 +201,6 @@ export class Crypto {
}
}

function getSubtle(win) {
if (!win.crypto) {
return null;
}
return win.crypto.subtle || win.crypto.webkitSubtle || null;
}

/**
* @param {!Window} win
*/
Expand Down