fix: return error early if the public key is not expected length or format with an appropriate message

This commit is contained in:
jubb 2021-05-24 14:01:20 +10:00
parent 95657195e6
commit 4f84b976c5
3 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,4 @@
/*
* Copyright (C) 2013 Open Whisper Systems
/* Copyright (C) 2013 Open Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -29,6 +29,7 @@ import org.session.libsession.utilities.DistributionTypes
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsession.utilities.GroupUtil
import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.PublicKeyValidation
import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.conversation.ConversationActivity
@ -37,7 +38,6 @@ import org.thoughtcrime.securesms.loki.api.OpenGroupManager
import org.thoughtcrime.securesms.loki.fragments.ScanQRCodeWrapperFragment
import org.thoughtcrime.securesms.loki.fragments.ScanQRCodeWrapperFragmentDelegate
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
import org.thoughtcrime.securesms.loki.viewmodel.DefaultGroupsViewModel
import org.thoughtcrime.securesms.loki.viewmodel.State
@ -86,6 +86,9 @@ class JoinPublicChatActivity : PassphraseRequiredActionBarActivity(), ScanQRCode
val room = url.pathSegments().firstOrNull()
val publicKey = url.queryParameter("public_key")
val isV2OpenGroup = !room.isNullOrEmpty()
if (isV2OpenGroup && (publicKey == null || !PublicKeyValidation.isValid(publicKey, 64,false))) {
return Toast.makeText(this, R.string.invalid_public_key, Toast.LENGTH_SHORT).show()
}
showLoader()
lifecycleScope.launch(Dispatchers.IO) {
try {

View File

@ -842,5 +842,6 @@
<string name="activity_prompt_passphrase_tap_to_unlock">Tap to Unlock</string>
<string name="fragment_user_details_bottom_sheet_edit_text_hint">Enter a nickname</string>
<string name="invalid_public_key">Invalid Public Key</string>
</resources>