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 00d226d7a..872fa19a6 100644 --- a/app/src/main/java/com/geeksville/mesh/model/Channel.kt +++ b/app/src/main/java/com/geeksville/mesh/model/Channel.kt @@ -9,6 +9,9 @@ import com.google.zxing.MultiFormatWriter import com.journeyapps.barcodescanner.BarcodeEncoder import java.net.MalformedURLException +/** Utility function to make it easy to declare byte arrays - FIXME move someplace better */ +fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() } + data class Channel( val settings: MeshProtos.ChannelSettings = MeshProtos.ChannelSettings.getDefaultInstance() @@ -17,6 +20,12 @@ data class Channel( // 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" + // These bytes must math the well known and not secret bytes used the default channel AES128 key device code + val channelDefaultKey = byteArrayOfInts( + 0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59, + 0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0xbf + ) + // Placeholder when emulating val emulated = Channel( MeshProtos.ChannelSettings.newBuilder().setName(defaultChannelName) 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 b4c3ba701..df8523a7c 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt @@ -147,12 +147,20 @@ class ChannelFragment : ScreenFragment("Channel"), Logging { newSettings.name = channelNameEdit.text.toString().trim() // Generate a new AES256 key (for any channel not named Default) - if (newSettings.name != Channel.defaultChannelName) { + if (!newSettings.name.equals( + Channel.defaultChannelName, + ignoreCase = true + ) + ) { debug("ASSIGNING NEW AES256 KEY") val random = SecureRandom() val bytes = ByteArray(32) random.nextBytes(bytes) newSettings.psk = ByteString.copyFrom(bytes) + } else { + debug("ASSIGNING NEW default AES128 KEY") + newSettings.name = Channel.defaultChannelName // Fix any case errors + newSettings.psk = ByteString.copyFrom(Channel.channelDefaultKey) } // Try to change the radio, if it fails, tell the user why and throw away their redits