Repository navigation
fix: install security provider before tls use #1416
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
5 commits
Select commit
Hold shift + click to select a range
e7222bf
fix: install security provider before tls use
Jasonvdb 1af4195
chore: add changelog fragment
Jasonvdb 52e949c
test: restore security providers to their pre-test state
Jasonvdb 00c6f8f
docs: keep the provider setup error handling note
Jasonvdb a1478a1
test: check the security provider is installed before app injection
Jasonvdb 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package to.bitkit | ||
|
|
||
| import org.bouncycastle.jce.provider.BouncyCastleProvider | ||
| import org.junit.After | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import to.bitkit.utils.AppError | ||
| import java.security.Provider | ||
| import java.security.Security | ||
| import kotlin.test.assertFailsWith | ||
| import kotlin.test.assertIs | ||
|
|
||
| class AppTest { | ||
| private companion object { | ||
| const val BC = BouncyCastleProvider.PROVIDER_NAME | ||
| } | ||
|
|
||
| private var baselineProvider: Provider? = null | ||
| private var baselinePosition = 0 | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| baselineProvider = Security.getProvider(BC) | ||
| baselinePosition = Security.getProviders().indexOfFirst { it === baselineProvider } + 1 | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| // The provider list is shared by the whole JVM, so restore BC as it was before this test started | ||
| Security.removeProvider(BC) | ||
| baselineProvider?.let { Security.insertProviderAt(it, baselinePosition) } | ||
| } | ||
|
|
||
| @Test | ||
| fun `onCreate installs the security provider before Hilt injects the app`() { | ||
| Security.removeProvider(BC) | ||
| Security.addProvider(OutdatedBcProvider()) | ||
| val app = InjectionProbeApp() | ||
|
|
||
| // The Hilt Gradle plugin rewrites App to extend the generated Hilt_App, whose onCreate() injects App through | ||
| // hiltInternalInject(). The probe's method of that name overrides it at runtime and stops onCreate() there. | ||
| assertFailsWith<InjectionReached> { app.onCreate() } | ||
|
|
||
| assertIs<BouncyCastleProvider>(app.providerAtInjection) | ||
| } | ||
|
|
||
| private class InjectionProbeApp : App() { | ||
| var providerAtInjection: Provider? = null | ||
|
|
||
| fun hiltInternalInject() { | ||
| providerAtInjection = Security.getProvider(BC) | ||
| throw InjectionReached() | ||
| } | ||
| } | ||
|
|
||
| private class InjectionReached : AppError("Reached Hilt injection") | ||
|
|
||
| private class OutdatedBcProvider : Provider(BC, 1.0, "Stub for the BC provider that Android registers") | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Pubky profile, contact and payment features no longer fail after a cold start until the app is restarted. |
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.