From aa3a8bf08900702a264f563cbdd6be1e857a08ea Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 12 Jun 2020 20:26:10 -0700 Subject: [PATCH] Add back AES256 key assignment (from TODO list) --- TODO.md | 1 - .../java/com/geeksville/mesh/model/Channel.kt | 6 ++++-- .../com/geeksville/mesh/ui/ChannelFragment.kt | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 886df109..c8d9fa6f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,6 @@ # Remaining tasks before declaring 1.0 * add a low level settings screen (let user change any of the RadioConfig parameters) -* if user edits the channel, generate a new AES256 key * add play store link with https://developers.google.com/analytics/devguides/collection/android/v4/campaigns#google-play-url-builder and the play icon Things for the betaish period. diff --git a/app/src/main/java/com/geeksville/mesh/model/Channel.kt b/app/src/main/java/com/geeksville/mesh/model/Channel.kt index a0323a8c..00d226d7 100644 --- a/app/src/main/java/com/geeksville/mesh/model/Channel.kt +++ b/app/src/main/java/com/geeksville/mesh/model/Channel.kt @@ -14,10 +14,12 @@ data class Channel( val settings: MeshProtos.ChannelSettings = MeshProtos.ChannelSettings.getDefaultInstance() ) { companion object { + // Note: this string _SHOULD NOT BE LOCALIZED_ because it directly hashes to values used on the device for the default channel name. + val defaultChannelName = "Default" + // Placeholder when emulating val emulated = Channel( - // Note: this string _SHOULD NOT BE LOCALIZED_ because it directly hashes to values used on the device for the default channel name. - MeshProtos.ChannelSettings.newBuilder().setName("Default") + MeshProtos.ChannelSettings.newBuilder().setName(defaultChannelName) .setModemConfig(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128).build() ) diff --git a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt index b012fb74..b4c3ba70 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt @@ -18,12 +18,15 @@ import com.geeksville.android.GeeksvilleApplication import com.geeksville.android.Logging import com.geeksville.android.hideKeyboard import com.geeksville.mesh.R +import com.geeksville.mesh.model.Channel import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.service.MeshService import com.geeksville.util.Exceptions import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar +import com.google.protobuf.ByteString import kotlinx.android.synthetic.main.channel_fragment.* +import java.security.SecureRandom // Make an image view dim @@ -142,7 +145,15 @@ class ChannelFragment : ScreenFragment("Channel"), Logging { UIViewModel.getChannel(model.radioConfig.value)?.let { old -> val newSettings = old.settings.toBuilder() newSettings.name = channelNameEdit.text.toString().trim() - // FIXME, regenerate a new preshared key! + + // Generate a new AES256 key (for any channel not named Default) + if (newSettings.name != Channel.defaultChannelName) { + debug("ASSIGNING NEW AES256 KEY") + val random = SecureRandom() + val bytes = ByteArray(32) + random.nextBytes(bytes) + newSettings.psk = ByteString.copyFrom(bytes) + } // Try to change the radio, if it fails, tell the user why and throw away their redits try { @@ -150,7 +161,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging { // Since we are writing to radioconfig, that will trigger the rest of the GUI update (QR code etc) } catch (ex: RemoteException) { setGUIfromModel() // Throw away user edits - + // Tell the user to try again Snackbar.make( editableCheckbox,