mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 11:13:46 +00:00
Added setting to not store key via lock options, only keeping it in memory. Fixed some i18n and created constants service
This commit is contained in:
6
src/services/constantsService.js
Normal file
6
src/services/constantsService.js
Normal file
@@ -0,0 +1,6 @@
|
||||
function ConstantsService() {
|
||||
return {
|
||||
disableGaKey: 'disableGa',
|
||||
lockOptionKey: 'lockOption'
|
||||
};
|
||||
};
|
||||
@@ -1,10 +1,13 @@
|
||||
function CryptoService() {
|
||||
function CryptoService(constantsService) {
|
||||
this.constantsService = constantsService;
|
||||
initCryptoService();
|
||||
};
|
||||
|
||||
function initCryptoService() {
|
||||
var _key,
|
||||
_b64Key,
|
||||
_keyHash,
|
||||
_b64KeyHash,
|
||||
_aes;
|
||||
|
||||
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
|
||||
@@ -14,9 +17,33 @@ function initCryptoService() {
|
||||
throw 'callback function required';
|
||||
}
|
||||
|
||||
var self = this;
|
||||
_key = key;
|
||||
|
||||
chrome.storage.local.get(self.constantsService.lockOptionKey, function (obj) {
|
||||
if (obj && (obj[self.constantsService.lockOptionKey] || obj[self.constantsService.lockOptionKey] === 0)) {
|
||||
// if we have a lock option set, we do not store the key
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.storage.local.set({
|
||||
'key': sjcl.codec.base64.fromBits(key)
|
||||
}, function () {
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
CryptoService.prototype.setKeyHash = function (keyHash, callback) {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
throw 'callback function required';
|
||||
}
|
||||
|
||||
_keyHash = sjcl.codec.base64.toBits(keyHash);
|
||||
|
||||
chrome.storage.local.set({
|
||||
'key': sjcl.codec.base64.fromBits(key)
|
||||
'keyHash': keyHash
|
||||
}, function () {
|
||||
callback();
|
||||
});
|
||||
@@ -28,23 +55,73 @@ function initCryptoService() {
|
||||
}
|
||||
|
||||
if (b64 && b64 === true && _b64Key) {
|
||||
return callback(_b64Key);
|
||||
callback(_b64Key);
|
||||
return;
|
||||
}
|
||||
else if (!b64 && _key) {
|
||||
return callback(_key);
|
||||
callback(_key);
|
||||
return;
|
||||
}
|
||||
else if (b64 && b64 === true && _key && !_b64Key) {
|
||||
_b64Key = sjcl.codec.base64.fromBits(_key);
|
||||
callback(_b64Key);
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.storage.local.get('key', function (obj) {
|
||||
if (obj && obj.key) {
|
||||
_key = sjcl.codec.base64.toBits(obj.key);
|
||||
var self = this;
|
||||
chrome.storage.local.get(self.constantsService.lockOptionKey, function (obj) {
|
||||
if (obj && (obj[self.constantsService.lockOptionKey] || obj[self.constantsService.lockOptionKey] === 0)) {
|
||||
// if we have a lock option set, we do not try to fetch the storage key since it should not even be there
|
||||
callback(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (b64 && b64 === true) {
|
||||
_b64Key = sjcl.codec.base64.fromBits(_key);
|
||||
return callback(_b64Key);
|
||||
chrome.storage.local.get('key', function (obj) {
|
||||
if (obj && obj.key) {
|
||||
_key = sjcl.codec.base64.toBits(obj.key);
|
||||
|
||||
if (b64 && b64 === true) {
|
||||
_b64Key = obj.key;
|
||||
callback(_b64Key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
callback(_key);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
CryptoService.prototype.getKeyHash = function (b64, callback) {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
throw 'callback function required';
|
||||
}
|
||||
|
||||
if (b64 && b64 === true && _b64KeyHash) {
|
||||
callback(_b64KeyHash);
|
||||
}
|
||||
else if (!b64 && _keyHash) {
|
||||
callback(_keyHash);
|
||||
return;
|
||||
}
|
||||
else if (b64 && b64 === true && _keyHash && !_b64KeyHash) {
|
||||
_b64KeyHash = sjcl.codec.base64.fromBits(_keyHash);
|
||||
callback(_b64KeyHash);
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.storage.local.get('keyHash', function (obj) {
|
||||
if (obj && obj.keyHash) {
|
||||
_keyHash = sjcl.codec.base64.toBits(obj.keyHash);
|
||||
|
||||
if (b64 && b64 === true) {
|
||||
_b64KeyHash = obj.keyHash;
|
||||
callback(_b64KeyHash);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return callback(_key);
|
||||
callback(_keyHash);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -59,6 +136,44 @@ function initCryptoService() {
|
||||
});
|
||||
};
|
||||
|
||||
CryptoService.prototype.clearKeyHash = function (callback) {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
throw 'callback function required';
|
||||
}
|
||||
|
||||
_keyHash = _b64KeyHash = null;
|
||||
chrome.storage.local.remove('keyHash', function () {
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
CryptoService.prototype.toggleKey = function (callback) {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
throw 'callback function required';
|
||||
}
|
||||
|
||||
var self = this;
|
||||
self.getKey(false, function (key) {
|
||||
chrome.storage.local.get(self.constantsService.lockOptionKey, function (obj) {
|
||||
if (obj && (obj[self.constantsService.lockOptionKey] || obj[self.constantsService.lockOptionKey] === 0)) {
|
||||
// if we have a lock option set, clear the key
|
||||
self.clearKey(function () {
|
||||
_key = key;
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
}
|
||||
else {
|
||||
// no lock option, so store the current key
|
||||
self.setKey(key, function () {
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
CryptoService.prototype.makeKey = function (password, salt, b64) {
|
||||
var key = sjcl.misc.pbkdf2(password, salt, 5000, 256, null);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
function i18nService() {
|
||||
return {
|
||||
appName: chrome.i18n.getMessage('appName'),
|
||||
loginOrCreateNewAccount: chrome.i18n.getMessage('loginOrCreateNewAccount'),
|
||||
createAccount: chrome.i18n.getMessage('createAccount'),
|
||||
login: chrome.i18n.getMessage('login'),
|
||||
@@ -91,6 +92,20 @@ function i18nService() {
|
||||
disableGa: chrome.i18n.getMessage('disableGa'),
|
||||
rateExtension: chrome.i18n.getMessage('rateExtension'),
|
||||
rateExtensionDesc: chrome.i18n.getMessage('rateExtensionDesc'),
|
||||
browserNotSupportClipboard: chrome.i18n.getMessage('browserNotSupportClipboard')
|
||||
browserNotSupportClipboard: chrome.i18n.getMessage('browserNotSupportClipboard'),
|
||||
verifyMasterPassword: chrome.i18n.getMessage('verifyMasterPassword'),
|
||||
invalidMasterPassword: chrome.i18n.getMessage('invalidMasterPassword'),
|
||||
errorsHaveOccurred: chrome.i18n.getMessage('errorsHaveOccurred'),
|
||||
lockOptions: chrome.i18n.getMessage('lockOptions'),
|
||||
immediately: chrome.i18n.getMessage('immediately'),
|
||||
oneMinute: chrome.i18n.getMessage('oneMinute'),
|
||||
fiveMinutes: chrome.i18n.getMessage('fiveMinutes'),
|
||||
fifteenMinutes: chrome.i18n.getMessage('fifteenMinutes'),
|
||||
thirtyMinutes: chrome.i18n.getMessage('thirtyMinutes'),
|
||||
oneHour: chrome.i18n.getMessage('oneHour'),
|
||||
fourHours: chrome.i18n.getMessage('fourHours'),
|
||||
onRestart: chrome.i18n.getMessage('onRestart'),
|
||||
never: chrome.i18n.getMessage('never'),
|
||||
security: chrome.i18n.getMessage('security')
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user