-
Notifications
You must be signed in to change notification settings - Fork 50
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
Trusted entitlements: Do not use etags if cache version not requested and verification enabled #1114
Merged
tonidero
merged 9 commits into
new-trusted-entitlements-signature-format
from
toni/do-not-use-etags-if-cache-version-not-requested
Jul 3, 2023
Merged
Trusted entitlements: Do not use etags if cache version not requested and verification enabled #1114
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bcd7739
Trusted entitlements: Use new signature verification format
tonidero a6cbd9a
Add comment specifying test keys used to generate signature
tonidero f530431
Add more tests
tonidero 3e83d5b
Add tests for signing with both etag and payload
tonidero 4a12774
Whoops
tonidero 0533130
Remove uneeded field from verification mode enum
tonidero 291fc74
Extract createIntermediateSignatureHelper
tonidero c5249fd
Fix detekt
tonidero 589dbb8
Do not use etags if cache version not requested and verification enabled
tonidero 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 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 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 |
---|---|---|
|
@@ -55,9 +55,11 @@ class ETagManager( | |
|
||
internal fun getETagHeaders( | ||
path: String, | ||
verificationRequested: Boolean, | ||
refreshETag: Boolean = false, | ||
): Map<String, String?> { | ||
val eTagData = if (refreshETag) null else getETagData(path) | ||
val storedResult = if (refreshETag) null else getStoredResultSavedInSharedPreferences(path) | ||
val eTagData = storedResult?.eTagData?.takeIf { shouldUseETag(storedResult, verificationRequested) } | ||
return mapOf( | ||
HTTPRequest.ETAG_HEADER_NAME to eTagData?.eTag.orEmpty(), | ||
HTTPRequest.ETAG_LAST_REFRESH_NAME to eTagData?.lastRefreshTime?.time?.toString(), | ||
|
@@ -146,17 +148,22 @@ class ETagManager( | |
} | ||
} | ||
|
||
private fun getETagData(path: String): ETagData? { | ||
return getStoredResultSavedInSharedPreferences(path)?.eTagData | ||
} | ||
|
||
private fun shouldStoreBackendResult(resultFromBackend: HTTPResult): Boolean { | ||
val responseCode = resultFromBackend.responseCode | ||
return responseCode != RCHTTPStatusCodes.NOT_MODIFIED && | ||
responseCode < RCHTTPStatusCodes.ERROR && | ||
resultFromBackend.verificationResult != VerificationResult.FAILED | ||
} | ||
|
||
private fun shouldUseETag(storedResult: HTTPResultWithETag, verificationRequested: Boolean): Boolean { | ||
return when (storedResult.httpResult.verificationResult) { | ||
VerificationResult.VERIFIED -> true | ||
VerificationResult.NOT_REQUESTED -> !verificationRequested | ||
// Should never happen since we don't store these verification results in the cache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ll add this comment too 👍🏻 |
||
VerificationResult.FAILED, VerificationResult.VERIFIED_ON_DEVICE -> false | ||
} | ||
} | ||
|
||
companion object { | ||
fun initializeSharedPreferences(context: Context): SharedPreferences = | ||
context.getSharedPreferences( | ||
|
This file contains 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 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 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 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 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 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.
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.
🙏🏻