forked from saschpe/android-exoplayer2-ext-icy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
TLSSocketFactory.kt
60 lines (44 loc) · 2.01 KB
/
TLSSocketFactory.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.stormacq.android.maxi80
import java.net.InetAddress
import java.net.Socket
import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSocket
import javax.net.ssl.SSLSocketFactory
class TLSSocketFactory : SSLSocketFactory() {
private var internalSSLSocketFactory : SSLSocketFactory
init {
val context = SSLContext.getInstance("TLS")
context.init(null, null, null)
internalSSLSocketFactory = context.socketFactory
}
override fun getDefaultCipherSuites() : Array<String> {
return internalSSLSocketFactory.defaultCipherSuites
}
override fun getSupportedCipherSuites() : Array<String> {
return internalSSLSocketFactory.supportedCipherSuites
}
override fun createSocket() : Socket? {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket())
}
override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean) : Socket? {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, host, port, autoClose))
}
override fun createSocket(host: String, port: Int) : Socket? {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port))
}
override fun createSocket(host: String, port: Int, localHost: InetAddress, localPort: Int) : Socket? {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port, localHost, localPort))
}
override fun createSocket(host: InetAddress, port: Int) : Socket? {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port))
}
override fun createSocket(address: InetAddress, port: Int, localAddress: InetAddress, localPort: Int) : Socket? {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(address, port, localAddress, localPort))
}
private fun enableTLSOnSocket(socket: Socket?) : Socket? {
if(socket != null && (socket is SSLSocket)) {
socket.enabledProtocols = arrayOf("TLSv1.1", "TLSv1.2")
}
return socket
}
}