Rename UserCrossSigningKeys
to UserIdentity
This commit is contained in:
parent
7e26c4b6f2
commit
30940cb937
@ -19,7 +19,7 @@ package org.matrix.android.sdk.api.session.crypto.crosssigning
|
|||||||
/**
|
/**
|
||||||
* Container for the three cross signing keys: master, self signing and user signing.
|
* Container for the three cross signing keys: master, self signing and user signing.
|
||||||
*/
|
*/
|
||||||
data class CryptoCrossSigningKeys(
|
data class UserIdentity(
|
||||||
val masterKey: CryptoCrossSigningKey?,
|
val masterKey: CryptoCrossSigningKey?,
|
||||||
val selfSigningKey: CryptoCrossSigningKey?,
|
val selfSigningKey: CryptoCrossSigningKey?,
|
||||||
val userSigningKey: CryptoCrossSigningKey?,
|
val userSigningKey: CryptoCrossSigningKey?,
|
@ -24,8 +24,8 @@ import org.matrix.android.sdk.api.MatrixPatterns
|
|||||||
import org.matrix.android.sdk.api.auth.data.Credentials
|
import org.matrix.android.sdk.api.auth.data.Credentials
|
||||||
import org.matrix.android.sdk.api.extensions.measureMetric
|
import org.matrix.android.sdk.api.extensions.measureMetric
|
||||||
import org.matrix.android.sdk.api.metrics.DownloadDeviceKeysMetricsPlugin
|
import org.matrix.android.sdk.api.metrics.DownloadDeviceKeysMetricsPlugin
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.CryptoCrossSigningKeys
|
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel
|
||||||
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.UserIdentity
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
|
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
|
||||||
import org.matrix.android.sdk.internal.crypto.model.CryptoInfoMapper
|
import org.matrix.android.sdk.internal.crypto.model.CryptoInfoMapper
|
||||||
@ -420,7 +420,7 @@ internal class DeviceListManager @Inject constructor(
|
|||||||
val userSigningKey = response.userSigningKeys?.get(userId)?.toCryptoModel()?.also {
|
val userSigningKey = response.userSigningKeys?.get(userId)?.toCryptoModel()?.also {
|
||||||
Timber.v("## CRYPTO | CrossSigning : Got keys for $userId : USK ${it.unpaddedBase64PublicKey}")
|
Timber.v("## CRYPTO | CrossSigning : Got keys for $userId : USK ${it.unpaddedBase64PublicKey}")
|
||||||
}
|
}
|
||||||
userDataToStore.userCrossSigningKeys[userId] = CryptoCrossSigningKeys(
|
userDataToStore.userIdentities[userId] = UserIdentity(
|
||||||
masterKey = masterKey,
|
masterKey = masterKey,
|
||||||
selfSigningKey = selfSigningKey,
|
selfSigningKey = selfSigningKey,
|
||||||
userSigningKey = userSigningKey
|
userSigningKey = userSigningKey
|
||||||
|
@ -22,9 +22,9 @@ import org.matrix.android.sdk.api.session.crypto.GlobalCryptoConfig
|
|||||||
import org.matrix.android.sdk.api.session.crypto.NewSessionListener
|
import org.matrix.android.sdk.api.session.crypto.NewSessionListener
|
||||||
import org.matrix.android.sdk.api.session.crypto.OutgoingKeyRequest
|
import org.matrix.android.sdk.api.session.crypto.OutgoingKeyRequest
|
||||||
import org.matrix.android.sdk.api.session.crypto.OutgoingRoomKeyRequestState
|
import org.matrix.android.sdk.api.session.crypto.OutgoingRoomKeyRequestState
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.CryptoCrossSigningKeys
|
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.PrivateKeysInfo
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.PrivateKeysInfo
|
||||||
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.UserIdentity
|
||||||
import org.matrix.android.sdk.api.session.crypto.keysbackup.SavedKeyBackupKeyInfo
|
import org.matrix.android.sdk.api.session.crypto.keysbackup.SavedKeyBackupKeyInfo
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.AuditTrail
|
import org.matrix.android.sdk.api.session.crypto.model.AuditTrail
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||||
@ -245,9 +245,12 @@ internal interface IMXCryptoStore {
|
|||||||
*/
|
*/
|
||||||
fun storeUserDevices(userId: String, devices: Map<String, CryptoDeviceInfo>?)
|
fun storeUserDevices(userId: String, devices: Map<String, CryptoDeviceInfo>?)
|
||||||
|
|
||||||
fun storeUserCrossSigningKeys(
|
/**
|
||||||
|
* Store the cross signing keys for the user userId.
|
||||||
|
*/
|
||||||
|
fun storeUserIdentity(
|
||||||
userId: String,
|
userId: String,
|
||||||
cryptoCrossSigningKeys: CryptoCrossSigningKeys
|
userIdentity: UserIdentity
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store
|
package org.matrix.android.sdk.internal.crypto.store
|
||||||
|
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.CryptoCrossSigningKeys
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.UserIdentity
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||||
|
|
||||||
internal data class UserDataToStore(
|
internal data class UserDataToStore(
|
||||||
@ -25,7 +25,7 @@ internal data class UserDataToStore(
|
|||||||
*/
|
*/
|
||||||
val userDevices: MutableMap<String, Map<String, CryptoDeviceInfo>> = mutableMapOf(),
|
val userDevices: MutableMap<String, Map<String, CryptoDeviceInfo>> = mutableMapOf(),
|
||||||
/**
|
/**
|
||||||
* Map of userId -> [CryptoCrossSigningKeys].
|
* Map of userId -> [UserIdentity].
|
||||||
*/
|
*/
|
||||||
val userCrossSigningKeys: MutableMap<String, CryptoCrossSigningKeys> = mutableMapOf(),
|
val userIdentities: MutableMap<String, UserIdentity> = mutableMapOf(),
|
||||||
)
|
)
|
||||||
|
@ -33,9 +33,9 @@ import org.matrix.android.sdk.api.session.crypto.GlobalCryptoConfig
|
|||||||
import org.matrix.android.sdk.api.session.crypto.NewSessionListener
|
import org.matrix.android.sdk.api.session.crypto.NewSessionListener
|
||||||
import org.matrix.android.sdk.api.session.crypto.OutgoingKeyRequest
|
import org.matrix.android.sdk.api.session.crypto.OutgoingKeyRequest
|
||||||
import org.matrix.android.sdk.api.session.crypto.OutgoingRoomKeyRequestState
|
import org.matrix.android.sdk.api.session.crypto.OutgoingRoomKeyRequestState
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.CryptoCrossSigningKeys
|
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.PrivateKeysInfo
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.PrivateKeysInfo
|
||||||
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.UserIdentity
|
||||||
import org.matrix.android.sdk.api.session.crypto.keysbackup.SavedKeyBackupKeyInfo
|
import org.matrix.android.sdk.api.session.crypto.keysbackup.SavedKeyBackupKeyInfo
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.AuditTrail
|
import org.matrix.android.sdk.api.session.crypto.model.AuditTrail
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||||
@ -330,23 +330,23 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun storeUserCrossSigningKeys(
|
override fun storeUserIdentity(
|
||||||
userId: String,
|
userId: String,
|
||||||
cryptoCrossSigningKeys: CryptoCrossSigningKeys,
|
userIdentity: UserIdentity,
|
||||||
) {
|
) {
|
||||||
doRealmTransaction("storeUserCrossSigningKeys", realmConfiguration) { realm ->
|
doRealmTransaction("storeUserIdentity", realmConfiguration) { realm ->
|
||||||
storeUserCrossSigningKeys(realm, userId, cryptoCrossSigningKeys)
|
storeUserIdentity(realm, userId, userIdentity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeUserCrossSigningKeys(
|
private fun storeUserIdentity(
|
||||||
realm: Realm,
|
realm: Realm,
|
||||||
userId: String,
|
userId: String,
|
||||||
keys: CryptoCrossSigningKeys,
|
userIdentity: UserIdentity,
|
||||||
) {
|
) {
|
||||||
UserEntity.getOrCreate(realm, userId)
|
UserEntity.getOrCreate(realm, userId)
|
||||||
.let { userEntity ->
|
.let { userEntity ->
|
||||||
if (keys.masterKey == null || keys.selfSigningKey == null) {
|
if (userIdentity.masterKey == null || userIdentity.selfSigningKey == null) {
|
||||||
// The user has disabled cross signing?
|
// The user has disabled cross signing?
|
||||||
userEntity.crossSigningInfoEntity?.deleteOnCascade()
|
userEntity.crossSigningInfoEntity?.deleteOnCascade()
|
||||||
userEntity.crossSigningInfoEntity = null
|
userEntity.crossSigningInfoEntity = null
|
||||||
@ -355,11 +355,11 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
CrossSigningInfoEntity.getOrCreate(realm, userId).let { signingInfo ->
|
CrossSigningInfoEntity.getOrCreate(realm, userId).let { signingInfo ->
|
||||||
// What should we do if we detect a change of the keys?
|
// What should we do if we detect a change of the keys?
|
||||||
val existingMaster = signingInfo.getMasterKey()
|
val existingMaster = signingInfo.getMasterKey()
|
||||||
if (existingMaster != null && existingMaster.publicKeyBase64 == keys.masterKey.unpaddedBase64PublicKey) {
|
if (existingMaster != null && existingMaster.publicKeyBase64 == userIdentity.masterKey.unpaddedBase64PublicKey) {
|
||||||
crossSigningKeysMapper.update(existingMaster, keys.masterKey)
|
crossSigningKeysMapper.update(existingMaster, userIdentity.masterKey)
|
||||||
} else {
|
} else {
|
||||||
Timber.d("## CrossSigning MSK change for $userId")
|
Timber.d("## CrossSigning MSK change for $userId")
|
||||||
val keyEntity = crossSigningKeysMapper.map(keys.masterKey)
|
val keyEntity = crossSigningKeysMapper.map(userIdentity.masterKey)
|
||||||
signingInfo.setMasterKey(keyEntity)
|
signingInfo.setMasterKey(keyEntity)
|
||||||
if (userId == this.userId) {
|
if (userId == this.userId) {
|
||||||
shouldResetMyDevicesLocalTrust = true
|
shouldResetMyDevicesLocalTrust = true
|
||||||
@ -374,11 +374,11 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val existingSelfSigned = signingInfo.getSelfSignedKey()
|
val existingSelfSigned = signingInfo.getSelfSignedKey()
|
||||||
if (existingSelfSigned != null && existingSelfSigned.publicKeyBase64 == keys.selfSigningKey.unpaddedBase64PublicKey) {
|
if (existingSelfSigned != null && existingSelfSigned.publicKeyBase64 == userIdentity.selfSigningKey.unpaddedBase64PublicKey) {
|
||||||
crossSigningKeysMapper.update(existingSelfSigned, keys.selfSigningKey)
|
crossSigningKeysMapper.update(existingSelfSigned, userIdentity.selfSigningKey)
|
||||||
} else {
|
} else {
|
||||||
Timber.d("## CrossSigning SSK change for $userId")
|
Timber.d("## CrossSigning SSK change for $userId")
|
||||||
val keyEntity = crossSigningKeysMapper.map(keys.selfSigningKey)
|
val keyEntity = crossSigningKeysMapper.map(userIdentity.selfSigningKey)
|
||||||
signingInfo.setSelfSignedKey(keyEntity)
|
signingInfo.setSelfSignedKey(keyEntity)
|
||||||
if (userId == this.userId) {
|
if (userId == this.userId) {
|
||||||
shouldResetMyDevicesLocalTrust = true
|
shouldResetMyDevicesLocalTrust = true
|
||||||
@ -390,13 +390,13 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only for me
|
// Only for me
|
||||||
if (keys.userSigningKey != null) {
|
if (userIdentity.userSigningKey != null) {
|
||||||
val existingUSK = signingInfo.getUserSigningKey()
|
val existingUSK = signingInfo.getUserSigningKey()
|
||||||
if (existingUSK != null && existingUSK.publicKeyBase64 == keys.userSigningKey.unpaddedBase64PublicKey) {
|
if (existingUSK != null && existingUSK.publicKeyBase64 == userIdentity.userSigningKey.unpaddedBase64PublicKey) {
|
||||||
crossSigningKeysMapper.update(existingUSK, keys.userSigningKey)
|
crossSigningKeysMapper.update(existingUSK, userIdentity.userSigningKey)
|
||||||
} else {
|
} else {
|
||||||
Timber.d("## CrossSigning USK change for $userId")
|
Timber.d("## CrossSigning USK change for $userId")
|
||||||
val keyEntity = crossSigningKeysMapper.map(keys.userSigningKey)
|
val keyEntity = crossSigningKeysMapper.map(userIdentity.userSigningKey)
|
||||||
signingInfo.setUserSignedKey(keyEntity)
|
signingInfo.setUserSignedKey(keyEntity)
|
||||||
if (userId == this.userId) {
|
if (userId == this.userId) {
|
||||||
shouldResetMyDevicesLocalTrust = true
|
shouldResetMyDevicesLocalTrust = true
|
||||||
@ -1857,8 +1857,8 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
userDataToStore.userDevices.forEach {
|
userDataToStore.userDevices.forEach {
|
||||||
storeUserDevices(realm, it.key, it.value)
|
storeUserDevices(realm, it.key, it.value)
|
||||||
}
|
}
|
||||||
userDataToStore.userCrossSigningKeys.forEach {
|
userDataToStore.userIdentities.forEach {
|
||||||
storeUserCrossSigningKeys(realm, it.key, it.value)
|
storeUserIdentity(realm, it.key, it.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user