Implemented an option to reset keys (and IP).

This commit is contained in:
Revertron 2022-12-10 22:32:50 +01:00
parent a07412d02d
commit 305b2ab7c2
5 changed files with 28 additions and 2 deletions

View file

@ -29,6 +29,14 @@ 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 updateJSON(fn: (JSONObject) -> Unit) {
json = JSONObject(file.readText(Charsets.UTF_8))
fn(json)

View file

@ -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,11 @@ class SettingsActivity : AppCompatActivity() {
builder.show()
}
findViewById<View>(R.id.resetKeysRow).setOnClickListener {
config.resetKeys()
updateView()
}
publicKeyLabel.setOnLongClickListener {
val clipboard: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("public key", publicKeyLabel.text)

View file

@ -234,6 +234,16 @@
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/reset_keys" />
</TableRow>
<TableRow
android:id="@+id/resetConfigurationRow"
style="@style/SelectableItemStyle">

View file

@ -64,6 +64,7 @@
<string name="node_info_hint">Эта информация публична и может появиться на картах сети.</string>
<string name="public_key">Публичный ключ</string>
<string name="public_key_hint">Ваш публичный ключ идентифицирует вас в сети. Его распространение безопасно.</string>
<string name="reset_keys">Сбросить ключи (и адрес IP)</string>
<string name="reset_configuration">Сбросить настройки</string>
<string name="reset_configuration_hint">Сброс создаст полностью новые настройки. Это изменит ваш публичный ключ и адрес IP.</string>
<string name="tile_disabled">Выключено</string>

View file

@ -64,6 +64,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="reset_keys">Reset keys (and IP-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>