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

Update: generate and apply header values when key wrapping #189

Merged
merged 8 commits into from
May 18, 2018

Conversation

linuxwolf
Copy link
Member

Closes #133

When wrapping keys in JWE, the algorithm can generate a missing value and it'll be applied to the JWE header(s).

For A*GCMKW:

  • generate "iv" of 12 random bytes

For PBES2-*:

  • generate "p2s" of 16 random bytes
  • apply "p2c" of 8192

@panva
Copy link
Contributor

panva commented May 17, 2018

@linuxwolf you have my continuous thanks for this outstanding work!

Shouldn't the changes from #161 that removed the support be reverted? Or is this only for generation and decryption will still remain broken?

The following still fails unless iv is provided, that expected?

const jose = require('.');
const format = 'compact';
const clientKS = jose.JWK.createKeyStore();
const secret = 'GfsT479VMy5ZZZPquadPbN3wKzaFGYo1CTkb0IFFzDNODLEAuC2GUV3QsTye3xNQ';
const alg = 'A128GCMKW';
const base64url = require('base64url');
const crypto = require('crypto');
const payload = JSON.stringify({ foo: 'bar' });
const fields = { alg };

const bufferderived = crypto.createHash('sha256')
      .update(secret)
      .digest()
      .slice(0, 128 / 8);

clientKS.add({
  k: base64url(bufferderived), kty: 'oct',
}).then(() => {
  // fields.iv = base64url(crypto.randomBytes(12)); // doesn't encrypt without iv => Error: invalid iv
  return jose.JWE.createEncrypt({ format, fields }, { key: clientKS.get(), reference: false })
    .update(payload)
    .final();
}).then((crypted) => {
  console.log(crypted)
  return jose.JWE.createDecrypt(clientKS.get()).decrypt(crypted).then(({ payload }) => payload.toString())
}).then(console.log)

PBES2-* i can confirm works as expected, p2s and p2c does not need to be explicitly provided

@linuxwolf
Copy link
Member Author

@panva something is still broken then. I thought I had tests in place, but I also had some hiccups bringin in master. Will take a look, and make better tests for it.

@linuxwolf
Copy link
Member Author

Right now, I see this as the thing that gets node-jose to 1.0.0.

@linuxwolf
Copy link
Member Author

@panva

Latest commit on this PR should address the problems, and tests for it! Would you confirm it meets your expectations?

@panva
Copy link
Contributor

panva commented May 18, 2018

@linuxwolf yes, it's great! 👍

@linuxwolf linuxwolf merged commit 370baa4 into cisco:master May 18, 2018
@linuxwolf linuxwolf deleted the keywrap-header branch May 18, 2018 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants