1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 03:03:43 +00:00

IE fixes and crypto shims

This commit is contained in:
Kyle Spearrin
2017-07-08 00:12:57 -04:00
parent ab12c990bc
commit b62950fa2b
14 changed files with 698 additions and 35 deletions

View File

@@ -9,6 +9,7 @@
'angulartics.google.analytics',
'angular-stripe',
'credit-cards',
'angular-promise-polyfill',
'bit.directives',
'bit.filters',

View File

@@ -55,6 +55,12 @@ angular
$httpProvider.defaults.headers.post['Content-Type'] = 'text/plain; charset=utf-8';
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
$httpProvider.interceptors.push('apiInterceptor');
$httpProvider.interceptors.push('jwtInterceptor');

View File

@@ -76,7 +76,7 @@ angular
var sign = function (keyBytes, timeBytes) {
return window.crypto.subtle.importKey('raw', keyBytes,
{ name: 'HMAC', hash: { name: 'SHA-1' } }, false, ['sign']).then(function (key) {
return window.crypto.subtle.sign({ name: 'HMAC' }, key, timeBytes);
return window.crypto.subtle.sign({ name: 'HMAC', hash: { name: 'SHA-1' } }, key, timeBytes);
}).then(function (signature) {
return buff2hex(signature);
}).catch(function (err) {

View File

@@ -2,7 +2,7 @@
.module('bit.organization')
.controller('organizationVaultAttachmentsController', function ($scope, apiService, $uibModalInstance, cryptoService,
cipherService, loginId, $analytics, validationService, toastr) {
cipherService, loginId, $analytics, validationService, toastr, $timeout) {
$analytics.eventTrack('organizationVaultAttachmentsController', { category: 'Modal' });
$scope.login = {};
$scope.loading = true;
@@ -31,8 +31,9 @@
var reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = function (evt) {
form.$loading = true;
$scope.$apply();
$timeout(function () {
form.$loading = true;
});
var key = cryptoService.getOrgKey($scope.login.organizationId);
var encFilename = cryptoService.encrypt(file.name, key);
@@ -61,8 +62,9 @@
req.responseType = 'arraybuffer';
req.onload = function (evt) {
if (!req.response) {
attachment.loading = false;
$scope.$apply();
$timeout(function () {
attachment.loading = false;
});
// error
return;
@@ -85,8 +87,9 @@
document.body.removeChild(a);
}
attachment.loading = false;
$scope.$apply();
$timeout(function () {
attachment.loading = false;
});
});
};
req.send(null);

View File

@@ -521,17 +521,17 @@ angular
return null;
}
ivBytes = encBytes.slice(1, 17);
macBytes = encBytes.slice(17, 49);
ctBytes = encBytes.slice(49);
ivBytes = slice(encBytes, 1, 17);
macBytes = slice(encBytes, 17, 49);
ctBytes = slice(encBytes, 49);
break;
case constants.encType.AesCbc256_B64:
if (encBytes.length <= 17) { // 1 + 16 + ctLength
return null;
}
ivBytes = encBytes.slice(1, 17);
ctBytes = encBytes.slice(17);
ivBytes = slice(encBytes, 1, 17);
ctBytes = slice(encBytes, 17);
break;
default:
return null;
@@ -578,7 +578,6 @@ angular
}
return window.crypto.subtle.decrypt({ name: 'AES-CBC', iv: ivBuf }, encKey, ctBuf);
});
}
_service.rsaDecrypt = function (encValue, privateKey, key) {
@@ -666,7 +665,7 @@ angular
function computeMacWC(dataBuf, macKeyBuf) {
return window.crypto.subtle.importKey('raw', macKeyBuf, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign'])
.then(function (key) {
return window.crypto.subtle.sign({ name: 'HMAC' }, key, dataBuf);
return window.crypto.subtle.sign({ name: 'HMAC', hash: { name: 'SHA-256' } }, key, dataBuf);
});
}
@@ -693,10 +692,10 @@ angular
return window.crypto.subtle.importKey('raw', macKeyBuf, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign'])
.then(function (key) {
macKey = key;
return window.crypto.subtle.sign({ name: 'HMAC' }, macKey, mac1Buf);
return window.crypto.subtle.sign({ name: 'HMAC', hash: { name: 'SHA-256' } }, macKey, mac1Buf);
}).then(function (mac) {
mac1 = mac;
return window.crypto.subtle.sign({ name: 'HMAC' }, macKey, mac2Buf);
return window.crypto.subtle.sign({ name: 'HMAC', hash: { name: 'SHA-256' } }, macKey, mac2Buf);
}).then(function (mac2) {
if (mac1.byteLength !== mac2.byteLength) {
return false;
@@ -775,8 +774,8 @@ angular
};
if (this.macKey) {
keys.encKey = key.slice(0, key.length / 2).buffer;
keys.macKey = key.slice(key.length / 2).buffer;
keys.encKey = slice(key, 0, key.length / 2).buffer;
keys.macKey = slice(key, key.length / 2).buffer;
}
else {
keys.encKey = key.buffer;
@@ -796,5 +795,48 @@ angular
return arr;
}
function slice(arr, begin, end) {
if (arr.slice) {
return arr.slice(begin, end);
}
// shim for IE
// ref: https://stackoverflow.com/a/21440217
arr = arr.buffer;
if (begin === void 0) {
begin = 0;
}
if (end === void 0) {
end = arr.byteLength;
}
begin = Math.floor(begin);
end = Math.floor(end);
if (begin < 0) {
begin += arr.byteLength;
}
if (end < 0) {
end += arr.byteLength;
}
begin = Math.min(Math.max(0, begin), arr.byteLength);
end = Math.min(Math.max(0, end), arr.byteLength);
if (end - begin <= 0) {
return new ArrayBuffer(0);
}
var result = new ArrayBuffer(end - begin);
var resultBytes = new Uint8Array(result);
var sourceBytes = new Uint8Array(arr, begin, end - begin);
resultBytes.set(sourceBytes);
return new Uint8Array(result);
}
return _service;
});

View File

@@ -45,14 +45,16 @@
return;
}
else if (data.errorCode) {
$scope.deviceError = true;
$scope.$apply();
$timeout(function () {
$scope.deviceError = true;
});
console.log('error: ' + data.errorCode);
return;
}
$scope.deviceResponse = JSON.stringify(data);
$scope.$apply();
$timeout(function () {
$scope.deviceResponse = JSON.stringify(data);
});
}, 10);
};

