-
Notifications
You must be signed in to change notification settings - Fork 9
Cbc UI d2 4571 cloud encryption cleanup #355
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
Merged
cody-constine-ttd
merged 13 commits into
main
from
cbc-UID2-4571-cloud-encryption-cleanup
Dec 17, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
32119f9
Adding the start of what is needed for salt encryption
cody-constine-ttd 7fe538c
[CI Pipeline] Released Snapshot version: 8.0.10-alpha-172-SNAPSHOT
3a808a2
Added more work
cody-constine-ttd e741256
Addressing PR comments
cody-constine-ttd b2e9b68
[CI Pipeline] Released Snapshot version: 8.0.11-alpha-173-SNAPSHOT
1a23d0d
Had to adjust to work with 1mil salts
cody-constine-ttd 65abd71
[CI Pipeline] Released Snapshot version: 8.0.12-alpha-174-SNAPSHOT
e66cd22
Adding encrypted version of ClientSideKeypairStore
cody-constine-ttd 9f9b37b
[CI Pipeline] Released Snapshot version: 8.0.13-alpha-175-SNAPSHOT
b9f29ed
Have the scope resolve the metadata path instead
cody-constine-ttd 9951667
[CI Pipeline] Released Snapshot version: 8.0.14-alpha-176-SNAPSHOT
445f111
Updating rotating cloud encryptionKeyProvider
cody-constine-ttd 73cf984
[CI Pipeline] Released Snapshot version: 8.0.15-alpha-177-SNAPSHOT
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/uid2/shared/store/EncryptedRotatingSaltProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.uid2.shared.store; | ||
|
|
||
| import com.uid2.shared.Const; | ||
| import com.uid2.shared.cloud.DownloadCloudStorage; | ||
| import com.uid2.shared.model.SaltEntry; | ||
| import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider; | ||
| import com.uid2.shared.store.scope.StoreScope; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Collection; | ||
|
|
||
| import static com.uid2.shared.util.CloudEncryptionHelpers.decryptInputStream; | ||
|
|
||
| public class EncryptedRotatingSaltProvider extends RotatingSaltProvider { | ||
| private final RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider; | ||
|
|
||
| public EncryptedRotatingSaltProvider(DownloadCloudStorage fileStreamProvider, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider, StoreScope scope) { | ||
| super(fileStreamProvider, scope.getMetadataPath().toString()); | ||
| this.cloudEncryptionKeyProvider = cloudEncryptionKeyProvider; | ||
| } | ||
|
|
||
| @Override | ||
| protected SaltEntry[] readInputStream(InputStream inputStream, SaltEntryBuilder entryBuilder, Integer size) throws IOException { | ||
| String decrypted = decryptInputStream(inputStream, cloudEncryptionKeyProvider); | ||
| SaltEntry[] entries = new SaltEntry[size]; | ||
| int idx = 0; | ||
| for (String line : decrypted.split("\n")) { | ||
| final SaltEntry entry = entryBuilder.toEntry(line); | ||
| entries[idx] = entry; | ||
| idx++; | ||
| } | ||
| return entries; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/uid2/shared/util/CloudEncryptionHelpers.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.uid2.shared.util; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonFactory; | ||
| import com.fasterxml.jackson.core.JsonParser; | ||
| import com.fasterxml.jackson.core.JsonToken; | ||
| import com.uid2.shared.encryption.AesGcm; | ||
| import com.uid2.shared.model.CloudEncryptionKey; | ||
|
|
||
| import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider; | ||
| import io.vertx.core.json.JsonObject; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Base64; | ||
|
|
||
| import java.io.*; | ||
|
|
||
| public class CloudEncryptionHelpers { | ||
| public static String decryptInputStream(InputStream inputStream, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider) throws IOException { | ||
| JsonFactory factory = new JsonFactory(); | ||
| JsonParser parser = factory.createParser(inputStream); | ||
| int keyId = -1; | ||
| byte[] encryptedPayload = null; | ||
| parser.nextToken(); | ||
| while (parser.nextToken() != JsonToken.END_OBJECT) { | ||
| String fieldName = parser.getCurrentName(); | ||
| if(fieldName.equals("key_id")) { | ||
| parser.nextToken(); | ||
| keyId = parser.getIntValue(); | ||
| } | ||
| if(fieldName.equals("encrypted_payload")) { | ||
| parser.nextToken(); | ||
| encryptedPayload = parser.getBinaryValue(); | ||
| } | ||
| } | ||
|
|
||
| if(keyId == -1 || encryptedPayload == null) { | ||
| throw new IllegalStateException("failed to parse json"); | ||
| } | ||
|
|
||
| CloudEncryptionKey decryptionKey = cloudEncryptionKeyProvider.getKey(keyId); | ||
|
|
||
| if (decryptionKey == null) { | ||
| throw new IllegalStateException("No matching S3 key found for decryption for key ID: " + keyId); | ||
| } | ||
|
|
||
| byte[] secret = Base64.getDecoder().decode(decryptionKey.getSecret()); | ||
| byte[] encryptedBytes = encryptedPayload; | ||
| byte[] decryptedBytes = AesGcm.decrypt(encryptedBytes, 0, secret); | ||
|
|
||
| return new String(decryptedBytes, StandardCharsets.UTF_8); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
where do we use this version of the constructor?
Uh oh!
There was an error while loading. Please reload this page.
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.
In tests, I did this as instead of making reader public.