-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Conscrypt provider, SSL classes, fix notifications and change fil…
…es item layout
- Loading branch information
Showing
12 changed files
with
164 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
22 changes: 22 additions & 0 deletions
22
app/src/main/java/ru/yourok/torrserve/utils/AllTrustManager.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ru.yourok.torrserve.utils | ||
|
||
import android.annotation.SuppressLint | ||
import java.security.cert.X509Certificate | ||
import javax.net.ssl.X509TrustManager | ||
|
||
@SuppressLint("CustomX509TrustManager") | ||
class AllTrustManager : X509TrustManager { | ||
@SuppressLint("TrustAllX509TrustManager") | ||
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) { | ||
// Perform no check whatsoever on the validity of the SSL certificate | ||
} | ||
|
||
@SuppressLint("TrustAllX509TrustManager") | ||
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) { | ||
// Perform no check whatsoever on the validity of the SSL certificate | ||
} | ||
|
||
override fun getAcceptedIssuers(): Array<X509Certificate> { | ||
return arrayOf() | ||
} | ||
} |
This file contains 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
This file contains 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
98 changes: 98 additions & 0 deletions
98
app/src/main/java/ru/yourok/torrserve/utils/TlsSocketFactory.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package ru.yourok.torrserve.utils | ||
|
||
import org.conscrypt.Conscrypt | ||
import java.io.IOException | ||
import java.net.InetAddress | ||
import java.net.Socket | ||
import java.security.KeyManagementException | ||
import java.security.NoSuchAlgorithmException | ||
import java.security.Provider | ||
import java.security.Security | ||
import javax.net.ssl.SSLContext | ||
import javax.net.ssl.SSLSocket | ||
import javax.net.ssl.SSLSocketFactory | ||
import javax.net.ssl.TrustManager | ||
|
||
class TlsSocketFactory : SSLSocketFactory { | ||
private val enabledProtocols: Array<String> | ||
private val delegate: SSLSocketFactory | ||
|
||
constructor(enabledProtocols: Array<String>) { | ||
this.enabledProtocols = enabledProtocols | ||
this.delegate = socketFactory | ||
} | ||
|
||
constructor() { | ||
this.enabledProtocols = TLS_RESTRICTED | ||
this.delegate = socketFactory | ||
} | ||
|
||
constructor(base: SSLSocketFactory) { | ||
this.enabledProtocols = TLS_RESTRICTED | ||
this.delegate = base | ||
} | ||
|
||
override fun getDefaultCipherSuites(): Array<String> { | ||
return delegate.defaultCipherSuites | ||
} | ||
|
||
override fun getSupportedCipherSuites(): Array<String> { | ||
return delegate.supportedCipherSuites | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun createSocket(): Socket { | ||
return patch(delegate.createSocket()) | ||
} | ||
|
||
@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) | ||
override fun createSocket(host: String, port: Int): Socket { | ||
return patch(delegate.createSocket(host, port)) | ||
} | ||
|
||
@Throws(IOException::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 = enabledProtocols | ||
} | ||
return s | ||
} | ||
|
||
companion object { | ||
private var conscrypt: Provider? = null | ||
val TLS_MODERN: Array<String> = arrayOf("TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3") | ||
val TLS_RESTRICTED: Array<String> = arrayOf("TLSv1.2", "TLSv1.3") | ||
|
||
@get:Throws(NoSuchAlgorithmException::class, KeyManagementException::class) | ||
private val socketFactory: SSLSocketFactory | ||
get() { | ||
if (conscrypt == null) { | ||
conscrypt = Conscrypt.newProvider() | ||
// Add as provider | ||
Security.insertProviderAt(conscrypt, 1) | ||
} | ||
val context = SSLContext.getInstance("TLS", conscrypt) | ||
context.init(null, arrayOf<TrustManager>(AllTrustManager()), null) | ||
return context.socketFactory | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
This file contains 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