mirror of
https://github.com/yggdrasil-network/yggdrasil-android.git
synced 2025-04-27 13:45:09 +03:00
Implemented an option to reset keys (and IP). (#40)
* Implemented an option to reset keys (and IP). * Implemented an option to set own keys (and IP). * Incremented app version.
This commit is contained in:
parent
a07412d02d
commit
05de180066
8 changed files with 113 additions and 7 deletions
|
@ -11,8 +11,8 @@ android {
|
|||
applicationId "eu.neilalexander.yggdrasil"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode 11
|
||||
versionName "0.1-011"
|
||||
versionCode 12
|
||||
versionName "0.1-012"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -29,6 +28,21 @@ object ConfigurationProxy {
|
|||
fix()
|
||||
}
|
||||
|
||||
fun resetKeys() {
|
||||
val newJson = JSONObject(String(Mobile.generateConfigJSON()))
|
||||
updateJSON { json ->
|
||||
json.put("PrivateKey", newJson.getString("PrivateKey"))
|
||||
json.put("PublicKey", newJson.getString("PublicKey"))
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import android.os.Bundle
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import org.json.JSONObject
|
||||
|
@ -32,8 +33,8 @@ class SettingsActivity : AppCompatActivity() {
|
|||
|
||||
deviceNameEntry.doOnTextChanged { text, _, _, _ ->
|
||||
config.updateJSON { cfg ->
|
||||
val nodeinfo = cfg.optJSONObject("NodeInfo")
|
||||
if (nodeinfo == null) {
|
||||
val nodeInfo = cfg.optJSONObject("NodeInfo")
|
||||
if (nodeInfo == null) {
|
||||
cfg.put("NodeInfo", JSONObject("{}"))
|
||||
}
|
||||
cfg.getJSONObject("NodeInfo").put("name", text)
|
||||
|
@ -56,6 +57,29 @@ class SettingsActivity : AppCompatActivity() {
|
|||
builder.show()
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.resetKeysRow).setOnClickListener {
|
||||
config.resetKeys()
|
||||
updateView()
|
||||
}
|
||||
|
||||
findViewById<View>(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<EditText>(R.id.private_key)
|
||||
val publicKey = view.findViewById<EditText>(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)
|
||||
|
|
|
@ -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" />
|
||||
|
@ -234,6 +234,26 @@
|
|||
android:paddingBottom="2pt"
|
||||
android:showDividers="middle">
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/resetKeysRow"
|
||||
style="@style/SelectableItemStyle">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/regenerate_keys" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/setKeysRow"
|
||||
style="@style/SelectableItemStyle">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/set_keys" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/resetConfigurationRow"
|
||||
style="@style/SelectableItemStyle">
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
android:id="@+id/textView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enter the full URI of the peer to add. Yggdrasil will automatically connect to this peer when started." />
|
||||
android:text="@string/add_peer_help" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
34
app/src/main/res/layout/dialog_set_keys.xml
Normal file
34
app/src/main/res/layout/dialog_set_keys.xml
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="10pt"
|
||||
android:paddingRight="10pt"
|
||||
android:paddingTop="4pt"
|
||||
android:paddingBottom="4pt">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/public_key_label" />
|
||||
<EditText
|
||||
android:id="@+id/public_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/private_key_label" />
|
||||
<EditText
|
||||
android:id="@+id/private_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
|
@ -38,6 +38,7 @@
|
|||
<string name="peers_no_connected_title">Нет подключенных пиров</string>
|
||||
<string name="peers_connected_title">Подключенные пиры</string>
|
||||
<string name="settings_warning_title">Внимание</string>
|
||||
<string name="settings_config">Конфигурация</string>
|
||||
<string name="settings_reset">Сброс</string>
|
||||
<string name="main_status">Состояние</string>
|
||||
<string name="main_enable_yggdrasil">Включить Yggdrasil</string>
|
||||
|
@ -64,6 +65,7 @@
|
|||
<string name="node_info_hint">Эта информация публична и может появиться на картах сети.</string>
|
||||
<string name="public_key">Публичный ключ</string>
|
||||
<string name="public_key_hint">Ваш публичный ключ идентифицирует вас в сети. Его распространение безопасно.</string>
|
||||
<string name="regenerate_keys">Сбросить ключи (и адрес IPv6)</string>
|
||||
<string name="reset_configuration">Сбросить настройки</string>
|
||||
<string name="reset_configuration_hint">Сброс создаст полностью новые настройки. Это изменит ваш публичный ключ и адрес IP.</string>
|
||||
<string name="tile_disabled">Выключено</string>
|
||||
|
@ -76,4 +78,9 @@
|
|||
<string name="channel_name">Сервис VPN</string>
|
||||
<string name="channel_description">Главный канал нотификаций сервиса</string>
|
||||
<string name="permission_notification_text">Нажмите здесь чтобы включить Yggdrasil.</string>
|
||||
<string name="add_peer_help">Введите полный URI пира для добавления. Yggdrasil будет автоматически подключаться к нему при запуске.</string>
|
||||
<string name="public_key_label">Публичный ключ:</string>
|
||||
<string name="private_key_label">Приватный ключ:</string>
|
||||
<string name="set_keys">Установить свои ключи</string>
|
||||
<string name="save">Сохранить</string>
|
||||
</resources>
|
|
@ -38,6 +38,7 @@
|
|||
<string name="peers_no_connected_title">No peers currently connected</string>
|
||||
<string name="peers_connected_title">Connected Peers</string>
|
||||
<string name="settings_warning_title">Warning</string>
|
||||
<string name="settings_config">Config</string>
|
||||
<string name="settings_reset">Reset</string>
|
||||
<string name="main_status">Status</string>
|
||||
<string name="main_enable_yggdrasil">Enable Yggdrasil</string>
|
||||
|
@ -64,6 +65,7 @@
|
|||
<string name="node_info_hint">Information entered here is public and may be shown on network maps.</string>
|
||||
<string name="public_key">Public Key</string>
|
||||
<string name="public_key_hint">Your public key forms your identity on the network. It is safe to be shared.</string>
|
||||
<string name="regenerate_keys">Regenerate keys (and IPv6-address)</string>
|
||||
<string name="reset_configuration">Reset configuration</string>
|
||||
<string name="reset_configuration_hint">Resetting will overwrite with newly generated configuration. Your public keys and IP address on the network will change.</string>
|
||||
<string name="tile_disabled">Disabled</string>
|
||||
|
@ -76,4 +78,9 @@
|
|||
<string name="channel_name">VPN Service</string>
|
||||
<string name="channel_description">Main channel for foreground notification</string>
|
||||
<string name="permission_notification_text">Tap here to enable Yggdrasil.</string>
|
||||
<string name="add_peer_help">Enter the full URI of the peer to add. Yggdrasil will automatically connect to this peer when started.</string>
|
||||
<string name="public_key_label">Public key:</string>
|
||||
<string name="private_key_label">Private key:</string>
|
||||
<string name="set_keys">Set your own keys</string>
|
||||
<string name="save">Save</string>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue