Bug : Use random IV in EncryptDecryptUsingTpm#5494
Bug : Use random IV in EncryptDecryptUsingTpm#5494shjala wants to merge 4 commits intolf-edge:masterfrom
Conversation
|
Note to self: publish an advisory after fix got merged. |
eriknordmark
left a comment
There was a problem hiding this comment.
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).
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% 30.93% +11.40%
===========================================
Files 19 18 -1
Lines 3021 2311 -710
===========================================
+ Hits 590 715 +125
+ Misses 2310 1433 -877
- Partials 121 163 +42 ☔ 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. |
|
@shjala I thought we found sufficient info about how the controllers behave to proceed with this fix. |
Update eve-api to include the latest changes. Signed-off-by: Shahriyar Jalayeri <shahriyar@posteo.de>
629eaf3 to
88beb05
Compare
|
@eriknordmark made some changes, please review. |
88beb05 to
a755a00
Compare
eriknordmark
left a comment
There was a problem hiding this comment.
LGTM but some revive and codespell issues to fix.
Changes EncryptDecryptUsingTpm function to support versioned encryption with proper random IV generation. Previously, the function used a static zero IV which is insecure. This commit: - Adds VaultKeyEncVersion enum (Unespecified, EncryptionAEAD) to track encryption method versions - Implements AES-GCM (AEAD) encryption/decryption with random nonce - Maintains backward compatibility with existing encrypted data using Unespecified version The new AEAD mode generates a random nonce per encryption operation and prepends it (with its size) to the ciphertext, providing authenticated encryption with proper IV randomness. Signed-off-by: Shahriyar Jalayeri <shahriyar@posteo.de>
a755a00 to
f32bad6
Compare
- Move GetCertHash to evetpm package for better reusability. - Migrate tpmmgr internal tests (testTpmEcdhSupport, testEcdhAES) to evetpm unit tests. - Add unit tests in encryptdecrypt_test.go covering AES GCM and TPM encryption. - Update TPM test setup scripts (tests/tpm/*.sh) to provision required keys and certificates. - Allow overriding of TPM file paths in locationconsts.go for testing purposes. Signed-off-by: Shahriyar Jalayeri <shahriyar@posteo.de>
f32bad6 to
026f608
Compare
Increase timeout durations for stability check and inventory collection in evaluation cycle tests. Signed-off-by: Shahriyar Jalayeri <shahriyar@posteo.de>
|
@shjala seems like the two upgrade tests fail repeatedly for this PR (and we don't see any intermittent failures for those tests elsewhere). Did you check how Eden/Adam saves the encrypted storage key? |
I'm working on something to make running Eden on local branch a bit easier, I will test both PRs with it and fix any remaining issues. |
|
Running against the commercial controller I see failures. The system updates fine to run the image in this PR, and as part of that it saves the encrypted key in the controller. Maybe this is a constraint but it means there will be issues if update to a newer version is done, and it saves the key in the new format with an IV, and then the system crashes during its first 10 minutes and we fallback to the previous version. Do we need to introduce this using two steps?
|
|
@eriknordmark I checked the code, the eve upgrade test in Eden has been a EVE downgrade for a while (or always? how can we upgrade from a PR to PR+1), it always upgrades to version "12.1.0", and the test you ran with commercial controller is technically a downgrade too. Yes, the problem is that if we "upgrade" to an older version, it can't decrypt the new version, but new version can decrypt the old version.
OK, I have to check in which order we do things, but I (foolishly) expect this to only happen if the previous version was in vault locked state, otherwise reverting to old version it should be able to unlock the vault and submit it's key to the controller during the attestation (or will it get the key from the controller first?), will the controller update the key every time it is received or ignores it if it is already set (even with different format)? |
Let me think about it a bit, but maybe we have to. |
|
Note that installing this PR on a device is toxic in that you can't later install anything else (like master). |
|
@eriknordmark What do you think about this strategy : Boot 1 : EVE is potentially unstable (PartitionState = inprogress), encrypt using AES-ZeroIV (LEGACY) regardless of what EVE version is running, Controller receives legacy data. If rollback happens, Controller has LEGACY data that every EVE version can understand. Boot 2 : EVE is stable (PartitionState = active), encrypt using AEAD, Controller receives new data. Rollback is not going to happen and we are committed to the latest version. This relies on no disk write and we don't have to worry about disk fails. We can indicate in the release notes that upgrading to this version makes downgrades not only officially but also technically impossible without losing vault data. |
That sounds workable and simple enough. Please make sure you put the release note text in the PR description, and let me know when you have updated the code so we can run this through the tests. We also need to check how we test things - in eden and in Zededa test setups to make sure we only test upgrades (from LTS releases to current PR or current master/release) and not try to move back and forth across releases. |
|
Plus some conflicts to resolve when you evolve the fix. |
Description
265c688 Changes EncryptDecryptUsingTpm function to support versioned encryption
with proper random IV generation. Previously, the function used a static
zero IV which is insecure. This commit:
encryption method versions
Unespecified version
The new AEAD mode generates a random nonce per encryption operation and
prepends it (with its size) to the ciphertext, providing authenticated
encryption with proper IV randomness.
f32bad6 Refactor TPM tests and add encryption unit tests
PR dependencies
None.
How to test and validate this PR
TPM Encryption Fix Validation
Ensure that device encryption keys (Vaults) continue to work correctly for new installations AND after upgrading existing devices.
1. Fresh Installation Verification
Ensure the new encryption method works on a new device.
tpmmgrlogs on the device or via Controller:2. Upgrade & Backward Compatibility
Ensure that updating an OLD device to this NEW version does not lock the user out of their existing encrypted data.
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.