Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple pub keys per recipient #1523

Merged
merged 39 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
21ca549
Added PublicKeyEntity. Refactored code. WIP.| #1188
DenBond7 Oct 23, 2021
ae23630
Fixed using ContactsDao.getAllContactsWithPgpLD().| #1188
DenBond7 Oct 25, 2021
77c8855
Fixed using ContactsDao.getAllContactsWithPgp()/getAllContactsWithPgp…
DenBond7 Oct 26, 2021
faa2e23
Renamed ContactEntity to RecipientEntity.| #1188
DenBond7 Oct 26, 2021
fda5a76
Renamed ContactsDao to RecipientDao.| #1188
DenBond7 Oct 26, 2021
91de167
Refactored code.| #1188
DenBond7 Oct 26, 2021
905aacf
Renamed ContactsViewModel to RecipientsViewModel.| #1188
DenBond7 Oct 26, 2021
55355f0
Fixed a few methods in RecipientDao. Refactored code.| #1188
DenBond7 Oct 26, 2021
c36f3ad
Fixed RecipientDao.getRecipientByEmail().| #1188
DenBond7 Oct 26, 2021
5803a9e
Fixed some moments with adding/updating a recipient with a pub key.| …
DenBond7 Oct 26, 2021
8f1644a
Made a workable version after switching to use 'recipients' and 'pub_…
DenBond7 Nov 1, 2021
d22ae4c
Fixed tests. Refactored code.| #1188
DenBond7 Nov 5, 2021
81874c2
Modified code to use a new logic to save contacts on the compose scre…
DenBond7 Nov 9, 2021
daa76eb
Modified code to use a new logic to apply colors to recipients(chips)…
DenBond7 Nov 10, 2021
8874988
Added changes to use all recipient's pub keys for ecnryption + use al…
DenBond7 Nov 10, 2021
bd9334f
Fixed signing option.| #1541
DenBond7 Nov 10, 2021
ece204c
Import recipients manually. Refactored code. Added LookUpPubKeysDialo…
DenBond7 Nov 10, 2021
9ec0be6
Added a base realization of importing pub keys manually.| #1542
DenBond7 Nov 12, 2021
1dd39c8
Added ImportAllPubKeysFromSourceDialogFragment.| #1542
DenBond7 Nov 17, 2021
02bbd10
Removed unused source.| #1542
DenBond7 Nov 18, 2021
57bddc7
Improved some classes.| #1566
DenBond7 Nov 19, 2021
4676fc2
Added RecipientDetailsFragment.| #1566
DenBond7 Nov 19, 2021
e69ff95
Fixed opening PublicKeyDetailsFragment. Refactored code.| #1566
DenBond7 Nov 19, 2021
beedaae
Fixed exporting pub key.| #1566
DenBond7 Nov 19, 2021
d12d609
Fixed deleting pub key.| #1566
DenBond7 Nov 19, 2021
13226a9
Fixed editing pub key.| #1566
DenBond7 Nov 23, 2021
44b85c6
Fixed database migration bug.| #1188
DenBond7 Nov 23, 2021
36d1d11
Fixed nav_graph.xml for test.| #1188
DenBond7 Nov 23, 2021
abc45b1
Temporary disabled some tests.| #1188
DenBond7 Nov 23, 2021
a41dcf0
Temporary disabled some tests(step 2).| #1188
DenBond7 Nov 23, 2021
b7fdee2
Fixed Junit tests.| #1188
DenBond7 Nov 23, 2021
09724be
Fixed some UI tests.| #1188
DenBond7 Nov 23, 2021
775f473
Merge remote-tracking branch 'origin/master' into issue_1188_support_…
DenBond7 Nov 25, 2021
c84d571
Fixed merge conflicts.| #1188
DenBond7 Nov 25, 2021
1a76ddd
Fixed some PR comments. Refactored code.| #1188
DenBond7 Nov 25, 2021
e6e08c2
Fixed some PR comments. Refactored code. Step 2.| #1188
DenBond7 Nov 25, 2021
b9a8b9d
Restored some code.| #1188
DenBond7 Nov 25, 2021
35a6e09
Renamed a file.| #1188
DenBond7 Nov 25, 2021
1170e2f
Fixed importing/updating pub keys for PublicKeyMsgBlock.| #1188
DenBond7 Nov 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class EmailUtil {
if (outgoingMsgInfo.encryptionType === MessageEncryptionType.ENCRYPTED) {
val recipients = outgoingMsgInfo.getAllRecipients().toMutableList()
pubKeys = mutableListOf()
pubKeys.addAll(SecurityUtils.getRecipientsPubKeys(context, recipients))
pubKeys.addAll(SecurityUtils.getRecipientsUsablePubKeys(context, recipients))
pubKeys.addAll(senderPgpKeyDetailsList.map { it.publicKey })
prvKeys = listOf(
senderPgpKeyDetailsList.firstOrNull()?.privateKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,18 +526,11 @@ abstract class FlowCryptRoomDatabase : RoomDatabase() {
database.execSQL("CREATE TEMP TABLE IF NOT EXISTS contacts_temp AS SELECT * FROM contacts;")

//create `recipients` table
database.execSQL(
"""CREATE TABLE IF NOT EXISTS `recipients`
(`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `email` TEXT NOT NULL,
`name` TEXT DEFAULT NULL, `last_use` INTEGER NOT NULL DEFAULT 0)""".trimMargin()
)
database.execSQL("CREATE TABLE IF NOT EXISTS `recipients` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `email` TEXT NOT NULL, `name` TEXT DEFAULT NULL, `last_use` INTEGER NOT NULL DEFAULT 0)")
IvanPizhenko marked this conversation as resolved.
Show resolved Hide resolved
database.execSQL("CREATE INDEX IF NOT EXISTS `name_in_recipients` ON `recipients` (`name`)")
database.execSQL("CREATE INDEX IF NOT EXISTS `last_use_in_recipients` ON `recipients` (`last_use`)")
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `email_in_recipients` ON `recipients` (`email`)")
database.execSQL(
"INSERT INTO recipients(email, name, last_use)" +
" SELECT email, name, last_use FROM contacts_temp"
)
database.execSQL("INSERT INTO recipients(email, name, last_use) SELECT email, name, last_use FROM contacts_temp")

//create `public_keys` table
database.execSQL("CREATE TABLE IF NOT EXISTS `public_keys` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `recipient` TEXT NOT NULL, `fingerprint` TEXT NOT NULL, `public_key` BLOB NOT NULL, FOREIGN KEY(`recipient`) REFERENCES `recipients`(`email`) ON UPDATE NO ACTION ON DELETE CASCADE )")
tomholub marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import kotlinx.coroutines.flow.Flow
*/
@Dao
interface PubKeyDao : BaseDao<PublicKeyEntity> {
@Query("SELECT * FROM public_keys")
@Query(SELECT_ALL_PUB_KEYS)
suspend fun getAllPublicKeys(): List<PublicKeyEntity>

@Query("SELECT * FROM public_keys")
@Query(SELECT_ALL_PUB_KEYS)
fun getAllPublicKeysFlow(): Flow<List<PublicKeyEntity>>

@Query("SELECT * FROM public_keys WHERE recipient = :recipient")
Expand All @@ -41,4 +41,8 @@ interface PubKeyDao : BaseDao<PublicKeyEntity> {

@Query("SELECT * FROM public_keys WHERE _id = :id")
fun getPublicKeyByIdFlow(id: Long): Flow<PublicKeyEntity?>

companion object {
private const val SELECT_ALL_PUB_KEYS = "SELECT * FROM public_keys"
}
Comment on lines +45 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means in the future we may be doing this for all. But that's also for another issue.

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RecipientsViewModel(application: Application) : AccountViewModel(applicati
}
}

fun deleteContact(recipientEntity: RecipientEntity) {
fun deleteRecipient(recipientEntity: RecipientEntity) {
viewModelScope.launch {
roomDatabase.recipientDao().deleteSuspend(recipientEntity)
}
Expand Down Expand Up @@ -220,7 +220,7 @@ class RecipientsViewModel(application: Application) : AccountViewModel(applicati
}
}

fun filterContacts(searchPattern: String?) {
fun filterContacts(searchPattern: String) {
searchPatternLiveData.value = searchPattern
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class ForwardedAttachmentsDownloaderWorker(context: Context, params: WorkerParam
val senderEmail = EmailUtil.getFirstAddressString(msgEntity.from)
val recipients = msgEntity.allRecipients.toMutableList()
pubKeys = mutableListOf()
pubKeys.addAll(SecurityUtils.getRecipientsPubKeys(applicationContext, recipients))
pubKeys.addAll(SecurityUtils.getRecipientsUsablePubKeys(applicationContext, recipients))
pubKeys.addAll(
SecurityUtils.getSenderPgpKeyDetailsList(applicationContext, account, senderEmail)
.map { it.publicKey }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SecurityUtils {
* @throws NoKeyAvailableException
*/
@JvmStatic
fun getRecipientsPubKeys(context: Context, emails: MutableList<String>): List<String> {
fun getRecipientsUsablePubKeys(context: Context, emails: MutableList<String>): List<String> {
val publicKeys = mutableListOf<String>()
val recipientsWithPubKeys = FlowCryptRoomDatabase.getDatabase(context).recipientDao()
.getRecipientsWithPubKeysByEmails(emails)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class PrepareOutgoingMessagesJobIntentService : JobIntentService() {
val senderEmail = outgoingMsgInfo.from
val recipients = outgoingMsgInfo.getAllRecipients().toMutableList()
pubKeys = mutableListOf()
pubKeys.addAll(SecurityUtils.getRecipientsPubKeys(applicationContext, recipients))
pubKeys.addAll(SecurityUtils.getRecipientsUsablePubKeys(applicationContext, recipients))
pubKeys.addAll(
SecurityUtils.getSenderPgpKeyDetailsList(applicationContext, accountEntity, senderEmail)
.map { it.publicKey }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RecipientsListFragment : BaseFragment(), ListProgressBehaviour {
true,
object : RecipientsRecyclerViewAdapter.OnRecipientActionsListener {
override fun onDeleteRecipient(recipientEntity: RecipientEntity) {
recipientsViewModel.deleteContact(recipientEntity)
recipientsViewModel.deleteRecipient(recipientEntity)
Toast.makeText(
context, getString(R.string.the_contact_was_deleted, recipientEntity.email),
Toast.LENGTH_SHORT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class CreateMessageFragment : BaseSyncFragment(), View.OnFocusChangeListener,
private var imageButtonAdditionalRecipientsVisibility: View? = null
private var iBShowQuotedText: View? = null

private var isRecipientsUpdateEnabled = true
private var isUpdateToCompleted = true
private var isUpdateCcCompleted = true
private var isUpdateBccCompleted = true
Expand Down Expand Up @@ -862,12 +861,8 @@ class CreateMessageFragment : BaseSyncFragment(), View.OnFocusChangeListener,
if (hasFocus) {
recipients?.clear()
} else {
if (isRecipientsUpdateEnabled) {
if (isAdded) {
fetchDetailsAboutRecipients(type)
}
} else {
progressBar?.visibility = View.INVISIBLE
if (isAdded) {
fetchDetailsAboutRecipients(type)
}
}
}
Expand Down Expand Up @@ -1498,8 +1493,6 @@ class CreateMessageFragment : BaseSyncFragment(), View.OnFocusChangeListener,
*/
private fun sendMsg() {
dismissCurrentSnackBar()

isRecipientsUpdateEnabled = false
onMsgSendListener.sendMsg(getOutgoingMsgInfo())
}

Expand Down