aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/data
diff options
context:
space:
mode:
authorpacien2018-08-07 00:19:57 +0200
committerpacien2018-08-07 00:19:57 +0200
commitdbba24ef009e5fa9ad428b0ba426b41672fa6b2e (patch)
treec7ff813d7ca0821b4866beeb59f7539cbff6bdca /app/src/main/java/org/pacien/tincapp/data
parent123d40dbf3921c5b39938f3b18460eb4a11bf3d6 (diff)
downloadtincapp-dbba24ef009e5fa9ad428b0ba426b41672fa6b2e.tar.gz
Rename source directory
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/data')
-rw-r--r--app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt39
-rw-r--r--app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt41
-rw-r--r--app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt92
3 files changed, 0 insertions, 172 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt b/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt
deleted file mode 100644
index 8157720..0000000
--- a/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.data
20
21import org.apache.commons.configuration2.ex.ConversionException
22
23/**
24 * @author pacien
25 */
26data class CidrAddress(val address: String, val prefix: Int) {
27 companion object {
28 private const val SEPARATOR = "/"
29
30 fun fromSlashSeparated(s: String) = try {
31 CidrAddress(s.substringBefore(SEPARATOR), Integer.parseInt(s.substringAfter(SEPARATOR)))
32 } catch (e: Exception) {
33 throw ConversionException(e.message, e)
34 }
35 }
36
37 fun toSlashSeparated() = address + SEPARATOR + prefix
38 override fun toString(): String = "$address/$prefix"
39}
diff --git a/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt b/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt
deleted file mode 100644
index f7bb15a..0000000
--- a/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.data
20
21import org.apache.commons.configuration2.Configuration
22import org.apache.commons.configuration2.builder.fluent.Configurations
23import org.pacien.tincapp.extensions.ApacheConfiguration.getFile
24import java.io.File
25
26/**
27 * @author pacien
28 */
29data class TincConfiguration(val ed25519PrivateKeyFile: File? = null,
30 val privateKeyFile: File? = null) {
31 companion object {
32
33 private const val KEY_ED25519_PRIVATE_KEY_FILE = "Ed25519PrivateKeyFile"
34 private const val KEY_PRIVATE_KEY_FILE = "PrivateKeyFile"
35
36 fun fromTincConfiguration(f: File) = fromTincConfiguration(Configurations().properties(f))
37 private fun fromTincConfiguration(c: Configuration) = TincConfiguration(
38 c.getFile(KEY_ED25519_PRIVATE_KEY_FILE),
39 c.getFile(KEY_PRIVATE_KEY_FILE))
40 }
41}
diff --git a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt
deleted file mode 100644
index 26a194c..0000000
--- a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt
+++ /dev/null
@@ -1,92 +0,0 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.data
20
21import org.apache.commons.configuration2.Configuration
22import org.apache.commons.configuration2.FileBasedConfiguration
23import org.apache.commons.configuration2.PropertiesConfiguration
24import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder
25import org.apache.commons.configuration2.builder.fluent.Configurations
26import org.apache.commons.configuration2.builder.fluent.Parameters
27import org.pacien.tincapp.extensions.ApacheConfiguration.getCidrList
28import org.pacien.tincapp.extensions.ApacheConfiguration.getIntList
29import org.pacien.tincapp.extensions.ApacheConfiguration.getStringList
30import org.pacien.tincapp.extensions.Java.applyIgnoringException
31import java.io.File
32
33/**
34 * @author pacien
35 */
36data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyList(),
37 val routes: List<CidrAddress> = emptyList(),
38 val dnsServers: List<String> = emptyList(),
39 val searchDomains: List<String> = emptyList(),
40 val allowedApplications: List<String> = emptyList(),
41 val disallowedApplications: List<String> = emptyList(),
42 val allowedFamilies: List<Int> = emptyList(),
43 val allowBypass: Boolean = false,
44 val blocking: Boolean = false,
45 val mtu: Int? = null) {
46 companion object {
47 private const val KEY_ADDRESSES = "Address"
48 private const val KEY_ROUTES = "Route"
49 private const val KEY_DNS_SERVERS = "DNSServer"
50 private const val KEY_SEARCH_DOMAINS = "SearchDomain"
51 private const val KEY_ALLOWED_APPLICATIONS = "AllowApplication"
52 private const val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication"
53 private const val KEY_ALLOWED_FAMILIES = "AllowFamily"
54 private const val KEY_ALLOW_BYPASS = "AllowBypass"
55 private const val KEY_BLOCKING = "Blocking"
56 private const val KEY_MTU = "MTU"
57
58 private const val INVITATION_KEY_ADDRESSES = "Ifconfig"
59 private const val INVITATION_KEY_ROUTES = "Route"
60
61 fun fromIfaceConfiguration(f: File) = fromIfaceConfiguration(Configurations().properties(f))
62 private fun fromIfaceConfiguration(c: Configuration) = VpnInterfaceConfiguration(
63 c.getCidrList(KEY_ADDRESSES),
64 c.getCidrList(KEY_ROUTES),
65 c.getStringList(KEY_DNS_SERVERS),
66 c.getStringList(KEY_SEARCH_DOMAINS),
67 c.getStringList(KEY_ALLOWED_APPLICATIONS),
68 c.getStringList(KEY_DISALLOWED_APPLICATIONS),
69 c.getIntList(KEY_ALLOWED_FAMILIES),
70 c.getBoolean(KEY_ALLOW_BYPASS, false),
71 c.getBoolean(KEY_BLOCKING, false),
72 c.getInteger(KEY_MTU, null))
73
74 fun fromInvitation(f: File) = fromInvitation(Configurations().properties(f))
75 private fun fromInvitation(c: Configuration) = VpnInterfaceConfiguration(
76 c.getStringList(INVITATION_KEY_ADDRESSES)
77 .map { applyIgnoringException(CidrAddress.Companion::fromSlashSeparated, it) }
78 .filterNotNull(),
79 c.getStringList(INVITATION_KEY_ROUTES)
80 .map { it.substringBefore(' ') }
81 .map { CidrAddress.fromSlashSeparated(it) })
82 }
83
84 fun write(f: File) = FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration::class.java)
85 .configure(Parameters().properties().setFile(f.apply { createNewFile() })).let { builder ->
86 builder.configuration.let { cfg ->
87 addresses.forEach { cfg.addProperty(KEY_ADDRESSES, it.toSlashSeparated()) }
88 routes.forEach { cfg.addProperty(KEY_ROUTES, it.toSlashSeparated()) }
89 }
90 builder.save()
91 }
92}