diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifierTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifierTest.kt index a87914a5e56a4e4ccb94c878ac7eed68392a3b09..e407a29e92aa85894788d3450a4409b301494068 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifierTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifierTest.kt @@ -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 diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt index 9ae34bda665a12a71ec9920d24a944321967cd26..ebae0addfe652721dfa1646da92285ec07593e1a 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt @@ -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( diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt index e0f2dc582aaa0d511307b5cd752e8ed9c2eb91ec..db0a9559c20c59b0671a9bddb49cbd4dc1eac113 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt @@ -1,7 +1,7 @@ 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 { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifyResult.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifyResult.kt index 99f87f3c26f46851e75635cfabfe4306ccdc1b58..24b3a2430321fbcf9788b8cc5eea8556d2cfcc59 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifyResult.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifyResult.kt @@ -1,15 +1,19 @@ 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 + } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt index b8730e425dc9dc22b1d524f8fb7c9a1560b401c7..b8c61317dba996501964090f76d8caa5774aeb2d 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt @@ -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 )