-
Notifications
You must be signed in to change notification settings - Fork 62
Fix JWE encryption not setting protected header correctly #114
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
Conversation
|
Hello @hawk259 : this change seems to break unit tests ... is it because they need to be changed? I am not sure change can be merged if unit tests are broken ... |
|
I have been trying to figure out how to fix the tests, but not making much progress. Here is a test that you can try to add to see how things break:
The |
|
We ran into this issue again trying to test different RSA keys and I wrote a bash script using the command line tool, here is an overview: Create a jwk: Create a jwe: Decrypt jwe [WORKS]: Compact jwe: Decrypt compact jwe [FAILS]: This fails because the compact protected header is missing key fields needed to decrypt. The jwe has in it, but the compact version protected header only has At the bottom of the script it generates a new compact file with the correct protected header: Decrypt compact jwe v2 [FAILS, but data matches]: The file that is written out matches the original data, but for some reason the command failed. I also added EC commands to show the issue as well. The EC jwe file contains but the compacted jwe protected field only contains which is not enough information to decrypt the compact jwe. |
|
@hawk259 : can you please rebase to check what is the current status with Unit tests? |
|
Update fork to latest code. This patch is not the real fix because it only works for EC via shared library API calls, doesn't fix the command line and breaks the unit tests. The script I added shows the issue, which is simple... using jose cli to create a jwk, enc data, fmt to compact/serialize format can not be decrypted because the protected header is missing important data. |
I see. I was working last weekend on verifying why the tests were failing, but could not get to a final patch yet. I will continue investigating |
|
Digging into this more I have fixed the jose cli program with a simple change, forcing this if block to always execute will make the jose cli work correctly. I am still digging into the share lib API, but I can tell you all the unit tests for jwe are broken. They all take a json object (jwe) as input, call After the Deleting the The compact format is Doing This making sense? |
|
I have updated the patch and I think I have everything working. cmd/jwe/enc.c this makes the compact code the default, so the right values get added to the protected header all the time. This only fixes the jose cli. lib/jwe.c calling tests/jose-jwe-enc this updates the tests to look in the protected value instead of the header value for things. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, if possible, fix indentation of cmd/jwe/enc.c
If not possible, let me know and I will update the patch to fix it.
Thanks for your PR, great job !!!
|
I think I fixed the indention. Today I will be replacing our patch with this in our internal build and running through our code testing to make sure nothing is broken. I don't believe there are any issues, but will report back either way. |
|
@sergio-correia : Could you PTAL? |
|
Patch looks good for our internal build and all the unit tests work, will be updating our build on Monday. |
|
Thanks, @hawk259! |
jose_jwe_enc using elliptic curve keys does not add the algo or epk values to the protected header value it generates.
These values will be missing when generating a compact serialized JWE string and will fail decrypting because the protected value is missing them.
The patch below tweaks things to include them in the protected value.
lib/jwe.c change to match lib/jws.c putting it protected instead of header.
lib/openssl/ecdhes.c changes to put things in both protected and header.
I do not have test cases for other encryption cases, but I think "protected" might need to be added to the add_entity call in other files in lib/openssl.