Skip to content
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

feat: allow http calls when checking Certificate Revocation List (WPB-6493) #2491

Merged
merged 10 commits into from
Feb 14, 2024

Conversation

ohassine
Copy link
Member

@ohassine ohassine commented Feb 13, 2024


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Issues

We need to verify certificates by fetching Certificate Revocation List. This CRL can only be called on HTTP, it's already signed by the issuer so there is no security issue.

BUT by default, Android OS does not allow HTTP calls and throw an exception for that.

Solutions

In AndroidManifest, I allowed usesCleartextTraffic and created in a new okhttp client that could be use on HTTP.

Others calls are still called on HTTPS as we okhttpClient with ConnectionSpec.RESTRICTED_TLS

Needs releases with:

  • GitHub link to other pull request

Testing

Test Coverage (Optional)

  • I have added automated test to this contribution

PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

PR Post Merge Checklist for internal contributors

  • If any soft of configuration variable was introduced by this PR, it has been added to the relevant documents and the CI jobs have been updated.

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

Copy link
Contributor

github-actions bot commented Feb 13, 2024

Test Results

2 271 tests   - 636   2 221 ✔️  - 564   14s ⏱️ - 2m 20s
   423 suites  -   87        50 💤  -   72 
   423 files    -   87          0 ±    0 

Results for commit a634d73. ± Comparison against base commit fff203c.

This pull request removes 2907 and adds 2271 tests. Note that renamed tests count towards both.
PocIntegrationTest ‑ givenApiWhenGettingACMEDirectoriesThenReturnAsExpectedBasedOnNetworkState
PocIntegrationTest ‑ givenEmailAndPasswordWhenLoggingInThenRegisterClientAndLogout
com.wire.kalium.HttpClientConnectionSpecsTest ‑ givenTheHttpClientIsCreated_ThenEnsureOnlySupportedSpecsArePresent[jvm]
com.wire.kalium.api.base.authenticated.notification.AccessUpdateTest ‑ givenPayloadWithAccessRoleAndDeprecatedAccessRoleField_whenDecoding_thenDeprecatedFieldIsPreferred[jvm]
com.wire.kalium.api.base.authenticated.notification.AccessUpdateTest ‑ givenPayloadWithDeprecatedAccessRoleField_whenDecoding_thenSuccess[jvm]
com.wire.kalium.api.base.authenticated.notification.AccessUpdateTest ‑ givenPayload_whenDecoding_thenSuccess[jvm]
com.wire.kalium.api.common.ACMEApiTest ‑ givenNoLocationInHeader_whenCallingSendAcmeRequestApi_theResponseShouldBeConfigureCorrectly[jvm]
com.wire.kalium.api.common.ACMEApiTest ‑ givenNoNonce_whenCallingSendAcmeRequestApi_theResponseShouldBeMissingNonce[jvm]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingGeTrustAnchorsApi_theResponseShouldBeConfigureCorrectly[jvm]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingGetACMEDirectoriesApi_theResponseShouldBeConfigureCorrectly[jvm]
…
com.wire.kalium.api.base.authenticated.notification.AccessUpdateTest ‑ givenPayloadWithAccessRoleAndDeprecatedAccessRoleField_whenDecoding_thenDeprecatedFieldIsPreferred[iosX64]
com.wire.kalium.api.base.authenticated.notification.AccessUpdateTest ‑ givenPayloadWithDeprecatedAccessRoleField_whenDecoding_thenSuccess[iosX64]
com.wire.kalium.api.base.authenticated.notification.AccessUpdateTest ‑ givenPayload_whenDecoding_thenSuccess[iosX64]
com.wire.kalium.api.common.ACMEApiTest ‑ givenNoLocationInHeader_whenCallingSendAcmeRequestApi_theResponseShouldBeConfigureCorrectly[iosX64]
com.wire.kalium.api.common.ACMEApiTest ‑ givenNoNonce_whenCallingSendAcmeRequestApi_theResponseShouldBeMissingNonce[iosX64]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingGeTrustAnchorsApi_theResponseShouldBeConfigureCorrectly[iosX64]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingGetACMEDirectoriesApi_theResponseShouldBeConfigureCorrectly[iosX64]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingGetACMENonceApi_theResponseShouldBeConfigureCorrectly[iosX64]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingSendAcmeRequestApi_theResponseShouldBeConfigureCorrectly[iosX64]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingSendChallengeRequestApi_theResponseShouldBeConfigureCorrectly[iosX64]
…
This pull request removes 122 skipped tests and adds 50 skipped tests. Note that renamed tests count towards both.
PocIntegrationTest ‑ givenApiWhenGettingACMEDirectoriesThenReturnAsExpectedBasedOnNetworkState
PocIntegrationTest ‑ givenEmailAndPasswordWhenLoggingInThenRegisterClientAndLogout
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingGeTrustAnchorsApi_theResponseShouldBeConfigureCorrectly[jvm]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingSendChallengeRequestApi_theResponseShouldBeConfigureCorrectly[jvm]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenAValidEmail_whenActivationEmailWIthCode_theRequestShouldBeConfiguredCorrectly[jvm]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenAValidEmail_whenRegisteringAccountWithEMail_theRequestShouldBeConfiguredCorrectly[jvm]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenAValidEmail_whenSendingActivationEmail_theRequestShouldBeConfiguredCorrectly[jvm]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenActivationCodeFail_thenErrorIsPropagated[jvm]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenRegistrationFail_whenRegisteringAccountWithEMMail_thenErrorIsPropagated[jvm]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenSendActivationCodeFail_thenErrorIsPropagated[jvm]
…
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingGeTrustAnchorsApi_theResponseShouldBeConfigureCorrectly[iosX64]
com.wire.kalium.api.common.ACMEApiTest ‑ whenCallingSendChallengeRequestApi_theResponseShouldBeConfigureCorrectly[iosX64]
com.wire.kalium.api.v0.message.QualifiedMessageApiV0Test ‑ givenAValid_whenSendingAMessage_theRequestShouldBeConfiguredCorrectly[iosX64]
com.wire.kalium.api.v0.message.QualifiedMessageApiV0Test ‑ givenDeletedUsersError_whenSendingAMessage_TheCorrectErrorIsPropagate[iosX64]
com.wire.kalium.api.v0.message.QualifiedMessageApiV0Test ‑ givenMissingUsersError_whenSendingAMessage_TheCorrectErrorIsPropagate[iosX64]
com.wire.kalium.api.v0.message.QualifiedMessageApiV0Test ‑ givenRedundantUsersError_whenSendingAMessage_TheCorrectErrorIsPropagate[iosX64]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenAValidEmail_whenActivationEmailWIthCode_theRequestShouldBeConfiguredCorrectly[iosX64]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenAValidEmail_whenRegisteringAccountWithEMail_theRequestShouldBeConfiguredCorrectly[iosX64]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenAValidEmail_whenSendingActivationEmail_theRequestShouldBeConfiguredCorrectly[iosX64]
com.wire.kalium.api.v0.user.register.RegisterApiV0Test ‑ givenActivationCodeFail_thenErrorIsPropagated[iosX64]
…

