implemented crypto polyfills for ms edge
This commit is contained in:
parent
5f44ed2598
commit
cd7da20024
10 changed files with 163 additions and 18 deletions
|
@ -1,10 +1,10 @@
|
|||
import 'fast-text-encoding'; // MS Edge support
|
||||
import 'fluent-intl-polyfill';
|
||||
import app from './routes';
|
||||
import locale from '../common/locales';
|
||||
import fileManager from './fileManager';
|
||||
import dragManager from './dragManager';
|
||||
import { canHasSend } from './utils';
|
||||
import assets from '../common/assets';
|
||||
import storage from './storage';
|
||||
import metrics from './metrics';
|
||||
import experiments from './experiments';
|
||||
|
@ -30,10 +30,7 @@ app.use((state, emitter) => {
|
|||
) {
|
||||
unsupportedReason = 'outdated';
|
||||
}
|
||||
if (/edge\/\d+/i.test(navigator.userAgent)) {
|
||||
unsupportedReason = 'edge';
|
||||
}
|
||||
const ok = await canHasSend(assets.get('cryptofill.js'));
|
||||
const ok = await canHasSend();
|
||||
if (!ok) {
|
||||
unsupportedReason = /firefox/i.test(navigator.userAgent)
|
||||
? 'outdated'
|
||||
|
|
20
app/utils.js
20
app/utils.js
|
@ -25,7 +25,7 @@ function loadShim(polyfill) {
|
|||
});
|
||||
}
|
||||
|
||||
async function canHasSend(polyfill) {
|
||||
async function canHasSend() {
|
||||
try {
|
||||
const key = await window.crypto.subtle.generateKey(
|
||||
{
|
||||
|
@ -35,7 +35,6 @@ async function canHasSend(polyfill) {
|
|||
true,
|
||||
['encrypt', 'decrypt']
|
||||
);
|
||||
|
||||
await window.crypto.subtle.encrypt(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
|
@ -45,9 +44,23 @@ async function canHasSend(polyfill) {
|
|||
key,
|
||||
new ArrayBuffer(8)
|
||||
);
|
||||
await window.crypto.subtle.importKey(
|
||||
'raw',
|
||||
window.crypto.getRandomValues(new Uint8Array(16)),
|
||||
'PBKDF2',
|
||||
false,
|
||||
['deriveKey']
|
||||
);
|
||||
await window.crypto.subtle.importKey(
|
||||
'raw',
|
||||
window.crypto.getRandomValues(new Uint8Array(16)),
|
||||
'HKDF',
|
||||
false,
|
||||
['deriveKey']
|
||||
);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return loadShim(polyfill);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,6 +180,7 @@ module.exports = {
|
|||
copyToClipboard,
|
||||
arrayToB64,
|
||||
b64ToArray,
|
||||
loadShim,
|
||||
canHasSend,
|
||||
isFile,
|
||||
openLinksInNewTab
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue