Skip to content

Commit

Permalink
Implemented an option to reset keys (and IP). (#40)
Browse files Browse the repository at this point in the history
* Implemented an option to reset keys (and IP).
* Implemented an option to set own keys (and IP).
* Incremented app version.
  • Loading branch information
Revertron authored Dec 14, 2022
1 parent a07412d commit 05de180
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 26 additions & 2 deletions app/src/main/java/eu/neilalexander/yggdrasil/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/dialog_addpeer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/layout/dialog_set_keys.xml
Original file line number Diff line number Diff line change
@@ -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>
7 changes: 7 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>

0 comments on commit 05de180

Please sign in to comment.