♻️ This comment has been updated with latest results.

Copy link
Member

@mchenani mchenani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect 🔥

@@ -35,8 +39,15 @@ private object OkHttpSingleton {
.writeTimeout(WEBSOCKET_TIMEOUT, TimeUnit.MILLISECONDS)
}.connectionSpecs(supportedConnectionSpecs()).build()
}
private val clearTextTrafficClient by lazy {
OkHttpClient.Builder().apply {
Copy link
Member

@MohamadJaara MohamadJaara Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not create multiple instances of okHttp you can reuse the same one that is already in the singleton

Copy link
Member

@MohamadJaara MohamadJaara Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like

fun buildClearTextTrafficOkhttpClient(): OkHttpClient = OkHttpSingleton.createNew {
        connectionSpecs(listOf(ConnectionSpec.CLEARTEXT))
    }

and the private val clearTextTrafficClient by lazy { can be deleted

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current okHttp client has RESTRICTED_TLS spec, I created another one that have CLEARTEXT spec to allow HTTP connection

@datadog-wireapp
Copy link

datadog-wireapp bot commented Feb 13, 2024

Datadog Report

All test runs ee5fd8f 🔗

2 Total Test Services: 0 Failed, 2 Passed

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Wall Time Test Service View
kalium-ios 0 0 0 2221 50 7m 32.13s Link
kalium-jvm 0 0 0 2786 122 8m 52.05s Link

@@ -103,5 +103,9 @@ private fun OkHttpClient.Builder.ignoreAllSSLErrors() {

fun supportedConnectionSpecs(): List<ConnectionSpec> {
val wireSpec = ConnectionSpec.Builder(ConnectionSpec.RESTRICTED_TLS).build()
return listOf(wireSpec, ConnectionSpec.CLEARTEXT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ConnectionSpec.CLEARTEXT was already added, so not sure why the new Http client is needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because wireSpec has RESTRICTED_TLS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which will only allow connections through HTTPS

@codecov-commenter
Copy link

Codecov Report

Attention: 23 lines in your changes are missing coverage. Please review.

Comparison is base (fff203c) 58.41% compared to head (a634d73) 58.38%.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #2491      +/-   ##
=============================================
- Coverage      58.41%   58.38%   -0.03%     
  Complexity        21       21              
=============================================
  Files           1172     1172              
  Lines          45313    45332      +19     
  Branches        4286     4287       +1     
=============================================
- Hits           26470    26468       -2     
- Misses         16920    16940      +20     
- Partials        1923     1924       +1     
Files Coverage Δ
...re/kalium/network/api/base/unbound/acme/ACMEApi.kt 30.85% <28.57%> (+0.08%) ⬆️
...etwork/networkContainer/UnboundNetworkContainer.kt 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fff203c...a634d73. Read the comment docs.

@ohassine ohassine added this pull request to the merge queue Feb 14, 2024
Merged via the queue into develop with commit 9101919 Feb 14, 2024
17 checks passed
@ohassine ohassine deleted the allow_http_call_when_checking_crl branch February 14, 2024 11:45
ohassine added a commit that referenced this pull request Feb 14, 2024
…-6493) (#2491)

* feat: allow http calls when checking Certificate Revocation List

* chore: detekt

* chore: unit test

* fix: use of okhttp sharedClient instead of creating a new one

* chore: unit test

* chore: unit test

* chore: add missing function for ios target

---------

Co-authored-by: Mojtaba Chenani <chenani@outlook.com>
ohassine added a commit that referenced this pull request Feb 14, 2024
…-6493) (#2491) (#2496)

* feat: allow http calls when checking Certificate Revocation List

* chore: detekt

* chore: unit test

* fix: use of okhttp sharedClient instead of creating a new one

* chore: unit test

* chore: unit test

* chore: add missing function for ios target

---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants