diff --git a/app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt b/app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt
index 586f310..a367c1a 100644
--- a/app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt
+++ b/app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt
@@ -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)
}
diff --git a/app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt b/app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt
index e51d1f4..020ba65 100644
--- a/app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt
+++ b/app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt
@@ -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!"
diff --git a/app/src/main/java/dev/lowrespalmtree/comet/Request.kt b/app/src/main/java/dev/lowrespalmtree/comet/Request.kt
index 8ca2371..b2f9219 100644
--- a/app/src/main/java/dev/lowrespalmtree/comet/Request.kt
+++ b/app/src/main/java/dev/lowrespalmtree/comet/Request.kt
@@ -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
}
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 6cf9ed4..883ddd2 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -1,12 +1,11 @@
-
-
- - Reply
- - Reply to all
+
+ - TLS v1.3
+ - TLS v1.2
-
- - reply
- - reply_all
+
+ - TLSv1.3
+ - TLSv1.2
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b5e01a5..b5adca5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -46,5 +46,6 @@
Edit
Active URL path
Enter a name to use as the certificate\'s subject common name. This can be left empty.
+ TLS version
\ No newline at end of file
diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml
index e2596ad..c1e4599 100644
--- a/app/src/main/res/xml/root_preferences.xml
+++ b/app/src/main/res/xml/root_preferences.xml
@@ -13,18 +13,18 @@
app:key="home_set"
app:title="@string/pref_home_set" />
-
-
+
+