wrong final block length after ugprading Google Chrome 131.0.6778.6
Is anyone meet following error or only me?
node:internal/crypto/cipher:199
const ret = this[kHandle].final();
^
Error: error:1C80006B:Provider routines::wrong final block length
at Decipheriv.final (node:internal/crypto/cipher:199:29)
at decrypt (/home/oliver/localprojects/read_cookie/node_modules/chrome-cookies-secure/index.js:41:19)
at Statement.<anonymous> (/home/oliver/localprojects/read_cookie/node_modules/chrome-cookies-secure/index.js:416:23) {
library: 'Provider routines',
reason: 'wrong final block length',
code: 'ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH'
}
I would be thankful for any hints to get this fixed
+1
Related: Crypto bumped to 0.10. Fixable via similar method to this: https://stackoverflow.com/questions/21292142/decrypting-aes256-with-node-js-returns-wrong-final-block-length
Same here
Would this work?
function decrypt(key, encryptedData) {
var decipher,
decoded,
final,
padding,
iv = new Buffer.from(new Array(KEYLENGTH + 1).join(' '), 'binary', 'utf-8');
decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
decipher.setAutoPadding(false);
encryptedData = encryptedData.slice(3);
decoded = decipher.update(encryptedData, 'binary', 'utf-8');
final = decipher.final('utf-8');
final.copy(decoded, decoded.length - 1);
padding = decoded[decoded.length - 1];
if (padding) {
decoded = decoded.slice(0, decoded.length - padding);
}
return decoded.toString('utf8');
}
The following approach worked for me, but I don't really understand exactly what I did, so use it with caution.
diff --git a/node_modules/chrome-cookies-secure/index.js b/node_modules/chrome-cookies-secure/index.js
index 882e958..d145a53 100644
--- a/node_modules/chrome-cookies-secure/index.js
+++ b/node_modules/chrome-cookies-secure/index.js
@@ -42,9 +42,7 @@ function decrypt(key, encryptedData) {
final.copy(decoded, decoded.length - 1);
padding = decoded[decoded.length - 1];
- if (padding) {
- decoded = decoded.slice(0, decoded.length - padding);
- }
+ decoded = decoded.slice(32, decoded.length - padding);
return decoded.toString('utf8');
}
@@ -396,7 +394,7 @@ const getCookies = async (uri, format, callback, profileOrPath) => {
}
if (cookie.value === '' && cookie.encrypted_value.length > 0) {
- encryptedValue = cookie.encrypted_value;
+ encryptedValue = Buffer.from(cookie.encrypted_value, 'binary');
if (process.platform === 'win32') {
if (encryptedValue[0] == 0x01 && encryptedValue[1] == 0x00 && encryptedValue[2] == 0x00 && encryptedValue[3] == 0x00){
hey folks - did some digging and Chrome made a change here: https://chromium-review.googlesource.com/c/chromium/src/+/5792044 that prepends a SHA256 hash of the domain name to the start of the encrypted data. Slicing off 32 chars should be right in most cases i can see, so @borodean that's why that works.
https://github.com/bertrandom/chrome-cookies-secure/pull/66
Should be fixed in 3.0.0
@rubengmurray still getting this error in 3.0.0
fwiw i'm not - it's working for me now after bumping
@codebytere I'm still getting this error
node:internal/crypto/cipher:184
const ret = this[kHandle].final();
^
Error: error:1C80006B:Provider routines::wrong final block length
at Decipheriv.final (node:internal/crypto/cipher:184:29)
at decrypt (/Users/asaf/Desktop/nodejs/node_modules/chrome-cookies-secure/index.js:66:18)
at Statement.<anonymous> (/Users/asaf/Desktop/nodejs/node_modules/chrome-cookies-secure/index.js:426:23) {
library: 'Provider routines',
reason: 'wrong final block length',
code: 'ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH'
}
Node.js v22.11.0
In case anyone is still encountering that error, I created my version, which works only on macOS: chrome-cookie-decrypt.
Care to share the site, and in which format they're failing?
I haven't tested on Node 22.
@rubengmurray I created a PR with the fix. Please take a look. #68
This has been fixed and can close issue(s). See #65 Thanks @rubengmurray & @IskenHuang 🍻
There is a report of this not working on Apple Silicon in #68.
Is anyone on this issue seeing this working on Apple Silicon?
https://github.com/bertrandom/chrome-cookies-secure/pull/69
Apple Silicon fix rolled in as @beta
3.0.0-beta.1
seems working now