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

Handling SSL/TLS errors during WellKnown lookup #5965

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5965.sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Including SSL/TLS error handing when doing WellKnown lookups without a custom HomeServerConnectionConfig
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,16 @@ internal class DefaultAuthenticationService @Inject constructor(
return getWellknownTask.execute(
GetWellknownTask.Params(
domain = matrixId.getDomain(),
homeServerConnectionConfig = homeServerConnectionConfig
homeServerConnectionConfig = homeServerConnectionConfig.orWellKnownDefaults()
)
)
}

private fun HomeServerConnectionConfig?.orWellKnownDefaults() = this ?: HomeServerConnectionConfig.Builder()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't too sure about this, I had originally planned to make the service entry point non null but it feels strange to pass the matrix id and a homeserver config (with the url already calculated from the matrix id)

Ideally the getWellKnownData could take the certificate parts of the homeserver config rather than the entire model

Copy link
Contributor

Choose a reason for hiding this comment

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

I also tried with non-null parameter in my local but it produces ugly code as so said.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe keep your original plan and add a in the builder something like HomeServerConnectionConfig.Builder.from(matrixId) or withMatrixId(matrixId) to avoid using dummy.org? But it's maybe more confusing :/.
This is not a blocker for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to add a build method and then remove the matrixId from the getWellKnownData 👍

Copy link
Contributor Author

@ouchadam ouchadam May 10, 2022

Choose a reason for hiding this comment

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

I had a go at using the builder for this however the direct usage of Android's Uri breaks the OnboardingViewModel tests
https://github.com/vector-im/element-android/compare/feature/adm/matrix-id-via-builder

there's a bit more refactoring needed to take into account using fake uris

will merge as is for the time being

// server uri is ignored when doing a wellknown lookup as we use the matrix id domain instead
.withHomeServerUri("https://dummy.org")
.build()

override suspend fun directAuthentication(homeServerConnectionConfig: HomeServerConnectionConfig,
matrixId: String,
password: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal interface GetWellknownTask : Task<GetWellknownTask.Params, WellknownRes
* the URL will be https://{domain}/.well-known/matrix/client
*/
val domain: String,
val homeServerConnectionConfig: HomeServerConnectionConfig?
val homeServerConnectionConfig: HomeServerConnectionConfig
)
}

Expand All @@ -61,15 +61,11 @@ internal class DefaultGetWellknownTask @Inject constructor(
return findClientConfig(params.domain, client)
}

private fun buildClient(homeServerConnectionConfig: HomeServerConnectionConfig?): OkHttpClient {
return if (homeServerConnectionConfig != null) {
okHttpClient.get()
.newBuilder()
.addSocketFactory(homeServerConnectionConfig)
.build()
} else {
okHttpClient.get()
}
private fun buildClient(homeServerConnectionConfig: HomeServerConnectionConfig): OkHttpClient {
return okHttpClient.get()
.newBuilder()
.addSocketFactory(homeServerConnectionConfig)
.build()
}

/**
Expand Down