smirzaei / rails-session-decoder

[UNMAINTAINED] Decode Rails 4.x session in node.js
MIT License
24 stars 13 forks source link

node-crypto : Invalid IV length 17 #1

Closed maxmcd closed 10 years ago

maxmcd commented 10 years ago

Getting an invalid key length warning.

Changed this line: https://github.com/smirzaei/rails-session-decoder/blob/master/index.js#L40

To this: var decipher = crypto.createDecipheriv('aes-256-cbc', derivedKey.slice(0, 32), iv.slice(0, 16));

To force the key length to length 16.

This seems to work, and returns the correct data, although I'm not sure why. Not an issue for now, but figured I would let you know.

Edit: full error trace:

node-crypto : Invalid IV length 17

crypto.js:360
  this._binding.initiv(cipher, toBuf(key), toBuf(iv));
                ^
Error: DecipherInitIv error
  at new Decipheriv (crypto.js:360:17)
  at Object.Decipheriv (crypto.js:357:12)
  at Object.<anonymous> (/Users/maxm/Sites/chat-node/node_modules/rails-session-decoder/index.js:40:29)
  at Object.ondone (/Users/maxm/Sites/chat-node/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)
smirzaei commented 10 years ago

Interesting, what is the rails version that you're using?

maxmcd commented 10 years ago

4.1.4

smirzaei commented 10 years ago

Looks like the IV should be 16 bytes in size, I don't know why it's 17 bytes in your case! I'm using 4.1.4 as well and never had this problem.

If you're getting the correct data, then I think it's a good change and a pull request is very welcome so others don't get this error.

Thanks.

maxmcd commented 10 years ago

Weird. Well, it is continuing to work for me after a bunch of testing. I'll open this up if anything goes wrong in production.

Pull request submitted.

And no problem, thanks for writing this awesome utility, saved me a lot of time.

smirzaei commented 10 years ago

Ok, thanks for the pull request and I'm glad to hear it's been helpful to you :)