diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchForDomainTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchForDomainTest.kt new file mode 100644 index 0000000000..a576ae250d --- /dev/null +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchForDomainTest.kt @@ -0,0 +1,93 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: DenBond7 + */ + +package com.flowcrypt.email.ui.activity + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.clearText +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.action.ViewActions.scrollTo +import androidx.test.espresso.action.ViewActions.typeText +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.rules.activityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import com.flowcrypt.email.R +import com.flowcrypt.email.api.retrofit.response.model.OrgRules +import com.flowcrypt.email.base.BaseTest +import com.flowcrypt.email.rules.AddAccountToDatabaseRule +import com.flowcrypt.email.rules.ClearAppSettingsRule +import com.flowcrypt.email.rules.RetryRule +import com.flowcrypt.email.rules.ScreenshotTestRule +import com.flowcrypt.email.util.AccountDaoManager +import org.junit.Rule +import org.junit.Test +import org.junit.rules.RuleChain +import org.junit.rules.TestRule +import org.junit.runner.RunWith + +/** + * @author Denis Bondarenko + * Date: 8/6/21 + * Time: 2:05 PM + * E-mail: DenBond7@gmail.com + */ +@MediumTest +@RunWith(AndroidJUnit4::class) +class ImportPgpContactActivityDisallowAttesterSearchForDomainTest : BaseTest() { + private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules( + OrgRules( + flags = listOf( + OrgRules.DomainRule.NO_PRV_CREATE, + OrgRules.DomainRule.NO_PRV_BACKUP + ), + customKeyserverUrl = null, + keyManagerUrl = "https://keymanagerurl.test", + disallowAttesterSearchForDomains = listOf(DISALLOWED_DOMAIN), + enforceKeygenAlgo = null, + enforceKeygenExpireMonths = null + ) + ) + + private val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules) + + override val useIntents: Boolean = true + override val activityScenarioRule = activityScenarioRule( + intent = ImportPgpContactActivity.newIntent( + context = getTargetContext(), + accountEntity = addAccountToDatabaseRule.account + ) + ) + + @get:Rule + var ruleChain: TestRule = RuleChain + .outerRule(ClearAppSettingsRule()) + .around(addAccountToDatabaseRule) + .around(RetryRule.DEFAULT) + .around(activityScenarioRule) + .around(ScreenshotTestRule()) + + @Test + fun testCanLookupThisRecipientOnAttester() { + onView(withId(R.id.editTextKeyIdOrEmail)) + .perform( + scrollTo(), + clearText(), + typeText("user@$DISALLOWED_DOMAIN"), + closeSoftKeyboard() + ) + onView(withId(R.id.iBSearchKey)) + .check(matches(isDisplayed())) + .perform(click()) + isToastDisplayed(getResString(R.string.supported_public_key_not_found)) + } + + companion object { + private const val DISALLOWED_DOMAIN = "disallowed.test" + } +} diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchTest.kt new file mode 100644 index 0000000000..1635596ed8 --- /dev/null +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchTest.kt @@ -0,0 +1,93 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: DenBond7 + */ + +package com.flowcrypt.email.ui.activity + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.clearText +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.action.ViewActions.scrollTo +import androidx.test.espresso.action.ViewActions.typeText +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.rules.activityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import com.flowcrypt.email.R +import com.flowcrypt.email.api.retrofit.response.model.OrgRules +import com.flowcrypt.email.base.BaseTest +import com.flowcrypt.email.rules.AddAccountToDatabaseRule +import com.flowcrypt.email.rules.ClearAppSettingsRule +import com.flowcrypt.email.rules.RetryRule +import com.flowcrypt.email.rules.ScreenshotTestRule +import com.flowcrypt.email.util.AccountDaoManager +import org.junit.Rule +import org.junit.Test +import org.junit.rules.RuleChain +import org.junit.rules.TestRule +import org.junit.runner.RunWith + +/** + * @author Denis Bondarenko + * Date: 8/6/21 + * Time: 2:14 PM + * E-mail: DenBond7@gmail.com + */ +@MediumTest +@RunWith(AndroidJUnit4::class) +class ImportPgpContactActivityDisallowAttesterSearchTest : BaseTest() { + private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules( + OrgRules( + flags = listOf( + OrgRules.DomainRule.NO_PRV_CREATE, + OrgRules.DomainRule.NO_PRV_BACKUP + ), + customKeyserverUrl = null, + keyManagerUrl = "https://keymanagerurl.test", + disallowAttesterSearchForDomains = listOf("*"), + enforceKeygenAlgo = null, + enforceKeygenExpireMonths = null + ) + ) + + private val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules) + + override val useIntents: Boolean = true + override val activityScenarioRule = activityScenarioRule( + intent = ImportPgpContactActivity.newIntent( + context = getTargetContext(), + accountEntity = addAccountToDatabaseRule.account + ) + ) + + @get:Rule + var ruleChain: TestRule = RuleChain + .outerRule(ClearAppSettingsRule()) + .around(addAccountToDatabaseRule) + .around(RetryRule.DEFAULT) + .around(activityScenarioRule) + .around(ScreenshotTestRule()) + + @Test + fun testDisallowLookupOnAttester() { + onView(withId(R.id.editTextKeyIdOrEmail)) + .perform( + scrollTo(), + clearText(), + typeText("user@$DISALLOWED_DOMAIN"), + closeSoftKeyboard() + ) + onView(withId(R.id.iBSearchKey)) + .check(matches(isDisplayed())) + .perform(click()) + isToastDisplayed(getResString(R.string.supported_public_key_not_found)) + } + + companion object { + private const val DISALLOWED_DOMAIN = "disallowed.test" + } +} diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/base/BaseCreateMessageActivityTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/base/BaseCreateMessageActivityTest.kt index b3eca64c81..6a230a686e 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/base/BaseCreateMessageActivityTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/base/BaseCreateMessageActivityTest.kt @@ -33,7 +33,7 @@ abstract class BaseCreateMessageActivityTest : BaseTest() { override val activityScenario: ActivityScenario<*>? get() = activeActivityRule.scenario - protected val addAccountToDatabaseRule = AddAccountToDatabaseRule() + protected open val addAccountToDatabaseRule = AddAccountToDatabaseRule() protected val intent: Intent = CreateMessageActivity.generateIntent( getTargetContext(), null, diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragmentDisallowAttesterSearchForDomainTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragmentDisallowAttesterSearchForDomainTest.kt new file mode 100644 index 0000000000..fa66ba87b9 --- /dev/null +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragmentDisallowAttesterSearchForDomainTest.kt @@ -0,0 +1,102 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: DenBond7 + */ + +package com.flowcrypt.email.ui.activity.fragment + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import com.flowcrypt.email.R +import com.flowcrypt.email.TestConstants +import com.flowcrypt.email.api.retrofit.response.model.OrgRules +import com.flowcrypt.email.database.entity.KeyEntity +import com.flowcrypt.email.matchers.CustomMatchers.Companion.withChipsBackgroundColor +import com.flowcrypt.email.model.KeyImportDetails +import com.flowcrypt.email.rules.AddAccountToDatabaseRule +import com.flowcrypt.email.rules.AddPrivateKeyToDatabaseRule +import com.flowcrypt.email.rules.ClearAppSettingsRule +import com.flowcrypt.email.rules.RetryRule +import com.flowcrypt.email.rules.ScreenshotTestRule +import com.flowcrypt.email.ui.activity.base.BaseCreateMessageActivityTest +import com.flowcrypt.email.ui.widget.CustomChipSpanChipCreator +import com.flowcrypt.email.util.AccountDaoManager +import com.flowcrypt.email.util.UIUtil +import org.junit.Rule +import org.junit.Test +import org.junit.rules.RuleChain +import org.junit.rules.TestRule +import org.junit.runner.RunWith + +/** + * @author Denis Bondarenko + * Date: 8/6/21 + * Time: 1:24 PM + * E-mail: DenBond7@gmail.com + */ +@MediumTest +@RunWith(AndroidJUnit4::class) +class CreateMessageFragmentDisallowAttesterSearchForDomainTest : BaseCreateMessageActivityTest() { + + private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules( + OrgRules( + flags = listOf( + OrgRules.DomainRule.NO_PRV_CREATE, + OrgRules.DomainRule.NO_PRV_BACKUP + ), + customKeyserverUrl = null, + keyManagerUrl = "https://keymanagerurl.test", + disallowAttesterSearchForDomains = listOf(DISALLOWED_DOMAIN), + enforceKeygenAlgo = null, + enforceKeygenExpireMonths = null + ) + ) + + override val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules) + private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule( + accountEntity = addAccountToDatabaseRule.account, + keyPath = "pgp/default@flowcrypt.test_fisrtKey_prv_strong.asc", + passphrase = TestConstants.DEFAULT_SECOND_STRONG_PASSWORD, + sourceType = KeyImportDetails.SourceType.EMAIL, + passphraseType = KeyEntity.PassphraseType.RAM + ) + + @get:Rule + var ruleChain: TestRule = RuleChain + .outerRule(ClearAppSettingsRule()) + .around(addAccountToDatabaseRule) + .around(addPrivateKeyToDatabaseRule) + .around(RetryRule.DEFAULT) + .around(activeActivityRule) + .around(ScreenshotTestRule()) + + @Test + fun testCanLookupThisRecipientOnAttester() { + activeActivityRule.launch(intent) + registerAllIdlingResources() + + val recipient = "user@$DISALLOWED_DOMAIN" + + fillInAllFields(recipient) + + onView(withId(R.id.editTextRecipientTo)) + .check( + matches( + withChipsBackgroundColor( + recipient, + UIUtil.getColor( + getTargetContext(), + CustomChipSpanChipCreator.CHIP_COLOR_RES_ID_PGP_NOT_EXISTS + ) + ) + ) + ) + } + + companion object { + private const val DISALLOWED_DOMAIN = "disallowed.test" + } +} diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragmentDisallowAttesterSearchTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragmentDisallowAttesterSearchTest.kt new file mode 100644 index 0000000000..565a8cdc88 --- /dev/null +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragmentDisallowAttesterSearchTest.kt @@ -0,0 +1,98 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: DenBond7 + */ + +package com.flowcrypt.email.ui.activity.fragment + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import com.flowcrypt.email.R +import com.flowcrypt.email.TestConstants +import com.flowcrypt.email.api.retrofit.response.model.OrgRules +import com.flowcrypt.email.database.entity.KeyEntity +import com.flowcrypt.email.matchers.CustomMatchers.Companion.withChipsBackgroundColor +import com.flowcrypt.email.model.KeyImportDetails +import com.flowcrypt.email.rules.AddAccountToDatabaseRule +import com.flowcrypt.email.rules.AddPrivateKeyToDatabaseRule +import com.flowcrypt.email.rules.ClearAppSettingsRule +import com.flowcrypt.email.rules.RetryRule +import com.flowcrypt.email.rules.ScreenshotTestRule +import com.flowcrypt.email.ui.activity.base.BaseCreateMessageActivityTest +import com.flowcrypt.email.ui.widget.CustomChipSpanChipCreator +import com.flowcrypt.email.util.AccountDaoManager +import com.flowcrypt.email.util.UIUtil +import org.junit.Rule +import org.junit.Test +import org.junit.rules.RuleChain +import org.junit.rules.TestRule +import org.junit.runner.RunWith + +/** + * @author Denis Bondarenko + * Date: 8/6/21 + * Time: 1:52 PM + * E-mail: DenBond7@gmail.com + */ +@MediumTest +@RunWith(AndroidJUnit4::class) +class CreateMessageFragmentDisallowAttesterSearchTest : BaseCreateMessageActivityTest() { + + private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules( + OrgRules( + flags = listOf( + OrgRules.DomainRule.NO_PRV_CREATE, + OrgRules.DomainRule.NO_PRV_BACKUP + ), + customKeyserverUrl = null, + keyManagerUrl = "https://keymanagerurl.test", + disallowAttesterSearchForDomains = listOf("*"), + enforceKeygenAlgo = null, + enforceKeygenExpireMonths = null + ) + ) + + override val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules) + private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule( + accountEntity = addAccountToDatabaseRule.account, + keyPath = "pgp/default@flowcrypt.test_fisrtKey_prv_strong.asc", + passphrase = TestConstants.DEFAULT_SECOND_STRONG_PASSWORD, + sourceType = KeyImportDetails.SourceType.EMAIL, + passphraseType = KeyEntity.PassphraseType.RAM + ) + + @get:Rule + var ruleChain: TestRule = RuleChain + .outerRule(ClearAppSettingsRule()) + .around(addAccountToDatabaseRule) + .around(addPrivateKeyToDatabaseRule) + .around(RetryRule.DEFAULT) + .around(activeActivityRule) + .around(ScreenshotTestRule()) + + @Test + fun testDisallowLookupOnAttester() { + activeActivityRule.launch(intent) + registerAllIdlingResources() + + val recipient = getResString(R.string.support_email) + + fillInAllFields(recipient) + + onView(withId(R.id.editTextRecipientTo)) + .check( + matches( + withChipsBackgroundColor( + recipient, + UIUtil.getColor( + getTargetContext(), + CustomChipSpanChipCreator.CHIP_COLOR_RES_ID_PGP_NOT_EXISTS + ) + ) + ) + ) + } +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/ApiRepository.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/ApiRepository.kt index 4fe369ff39..d5a18473c1 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/ApiRepository.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/ApiRepository.kt @@ -81,13 +81,16 @@ interface ApiRepository : BaseApiRepository { ): Result /** + * @param requestCode A unique request code for this call * @param context Interface to global information about an application environment. * @param identData A key id or the user email or a fingerprint. + * @param orgRules Contains client configurations. */ suspend fun getPub( requestCode: Long = 0L, context: Context, - identData: String + identData: String, + orgRules: OrgRules? = null ): Result /** diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/FlowcryptApiRepository.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/FlowcryptApiRepository.kt index 79911fcb3a..965664547a 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/FlowcryptApiRepository.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/FlowcryptApiRepository.kt @@ -18,6 +18,7 @@ import com.flowcrypt.email.api.retrofit.response.attester.PubResponse import com.flowcrypt.email.api.retrofit.response.attester.TestWelcomeResponse import com.flowcrypt.email.api.retrofit.response.base.ApiResponse import com.flowcrypt.email.api.retrofit.response.base.Result +import com.flowcrypt.email.api.retrofit.response.model.OrgRules import com.flowcrypt.email.api.retrofit.response.oauth2.MicrosoftOAuth2TokenResponse import com.google.gson.JsonObject import kotlinx.coroutines.Dispatchers @@ -97,12 +98,27 @@ class FlowcryptApiRepository : ApiRepository { override suspend fun getPub( requestCode: Long, context: Context, - identData: String + identData: String, + orgRules: OrgRules? ): Result = withContext(Dispatchers.IO) { val apiService = ApiHelper.getInstance(context).retrofit.create(ApiService::class.java) + if (identData.contains('@')) { + if (orgRules?.canLookupThisRecipientOnAttester(identData) == false) { + return@withContext Result.success( + requestCode = requestCode, + data = PubResponse(null, null) + ) + } + } else if (orgRules?.disallowLookupOnAttester() == true) { + return@withContext Result.success( + requestCode = requestCode, + data = PubResponse(null, null) + ) + } + val result = getResult(requestCode = requestCode) { apiService.getPub(identData) } - when (result.status) { + return@withContext when (result.status) { Result.Status.SUCCESS -> Result.success( requestCode = requestCode, data = PubResponse(null, result.data) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/model/OrgRules.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/model/OrgRules.kt index 59ff0455e4..856d07cd4f 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/model/OrgRules.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/model/OrgRules.kt @@ -184,9 +184,25 @@ data class OrgRules constructor( * public keys for these domains, such as from their own internal keyserver */ fun canLookupThisRecipientOnAttester(emailAddr: String): Boolean { - val domain = EmailUtil.getDomain(emailAddr) - val domains = disallowAttesterSearchForDomains ?: emptyList() - return !domains.contains(if (domain.isEmpty()) "NONE" else domain) + if (disallowLookupOnAttester()) { + return false + } + + val userDomain = EmailUtil.getDomain(emailAddr) + if (userDomain.isEmpty()) { + throw IllegalStateException("Not a valid email $emailAddr") + } + + val disallowedDomains = disallowAttesterSearchForDomains ?: emptyList() + return !disallowedDomains.any { it.equals(userDomain, true) } + } + + /** + * + * Some orgs might want to disallow lookup on attester completely + */ + fun disallowLookupOnAttester(): Boolean { + return (disallowAttesterSearchForDomains ?: emptyList()).contains("*") } /** diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountKeysInfoViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountKeysInfoViewModel.kt index 116a14218f..04ce9961e2 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountKeysInfoViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountKeysInfoViewModel.kt @@ -104,7 +104,11 @@ class AccountKeysInfoViewModel(application: Application) : AccountViewModel(appl } for (email in emails) { - val pubResponseResult = apiRepository.getPub(context = getApplication(), identData = email) + val pubResponseResult = apiRepository.getPub( + context = getApplication(), + identData = email, + orgRules = accountEntity.clientConfiguration + ) pubResponseResult.data?.pubkey?.let { key -> results.addAll(PgpKey.parseKeys(key).toPgpKeyDetailsList()) } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ContactsViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ContactsViewModel.kt index d802598ff0..ae91343045 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ContactsViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ContactsViewModel.kt @@ -13,7 +13,6 @@ import androidx.lifecycle.liveData import androidx.lifecycle.viewModelScope import com.flowcrypt.email.api.retrofit.ApiRepository import com.flowcrypt.email.api.retrofit.FlowcryptApiRepository -import com.flowcrypt.email.api.retrofit.node.NodeRepository import com.flowcrypt.email.api.retrofit.response.attester.PubResponse import com.flowcrypt.email.api.retrofit.response.base.ApiError import com.flowcrypt.email.api.retrofit.response.base.Result @@ -38,7 +37,6 @@ import java.util.* */ class ContactsViewModel(application: Application) : AccountViewModel(application) { private val apiRepository: ApiRepository = FlowcryptApiRepository() - private val pgpApiRepository = NodeRepository() private val searchPatternLiveData: MutableLiveData = MutableLiveData() val allContactsLiveData: LiveData> = @@ -278,10 +276,12 @@ class ContactsViewModel(application: Application) : AccountViewModel(application fun fetchPubKeys(keyIdOrEmail: String, requestCode: Long) { viewModelScope.launch { pubKeysFromAttesterLiveData.value = Result.loading(requestCode = requestCode) + val activeAccount = getActiveAccountSuspend() pubKeysFromAttesterLiveData.value = apiRepository.getPub( requestCode = requestCode, context = getApplication(), - identData = keyIdOrEmail + identData = keyIdOrEmail, + orgRules = activeAccount?.clientConfiguration ) } } @@ -315,45 +315,45 @@ class ContactsViewModel(application: Application) : AccountViewModel(application private suspend fun getPgpContactInfoFromServer( email: String? = null, fingerprint: String? = null - ): - PgpContact? = - withContext(Dispatchers.IO) { - try { - val response = apiRepository.getPub( - context = getApplication(), - identData = email ?: fingerprint ?: "" - ) + ): PgpContact? = withContext(Dispatchers.IO) { + try { + val activeAccount = getActiveAccountSuspend() + val response = apiRepository.getPub( + context = getApplication(), + identData = email ?: fingerprint ?: "", + orgRules = activeAccount?.clientConfiguration + ) - when (response.status) { - Result.Status.SUCCESS -> { - val pubKeyString = response.data?.pubkey - val client = ContactEntity.CLIENT_PGP - - if (pubKeyString?.isNotEmpty() == true) { - PgpKey.parseKeys(pubKeyString).toPgpKeyDetailsList().firstOrNull()?.let { - val pgpContact = it.primaryPgpContact - pgpContact.client = client - pgpContact.pgpKeyDetails = it - return@withContext pgpContact - } + when (response.status) { + Result.Status.SUCCESS -> { + val pubKeyString = response.data?.pubkey + val client = ContactEntity.CLIENT_PGP + + if (pubKeyString?.isNotEmpty() == true) { + PgpKey.parseKeys(pubKeyString).toPgpKeyDetailsList().firstOrNull()?.let { + val pgpContact = it.primaryPgpContact + pgpContact.client = client + pgpContact.pgpKeyDetails = it + return@withContext pgpContact } } + } - Result.Status.ERROR -> { - throw ApiException( - response.data?.apiError - ?: ApiError(code = -1, msg = "Unknown API error") - ) - } + Result.Status.ERROR -> { + throw ApiException( + response.data?.apiError + ?: ApiError(code = -1, msg = "Unknown API error") + ) + } - else -> { - throw response.exception ?: java.lang.Exception() - } + else -> { + throw response.exception ?: java.lang.Exception() } - } catch (e: IOException) { - e.printStackTrace() } - - null + } catch (e: IOException) { + e.printStackTrace() } + + null + } }