1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-19 02:51:14 +02:00

added error logs for decrypt methods

This commit is contained in:
Kyle Spearrin 2017-07-31 23:19:02 -04:00
parent 747b5608e8
commit 2beb22e8cf

View File

@ -477,6 +477,7 @@ angular
}; };
_service.decrypt = function (encValue, key, outputEncoding) { _service.decrypt = function (encValue, key, outputEncoding) {
try {
key = key || _service.getEncKey() || _service.getKey(); key = key || _service.getEncKey() || _service.getKey();
var headerPieces = encValue.split('.'), var headerPieces = encValue.split('.'),
@ -489,6 +490,7 @@ angular
encPieces = headerPieces[1].split('|'); encPieces = headerPieces[1].split('|');
} }
catch (e) { catch (e) {
console.error('Cannot parse headerPieces.');
return null; return null;
} }
} }
@ -513,15 +515,18 @@ angular
case constants.encType.AesCbc128_HmacSha256_B64: case constants.encType.AesCbc128_HmacSha256_B64:
case constants.encType.AesCbc256_HmacSha256_B64: case constants.encType.AesCbc256_HmacSha256_B64:
if (encPieces.length !== 3) { if (encPieces.length !== 3) {
console.error('Enc type (' + encType + ') not valid.');
return null; return null;
} }
break; break;
case constants.encType.AesCbc256_B64: case constants.encType.AesCbc256_B64:
if (encPieces.length !== 2) { if (encPieces.length !== 2) {
console.error('Enc type (' + encType + ') not valid.');
return null; return null;
} }
break; break;
default: default:
console.error('Enc type (' + encType + ') not supported.');
return null; return null;
} }
@ -550,9 +555,15 @@ angular
else { else {
return decipher.output.getBytes(); return decipher.output.getBytes();
} }
}
catch (e) {
console.error('Caught unhandled error in decrypt: ' + e);
throw e;
}
}; };
_service.decryptFromBytes = function (encBuf, key) { _service.decryptFromBytes = function (encBuf, key) {
try {
if (!encBuf) { if (!encBuf) {
throw 'no encBuf.'; throw 'no encBuf.';
} }
@ -567,6 +578,7 @@ angular
case constants.encType.AesCbc128_HmacSha256_B64: case constants.encType.AesCbc128_HmacSha256_B64:
case constants.encType.AesCbc256_HmacSha256_B64: case constants.encType.AesCbc256_HmacSha256_B64:
if (encBytes.length <= 49) { // 1 + 16 + 32 + ctLength if (encBytes.length <= 49) { // 1 + 16 + 32 + ctLength
console.error('Enc type (' + encType + ') not valid.');
return null; return null;
} }
@ -576,6 +588,7 @@ angular
break; break;
case constants.encType.AesCbc256_B64: case constants.encType.AesCbc256_B64:
if (encBytes.length <= 17) { // 1 + 16 + ctLength if (encBytes.length <= 17) { // 1 + 16 + ctLength
console.error('Enc type (' + encType + ') not valid.');
return null; return null;
} }
@ -583,6 +596,7 @@ angular
ctBytes = slice(encBytes, 17); ctBytes = slice(encBytes, 17);
break; break;
default: default:
console.error('Enc type (' + encType + ') not supported.');
return null; return null;
} }
@ -592,6 +606,11 @@ angular
ivBytes.buffer, ivBytes.buffer,
macBytes ? macBytes.buffer : null, macBytes ? macBytes.buffer : null,
key); key);
}
catch (e) {
console.error('Caught unhandled error in decryptFromBytes: ' + e);
throw e;
}
}; };
function aesDecryptWC(encType, ctBuf, ivBuf, macBuf, key) { function aesDecryptWC(encType, ctBuf, ivBuf, macBuf, key) {