Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser decryption failed with "Bad MAC" #63

Open
pranavburnwal opened this issue Jun 22, 2020 · 10 comments
Open

Browser decryption failed with "Bad MAC" #63

pranavburnwal opened this issue Jun 22, 2020 · 10 comments
Labels

Comments

@pranavburnwal
Copy link

The decryption failed with the "Bad MAC" error on the browser. This is happening on 'eth-crypto' module which uses this as a dependency.
This case happens only like ~ 1/300 cases. Rest 299 decrypt with perfectly fine on the browser itself.

Even the cases that failed on browser are being able to decrypt on Node easily without any problems. Points me to check the newer builds.
We are using Webpack and have been using this same module the same version for more than a year. and this started recently. I am trying to trace right now but any help would be appreciated.

Thank you for your time.

Ref ticket for Eth-crypto: https://github.com/pubkey/eth-crypto/issues/281

@JBaczuk
Copy link
Contributor

JBaczuk commented Jun 29, 2020

Without more info, it is hard to be helpful, but it sounds similar to this issue, which appears to have been an environment issue: #52

@pranavburnwal
Copy link
Author

Please share what more info I can provide?

@pranavburnwal
Copy link
Author

So we have packed the module in a webpack deployment. There is no compilation error.
We use the same module version In server and browser. The same code with the same parameters decrypts on Server(nodeJS) but does not decrypt on the browser.
Again on more testing the whole the cases are rare like 1/300 ~ 1/500 cases.

The same code and modules are used for all of those cases but a few in thousand fail.

@JBaczuk
Copy link
Contributor

JBaczuk commented Jun 30, 2020

Without anything to reproduce this issue, I'm afraid I'm not sure how to help. Are you using the latest browser versions? Which browser are you using. is there any pattern with the cases that fail (like character length)?

@pranavburnwal
Copy link
Author

Not sure about that, The data all cases are like similar in structure and format.
I stopped working on that for now. I will retry over this weekend.
Is there any way I can share the base with you so you can replicate it? The problem is whenever I manually encrypt it always decrpts easily. I manually cannot do 500 cases for test

@ibudisteanu
Copy link

I get a lot of BAD MAC on nodejs decryption using encryption from Browser. Probably about 10% of (priv, pub) pairs

@pranavburnwal
Copy link
Author

I get a lot of BAD MAC on nodejs decryption using encryption from Browser. Probably about 10% of (priv, pub) pairs

Yeah, any luck on debugging? Anything special you are trying?

@fredeno
Copy link

fredeno commented Oct 21, 2021

We are facing a similar problem when data is encrypted in Browser and decrypted in Node.js, and vice versa.
This works fine most of the time but we see some "Bad MAC" failures occuring. Failure probability is arround 1 for 300 occurences, even when encrypting the same data in a loop with the same key (using eccrypto version 1.1.6).

When decrypt failure occurs on Node, executing the decrypt function for browser works ! In other words, Node and Browser implementation do not seem to be plainly compatible.

@AgentRX
Copy link

AgentRX commented Mar 15, 2023

Hi! Here is stack trace of error:
{"type":"Error","message":"Bad MAC","stack":"Error: Bad MAC\n at assert (/home/node/node_modules/eccrypto/browser.js:16:11)\n at /home/node/node_modules/eccrypto/browser.js:258:5\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"},

Here is data to reproduce Bad MAC:
{"iv":"YqX1RJMwOldgk60iYE4xiw==","ephemPublicKey":"BJh5d3wGrtVCnTw7BYdBca3e+FW4XRq8U/y3IlnBwnR95euUQZIu1na1GwD4BJeX0zA2yamVngnsII8gyo0AApQ=","mac":"OYGjpPWkCaqCjMdAexn/GGhhuUqVto7FYPgXt9OOtyw=","encoding":"base64","algo":"ECIES","ciphertext":"awAMbQmDmr0TWrxDRLRPCuOKwGfjyzwP5oFvNIcizoqM87rrTZoNGd/8f2e+naeYwKEyv9UuE9btc1jKfJq9N/C+7i+4/j61EQIfnkVE0A9nJjf5jfOZSb7FzPaNB/YIJvHRpnyAVbX8S55NeHnemVg5zHPxkA2C4e5vvBJjdda1VffAlZ17rmAxBtNxrGRfuBME2TcjuN9KvjBjYblrXgyYRMT0eIth+gdxWrudJKM="}}\""

"key":"gX7jM+34dQLfDSbO3vMBlAu3m+vRn2Es9+NUGpZSW+w="

@mystiko0x1
Copy link

We found the possible root cause related to this issue, please refer to PR #96 for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants