mirror of
https://github.com/jellyfin/jellyfin-sdk-kotlin.git
synced 2024-11-23 05:49:59 +00:00
Remove specific HTTPS exceptions
This commit is contained in:
parent
a529daa8e9
commit
2e38c0dc72
@ -27,10 +27,6 @@ import org.jellyfin.sdk.api.client.exception.InvalidContentException
|
||||
import org.jellyfin.sdk.api.client.exception.InvalidStatusException
|
||||
import org.jellyfin.sdk.api.client.exception.SecureConnectionException
|
||||
import org.jellyfin.sdk.api.client.exception.TimeoutException
|
||||
import org.jellyfin.sdk.api.client.exception.ssl.BadPeerSSLKeyException
|
||||
import org.jellyfin.sdk.api.client.exception.ssl.HandshakeCertificateException
|
||||
import org.jellyfin.sdk.api.client.exception.ssl.InvalidSSLProtocolImplementationException
|
||||
import org.jellyfin.sdk.api.client.exception.ssl.PeerNotAuthenticatedException
|
||||
import org.jellyfin.sdk.api.client.util.ApiSerializer
|
||||
import org.jellyfin.sdk.api.client.util.AuthorizationHeaderBuilder
|
||||
import org.jellyfin.sdk.api.sockets.DefaultSocketApi
|
||||
@ -42,10 +38,6 @@ import java.io.IOException
|
||||
import java.net.ConnectException
|
||||
import java.net.UnknownHostException
|
||||
import javax.net.ssl.SSLException
|
||||
import javax.net.ssl.SSLHandshakeException
|
||||
import javax.net.ssl.SSLKeyException
|
||||
import javax.net.ssl.SSLPeerUnverifiedException
|
||||
import javax.net.ssl.SSLProtocolException
|
||||
import io.ktor.http.HttpMethod as KtorHttpMethod
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
@ -158,18 +150,6 @@ public actual open class KtorClient actual constructor(
|
||||
} catch (err: SerializationException) {
|
||||
logger.error(err) { "Serialization failed" }
|
||||
throw InvalidContentException("Serialization failed", err)
|
||||
} catch (err: SSLKeyException) {
|
||||
logger.error(err) { "Invalid SSL peer key format" }
|
||||
throw BadPeerSSLKeyException("Invalid SSL peer key format", err)
|
||||
} catch (err: SSLPeerUnverifiedException) {
|
||||
logger.error(err) { "Couldn't authenticate peer" }
|
||||
throw PeerNotAuthenticatedException("Couldn't authenticate peer", err)
|
||||
} catch (err: SSLHandshakeException) {
|
||||
logger.error(err) { "SSL Invalid handshake" }
|
||||
throw HandshakeCertificateException("Invalid handshake", err)
|
||||
} catch (err: SSLProtocolException) {
|
||||
logger.error(err) { "Invalid SSL protocol implementation" }
|
||||
throw InvalidSSLProtocolImplementationException("Invalid SSL protocol implementation", err)
|
||||
} catch (err: SSLException) {
|
||||
logger.error(err) { "Unknown SSL error occurred" }
|
||||
throw SecureConnectionException("Unknown SSL error occurred", err)
|
||||
|
@ -4,7 +4,7 @@ package org.jellyfin.sdk.api.client.exception
|
||||
* An error occurred while attempting to establish a secure connection. This can happen when the server doesn't have
|
||||
* HTTPS enabled or the certificate is invalid.
|
||||
*/
|
||||
public open class SecureConnectionException(
|
||||
public class SecureConnectionException(
|
||||
message: String? = null,
|
||||
cause: Throwable? = null,
|
||||
) : ApiClientException(message, cause)
|
||||
|
@ -1,12 +0,0 @@
|
||||
package org.jellyfin.sdk.api.client.exception.ssl
|
||||
|
||||
import org.jellyfin.sdk.api.client.exception.SecureConnectionException
|
||||
|
||||
/**
|
||||
* An error occurred while attempting to establish a secure connection.
|
||||
* This can happen when a bad key format is given.
|
||||
*/
|
||||
public class BadPeerSSLKeyException(
|
||||
message: String,
|
||||
exception: Throwable,
|
||||
) : SecureConnectionException(message, exception)
|
@ -1,12 +0,0 @@
|
||||
package org.jellyfin.sdk.api.client.exception.ssl
|
||||
|
||||
import org.jellyfin.sdk.api.client.exception.SecureConnectionException
|
||||
|
||||
/**
|
||||
* An error occurred while attempting to establish a secure connection.
|
||||
* Indicates that the client and server could not negotiate the desired level of security or the certificate was
|
||||
* revoked.
|
||||
*/
|
||||
public class HandshakeCertificateException(
|
||||
message: String, exception: Throwable
|
||||
): SecureConnectionException(message, exception)
|
@ -1,12 +0,0 @@
|
||||
package org.jellyfin.sdk.api.client.exception.ssl
|
||||
|
||||
import org.jellyfin.sdk.api.client.exception.SecureConnectionException
|
||||
|
||||
/**
|
||||
* An error occurred while attempting to establish a secure connection.
|
||||
* Normally this indicates a flaw in one of the protocol implementations.
|
||||
*/
|
||||
public class InvalidSSLProtocolImplementationException(
|
||||
message: String,
|
||||
exception: Throwable,
|
||||
) : SecureConnectionException(message, exception)
|
@ -1,15 +0,0 @@
|
||||
package org.jellyfin.sdk.api.client.exception.ssl
|
||||
|
||||
import org.jellyfin.sdk.api.client.exception.SecureConnectionException
|
||||
|
||||
/**
|
||||
* An error occurred while attempting to establish a secure connection.
|
||||
* Indicates that the peer's identity has not been verified.
|
||||
* When the peer was not able to identify itself (for example; no certificate, wrong host, the particular cipher
|
||||
* suite being used does not support authentication, no peer authentication was established during SSL handshaking)
|
||||
* this exception is thrown.
|
||||
*/
|
||||
public class PeerNotAuthenticatedException(
|
||||
message: String,
|
||||
exception: Throwable,
|
||||
) : SecureConnectionException(message, exception)
|
@ -4,8 +4,6 @@ import io.kotest.assertions.retry
|
||||
import io.kotest.assertions.throwables.shouldThrow
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import org.jellyfin.sdk.api.client.exception.SecureConnectionException
|
||||
import org.jellyfin.sdk.api.client.exception.ssl.HandshakeCertificateException
|
||||
import org.jellyfin.sdk.api.client.exception.ssl.PeerNotAuthenticatedException
|
||||
import org.jellyfin.sdk.createJellyfin
|
||||
import org.jellyfin.sdk.model.ClientInfo
|
||||
import org.jellyfin.sdk.model.DeviceInfo
|
||||
@ -17,25 +15,25 @@ class SSLResolverTests : FunSpec({
|
||||
deviceInfo = DeviceInfo("test", "test")
|
||||
}
|
||||
|
||||
xtest("should throw HandShakeCertificateException when calling an https endpoint with revoked certificate") {
|
||||
xtest("should throw SecureConnectionException when calling an https endpoint with revoked certificate") {
|
||||
val api = getInstance().createApi(
|
||||
baseUrl = "https://revoked.badssl.com"
|
||||
)
|
||||
|
||||
retry(3, 1.minutes) {
|
||||
shouldThrow<HandshakeCertificateException> {
|
||||
shouldThrow<SecureConnectionException> {
|
||||
api.request(pathTemplate = "/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xtest("should throw PeerNotAuthenticatedException when wrong host is returned from https endpoint") {
|
||||
xtest("should throw SecureConnectionException when wrong host is returned from https endpoint") {
|
||||
val api = getInstance().createApi(
|
||||
baseUrl = "https://wrong.host.badssl.com"
|
||||
)
|
||||
|
||||
retry(3, 1.minutes) {
|
||||
shouldThrow<PeerNotAuthenticatedException> {
|
||||
shouldThrow<SecureConnectionException> {
|
||||
api.request(pathTemplate = "/")
|
||||
}
|
||||
}
|
||||
@ -52,4 +50,16 @@ class SSLResolverTests : FunSpec({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("should throw SecureConnectionException when using self signed certificate") {
|
||||
val api = getInstance().createApi(
|
||||
baseUrl = "https://self-signed.badssl.com"
|
||||
)
|
||||
|
||||
retry(3, 1.minutes) {
|
||||
shouldThrow<SecureConnectionException> {
|
||||
api.request(pathTemplate = "/")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user