diff options
author | pacien | 2018-08-06 12:16:22 +0200 |
---|---|---|
committer | pacien | 2018-08-06 12:16:22 +0200 |
commit | aef4ce4fb1cde5fda83c02d85b06238a934ab93a (patch) | |
tree | 0a569ca7bb9a9abdf8018b816e4946b79e7b6bd6 /app/src/main | |
parent | 23a081743c8e78baba8011646a65ceaf344173c2 (diff) | |
download | tincapp-aef4ce4fb1cde5fda83c02d85b06238a934ab93a.tar.gz |
Change VPN set-up order
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt | 28 |
1 files changed, 14 insertions, 14 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 25eb897..e499e84 100644 --- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt +++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt | |||
@@ -91,6 +91,20 @@ class TincVpnService : VpnService() { | |||
91 | logger?.info("Starting tinc daemon for network \"$netName\".") | 91 | logger?.info("Starting tinc daemon for network \"$netName\".") |
92 | if (isConnected()) stopVpn() | 92 | if (isConnected()) stopVpn() |
93 | 93 | ||
94 | val privateKeys = try { | ||
95 | TincConfiguration.fromTincConfiguration(AppPaths.existing(AppPaths.tincConfFile(netName))).let { tincCfg -> | ||
96 | Pair( | ||
97 | TincKeyring.openPrivateKey(tincCfg.ed25519PrivateKeyFile ?: AppPaths.defaultEd25519PrivateKeyFile(netName), passphrase), | ||
98 | TincKeyring.openPrivateKey(tincCfg.privateKeyFile ?: AppPaths.defaultRsaPrivateKeyFile(netName), passphrase)) | ||
99 | } | ||
100 | } catch (e: FileNotFoundException) { | ||
101 | Pair(null, null) | ||
102 | } catch (e: PEMException) { | ||
103 | return reportError(resources.getString(R.string.message_could_not_decrypt_private_keys_format, e.message)) | ||
104 | } catch (e: Exception) { | ||
105 | return reportError(resources.getString(R.string.message_could_not_read_private_key_format, e.defaultMessage()), e) | ||
106 | } | ||
107 | |||
94 | val interfaceCfg = try { | 108 | val interfaceCfg = try { |
95 | VpnInterfaceConfiguration.fromIfaceConfiguration(AppPaths.existing(AppPaths.netConfFile(netName))) | 109 | VpnInterfaceConfiguration.fromIfaceConfiguration(AppPaths.existing(AppPaths.netConfFile(netName))) |
96 | } catch (e: FileNotFoundException) { | 110 | } catch (e: FileNotFoundException) { |
@@ -114,20 +128,6 @@ class TincVpnService : VpnService() { | |||
114 | return reportError(resources.getString(R.string.message_could_not_configure_iface, e.defaultMessage()), e) | 128 | return reportError(resources.getString(R.string.message_could_not_configure_iface, e.defaultMessage()), e) |
115 | } | 129 | } |
116 | 130 | ||
117 | val privateKeys = try { | ||
118 | TincConfiguration.fromTincConfiguration(AppPaths.existing(AppPaths.tincConfFile(netName))).let { tincCfg -> | ||
119 | Pair( | ||
120 | TincKeyring.openPrivateKey(tincCfg.ed25519PrivateKeyFile ?: AppPaths.defaultEd25519PrivateKeyFile(netName), passphrase), | ||
121 | TincKeyring.openPrivateKey(tincCfg.privateKeyFile ?: AppPaths.defaultRsaPrivateKeyFile(netName), passphrase)) | ||
122 | } | ||
123 | } catch (e: FileNotFoundException) { | ||
124 | Pair(null, null) | ||
125 | } catch (e: PEMException) { | ||
126 | return reportError(resources.getString(R.string.message_could_not_decrypt_private_keys_format, e.message)) | ||
127 | } catch (e: Exception) { | ||
128 | return reportError(resources.getString(R.string.message_could_not_read_private_key_format, e.defaultMessage()), e) | ||
129 | } | ||
130 | |||
131 | val daemon = Tincd.start(netName, deviceFd.fd, privateKeys.first?.fd, privateKeys.second?.fd) | 131 | val daemon = Tincd.start(netName, deviceFd.fd, privateKeys.first?.fd, privateKeys.second?.fd) |
132 | setState(netName, interfaceCfg, deviceFd, daemon) | 132 | setState(netName, interfaceCfg, deviceFd, daemon) |
133 | 133 | ||