mirror of
https://github.com/Corewala/Buran
synced 2025-03-13 07:33:24 +00:00
Removed TLS switches
This commit is contained in:
parent
e644957016
commit
5910257488
2 changed files with 1 additions and 113 deletions
|
@ -17,7 +17,6 @@ import java.net.URI
|
|||
import java.net.UnknownHostException
|
||||
import javax.net.ssl.*
|
||||
|
||||
const val GEMINI_SCHEME = "gemini"
|
||||
|
||||
class GeminiDatasource(private val context: Context, val history: BuranHistory): Datasource {
|
||||
|
||||
|
@ -61,7 +60,7 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
|
|||
}
|
||||
|
||||
private fun geminiRequest(uri: URI, onUpdate: (state: GemState) -> Unit){
|
||||
val protocol = prefs.getString("tls_protocol", "TLS")
|
||||
val protocol = "TLS"
|
||||
val useClientCert = prefs.getBoolean(Buran.PREF_KEY_CLIENT_CERT_ACTIVE, false)
|
||||
|
||||
//Update factory if operating mode has changed
|
||||
|
@ -71,19 +70,10 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
|
|||
!useClientCert && buranKeyManager.lastCallUsedKey -> initSSLFactory(protocol!!)
|
||||
}
|
||||
|
||||
println("REQ_PROTOCOL: $protocol")
|
||||
|
||||
val socket: SSLSocket?
|
||||
try {
|
||||
socket = socketFactory?.createSocket(uri.host, 1965) as SSLSocket
|
||||
|
||||
when (protocol) {
|
||||
"TLS" -> {
|
||||
}//Use default enabled protocols
|
||||
"TLS_ALL" -> socket.enabledProtocols = socket.supportedProtocols
|
||||
else -> socket.enabledProtocols = arrayOf(protocol)
|
||||
}
|
||||
|
||||
println("Buran socket handshake with ${uri.host}")
|
||||
socket.startHandshake()
|
||||
}catch (uhe: UnknownHostException){
|
||||
|
|
|
@ -14,11 +14,6 @@ import androidx.appcompat.app.AppCompatDelegate
|
|||
import androidx.preference.*
|
||||
import corewala.buran.Buran
|
||||
import corewala.buran.R
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.SSLSocket
|
||||
import javax.net.ssl.SSLSocketFactory
|
||||
|
||||
|
||||
const val PREFS_SET_CLIENT_CERT_REQ = 20
|
||||
|
@ -26,7 +21,6 @@ const val PREFS_SET_CLIENT_CERT_REQ = 20
|
|||
class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
||||
|
||||
lateinit var prefs: SharedPreferences
|
||||
lateinit var protocols: Array<String>
|
||||
|
||||
private lateinit var clientCertPref: Preference
|
||||
private lateinit var useClientCertPreference: SwitchPreferenceCompat
|
||||
|
@ -83,9 +77,6 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
|||
//Web ----------------------------------------------
|
||||
buildWebSection(context, screen)
|
||||
|
||||
//TLS ----------------------------------------------
|
||||
buildTLSSection(context, screen)
|
||||
|
||||
preferenceScreen = screen
|
||||
}
|
||||
|
||||
|
@ -204,48 +195,6 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
|||
accessibilityCategory.addPreference(showInlineIconsPreference)
|
||||
}
|
||||
|
||||
private fun buildTLSSection(context: Context?, screen: PreferenceScreen) {
|
||||
val tlsCategory = PreferenceCategory(context)
|
||||
tlsCategory.key = "tls_category"
|
||||
tlsCategory.title = getString(R.string.tls_config)
|
||||
screen.addPreference(tlsCategory)
|
||||
|
||||
val tlsDefaultPreference = SwitchPreferenceCompat(context)
|
||||
tlsDefaultPreference.key = "tls_Default"
|
||||
tlsDefaultPreference.title = getString(R.string.tls_default)
|
||||
tlsDefaultPreference.onPreferenceChangeListener = this
|
||||
tlsCategory.addPreference(tlsDefaultPreference)
|
||||
|
||||
//This feel inelegant:
|
||||
var tlsPrefSet = false
|
||||
prefs.all.forEach { pref ->
|
||||
if (pref.key.startsWith("tls_")) tlsPrefSet = true
|
||||
}
|
||||
|
||||
if (!tlsPrefSet) {
|
||||
tlsDefaultPreference.isChecked = true
|
||||
}
|
||||
|
||||
val tlsAllSupportedPreference = SwitchPreferenceCompat(context)
|
||||
tlsAllSupportedPreference.key = "tls_All_Supported"
|
||||
tlsAllSupportedPreference.title = getString(R.string.tls_enable_all_supported)
|
||||
tlsAllSupportedPreference.onPreferenceChangeListener = this
|
||||
tlsCategory.addPreference(tlsAllSupportedPreference)
|
||||
|
||||
val sslContext = SSLContext.getInstance("TLS")
|
||||
sslContext.init(null, null, SecureRandom())
|
||||
val factory: SSLSocketFactory = sslContext.socketFactory
|
||||
val socket = factory.createSocket() as SSLSocket
|
||||
protocols = socket.supportedProtocols
|
||||
protocols.forEach { protocol ->
|
||||
val tlsPreference = SwitchPreferenceCompat(context)
|
||||
tlsPreference.key = "tls_${protocol.toLowerCase(Locale.getDefault())}"
|
||||
tlsPreference.title = protocol
|
||||
tlsPreference.onPreferenceChangeListener = this
|
||||
tlsCategory.addPreference(tlsPreference)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildClientCertificateSection(context: Context?, appCategory: PreferenceCategory) {
|
||||
if (Buran.FEATURE_CLIENT_CERTS) {
|
||||
|
||||
|
@ -332,60 +281,9 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
|||
}
|
||||
|
||||
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
|
||||
if(preference == null) return false
|
||||
|
||||
if(preference.key.startsWith("tls")){
|
||||
tlsChangeListener(preference, newValue)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun tlsChangeListener(
|
||||
preference: Preference?, newValue: Any?
|
||||
) {
|
||||
if (preference is SwitchPreferenceCompat && newValue is Boolean && newValue == true) {
|
||||
preference.key?.let { key ->
|
||||
when {
|
||||
key.startsWith("tls_") -> {
|
||||
if (key != "tls_Default") {
|
||||
val default = preferenceScreen.findPreference<SwitchPreferenceCompat>("tls_Default")
|
||||
default?.isChecked = false
|
||||
}
|
||||
if (key != "tls_All_Supported") {
|
||||
val all = preferenceScreen.findPreference<SwitchPreferenceCompat>("tls_All_Supported")
|
||||
all?.isChecked = false
|
||||
}
|
||||
protocols.forEach { protocol ->
|
||||
val tlsSwitchKey = "tls_${protocol.toLowerCase(Locale.getDefault())}"
|
||||
if (tlsSwitchKey != key) {
|
||||
val otherTLSSwitch =
|
||||
preferenceScreen.findPreference<SwitchPreferenceCompat>(
|
||||
tlsSwitchKey
|
||||
)
|
||||
otherTLSSwitch?.isChecked = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
when (preference.key) {
|
||||
"tls_Default" -> setTLSProtocol("TLS")
|
||||
"tls_All_Supported" -> setTLSProtocol("TLS_ALL")
|
||||
else -> {
|
||||
val prefTitle = preference.title.toString()
|
||||
setTLSProtocol(prefTitle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setTLSProtocol(protocol: String) = preferenceManager.sharedPreferences.edit().putString(
|
||||
"tls_protocol",
|
||||
protocol
|
||||
).apply()
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if(requestCode == PREFS_SET_CLIENT_CERT_REQ && resultCode == RESULT_OK){
|
||||
data?.data?.also { uri ->
|
||||
|
|
Loading…
Add table
Reference in a new issue