Skip to content

Crypto overhaul - #29

Closed
veeti wants to merge 32 commits into
crypto-utils:masterfrom
veeti:crypto
Closed

veeti wants to merge 32 commits into
crypto-utils:masterfrom
veeti:crypto

Conversation

@veeti

@veeti veeti commented May 27, 2016

Copy link
Copy Markdown

I promised to submit a PR ages ago, but here it finally goes. This is a first shot at it so any feedback would be appreciated.

  • Stop using the user's keys directly for signing and encryption. Instead, derive three different contextual subkeys: one for signing the user's payloads, one for encrypting the user's payloads and one for authenticating the resulting ciphertexts.

    PBKDF2 is used, as it is available in the standard library. A static salt and low iteration count are sufficient, as the user is expected to bring their own securely generated key(s).

    Also added a one-line Node command for generating secure keys to the README.

  • Completely rewrote the previous encryption logic, which was completely broken and unsafe. 256-bit AES is now used in CBC mode with PKCS#7 padding. Random initialization vectors are generated. The resulting IV and ciphertext are authenticated using HMAC-SHA256.

  • Removed the user API for changing the used cipher or hash. This is more effort than it is worth and makes implementation more difficult. The defaults are sufficient choices for anyone.

  • Also overhauled the test suite, as it was previously order-dependent and individual tests couldn't be run on their own.

Some considerations:

  • I removed the capability to hotswap keys in an existing instance in the name of immutability. Thoughts?
  • I removed the compatibility for ancient Node returning strings instead of buffers, but that can be added back if really necessary.

dougwilson and others added 2 commits May 10, 2015 01:53
* Stop using the user's keys directly for signing and encryption.
  Instead, derive three different contextual subkeys: one for signing the
  user's payloads, one for encrypting the user's payloads and one for
  authenticating the resulting ciphertexts.

  PBKDF2 is used, as it is available in the standard library. A static
  salt and low iteration count are sufficient, as the user is expected to
  bring their own securely generated key(s).

  Also added a one-line Node command for generating secure keys to the README.

* Completely rewrote the previous encryption logic, which was completely
  broken and unsafe. 256-bit AES is now used in CBC mode with PKCS#7
  padding. Random initialization vectors are generated. The resulting IV and
  ciphertext are authenticated using HMAC-SHA256.

* Removed the user API for changing the used cipher or hash. This is more
  effort than it is worth and makes implementation more difficult. The
  defaults are sufficient choices for anyone.

* Also overhauled the test suite, as it was previously order-dependent and
  individual tests couldn't be run on their own.
@dougwilson

Copy link
Copy Markdown
Member

Awesome, @veeti, I really appreciate it! It is a large-ish PR, so will take a bit to go over, but will definitely do! One thing you may want to consider as well is what will the upgrade path from 1.x to this new 2.x be, just in case you haven't thought much about it, while I get to looking this over.

@jonathanong jonathanong self-assigned this Jun 7, 2016
@jessaustin jessaustin mentioned this pull request Aug 3, 2016
@blakeembrey

Copy link
Copy Markdown

@dougwilson What can I do to help push this PR along and release a 2.0 version? I'd love to use this module, but in the 1.0 state I'm afraid I'd end up just writing my own wrappers when a OSS project would be better.

@richthegeek

Copy link
Copy Markdown

Hi, this functionality looks ideal for something I'm working on. How can I help out to get this release-ready?

@dougwilson

Copy link
Copy Markdown
Member

Resolve merge conflicts, pass the CI, and break apart into smaller PRs that can more easily be reviewed and discussed. The OP never responded with anything, so I'm just closing this as stale. Someone is welcome to take up the mantle on the three points above.

@dougwilson dougwilson closed this May 3, 2018
@crypto-utils crypto-utils deleted a comment from veeti May 3, 2018
@crypto-utils crypto-utils locked as too heated and limited conversation to collaborators May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants