[FIX] SSL handling#4861
Merged
Merged
Conversation
Contributor
Author
|
Some checks done with badssl.com
|
joragua
approved these changes
May 26, 2026
There was a problem hiding this comment.
Pull request overview
This PR tightens SSL/TLS handling by replacing the permissive hostname verifier with logic that validates the hostname normally, and falls back to trusting previously accepted server certificates. It also improves propagation/UI handling of SSLPeerUnverifiedException so the app can present an appropriate alert and abort the connection/certificate flow.
Changes:
- Replace the always-true hostname verifier with
KnownServersHostnameVerifierthat delegates to standard hostname checks and falls back to the known-servers certificate store. - Wrap
SSLPeerUnverifiedExceptionintoCertificateCombinedException(carrying the last seen certificate) to route it through the existing recoverable SSL error path. - Update the untrusted certificate dialog behavior for hostname-not-verified cases and add a security changelog entry.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java | Wrap SSLPeerUnverifiedException into CertificateCombinedException using a thread-local last certificate. |
| owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/NetworkUtils.java | Add helper to check if a certificate exists in the known-servers store. |
| owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/KnownServersHostnameVerifier.java | New hostname verifier that delegates to default verification and falls back to known-servers cert store. |
| owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/AdvancedX509TrustManager.java | Track “last certificate” in a ThreadLocal for later error wrapping. |
| owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java | Wire the new hostname verifier into OkHttp client configuration. |
| owncloudApp/src/main/java/com/owncloud/android/ui/dialog/SslUntrustedCertDialog.java | Adjust dialog UI/flow when hostname verification fails (peer unverified). |
| changelog/unreleased/4861 | Add changelog entry for SSL verification/trusted host handling improvements. |
Comments suppressed due to low confidence (1)
owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/AdvancedX509TrustManager.java:102
checkServerTrustedguardscertificateswith a null/length check, but then immediately dereferencescertificates[0]regardless. As written, a null/empty chain will still crash with NPE/ArrayIndexOutOfBounds. Either enforce the contract at the top (return/throw) or update all subsequent uses to handle null/empty safely.
public void checkServerTrusted(X509Certificate[] certificates, String authType) {
if (certificates != null && certificates.length > 0) {
sLastCert.set(certificates[0]);
}
if (!isKnownServer(certificates[0])) {
CertificateCombinedException result = new CertificateCombinedException(certificates[0]);
try {
certificates[0].checkValidity();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2
to
+16
| * ownCloud Android client application | ||
| * | ||
| * Copyright (C) 2026 ownCloud GmbH. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Comment on lines
+21
to
+37
| import android.content.Context; | ||
| import okhttp3.internal.tls.OkHostnameVerifier; | ||
| import timber.log.Timber; | ||
| import javax.net.ssl.HostnameVerifier; | ||
| import javax.net.ssl.SSLPeerUnverifiedException; | ||
| import javax.net.ssl.SSLSession; | ||
| import java.security.cert.Certificate; | ||
| import java.security.cert.X509Certificate; | ||
|
|
||
| public class KnownServersHostnameVerifier implements HostnameVerifier { | ||
|
|
||
| private final Context mContext; | ||
| private final HostnameVerifier mDelegate; | ||
|
|
||
| public KnownServersHostnameVerifier(Context context) { | ||
| this(context, OkHostnameVerifier.INSTANCE); | ||
| } |
Comment on lines
+89
to
99
| public static final ThreadLocal<X509Certificate> sLastCert = new ThreadLocal<>(); | ||
|
|
||
| /** | ||
| * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[], | ||
| * String authType) | ||
| */ | ||
| public void checkServerTrusted(X509Certificate[] certificates, String authType) { | ||
| if (certificates != null && certificates.length > 0) { | ||
| sLastCert.set(certificates[0]); | ||
| } | ||
| if (!isKnownServer(certificates[0])) { |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
From
opencloud-eu/android#121
opencloud-eu/android#126
Host is now correctly verified with a
KnownServersHostnameVerifierthat checks if:If a
SslPeerUnverifiedExceptionraises, it is enclosed in aCertificateCombinedExceptionto be handled separately from a genericSSLExceptionWhen
SslPeerUnverifiedExceptionraises, the certificate accepting dialog turns into an alertCertificate and connection are aborted
Related Issues
App:
ReleaseNotesViewModel.ktcreating a newReleaseNote()with String resources (if required)QA