Request: add a TLS version preference
This commit is contained in:
parent
1d69c075a1
commit
4282567f5f
|
@ -118,11 +118,13 @@ class PageFragment : Fragment(), PageAdapter.Listener {
|
|||
when (uri.scheme) {
|
||||
"gemini" -> {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val protocol =
|
||||
prefs.getString("tls_version", Request.DEFAULT_TLS_VERSION)!!
|
||||
val connectionTimeout =
|
||||
prefs.getInt("connection_timeout", Request.DEFAULT_CONNECTION_TIMEOUT_SEC)
|
||||
val readTimeout =
|
||||
prefs.getInt("read_timeout", Request.DEFAULT_READ_TIMEOUT_SEC)
|
||||
vm.sendGeminiRequest(uri, connectionTimeout, readTimeout)
|
||||
vm.sendGeminiRequest(uri, protocol, connectionTimeout, readTimeout)
|
||||
}
|
||||
else -> openUnknownScheme(uri)
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
|
|||
* The URI must be valid, absolute and with a gemini scheme.
|
||||
*/
|
||||
@ExperimentalCoroutinesApi
|
||||
fun sendGeminiRequest(uri: Uri, connectionTimeout: Int, readTimeout: Int, redirects: Int = 0) {
|
||||
fun sendGeminiRequest(uri: Uri, protocol: String, connectionTimeout: Int, readTimeout: Int, redirects: Int = 0) {
|
||||
Log.d(TAG, "sendRequest: URI \"$uri\"")
|
||||
loadingUrl = uri
|
||||
state.postValue(State.CONNECTING)
|
||||
|
@ -60,7 +60,7 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
|
|||
requestJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val response = try {
|
||||
val request = Request(uri)
|
||||
val socket = request.connect(connectionTimeout, readTimeout)
|
||||
val socket = request.connect(protocol, connectionTimeout, readTimeout)
|
||||
val channel = request.proceed(socket, this)
|
||||
Response.from(channel, viewModelScope)
|
||||
} catch (e: Exception) {
|
||||
|
@ -71,7 +71,7 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
|
|||
signalError(
|
||||
when (e) {
|
||||
is UnknownHostException -> "Unknown host \"${uri.authority}\"."
|
||||
is ConnectException -> "Can't connect to this server: ${e.localizedMessage}."
|
||||
is ConnectException -> "Can't connect to this server: ${e.message}."
|
||||
is SocketTimeoutException -> "Connection timed out."
|
||||
is CancellationException -> "Connection cancelled: ${e.message}."
|
||||
else -> "Oops, something failed!"
|
||||
|
|
|
@ -17,9 +17,9 @@ import javax.net.ssl.X509TrustManager
|
|||
class Request(private val uri: Uri) {
|
||||
private val port get() = if (uri.port > 0) uri.port else 1965
|
||||
|
||||
fun connect(connectionTimeout: Int, readTimeout: Int): SSLSocket {
|
||||
Log.d(TAG, "connect")
|
||||
val context = SSLContext.getInstance("TLSv1.2")
|
||||
fun connect(protocol: String, connectionTimeout: Int, readTimeout: Int): SSLSocket {
|
||||
Log.d(TAG, "connect: $protocol, c.to. $connectionTimeout, r.to. $readTimeout")
|
||||
val context = SSLContext.getInstance(protocol)
|
||||
context.init(null, arrayOf(TrustManager()), null)
|
||||
val socket = context.socketFactory.createSocket() as SSLSocket
|
||||
socket.soTimeout = readTimeout * 1000
|
||||
|
@ -70,6 +70,7 @@ class Request(private val uri: Uri) {
|
|||
|
||||
companion object {
|
||||
private const val TAG = "Request"
|
||||
const val DEFAULT_TLS_VERSION = "TLSv1.3"
|
||||
const val DEFAULT_CONNECTION_TIMEOUT_SEC = 10
|
||||
const val DEFAULT_READ_TIMEOUT_SEC = 10
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<resources>
|
||||
<!-- Reply Preference -->
|
||||
<string-array name="reply_entries">
|
||||
<item>Reply</item>
|
||||
<item>Reply to all</item>
|
||||
<string-array name="tls_version_entries">
|
||||
<item>TLS v1.3</item>
|
||||
<item>TLS v1.2</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="reply_values">
|
||||
<item>reply</item>
|
||||
<item>reply_all</item>
|
||||
<string-array name="tls_version_values">
|
||||
<item>TLSv1.3</item>
|
||||
<item>TLSv1.2</item>
|
||||
</string-array>
|
||||
</resources>
|
|
@ -46,5 +46,6 @@
|
|||
<string name="edit">Edit</string>
|
||||
<string name="identity_usages">Active URL path</string>
|
||||
<string name="input_common_name">Enter a name to use as the certificate\'s subject common name. This can be left empty.</string>
|
||||
<string name="tls_version">TLS version</string>
|
||||
|
||||
</resources>
|
|
@ -13,18 +13,18 @@
|
|||
app:key="home_set"
|
||||
app:title="@string/pref_home_set" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="reply"
|
||||
app:entries="@array/reply_entries"
|
||||
app:entryValues="@array/reply_values"
|
||||
app:key="reply"
|
||||
app:title="@string/reply_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/pref_protocol_header">
|
||||
|
||||
<DropDownPreference
|
||||
app:key="tls_version"
|
||||
app:entries="@array/tls_version_entries"
|
||||
app:entryValues="@array/tls_version_values"
|
||||
app:defaultValue="TLSv1.3"
|
||||
app:useSimpleSummaryProvider="true"
|
||||
app:title="@string/tls_version" />
|
||||
|
||||
<SeekBarPreference
|
||||
android:defaultValue="10"
|
||||
android:max="60"
|
||||
|
|
Reference in a new issue