Skip to content

Commit 05de180

Browse files
authored
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.
1 parent a07412d commit 05de180

File tree

8 files changed

+113
-7
lines changed

8 files changed

+113
-7
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
applicationId "eu.neilalexander.yggdrasil"
1212
minSdkVersion 21
1313
targetSdkVersion 29
14-
versionCode 11
15-
versionName "0.1-011"
14+
versionCode 12
15+
versionName "0.1-012"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}

app/src/main/java/eu/neilalexander/yggdrasil/ConfigurationProxy.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package eu.neilalexander.yggdrasil
22

33
import android.content.Context
4-
import android.provider.Settings
54
import mobile.Mobile
65
import org.json.JSONArray
76
import org.json.JSONObject
@@ -29,6 +28,21 @@ object ConfigurationProxy {
2928
fix()
3029
}
3130

31+
fun resetKeys() {
32+
val newJson = JSONObject(String(Mobile.generateConfigJSON()))
33+
updateJSON { json ->
34+
json.put("PrivateKey", newJson.getString("PrivateKey"))
35+
json.put("PublicKey", newJson.getString("PublicKey"))
36+
}
37+
}
38+
39+
fun setKeys(privateKey: String, publicKey: String) {
40+
updateJSON { json ->
41+
json.put("PrivateKey", privateKey)
42+
json.put("PublicKey", publicKey)
43+
}
44+
}
45+
3246
fun updateJSON(fn: (JSONObject) -> Unit) {
3347
json = JSONObject(file.readText(Charsets.UTF_8))
3448
fn(json)

app/src/main/java/eu/neilalexander/yggdrasil/SettingsActivity.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
77
import android.os.Bundle
88
import android.view.ContextThemeWrapper
99
import android.view.LayoutInflater
10+
import android.view.View
1011
import android.widget.*
1112
import androidx.core.widget.doOnTextChanged
1213
import org.json.JSONObject
@@ -32,8 +33,8 @@ class SettingsActivity : AppCompatActivity() {
3233

3334
deviceNameEntry.doOnTextChanged { text, _, _, _ ->
3435
config.updateJSON { cfg ->
35-
val nodeinfo = cfg.optJSONObject("NodeInfo")
36-
if (nodeinfo == null) {
36+
val nodeInfo = cfg.optJSONObject("NodeInfo")
37+
if (nodeInfo == null) {
3738
cfg.put("NodeInfo", JSONObject("{}"))
3839
}
3940
cfg.getJSONObject("NodeInfo").put("name", text)
@@ -56,6 +57,29 @@ class SettingsActivity : AppCompatActivity() {
5657
builder.show()
5758
}
5859

60+
findViewById<View>(R.id.resetKeysRow).setOnClickListener {
61+
config.resetKeys()
62+
updateView()
63+
}
64+
65+
findViewById<View>(R.id.setKeysRow).setOnClickListener {
66+
val view = inflater.inflate(R.layout.dialog_set_keys, null)
67+
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
68+
val privateKey = view.findViewById<EditText>(R.id.private_key)
69+
val publicKey = view.findViewById<EditText>(R.id.public_key)
70+
builder.setTitle(getString(R.string.set_keys))
71+
builder.setView(view)
72+
builder.setPositiveButton(getString(R.string.save)) { dialog, _ ->
73+
config.setKeys(privateKey.text.toString(), publicKey.text.toString())
74+
updateView()
75+
dialog.dismiss()
76+
}
77+
builder.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
78+
dialog.cancel()
79+
}
80+
builder.show()
81+
}
82+
5983
publicKeyLabel.setOnLongClickListener {
6084
val clipboard: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
6185
val clip = ClipData.newPlainText("public key", publicKeyLabel.text)

app/src/main/res/layout/activity_settings.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
android:layout_marginBottom="2pt"
212212
android:alpha="0.7"
213213
android:paddingRight="8pt"
214-
android:text="@string/settings_reset"
214+
android:text="@string/settings_config"
215215
android:textAllCaps="true"
216216
android:textAppearance="@style/TextAppearance.AppCompat.Small"
217217
android:textSize="12sp" />
@@ -234,6 +234,26 @@
234234
android:paddingBottom="2pt"
235235
android:showDividers="middle">
236236

237+
<TableRow
238+
android:id="@+id/resetKeysRow"
239+
style="@style/SelectableItemStyle">
240+
241+
<TextView
242+
android:layout_width="wrap_content"
243+
android:layout_height="wrap_content"
244+
android:text="@string/regenerate_keys" />
245+
</TableRow>
246+
247+
<TableRow
248+
android:id="@+id/setKeysRow"
249+
style="@style/SelectableItemStyle">
250+
251+
<TextView
252+
android:layout_width="wrap_content"
253+
android:layout_height="wrap_content"
254+
android:text="@string/set_keys" />
255+
</TableRow>
256+
237257
<TableRow
238258
android:id="@+id/resetConfigurationRow"
239259
style="@style/SelectableItemStyle">

app/src/main/res/layout/dialog_addpeer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
android:id="@+id/textView2"
1717
android:layout_width="match_parent"
1818
android:layout_height="wrap_content"
19-
android:text="Enter the full URI of the peer to add. Yggdrasil will automatically connect to this peer when started." />
19+
android:text="@string/add_peer_help" />
2020

2121
<com.google.android.material.textfield.TextInputLayout
2222
android:layout_width="match_parent"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<LinearLayout
7+
android:layout_width="match_parent"
8+
android:layout_height="wrap_content"
9+
android:orientation="vertical"
10+
android:paddingLeft="10pt"
11+
android:paddingRight="10pt"
12+
android:paddingTop="4pt"
13+
android:paddingBottom="4pt">
14+
15+
<TextView
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:text="@string/public_key_label" />
19+
<EditText
20+
android:id="@+id/public_key"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content" />
23+
24+
<TextView
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:layout_marginTop="4dp"
28+
android:text="@string/private_key_label" />
29+
<EditText
30+
android:id="@+id/private_key"
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content" />
33+
</LinearLayout>
34+
</FrameLayout>

app/src/main/res/values-ru/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<string name="peers_no_connected_title">Нет подключенных пиров</string>
3939
<string name="peers_connected_title">Подключенные пиры</string>
4040
<string name="settings_warning_title">Внимание</string>
41+
<string name="settings_config">Конфигурация</string>
4142
<string name="settings_reset">Сброс</string>
4243
<string name="main_status">Состояние</string>
4344
<string name="main_enable_yggdrasil">Включить Yggdrasil</string>
@@ -64,6 +65,7 @@
6465
<string name="node_info_hint">Эта информация публична и может появиться на картах сети.</string>
6566
<string name="public_key">Публичный ключ</string>
6667
<string name="public_key_hint">Ваш публичный ключ идентифицирует вас в сети. Его распространение безопасно.</string>
68+
<string name="regenerate_keys">Сбросить ключи (и адрес IPv6)</string>
6769
<string name="reset_configuration">Сбросить настройки</string>
6870
<string name="reset_configuration_hint">Сброс создаст полностью новые настройки. Это изменит ваш публичный ключ и адрес IP.</string>
6971
<string name="tile_disabled">Выключено</string>
@@ -76,4 +78,9 @@
7678
<string name="channel_name">Сервис VPN</string>
7779
<string name="channel_description">Главный канал нотификаций сервиса</string>
7880
<string name="permission_notification_text">Нажмите здесь чтобы включить Yggdrasil.</string>
81+
<string name="add_peer_help">Введите полный URI пира для добавления. Yggdrasil будет автоматически подключаться к нему при запуске.</string>
82+
<string name="public_key_label">Публичный ключ:</string>
83+
<string name="private_key_label">Приватный ключ:</string>
84+
<string name="set_keys">Установить свои ключи</string>
85+
<string name="save">Сохранить</string>
7986
</resources>

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<string name="peers_no_connected_title">No peers currently connected</string>
3939
<string name="peers_connected_title">Connected Peers</string>
4040
<string name="settings_warning_title">Warning</string>
41+
<string name="settings_config">Config</string>
4142
<string name="settings_reset">Reset</string>
4243
<string name="main_status">Status</string>
4344
<string name="main_enable_yggdrasil">Enable Yggdrasil</string>
@@ -64,6 +65,7 @@
6465
<string name="node_info_hint">Information entered here is public and may be shown on network maps.</string>
6566
<string name="public_key">Public Key</string>
6667
<string name="public_key_hint">Your public key forms your identity on the network. It is safe to be shared.</string>
68+
<string name="regenerate_keys">Regenerate keys (and IPv6-address)</string>
6769
<string name="reset_configuration">Reset configuration</string>
6870
<string name="reset_configuration_hint">Resetting will overwrite with newly generated configuration. Your public keys and IP address on the network will change.</string>
6971
<string name="tile_disabled">Disabled</string>
@@ -76,4 +78,9 @@
7678
<string name="channel_name">VPN Service</string>
7779
<string name="channel_description">Main channel for foreground notification</string>
7880
<string name="permission_notification_text">Tap here to enable Yggdrasil.</string>
81+
<string name="add_peer_help">Enter the full URI of the peer to add. Yggdrasil will automatically connect to this peer when started.</string>
82+
<string name="public_key_label">Public key:</string>
83+
<string name="private_key_label">Private key:</string>
84+
<string name="set_keys">Set your own keys</string>
85+
<string name="save">Save</string>
7986
</resources>

0 commit comments

Comments
 (0)