Skip to content

Commit

Permalink
ATL-432: Update Checks If Master Key Revoked (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoKnightIOG authored May 16, 2022
1 parent d866707 commit 40b5452
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ case class UpdateDIDOperation(
}.subflatMap { didKey =>
Either.cond(
didKey.keyUsage == KeyUsage.MasterKey,
didKey.key,
didKey,
StateError.InvalidKeyUsed("master key")
)
}
}.subflatMap { didKey =>
Either.cond(
didKey.revokedOn.isEmpty,
didKey,
StateError.KeyAlreadyRevoked()
)
}.map(_.key)
} yield CorrectnessData(key, Some(lastOperation))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.iohk.atala.prism.node.DataPreparation
import io.iohk.atala.prism.node.DataPreparation.{dummyApplyOperationConfig, dummyLedgerData}
import io.iohk.atala.prism.node.models.{DIDPublicKey, KeyUsage}
import io.iohk.atala.prism.node.operations.CreateDIDOperationSpec.{randomCompressedECKeyData, randomECKeyData}
import io.iohk.atala.prism.node.repositories.daos.PublicKeysDAO
import io.iohk.atala.prism.node.services.BlockProcessingServiceSpec
import io.iohk.atala.prism.protos.node_models
import org.scalatest.EitherValues._
Expand Down Expand Up @@ -234,6 +235,28 @@ class UpdateDIDOperationSpec extends AtalaWithPostgresSpec with ProtoParsingTest
key mustBe masterKeys.getPublicKey
previousOperation mustBe Some(createDidOperation.digest)
}

"fail given master key revoked" in {
createDidOperation.applyState(dummyApplyOperationConfig).transact(database).value.unsafeRunSync()

PublicKeysDAO
.revoke(createDidOperation.id, "master", dummyLedgerData)
.transact(database)
.unsafeRunSync()

val parsedOperation = UpdateDIDOperation
.parse(signedExampleOperation, dummyLedgerData)
.toOption
.value

val result = parsedOperation
.getCorrectnessData("master")
.transact(database)
.value
.unsafeRunSync()

result mustBe Left(StateError.KeyAlreadyRevoked())
}
}

"UpdateDIDOperation.applyState" should {
Expand Down

0 comments on commit 40b5452

Please sign in to comment.