Fix SSL certificate out-of-date detection (#2028)

This commit is contained in:
Mikołaj Pich 2022-10-28 11:10:05 +02:00 committed by GitHub
parent 515a3973b7
commit c5e2b18695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,16 +15,17 @@ import java.net.ConnectException
import java.net.SocketException import java.net.SocketException
import java.net.SocketTimeoutException import java.net.SocketTimeoutException
import java.net.UnknownHostException import java.net.UnknownHostException
import java.security.cert.CertPathValidatorException
import java.security.cert.CertificateExpiredException import java.security.cert.CertificateExpiredException
import java.security.cert.CertificateNotYetValidException import java.security.cert.CertificateNotYetValidException
import javax.net.ssl.SSLHandshakeException import javax.net.ssl.SSLHandshakeException
fun Resources.getErrorString(error: Throwable): String = when (error) { fun Resources.getErrorString(error: Throwable): String = when (error) {
is UnknownHostException -> R.string.error_no_internet is UnknownHostException -> R.string.error_no_internet
is ConnectException,
is SocketException, is SocketException,
is SocketTimeoutException, is SocketTimeoutException,
is InterruptedIOException, is InterruptedIOException,
is ConnectException,
is StreamResetException -> R.string.error_timeout is StreamResetException -> R.string.error_timeout
is NotLoggedInException -> R.string.error_login_failed is NotLoggedInException -> R.string.error_login_failed
is PasswordChangeRequiredException -> R.string.error_password_change_required is PasswordChangeRequiredException -> R.string.error_password_change_required
@ -42,10 +43,10 @@ fun Resources.getErrorString(error: Throwable): String = when (error) {
fun Throwable.isShouldBeReported(): Boolean = when (this) { fun Throwable.isShouldBeReported(): Boolean = when (this) {
is UnknownHostException, is UnknownHostException,
is ConnectException,
is SocketException, is SocketException,
is SocketTimeoutException, is SocketTimeoutException,
is InterruptedIOException, is InterruptedIOException,
is ConnectException,
is StreamResetException, is StreamResetException,
is ServiceUnavailableException, is ServiceUnavailableException,
is FeatureDisabledException, is FeatureDisabledException,
@ -70,5 +71,6 @@ private fun Throwable?.isCausedByCertificateNotValidNow(): Boolean {
private fun Throwable?.isCertificateNotValidNow(): Boolean { private fun Throwable?.isCertificateNotValidNow(): Boolean {
val isNotYetValid = this is CertificateNotYetValidException val isNotYetValid = this is CertificateNotYetValidException
val isExpired = this is CertificateExpiredException val isExpired = this is CertificateExpiredException
return isNotYetValid || isExpired val isInvalidPath = this is CertPathValidatorException
return isNotYetValid || isExpired || isInvalidPath
} }