View File

@@ -2,7 +2,7 @@
.module('bit.vault')
.controller('vaultAttachmentsController', function ($scope, apiService, $uibModalInstance, cryptoService, cipherService,
loginId, $analytics, validationService, toastr) {
loginId, $analytics, validationService, toastr, $timeout) {
$analytics.eventTrack('vaultAttachmentsController', { category: 'Modal' });
$scope.login = {};
$scope.readOnly = true;
@@ -33,8 +33,9 @@
var reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = function (evt) {
form.$loading = true;
$scope.$apply();
$timeout(function () {
form.$loading = true;
});
var key = getKeyForLogin();
@@ -65,8 +66,9 @@
req.responseType = 'arraybuffer';
req.onload = function (evt) {
if (!req.response) {
attachment.loading = false;
$scope.$apply();
$timeout(function () {
attachment.loading = false;
});
// error
return;
@@ -87,9 +89,10 @@
a.click();
document.body.removeChild(a);
}
attachment.loading = false;
$scope.$apply();
$timeout(function () {
attachment.loading = false;
});
});
};
req.send(null);

View File

@@ -38,7 +38,7 @@
<a href="#" stop-click ng-click="download(attachment)">{{attachment.fileName}}</a>
<i class="fa fa-spinner fa-spin text-muted" ng-if="attachment.loading"></i>
</td>
<td style="width: 80px; min-width: 80px;">
<td style="width: 90px; min-width: 90px;">
{{attachment.size}}
</td>
</tr>