-
Notifications
You must be signed in to change notification settings - Fork 125
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
Conversation
@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)
|
@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. |
Right now, I see this as the thing that gets |
Latest commit on this PR should address the problems, and tests for it! Would you confirm it meets your expectations? |
@linuxwolf yes, it's great! 👍 |
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
:"iv"
of 12 random bytesFor
PBES2-*
:"p2s"
of 16 random bytes"p2c"
of 8192