serverless / serverless-secrets-plugin

MIT License
66 stars 16 forks source link

Encrypt and Decrypt are not compatible between OSX and Windows OS. #11

Open voiceactivity opened 6 years ago

voiceactivity commented 6 years ago

How to reproduce:

  1. Execute on OSX: sls encrypt -s stag --password 'xxx'

  2. Commit to git secrets.prod.yml.encrypted.

  3. Make git pull of the same file on Win10.

  4. Execute on Win10: sls decrypt -s stag --password 'xxx'

  5. Error: Error -------------------------------------------------- error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable. Get Support -------------------------------------------- Docs: docs.serverless.com Bugs: github.com/serverless/serverless/issues Issues: forum.serverless.com Your Environment Information ----------------------------- OS: win32 Node Version: 8.9.1 Serverless Version: 1.28.0

  6. File unreadable. Note: the passwords used are correct. I double checked and the encrypt|decrypt still work on my Mac (where I initially encrypted files).

voiceactivity commented 6 years ago

Just finished another test in reversed order:

  1. Encrypt on Win10
  2. Git push.
  3. Git pull on OSX
  4. Decrypt on OSX failed with the same error. Password was correct! :-)
QAnders commented 5 years ago

We are experiencing the same issue now in our team, MAC encrypt can't be decrypted on Windows 10 (neither Win10 native sls not Win10 subsystem linux (Ubuntu)).

QAnders commented 5 years ago

I did a "quick-fix" as I can't figure out where the inconsistency comes from... I couldn't open a Pull Request, so here we go:

package.js: + line 37: "stream-replace": "^1.0.0"

index.js:

  • line 7: const replace = require('stream-replace'); line 92: .pipe(crypto.createDecipher(algorithm, this.options.password).setAutoPadding(false))
  • line 94: .pipe(replace(/\4/g, ''))
  • line 95: .on('error', reject)

I've added stream-replace to the project and setting .setAutoPadding(false) in decrypt() function. As there still is an issue with four EOT characters (char hex: 04) appearing as the last four characters in the decrypted data I replace them with empty string.