If user changes back to default channel, use the standard key

This commit is contained in:
geeksville 2020-06-12 20:38:43 -07:00
parent aa3a8bf089
commit 6195874982
2 changed files with 18 additions and 1 deletions

View file

@ -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