Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix(server:encryption): don't ignore ignoredKeyGroups
Browse files Browse the repository at this point in the history
  • Loading branch information
John Doe committed Feb 3, 2016
1 parent 446f1c4 commit ab5e32b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,23 @@ final class EncryptionExtension(system: ActorSystem) extends Extension {
actionT.value map (_.valueOr(throw _))
}

def checkBox(box: ApiEncryptedBox): Future[Either[(Vector[ApiKeyGroupId], Vector[ApiKeyGroupId]), Map[Int, Vector[(Int, ApiEncryptedBox)]]]] = {
def checkBox(
box: ApiEncryptedBox,
ignoredKeyGroups: Map[Int, Set[Int]]
): Future[Either[(Vector[ApiKeyGroupId], Vector[ApiKeyGroupId]), Map[Int, Vector[(Int, ApiEncryptedBox)]]]] = {
val userChecksFu: Iterable[Future[(Seq[ApiKeyGroupId], Seq[ApiKeyGroupId], Seq[EncryptionKeyGroup])]] =
box.keys.groupBy(_.usersId) map {
case (userId, keys)
db.run(EncryptionKeyGroupRepo.fetch(userId)) map { kgs
// kgs not presented in box

val ignored = ignoredKeyGroups.getOrElse(userId, Set.empty)

val missingKgs = kgs.view
.filterNot(kg keys.exists(_.keyGroupId == kg.id))
.map(kg ApiKeyGroupId(userId, kg.id)).force
.filterNot(kg ignored.contains(kg.id))
.map(kg ApiKeyGroupId(userId, kg.id))
.force

// kgs presented in box but deleted by receiver
val obsKgs = keys.view
Expand All @@ -236,15 +244,15 @@ final class EncryptionExtension(system: ActorSystem) extends Extension {
if (missing.nonEmpty || obs.nonEmpty) Left(missing obs)
else Right(
kgs
.groupBy(_.userId)
.map {
case (userId, ukgs)
(userId,
ukgs map { kg
val keys = box.keys.filter(_.keyGroupId == kg.id)
(kg.authSid.get.value, box.copy(keys = keys))
})
}.toMap
.groupBy(_.userId)
.map {
case (userId, ukgs)
(userId,
ukgs map { kg
val keys = box.keys.filter(_.keyGroupId == kg.id)
(kg.authSid.get.value, box.copy(keys = keys))
})
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ final class EncryptionServiceImpl(implicit system: ActorSystem) extends Encrypti
db.run {
withUserOutPeers(destPeers) {
DBIO.from {
encExt.checkBox(encryptedBox) flatMap {
encExt.checkBox(encryptedBox, ignoredKeyGroups.groupBy(_.userId).mapValues(_.map(_.keyGroupId).toSet)) flatMap {
case Left((missing, obs))
FastFuture.successful(Ok(ResponseSendEncryptedPackage(
seq = None,
Expand Down

0 comments on commit ab5e32b

Please sign in to comment.