tryethernal / ethernal

Ethernal is a block explorer for EVM-based chains. In a few seconds, spin up a fully-featured explorer for your L1/L2 rollup/testnet. Compatible with Optimism, ZK, Anvil, Hardhat, Geth...
https://www.tryethernal.com
Other
204 stars 47 forks source link

[self-hosted] trying to create an account brings error "Invalid key length" #242

Closed DegenComedian closed 1 year ago

DegenComedian commented 1 year ago

Hi developers,

When I run the latest docker version of ethernal self-hosted and try to create a new account on the website startpage, I see the error message in the front-end

Invalid key length

In the web container log files I see the following log event for it

web                             | error: Invalid key length {"data":{"email":"comedian@example.com","password":"ohmygod"},"error":{"code":"ERR_CRYPTO_INVALID_KEYLEN","message":"Invalid key length","stack":"RangeError: Invalid key length\n    at Cipheriv.createCipherBase (node:internal/crypto/cipher:116:19)\n    at Cipheriv.createCipherWithIV (node:internal/crypto/cipher:135:3)\n    at new Cipheriv (node:internal/crypto/cipher:243:3)\n    at Object.createCipheriv (node:crypto:138:10)\n    at encrypt (/app/lib/crypto.js:18:31)\n    at /app/api/users.js:114:30\n    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)\n    at next (/app/node_modules/express/lib/router/route.js:144:13)\n    at Route.dispatch (/app/node_modules/express/lib/router/route.js:114:3)\n    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)\n    at /app/node_modules/express/lib/router/index.js:284:15\n    at Function.process_params (/app/node_modules/express/lib/router/index.js:346:12)\n    at next (/app/node_modules/express/lib/router/index.js:280:10)\n    at Function.handle (/app/node_modules/express/lib/router/index.js:175:3)\n    at router (/app/node_modules/express/lib/router/index.js:47:12)\n    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)"},"location":"get.api.users"}

I tried different password length and characters, but they all lead to the same problem.

Thank you very much Comedian

antoinedc commented 1 year ago

Looks like an issue with the ENCRYPTION_KEY env variable. It needs to be 32 characters, and I just realized I forgot to put it in the doc!

DegenComedian commented 1 year ago

Yes, I set the ENCRYPTION_KEY but not 32 chars long :). Now that I set it, I get the following error when trying to create an account web frontend:

secretOrPrivateKey must have a value

log:

error: secretOrPrivateKey must have a value {"data":{"email":"comedian@example.com","password":"ohmygod"},"error":{"message":"secretOrPrivateKey must have a value","stack":"Error: secretOrPrivateKey must have a value\n    at Object.module.exports [as sign] (/app/node_modules/jsonwebtoken/sign.js:107:20)\n    at encode (/app/lib/crypto.js:39:20)\n    at User.get (/app/models/user.js:128:17)\n    at User.get (/app/node_modules/sequelize/lib/model.js:2108:41)\n    at User.get (/app/node_modules/sequelize/lib/model.js:2130:33)\n    at User.toJSON (/app/node_modules/sequelize/lib/model.js:2618:29)\n    at stringifyFnReplacer (/app/node_modules/safe-stable-stringify/index.js:234:21)\n    at stringifyFnReplacer (/app/node_modules/safe-stable-stringify/index.js:314:23)\n    at stringify (/app/node_modules/safe-stable-stringify/index.js:659:18)\n    at Format.transform (/app/node_modules/logform/json.js:28:19)\n    at DerivedLogger._transform (/app/node_modules/winston/lib/winston/logger.js:313:29)\n    at DerivedLogger.Transform._read (/app/node_modules/readable-stream/lib/_stream_transform.js:177:10)\n    at DerivedLogger.Transform._write (/app/node_modules/readable-stream/lib/_stream_transform.js:164:83)\n    at doWrite (/app/node_modules/readable-stream/lib/_stream_writable.js:409:139)\n    at writeOrBuffer (/app/node_modules/readable-stream/lib/_stream_writable.js:398:5)\n    at DerivedLogger.Writable.write (/app/node_modules/readable-stream/lib/_stream_writable.js:307:11)"},"location":"get.api.users"}
antoinedc commented 1 year ago

And ENCRYPTION_JWT_SECRET needs to be 64 chars long, sorry it's early here ahah should have put that in my previous message

DegenComedian commented 1 year ago

works now!