aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt')
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt17
1 files changed, 11 insertions, 6 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
index 69811f4..ec3e774 100644
--- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
+++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
@@ -18,6 +18,7 @@ import org.pacien.tincapp.context.AppPaths
18import org.pacien.tincapp.data.TincConfiguration 18import org.pacien.tincapp.data.TincConfiguration
19import org.pacien.tincapp.data.VpnInterfaceConfiguration 19import org.pacien.tincapp.data.VpnInterfaceConfiguration
20import org.pacien.tincapp.extensions.Java.applyIgnoringException 20import org.pacien.tincapp.extensions.Java.applyIgnoringException
21import org.pacien.tincapp.extensions.Java.defaultMessage
21import org.pacien.tincapp.extensions.VpnServiceBuilder.applyCfg 22import org.pacien.tincapp.extensions.VpnServiceBuilder.applyCfg
22import org.pacien.tincapp.intent.Actions 23import org.pacien.tincapp.intent.Actions
23import org.pacien.tincapp.utils.TincKeyring 24import org.pacien.tincapp.utils.TincKeyring
@@ -75,9 +76,11 @@ class TincVpnService : VpnService() {
75 val interfaceCfg = try { 76 val interfaceCfg = try {
76 VpnInterfaceConfiguration.fromIfaceConfiguration(AppPaths.existing(AppPaths.netConfFile(netName))) 77 VpnInterfaceConfiguration.fromIfaceConfiguration(AppPaths.existing(AppPaths.netConfFile(netName)))
77 } catch (e: FileNotFoundException) { 78 } catch (e: FileNotFoundException) {
78 return reportError(resources.getString(R.string.message_network_config_not_found_format, e.message!!), e, "configuration") 79 return reportError(resources.getString(R.string.message_network_config_not_found_format, e.defaultMessage()), e, "configuration")
79 } catch (e: ConversionException) { 80 } catch (e: ConversionException) {
80 return reportError(resources.getString(R.string.message_network_config_invalid_format, e.message!!), e, "network-interface") 81 return reportError(resources.getString(R.string.message_network_config_invalid_format, e.defaultMessage()), e, "network-interface")
82 } catch (e: Exception) {
83 return reportError(resources.getString(R.string.message_could_not_read_network_configuration_format, e.defaultMessage()), e)
81 } 84 }
82 85
83 val deviceFd = try { 86 val deviceFd = try {
@@ -86,11 +89,11 @@ class TincVpnService : VpnService() {
86 .also { applyIgnoringException(it::addDisallowedApplication, BuildConfig.APPLICATION_ID) } 89 .also { applyIgnoringException(it::addDisallowedApplication, BuildConfig.APPLICATION_ID) }
87 .establish()!! 90 .establish()!!
88 } catch (e: IllegalArgumentException) { 91 } catch (e: IllegalArgumentException) {
89 return reportError(resources.getString(R.string.message_network_config_invalid_format, e.message!!), e, "network-interface") 92 return reportError(resources.getString(R.string.message_network_config_invalid_format, e.defaultMessage()), e, "network-interface")
90 } catch (e: IllegalStateException) {
91 return reportError(resources.getString(R.string.message_could_not_configure_iface, e.message!!), e)
92 } catch (e: NullPointerException) { 93 } catch (e: NullPointerException) {
93 return reportError(resources.getString(R.string.message_could_not_bind_iface), e) 94 return reportError(resources.getString(R.string.message_could_not_bind_iface), e)
95 } catch (e: Exception) {
96 return reportError(resources.getString(R.string.message_could_not_configure_iface, e.defaultMessage()), e)
94 } 97 }
95 98
96 val privateKeys = try { 99 val privateKeys = try {
@@ -103,6 +106,8 @@ class TincVpnService : VpnService() {
103 Pair(null, null) 106 Pair(null, null)
104 } catch (e: PEMException) { 107 } catch (e: PEMException) {
105 return reportError(resources.getString(R.string.message_could_not_decrypt_private_keys_format, e.message)) 108 return reportError(resources.getString(R.string.message_could_not_decrypt_private_keys_format, e.message))
109 } catch (e: Exception) {
110 return reportError(resources.getString(R.string.message_could_not_read_private_key_format, e.defaultMessage()), e)
106 } 111 }
107 112
108 val daemon = Tincd.start(netName, deviceFd.fd, privateKeys.first?.fd, privateKeys.second?.fd) 113 val daemon = Tincd.start(netName, deviceFd.fd, privateKeys.first?.fd, privateKeys.second?.fd)
@@ -114,7 +119,7 @@ class TincVpnService : VpnService() {
114 privateKeys.second?.close() 119 privateKeys.second?.close()
115 120
116 if (exception != null) { 121 if (exception != null) {
117 reportError(resources.getString(R.string.message_daemon_exited, exception.cause!!.message!!), exception) 122 reportError(resources.getString(R.string.message_daemon_exited, exception.cause!!.defaultMessage()), exception)
118 } else { 123 } else {
119 logger?.info("tinc daemon started.") 124 logger?.info("tinc daemon started.")
120 broadcastEvent(Actions.EVENT_CONNECTED) 125 broadcastEvent(Actions.EVENT_CONNECTED)