-
Notifications
You must be signed in to change notification settings - Fork 177
[WIP] Bug : Use random IV in EncryptDecryptUsingTpm #5494
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
base: master
Are you sure you want to change the base?
Conversation
|
Note to self: publish an advisory after fix got merged. |
eriknordmark
left a comment
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.
This assumes that the controllers do not care about the length of the encrypted blob. Need to check whether that is the case. Does it place any other requirements on the controllers?
Also, presumably the decryption needs to handle the case when there is no prepended IV and use the old zeros approach so that one can transition.
(When it does that, does it always send the new encrypted blob to the controller meaning the IV would be added on the next boot of a device?)
Last but nost least, the API proto files which describe this as an encrypted key should have their comments expanded; key thing is to not assume anything about the length of the blob since the blob may or may not include an IV (for new vs old EVE versions).
The EncryptDecryptUsingTpm function was using a zero-initialized IV for AES-CFB encryption, which is cryptographically insecure. This commit fixes the issue by generating a cryptographically random IV for each encryption and prepending the IV to the ciphertext (IV is public, not secret). We subsequently extract the IV from the first aes.BlockSize bytes during decryption. Signed-off-by: Shahriyar Jalayeri <shahriyar@posteo.de>
d91525a to
629eaf3
Compare
EVE-API places no restriction on the size. The implementation should threat this data as is and just stored it. Adam doesn't care about the size or content, I'll check to make sure the same is true for commercial controller.
Added fallback for backward compatibility on the decryption path.
I'll open a PR when this is ready to be merged. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5494 +/- ##
==========================================
+ Coverage 19.52% 27.88% +8.35%
==========================================
Files 19 19
Lines 3021 2331 -690
==========================================
+ Hits 590 650 +60
+ Misses 2310 1537 -773
- Partials 121 144 +23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
You are making this very hard to change in the future, you should properly version the new interface. CFB encryption is no longer recommended (as it is not authenticated), and CFB modes are marked as deprectaed in Go standard library, so you are going to have to change this again, so you might as well make this easier. |
I did consider that, with complete json output or magic bytes, but I need to first make sure how controller handles this filed. |
Description
The EncryptDecryptUsingTpm function was using a zero-initialized IV for AES-CFB encryption, which is cryptographically insecure.
This commit fixes the issue by generating a cryptographically random IV for each encryption and prepending the IV to the ciphertext (IV is public, not secret). We subsequently extract the IV from the first aes.BlockSize bytes during decryption.
PR dependencies
None.
How to test and validate this PR
Please describe how the changes in this PR can be validated or verified. For
example:
This will be used
The first is especially important, so, please make sure to provide as much
detail as possible.
If it's covered by an automated test, please mention it here.
Changelog notes
Fix AES-CFB encryption in EVE by using a random IV instead of a zero-initialized IV.
PR Backports
For all current LTS branches, please state explicitly if this PR should be
backported or not. This section is used by our scripts to track the backports,
so, please, do not omit it.
Here is the list of current LTS branches (it should be always up to date):
For example, if this PR fixes a bug in a feature that was introduced in 14.5,
you can write:
Also, to the PRs that should be backported into any stable branch, please
add a label
stable.Checklist
For backport PRs (remove it if it's not a backport):
And the last but not least:
check them.
Please, check the boxes above after submitting the PR in interactive mode.