diff options
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/extensions/Java.kt | 2 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt | 17 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 2 |
3 files changed, 15 insertions, 6 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/extensions/Java.kt b/app/src/main/java/org/pacien/tincapp/extensions/Java.kt index 95fecbf..e51e9db 100644 --- a/app/src/main/java/org/pacien/tincapp/extensions/Java.kt +++ b/app/src/main/java/org/pacien/tincapp/extensions/Java.kt | |||
@@ -15,4 +15,6 @@ object Java { | |||
15 | alt | 15 | alt |
16 | } | 16 | } |
17 | 17 | ||
18 | fun Throwable.defaultMessage() = this.message ?: "null" | ||
19 | |||
18 | } | 20 | } |
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 | |||
18 | import org.pacien.tincapp.data.TincConfiguration | 18 | import org.pacien.tincapp.data.TincConfiguration |
19 | import org.pacien.tincapp.data.VpnInterfaceConfiguration | 19 | import org.pacien.tincapp.data.VpnInterfaceConfiguration |
20 | import org.pacien.tincapp.extensions.Java.applyIgnoringException | 20 | import org.pacien.tincapp.extensions.Java.applyIgnoringException |
21 | import org.pacien.tincapp.extensions.Java.defaultMessage | ||
21 | import org.pacien.tincapp.extensions.VpnServiceBuilder.applyCfg | 22 | import org.pacien.tincapp.extensions.VpnServiceBuilder.applyCfg |
22 | import org.pacien.tincapp.intent.Actions | 23 | import org.pacien.tincapp.intent.Actions |
23 | import org.pacien.tincapp.utils.TincKeyring | 24 | import 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) |
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6ff9ab5..6ac776f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml | |||
@@ -96,6 +96,8 @@ | |||
96 | <string name="message_app_crash">The application has previously encountered a fatal error.</string> | 96 | <string name="message_app_crash">The application has previously encountered a fatal error.</string> |
97 | <string name="message_crash_logged">The crash details have been saved in \"%1$s\".</string> | 97 | <string name="message_crash_logged">The crash details have been saved in \"%1$s\".</string> |
98 | <string name="message_no_daemon">No running tinc daemon has been found.</string> | 98 | <string name="message_no_daemon">No running tinc daemon has been found.</string> |
99 | <string name="message_could_not_read_network_configuration_format">Could not read network interface configuration:\n\n%1$s</string> | ||
100 | <string name="message_could_not_read_private_key_format">Could not read tinc private keys:\n\n%1$s</string> | ||
99 | 101 | ||
100 | <string name="value_none">none</string> | 102 | <string name="value_none">none</string> |
101 | <string name="value_yes">yes</string> | 103 | <string name="value_yes">yes</string> |