small BlobCipher and SimKmsConnector fixes and changes#6936
Conversation
Doxense CI Report for Windows 10
|
AWS CodeBuild CI Report for Linux CentOS 7
|
| throw encrypt_key_not_found(); | ||
| // ENCRYPT_INVALID_CIPHER_KEY_ID indicate there was no key inserted. In this case we return empty key instead of | ||
| // throwing encrypt_invalid_id. | ||
| if (latestBaseCipherKeyId == ENCRYPT_INVALID_CIPHER_KEY_ID) { |
There was a problem hiding this comment.
@sfc-gh-ahusain I'm still making this change since I want to make it consistent that things isn't actually an error don't throw an exception. Or if you prefer to, I can make latestBaseCipherKeyId an Optional, and testing against Optional::present() rather than whether the id is invalid to tell if the cache is empty.
There was a problem hiding this comment.
I think you need to rebase the branch with the latest main, I updated this code as part of re-merging the auth header changes. API throws encyrpt_key_not_found if cache is empty; otherwise, it asserts that member values are valid.
There was a problem hiding this comment.
yeah I saw that change. I'm just so tempting to do without exception :/
There was a problem hiding this comment.
My suggestion was to pull the change and replace exception with "empty reference"; I thought we agreed that "invalid_id" will be thrown and if key is not present due to: empty cache and/or key_not_found, then "empty reference" will be returned ?
There was a problem hiding this comment.
updated to use Optional. does it look a little bit better?
sfc-gh-ahusain
left a comment
There was a problem hiding this comment.
LGTM. Thanks for doing it
d7eaeeb to
428bd84
Compare
Doxense CI Report for Windows 10
|
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for macOS BigSur 11.5.2
|
Doxense CI Report for Windows 10
|
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for Linux CentOS 7
|
| BlobCipherKeyIdCacheKey BlobCipherKeyIdCache::getCacheKey(const EncryptCipherBaseKeyId& baseCipherKeyId, | ||
| const EncryptCipherRandomSalt& salt) { | ||
| if (baseCipherKeyId == ENCRYPT_INVALID_CIPHER_KEY_ID || salt == ENCRYPT_INVALID_RANDOM_SALT) { | ||
| if (baseCipherKeyId == ENCRYPT_INVALID_CIPHER_KEY_ID) { |
There was a problem hiding this comment.
any reason we removed the 'salt' validity check? We can force the invariant that salt > 0?
There was a problem hiding this comment.
I changed to use Optional for latest salt so there's no need to add an invalid salt value as a placeholder. plus... I'm a bit paranoid as when we create the random salt in theory it can be 0, so 0 is still a valid salt. True we can control how the salt is generated, but there's probably no need to do so.
There was a problem hiding this comment.
as when we create the random salt in theory it can be 0
RandomSalt generation is controlled by BlobCipher and happens as part of BaseCipher KeyDerivation (https://github.com/apple/foundationdb/blob/main/flow/BlobCipher.cpp#L48); if it fair that std::mt19937 random; can generate 0 as the output, we could code to handle '0' random-num generated (it is super rate to happen, but, could) to the BlobCipherKey::BlobCipherKey() to distinguish salt from its default/invalid value i.e. 0
However, once we make above changes, the library controls the salt generation and I don't think it can be modified other than tampering with plaintext EncryptHeader (brute force attack..)
There was a problem hiding this comment.
changed to use Optional for latest salt
Am not sure if Optional is the right choice, the values will be always present after a first latestKey gets inserted; to me they is a "default" value at the time of object construction and then value keeps updating with time.
It is not a biggy either ways and we have discussed this more than needed, if you prefer Optional, please proceed with it; no strong opinions from my side.
Thanks .
There was a problem hiding this comment.
The "default" value effectively make the salt an Optional. To me, Optional is just an explicit way to represent nullable value.
And I put back the invalid random salt check, just in case you think it is handy somewhere else.
c926d2b to
5de271f
Compare
|
Adding another fix to make SimKmsConnector return fixed keys after restart. |
Doxense CI Report for Windows 10
|
Doxense CI Report for Windows 10
|
AWS CodeBuild CI Report for macOS BigSur 11.5.2
|
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for Linux CentOS 7
|
5e9f6ab to
5de271f
Compare
AWS CodeBuild CI Report for macOS BigSur 11.5.2
|
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for macOS BigSur 11.5.2
|
Doxense CI Report for Windows 10
|
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for Linux CentOS 7
|
Doxense CI Report for Windows 10
|
|
@sfc-gh-ahusain Do you have more comments on this one? I'm wanting to merge this one so I can rebase #6942 onto it. Thanks. |
|
|
||
| explicit SimKmsConnectorContext(uint32_t keyCount) : maxEncryptionKeys(keyCount) { | ||
| uint8_t buffer[AES_256_KEY_LENGTH]; | ||
| const unsigned char SHA_KEY[] = "0c39e7906db6d51ac0573d328ce1b6be"; |
There was a problem hiding this comment.
Do we intend to checkin this code?
There was a problem hiding this comment.
This is not debug code. It is intent to make the encrypt keys deterministic after restart, otherwise SimKmsConnector will return different set of cipher keys after a crash in simulation.
Looks great. One minor comment, I think some debugging changes are still in the code that you might want to get rid off before checking in. Thanks for doing this change. |
Code-Reviewer Section
The general guidelines can be found here.
Please check each of the following things and check all boxes before accepting a PR.
For Release-Branches
If this PR is made against a release-branch, please also check the following:
release-branchormainif this is the youngest branch)