This commit is contained in:
Valere 2020-03-12 16:09:41 +01:00
parent 1bf8fef292
commit 8051d9e3be
6 changed files with 15 additions and 135 deletions

View file

@ -48,17 +48,6 @@ class KeyShareTests : InstrumentedTest {
private val mTestHelper = CommonTestHelper(context())
// @Before
// fun setup() {
// mockkStatic(Log::class)
// every { Log.v(any(), any()) } returns 0
// every { Log.d(any(), any()) } returns 0
// every { Log.i(any(), any()) } returns 0
// every { Log.e(any(), any()) } returns 0
// // every { Log.println(any(), any(), any()) } returns 0
// // every { Log.wtf(any(), any(), any()) } returns 0
// }
@Test
fun test_DoNotSelfShareIfNotTrusted() {
val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true))

View file

@ -41,14 +41,14 @@ internal class IncomingRoomKeyRequestManager @Inject constructor(
// list of IncomingRoomKeyRequests/IncomingRoomKeyRequestCancellations
// we received in the current sync.
private val receiveGossipingRequests = ArrayList<IncomingShareRequestCommon>()
private val receivedGossipingRequests = ArrayList<IncomingShareRequestCommon>()
private val receivedRequestCancellations = ArrayList<IncomingRequestCancellation>()
// the listeners
private val gossipingRequestListeners: MutableSet<GossipingRequestListener> = HashSet()
init {
receiveGossipingRequests.addAll(cryptoStore.getPendingIncomingGossipingRequests())
receivedGossipingRequests.addAll(cryptoStore.getPendingIncomingGossipingRequests())
}
/**
@ -71,7 +71,7 @@ internal class IncomingRoomKeyRequestManager @Inject constructor(
} else {
// save in DB
cryptoStore.storeIncomingGossipingRequest(it, ageLocalTs)
receiveGossipingRequests.add(it)
receivedGossipingRequests.add(it)
}
}
} else if (event.getClearType() == EventType.ROOM_KEY_REQUEST) {
@ -81,7 +81,7 @@ internal class IncomingRoomKeyRequestManager @Inject constructor(
Timber.v("## onGossipingRequestEvent type ${event.type} ignore remote echo")
} else {
cryptoStore.storeIncomingGossipingRequest(it, ageLocalTs)
receiveGossipingRequests.add(it)
receivedGossipingRequests.add(it)
}
}
}
@ -105,8 +105,8 @@ internal class IncomingRoomKeyRequestManager @Inject constructor(
fun processReceivedGossipingRequests() {
Timber.v("## processReceivedGossipingRequests()")
val roomKeyRequestsToProcess = receiveGossipingRequests.toList()
receiveGossipingRequests.clear()
val roomKeyRequestsToProcess = receivedGossipingRequests.toList()
receivedGossipingRequests.clear()
for (request in roomKeyRequestsToProcess) {
if (request is IncomingRoomKeyRequest) {
processIncomingRoomKeyRequest(request)

View file

@ -1,79 +0,0 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.internal.crypto
/**
* possible states for a room key request
*
*
* The state machine looks like:
* <pre>
*
* |
* V
* UNSENT -----------------------------+
* | |
* | (send successful) | (cancellation requested)
* V |
* SENT |
* |-------------------------------- | --------------+
* | | |
* | | | (cancellation requested with intent
* | | | to resend a new request)
* | (cancellation requested) | |
* V | V
* CANCELLATION_PENDING | CANCELLATION_PENDING_AND_WILL_RESEND
* | | |
* | (cancellation sent) | | (cancellation sent. Create new request
* | | | in the UNSENT state)
* V | |
* (deleted) <---------------------------+----------------+
* </pre>
*/
enum class ShareRequestState {
/**
* request not yet sent
*/
UNSENT,
/**
* request sent, awaiting reply
*/
SENT,
/**
* reply received, cancellation not yet sent
*/
CANCELLATION_PENDING,
/**
* Cancellation not yet sent, once sent, a new request will be done
*/
CANCELLATION_PENDING_AND_WILL_RESEND,
/**
* sending failed
*/
FAILED;
companion object {
fun from(state: Int) = when (state) {
0 -> UNSENT
1 -> SENT
2 -> CANCELLATION_PENDING
3 -> CANCELLATION_PENDING_AND_WILL_RESEND
else /*4*/ -> FAILED
}
}
}

View file

@ -361,42 +361,6 @@ internal interface IMXCryptoStore {
fun getOrAddOutgoingSecretShareRequest(secretName: String, recipients: Map<String, List<String>>): OutgoingSecretRequest?
fun saveGossipingEvent(event: Event)
/**
* Look for room key requests by state.
*
* @param states the states
* @return an OutgoingRoomKeyRequest or null
*/
// fun getOutgoingRoomKeyRequestByState(states: Set<ShareRequestState>): OutgoingRoomKeyRequest?
// fun getOutgoingSecretShareRequestByState(states: Set<ShareRequestState>): OutgoingSecretRequest?
/**
* Update an existing outgoing request.
*
* @param request the request
*/
// fun updateOutgoingRoomKeyRequest(request: OutgoingRoomKeyRequest)
/**
* Delete an outgoing room key request.
*
* @param transactionId the transaction id.
*/
// fun deleteOutgoingRoomKeyRequest(transactionId: String)
/**
* Store an incomingRoomKeyRequest instance
*
* @param incomingRoomKeyRequest the incoming key request
*/
// fun storeIncomingRoomKeyRequest(incomingRoomKeyRequest: IncomingRoomKeyRequest?)
/**
* Delete an incomingRoomKeyRequest instance
*
* @param incomingRoomKeyRequest the incoming key request
*/
// fun deleteIncomingRoomKeyRequest(incomingRoomKeyRequest: IncomingShareRequestCommon)
fun updateGossipingRequestState(request: IncomingShareRequestCommon, state: GossipingRequestState)

View file

@ -1240,7 +1240,8 @@ internal class RealmCryptoStore @Inject constructor(
.equalTo(OutgoingGossipingRequestEntityFields.TYPE_STR, GossipRequestType.KEY.name)
}, { entity ->
entity.toOutgoingGossipingRequest() as? OutgoingRoomKeyRequest
}).filterNotNull()
})
.filterNotNull()
}
override fun getOutgoingSecretKeyRequests(): List<OutgoingSecretRequest> {
@ -1250,7 +1251,8 @@ internal class RealmCryptoStore @Inject constructor(
.equalTo(OutgoingGossipingRequestEntityFields.TYPE_STR, GossipRequestType.SECRET.name)
}, { entity ->
entity.toOutgoingGossipingRequest() as? OutgoingSecretRequest
}).filterNotNull()
})
.filterNotNull()
}
override fun getCrossSigningInfo(userId: String): MXCrossSigningInfo? {

View file

@ -66,7 +66,11 @@ internal open class OutgoingGossipingRequestEntity(
companion object {
private val recipientsDataMapper: JsonAdapter<Map<String, List<String>>> =
MoshiProvider.providesMoshi().adapter<Map<String, List<String>>>(Types.newParameterizedType(Map::class.java, String::class.java, List::class.java))
MoshiProvider
.providesMoshi()
.adapter<Map<String, List<String>>>(
Types.newParameterizedType(Map::class.java, String::class.java, List::class.java)
)
}
fun toOutgoingGossipingRequest(): OutgoingGossipingRequest {