From 48965b424a375d4c93384931e745f542dff28f66 Mon Sep 17 00:00:00 2001 From: Revertron Date: Sun, 11 Dec 2022 11:21:41 +0100 Subject: [PATCH] Implemented an option to set own keys (and IP). --- .../yggdrasil/ConfigurationProxy.kt | 8 ++++- .../yggdrasil/SettingsActivity.kt | 18 ++++++++++ app/src/main/res/layout/activity_settings.xml | 14 ++++++-- app/src/main/res/layout/dialog_addpeer.xml | 2 +- app/src/main/res/layout/dialog_set_keys.xml | 34 +++++++++++++++++++ app/src/main/res/values-ru/strings.xml | 8 ++++- app/src/main/res/values/strings.xml | 8 ++++- 7 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/layout/dialog_set_keys.xml diff --git a/app/src/main/java/eu/neilalexander/yggdrasil/ConfigurationProxy.kt b/app/src/main/java/eu/neilalexander/yggdrasil/ConfigurationProxy.kt index 1040c60..e5dd0ba 100644 --- a/app/src/main/java/eu/neilalexander/yggdrasil/ConfigurationProxy.kt +++ b/app/src/main/java/eu/neilalexander/yggdrasil/ConfigurationProxy.kt @@ -1,7 +1,6 @@ package eu.neilalexander.yggdrasil import android.content.Context -import android.provider.Settings import mobile.Mobile import org.json.JSONArray import org.json.JSONObject @@ -37,6 +36,13 @@ object ConfigurationProxy { } } + fun setKeys(privateKey: String, publicKey: String) { + updateJSON { json -> + json.put("PrivateKey", privateKey) + json.put("PublicKey", publicKey) + } + } + fun updateJSON(fn: (JSONObject) -> Unit) { json = JSONObject(file.readText(Charsets.UTF_8)) fn(json) diff --git a/app/src/main/java/eu/neilalexander/yggdrasil/SettingsActivity.kt b/app/src/main/java/eu/neilalexander/yggdrasil/SettingsActivity.kt index c7d6b0a..b4e8779 100644 --- a/app/src/main/java/eu/neilalexander/yggdrasil/SettingsActivity.kt +++ b/app/src/main/java/eu/neilalexander/yggdrasil/SettingsActivity.kt @@ -62,6 +62,24 @@ class SettingsActivity : AppCompatActivity() { updateView() } + findViewById(R.id.setKeysRow).setOnClickListener { + val view = inflater.inflate(R.layout.dialog_set_keys, null) + val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog)) + val privateKey = view.findViewById(R.id.private_key) + val publicKey = view.findViewById(R.id.public_key) + builder.setTitle(getString(R.string.set_keys)) + builder.setView(view) + builder.setPositiveButton(getString(R.string.save)) { dialog, _ -> + config.setKeys(privateKey.text.toString(), publicKey.text.toString()) + updateView() + dialog.dismiss() + } + builder.setNegativeButton(getString(R.string.cancel)) { dialog, _ -> + dialog.cancel() + } + builder.show() + } + publicKeyLabel.setOnLongClickListener { val clipboard: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager val clip = ClipData.newPlainText("public key", publicKeyLabel.text) diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 89bdbe3..24bd1a4 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -211,7 +211,7 @@ android:layout_marginBottom="2pt" android:alpha="0.7" android:paddingRight="8pt" - android:text="@string/settings_reset" + android:text="@string/settings_config" android:textAllCaps="true" android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textSize="12sp" /> @@ -241,7 +241,17 @@ + android:text="@string/regenerate_keys" /> + + + + + + android:text="@string/add_peer_help" /> + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 85226ce..0ee17d1 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -38,6 +38,7 @@ Нет подключенных пиров Подключенные пиры Внимание + Конфигурация Сброс Состояние Включить Yggdrasil @@ -64,7 +65,7 @@ Эта информация публична и может появиться на картах сети. Публичный ключ Ваш публичный ключ идентифицирует вас в сети. Его распространение безопасно. - Сбросить ключи (и адрес IP) + Сбросить ключи (и адрес IPv6) Сбросить настройки Сброс создаст полностью новые настройки. Это изменит ваш публичный ключ и адрес IP. Выключено @@ -77,4 +78,9 @@ Сервис VPN Главный канал нотификаций сервиса Нажмите здесь чтобы включить Yggdrasil. + Введите полный URI пира для добавления. Yggdrasil будет автоматически подключаться к нему при запуске. + Публичный ключ: + Приватный ключ: + Установить свои ключи + Сохранить \ 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 bf571d7..96e6545 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,6 +38,7 @@ No peers currently connected Connected Peers Warning + Config Reset Status Enable Yggdrasil @@ -64,7 +65,7 @@ Information entered here is public and may be shown on network maps. Public Key Your public key forms your identity on the network. It is safe to be shared. - Reset keys (and IP-address) + Regenerate keys (and IPv6-address) Reset configuration Resetting will overwrite with newly generated configuration. Your public keys and IP address on the network will change. Disabled @@ -77,4 +78,9 @@ VPN Service Main channel for foreground notification Tap here to enable Yggdrasil. + Enter the full URI of the peer to add. Yggdrasil will automatically connect to this peer when started. + Public key: + Private key: + Set your own keys + Save \ No newline at end of file