Skip to content
Snippets Groups Projects
Unverified Commit df4df8a8 authored by Mohamed Metwalli's avatar Mohamed Metwalli
Browse files

Use SignedTraceLocation

parent 13a58b29
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ class DefaultQRCodeVerifierTest : BaseTestInstrumentation() {
shouldNotThrowAny {
val verifyResult = qrCodeVerifier.verify(ENCODED_EVENT)
verifyResult.apply {
singedTraceLocation.event.description shouldBe "CWA Launch Party"
singedTraceLocation.location.description shouldBe "CWA Launch Party"
verifyResult.isBeforeStartTime(instant) shouldBe false
verifyResult.isAfterEndTime(instant) shouldBe false
}
......@@ -50,7 +50,7 @@ class DefaultQRCodeVerifierTest : BaseTestInstrumentation() {
shouldNotThrowAny {
val verifyResult = qrCodeVerifier.verify(ENCODED_EVENT)
verifyResult.apply {
singedTraceLocation.event.description shouldBe "CWA Launch Party"
singedTraceLocation.location.description shouldBe "CWA Launch Party"
}
verifyResult.isBeforeStartTime(instant) shouldBe true
verifyResult.isAfterEndTime(instant) shouldBe false
......@@ -63,7 +63,7 @@ class DefaultQRCodeVerifierTest : BaseTestInstrumentation() {
shouldNotThrowAny {
val verifyResult = qrCodeVerifier.verify(ENCODED_EVENT)
verifyResult.apply {
singedTraceLocation.event.description shouldBe "CWA Launch Party"
singedTraceLocation.location.description shouldBe "CWA Launch Party"
}
verifyResult.isBeforeStartTime(instant) shouldBe false
verifyResult.isAfterEndTime(instant) shouldBe true
......
......@@ -2,7 +2,7 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin
import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifyResult
import de.rki.coronawarnapp.eventregistration.common.decodeBase32
import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass
import de.rki.coronawarnapp.server.protocols.internal.pt.TraceLocationOuterClass
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.matchers.shouldBe
import org.joda.time.Instant
......@@ -18,7 +18,9 @@ class VerifiedTraceLocationKtTest : BaseTestInstrumentation() {
fun testVerifiedTraceLocationMapping() {
shouldNotThrowAny {
val signedTraceLocation =
SignedEventOuterClass.SignedEvent.parseFrom(DECODED_TRACE_LOCATION.decodeBase32().toByteArray())
TraceLocationOuterClass.SignedTraceLocation.parseFrom(
DECODED_TRACE_LOCATION.decodeBase32().toByteArray()
)
val verifiedTraceLocation =
QRCodeVerifyResult(singedTraceLocation = signedTraceLocation).toVerifiedTraceLocation()
verifiedTraceLocation shouldBe VerifiedTraceLocation(
......
package de.rki.coronawarnapp.eventregistration.checkins.qrcode
import de.rki.coronawarnapp.eventregistration.common.decodeBase32
import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass
import de.rki.coronawarnapp.server.protocols.internal.pt.TraceLocationOuterClass
import de.rki.coronawarnapp.util.security.SignatureValidation
import timber.log.Timber
import javax.inject.Inject
......@@ -10,20 +10,20 @@ class DefaultQRCodeVerifier @Inject constructor(
private val signatureValidation: SignatureValidation
) : QRCodeVerifier {
override suspend fun verify(encodedEvent: String): QRCodeVerifyResult {
Timber.tag(TAG).v("Verifying: %s", encodedEvent)
override suspend fun verify(encodedTraceLocation: String): QRCodeVerifyResult {
Timber.tag(TAG).v("Verifying: %s", encodedTraceLocation)
val signedEvent = try {
SignedEventOuterClass.SignedEvent.parseFrom(encodedEvent.decodeBase32().toByteArray())
val signedTraceLocation = try {
TraceLocationOuterClass.SignedTraceLocation.parseFrom(encodedTraceLocation.decodeBase32().toByteArray())
} catch (e: Exception) {
throw InvalidQRCodeDataException(cause = e, message = "QR-code data could not be parsed.")
}
Timber.tag(TAG).d("Parsed to signed event: %s", signedEvent)
Timber.tag(TAG).d("Parsed to signed location: %s", signedTraceLocation)
val isValid = try {
signatureValidation.hasValidSignature(
signedEvent.event.toByteArray(),
sequenceOf(signedEvent.signature.toByteArray())
signedTraceLocation.location.toByteArray(),
sequenceOf(signedTraceLocation.signature.toByteArray())
)
} catch (e: Exception) {
throw InvalidQRCodeDataException(cause = e, message = "Verification failed.")
......@@ -33,7 +33,7 @@ class DefaultQRCodeVerifier @Inject constructor(
throw InvalidQRCodeSignatureException(message = "QR-code did not match signature.")
}
return QRCodeVerifyResult(signedEvent)
return QRCodeVerifyResult(signedTraceLocation)
}
companion object {
......
package de.rki.coronawarnapp.eventregistration.checkins.qrcode
import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass
import de.rki.coronawarnapp.server.protocols.internal.pt.TraceLocationOuterClass
import de.rki.coronawarnapp.util.TimeAndDateExtensions.seconds
import org.joda.time.Instant
data class QRCodeVerifyResult(
val singedTraceLocation: SignedEventOuterClass.SignedEvent
val singedTraceLocation: TraceLocationOuterClass.SignedTraceLocation
) {
fun isBeforeStartTime(now: Instant): Boolean =
singedTraceLocation.event.start != 0L && singedTraceLocation.event.start > now.seconds
fun isBeforeStartTime(now: Instant): Boolean {
val startTimestamp = singedTraceLocation.location.startTimestamp
return startTimestamp != 0L && startTimestamp > now.seconds
}
fun isAfterEndTime(now: Instant): Boolean =
singedTraceLocation.event.end != 0L && singedTraceLocation.event.end < now.seconds
fun isAfterEndTime(now: Instant): Boolean {
val endTimestamp = singedTraceLocation.location.endTimestamp
return endTimestamp != 0L && endTimestamp < now.seconds
}
}
......@@ -18,11 +18,11 @@ data class VerifiedTraceLocation(
) : Parcelable
fun QRCodeVerifyResult.toVerifiedTraceLocation() =
with(singedTraceLocation.event) {
with(singedTraceLocation.location) {
VerifiedTraceLocation(
guid = guid.toByteArray().toByteString().base64(),
start = start.toInstant(),
end = end.toInstant(),
start = startTimestamp.toInstant(),
end = endTimestamp.toInstant(),
description = description,
defaultCheckInLengthInMinutes = defaultCheckInLengthInMinutes
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment