mirror of
https://github.com/etesync/android
synced 2025-01-14 09:40:58 +00:00
Fix collection editing following an encryption password change.
A lot of the code dealing with collections assumes that the editing is done by the owner (true assumption, for now), and therefore the encryption key is derived from the master key (not true anymore, as it could be a stored version of the old key). This commit removes this wrong assumption.
This commit is contained in:
parent
6f453faf06
commit
9f0b492c42
@ -96,30 +96,36 @@ class CreateCollectionFragment : DialogFragment(), LoaderManager.LoaderCallbacks
|
||||
}
|
||||
|
||||
val serviceEntity = JournalModel.Service.fetch(data, account.name, info.type)
|
||||
info.serviceID = serviceEntity.id
|
||||
|
||||
val settings = AccountSettings(context, account)
|
||||
val principal = HttpUrl.get(settings.uri!!)
|
||||
|
||||
val journalManager = JournalManager(HttpClient.create(context, settings), principal!!)
|
||||
var uid = info.uid
|
||||
|
||||
if (uid == null) {
|
||||
uid = JournalManager.Journal.genUid()
|
||||
info.uid = uid
|
||||
val crypto = Crypto.CryptoManager(info.version, settings.password(), uid)
|
||||
val journal = JournalManager.Journal(crypto, info.toJson(), uid)
|
||||
journalManager.create(journal)
|
||||
|
||||
val journalEntity = JournalEntity.fetchOrCreate(data, info)
|
||||
data.upsert(journalEntity)
|
||||
} else {
|
||||
val crypto = Crypto.CryptoManager(info.version, settings.password(), uid)
|
||||
val crypto: Crypto.CryptoManager
|
||||
val journalEntity = JournalEntity.fetch(data, serviceEntity, uid)
|
||||
|
||||
if (journalEntity.encryptedKey != null) {
|
||||
crypto = Crypto.CryptoManager(info.version, settings.keyPair!!, journalEntity.encryptedKey)
|
||||
} else {
|
||||
crypto = Crypto.CryptoManager(info.version, settings.password(), uid)
|
||||
}
|
||||
val journal = JournalManager.Journal(crypto, info.toJson(), uid)
|
||||
journalManager.update(journal)
|
||||
}
|
||||
|
||||
// 2. add collection to service
|
||||
info.serviceID = serviceEntity.id
|
||||
val journalEntity = JournalEntity.fetchOrCreate(data, info)
|
||||
data.upsert(journalEntity)
|
||||
|
||||
|
||||
requestSync(authority)
|
||||
} catch (e: IllegalStateException) {
|
||||
return e
|
||||
|
Loading…
Reference in New Issue
Block a user