-
Notifications
You must be signed in to change notification settings - Fork 2
feat(core): Adding key cache, tests for specificity #126
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
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
01cd832
add it to the manifest
elizabethhealy 35f0a71
add split logic on decrypt
elizabethhealy ec5e91b
update cli exception handling
elizabethhealy 484dcaa
make custom exception type
elizabethhealy 4552d07
null check
elizabethhealy 8b006dd
check for null pointer
elizabethhealy fb889a3
encrypt w key splits
elizabethhealy 03fae78
try to fix test, exception fix, sets
elizabethhealy ee193e3
fix test
elizabethhealy 93bae72
Merge branch 'main' into split-key-implementation
elizabethhealy 44a8d96
set up attributes client
elizabethhealy 895592e
add autoconfigure
elizabethhealy 7828af8
Merge branch 'main' into add-attributes-client
elizabethhealy caccf55
Merge branch 'autoconfiguration-key-splitting' into add-multikas-auto…
elizabethhealy 3dfb9c3
Merge branch 'main' into add-multikas-autoconfigure
elizabethhealy 3610633
most tests working
elizabethhealy 8d2ea13
tests passing
elizabethhealy dc8a1ba
multikas e2e (#122)
elizabethhealy b17950c
fix ci trigger
elizabethhealy 8d512f7
Merge branch 'main' into add-multikas-autoconfigure
elizabethhealy d879fff
addressing some comments
elizabethhealy d337c92
resolving more suggestions
elizabethhealy 1ac7a20
hashcode
elizabethhealy 42d05e9
Merge branch 'main' into add-multikas-autoconfigure
elizabethhealy 06aedff
reverting attributes client change
elizabethhealy ac005f9
adding key cache
elizabethhealy 744f660
add tests, get keys from grants
elizabethhealy 1a25269
Merge branch 'main' into add-kas-key-cache
elizabethhealy 7644218
more tests
elizabethhealy 64c76c3
change to 5 mins
elizabethhealy 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
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
82 changes: 82 additions & 0 deletions
82
sdk/src/main/java/io/opentdf/platform/sdk/KASKeyCache.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,82 @@ | ||
| package io.opentdf.platform.sdk; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class KASKeyCache { | ||
| Map<KASKeyRequest, TimeStampedKASInfo> cache; | ||
|
|
||
| public KASKeyCache() { | ||
| this.cache = new HashMap<>(); | ||
| } | ||
|
|
||
| public void clear() { | ||
| this.cache = new HashMap<>(); | ||
| } | ||
|
|
||
| public Config.KASInfo get(String url, String algorithm) { | ||
| KASKeyRequest cacheKey = new KASKeyRequest(url, algorithm); | ||
| LocalDateTime now = LocalDateTime.now(); | ||
| TimeStampedKASInfo cachedValue = cache.get(cacheKey); | ||
|
|
||
| if (cachedValue == null) { | ||
| return null; | ||
| } | ||
|
|
||
| LocalDateTime aMinAgo = now.minus(5, ChronoUnit.MINUTES); | ||
| if (aMinAgo.isAfter(cachedValue.timestamp)) { | ||
| cache.remove(cacheKey); | ||
| return null; | ||
| } | ||
|
|
||
| return cachedValue.kasInfo; | ||
| } | ||
|
|
||
| public void store(Config.KASInfo kasInfo) { | ||
| KASKeyRequest cacheKey = new KASKeyRequest(kasInfo.URL, kasInfo.Algorithm); | ||
| cache.put(cacheKey, new TimeStampedKASInfo(kasInfo, LocalDateTime.now())); | ||
| } | ||
| } | ||
|
|
||
| class TimeStampedKASInfo { | ||
| Config.KASInfo kasInfo; | ||
| LocalDateTime timestamp; | ||
|
|
||
| public TimeStampedKASInfo(Config.KASInfo kasInfo, LocalDateTime timestamp) { | ||
| this.kasInfo = kasInfo; | ||
| this.timestamp = timestamp; | ||
| } | ||
| } | ||
|
|
||
| class KASKeyRequest { | ||
| private String url; | ||
| private String algorithm; | ||
|
|
||
| public KASKeyRequest(String url, String algorithm) { | ||
| this.url = url; | ||
| this.algorithm = algorithm; | ||
| } | ||
|
|
||
| // Override equals and hashCode to ensure proper functioning of the HashMap | ||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || !(o instanceof KASKeyRequest)) return false; | ||
| KASKeyRequest that = (KASKeyRequest) o; | ||
| if (algorithm == null){ | ||
| return url.equals(that.url); | ||
| } | ||
| return url.equals(that.url) && algorithm.equals(that.algorithm); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| int result = 31 * url.hashCode(); | ||
| if (algorithm != null) { | ||
| result = result + algorithm.hashCode(); | ||
| } | ||
| return result; | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.