mirror of https://github.com/lizongying/my-tv.git
parent
5c0152e36c
commit
188431a29f
Binary file not shown.
Binary file not shown.
@ -0,0 +1,74 @@ |
||||
package com.lizongying.mytv.api |
||||
|
||||
import java.io.IOException |
||||
import java.net.InetAddress |
||||
import java.net.Socket |
||||
import java.net.UnknownHostException |
||||
import javax.net.ssl.SSLSocket |
||||
import javax.net.ssl.SSLSocketFactory |
||||
|
||||
|
||||
/** |
||||
* Enables TLS v1.2 when creating SSLSockets. |
||||
* |
||||
* |
||||
* For some reason, android supports TLS v1.2 from API 16, but enables it by |
||||
* default only from API 20. |
||||
* @link https://developer.android.com/reference/javax/net/ssl/SSLSocket.html |
||||
* @see SSLSocketFactory |
||||
*/ |
||||
class Tls12SocketFactory(val delegate: SSLSocketFactory) : SSLSocketFactory() { |
||||
override fun getDefaultCipherSuites(): Array<String> { |
||||
return delegate.defaultCipherSuites |
||||
} |
||||
|
||||
override fun getSupportedCipherSuites(): Array<String> { |
||||
return delegate.supportedCipherSuites |
||||
} |
||||
|
||||
@Throws(IOException::class) |
||||
override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket { |
||||
return patch(delegate.createSocket(s, host, port, autoClose)) |
||||
} |
||||
|
||||
@Throws(IOException::class, UnknownHostException::class) |
||||
override fun createSocket(host: String, port: Int): Socket { |
||||
return patch(delegate.createSocket(host, port)) |
||||
} |
||||
|
||||
@Throws(IOException::class, UnknownHostException::class) |
||||
override fun createSocket( |
||||
host: String, |
||||
port: Int, |
||||
localHost: InetAddress, |
||||
localPort: Int |
||||
): Socket { |
||||
return patch(delegate.createSocket(host, port, localHost, localPort)) |
||||
} |
||||
|
||||
@Throws(IOException::class) |
||||
override fun createSocket(host: InetAddress, port: Int): Socket { |
||||
return patch(delegate.createSocket(host, port)) |
||||
} |
||||
|
||||
@Throws(IOException::class) |
||||
override fun createSocket( |
||||
address: InetAddress, |
||||
port: Int, |
||||
localAddress: InetAddress, |
||||
localPort: Int |
||||
): Socket { |
||||
return patch(delegate.createSocket(address, port, localAddress, localPort)) |
||||
} |
||||
|
||||
private fun patch(s: Socket): Socket { |
||||
if (s is SSLSocket) { |
||||
s.enabledProtocols = TLS_V12_ONLY |
||||
} |
||||
return s |
||||
} |
||||
|
||||
companion object { |
||||
private val TLS_V12_ONLY = arrayOf("TLSv1.2") |
||||
} |
||||
} |
||||
Loading…
Reference in new issue