fix: Refactor AnkiServer for future HTTPS support (Issue #15991)#20885
fix: Refactor AnkiServer for future HTTPS support (Issue #15991)#20885mixelas wants to merge 6 commits intoankidroid:mainfrom
Conversation
david-allison
left a comment
There was a problem hiding this comment.
Are you planning on adding an implementation? Otherwise this PR doesn't feel mergeable on its own
BrayanDSO
left a comment
There was a problem hiding this comment.
Have you used AI on this PR?
| @@ -0,0 +1,78 @@ | |||
| /* | |||
| * Copyright (c) 2024 AnkiDroid Contributors | |||
There was a problem hiding this comment.
I just copied this from another file in the codebase. I wanted it to look like the other files in there. I also didn't add my name because i didn't think that this would get merged.
| private const val KEYSTORE_FILENAME = "anki_keystore.bks" | ||
| private const val KEYSTORE_PASSWORD = "ankidroid" | ||
| private const val KEY_PASSWORD = "ankidroid" |
There was a problem hiding this comment.
I guess that hardcoding these values isn't safe
There was a problem hiding this comment.
Their purpose was strictly as a placeholder. I didn't think that you would entrust me to do the whole thing so i made this instead.
|
|
||
| // TODO: Generate self-signed X.509 certificate | ||
| // Currently creates empty keystore. Future implementations should use: | ||
| // - Android KeyStore API (preferred), or |
There was a problem hiding this comment.
we probably should be doing that now
There was a problem hiding this comment.
I acknowledge this is incomplete. I didn't know which architecture you preferred.
| val statesMutationEvalFlow = MutableSharedFlow<String>() | ||
|
|
||
| override val server: AnkiServer = AnkiServer(this, repository.getServerPort()).also { it.start() } | ||
| override val server: AnkiServer = AnkiServer(this, null, repository.getServerPort()).also { it.start() } |
There was a problem hiding this comment.
this means the issue still isn't fixed on the new study screen
There was a problem hiding this comment.
I see the concern, if I passed null as the context, HTTPS wouldn't be enabled on the new study screen, which defeats the purpose of this PR.
| * Ignores any matching test defined with `@Flaky` in CI | ||
| * @see Flaky | ||
| */ | ||
| class IgnoreFlakyTestsInCIRule : TestRule { |
There was a problem hiding this comment.
idk why are you copying this file
There was a problem hiding this comment.
These files aren't in my commits.
| * @param runnable a function that is expected to throw an exception when executed | ||
| * @return the exception thrown by [runnable] | ||
| */ | ||
| inline fun <reified T : Throwable> assertThrows( |
There was a problem hiding this comment.
idk why you are copying this file
There was a problem hiding this comment.
These files aren't in my commits. they appear to be pre-existing in the repository or from the base branch
|
This was initially a placeholder as i didn't think that I had to make the complete HTTPS support. That is why it looks bad and AI generated, as I tried to do a simple fix. I will get on with pushing a PR with complete HTTPS support and give it my best. |
|
@david-allison can you please review again. |
|
The emulator tests are broken (and please remove the merge commit and rebase/force push onto main) |
ba113ab to
ffb28ba
Compare
| @@ -0,0 +1,36 @@ | |||
| /* | |||
| * Copyright (c) 2024 David Allison <davidallisongithub@gmail.com> | |||
There was a problem hiding this comment.
Please remove these files, they shouldn't have been committed. testutils and testlib have been replaced with test fixtures
Purpose / Description
This PR prepares the codebase for HTTPS support by refactoring AnkiServer to support SSL/TLS configuration, while maintaining backward compatibility.
Fixes
Approach
Added Context parameter to AnkiServer constructor to enable SSL setup when needed
How Has This Been Tested?
AnkiServer baseUrl() returning HTTP when context not provided
AnkiServer baseUrl() containing localhost address
SslUtil placeholder initialization
Tested on:
Learning (optional, can help others)
While i was working with Android SDK, i noticed that it doesn't include sun.security internal APIs in modern versions. The proper approach for self-signed certificate generation on Android involves either:
Checklist
Please, go through these checks before submitting the PR.