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

Rewrite base45 encoding/decoding, delete vaccination certificates with malformed base45 (Community) EXPOSUREAPP-10556 #4356

Closed
wants to merge 15 commits into from

Conversation

floscher
Copy link

@floscher floscher commented Nov 10, 2021

Description

A while ago I wrote a Kotlin multiplatform (Java/JS) base45 encoder, I adapted it a bit for this project and this PR proposes to use that for base45 encoding/decoding, in case you would like to use that. It was built with the goal to produce the same results as the encoder you currently use, but developed from scratch independently.

It's more compact and in my opinion more readable and as far as I can see it also takes edge cases into account that were fixed e.g. in #4341 for the currently used encoder.


Internal Tracking ID: EXPOSUREAPP-10556

@floscher floscher requested a review from a team November 10, 2021 07:45
@mtwalli mtwalli added the community Tag issues created by community members label Nov 10, 2021
@mtwalli mtwalli changed the title Base45 encoding/decoding Base45 encoding/decoding (Community) Nov 10, 2021
@mtwalli mtwalli added this to the 2.13.0 milestone Nov 10, 2021
…xceptions

This should allow easier tracking, where handling of decoding errors is needed, because exceptions are unchecked and might not be catched everywhere.
…lure value instead of thrown exceptions)

The main part of the change is, that in the VaccinationContainer the contents of the certificate are optional (filled only when decoding was successful).
Only when the container is converted `toVaccinationCertificate()` in the `VaccinationCertificate` those fields are always present.

This change makes it so that vaccination certificates with invalid Base45 are silently removed, if they were imported in an earlier version of the app.
@floscher
Copy link
Author

The PR is now updated to no longer have merge conflicts.

Also it now also addresses #4368 in a slightly different way. The decoder now does not throw exceptions, but returns an object of type DecodingFailure when decoding fails. This should help prevent crashes caused by uncatched exceptions.

This also made more changes necessary, especially to VaccinationContainer, where the contents of the certificate are nullable (in case of decoding failure).

For now vaccination certificates with malformed Base45 that were imported in a previous version are silently deleted and no longer displayed. I'd prefer if they were just marked as invalid, but for now it was easier to just simply drop them.

@floscher floscher changed the title Base45 encoding/decoding (Community) Rewrite base45 encoding/decoding, delete vaccination certificates with malformed base45 (Community) Nov 12, 2021
@dsarkar dsarkar added the mirrored-to-jira This item is also tracked internally in JIRA label Nov 12, 2021
@dsarkar
Copy link
Member

dsarkar commented Nov 12, 2021

@floscher Thanks. Internal Tracking ID: EXPOSUREAPP-10556

@dsarkar dsarkar changed the title Rewrite base45 encoding/decoding, delete vaccination certificates with malformed base45 (Community) Rewrite base45 encoding/decoding, delete vaccination certificates with malformed base45 (Community) EXPOSUREAPP-10556 Nov 12, 2021
@floscher
Copy link
Author

Note: I noticed that these edge cases are currently not addressed in this PR:
https://github.com/ehn-dcc-development/hcert-kotlin/blob/af2aa4da2288548258ee2fe8c0a987c288438ec8/src/commonMain/kotlin/ehn/techiop/hcert/kotlin/chain/common/Base45Encoder.kt#L55-L56

Will add a commit fixing them later, when I have time again.

@floscher
Copy link
Author

Ok, now the decoder should recognize these edge cases too, where three characters in base45 are too big to fit into two bytes, or when two characters in base45 are too big to fit into one byte.

And I also added the suggestion from #4341 (comment)

As suggested here: corona-warn-app#4341 (comment)

I also split the certificate into the first part that should decode fine and the next part that was appended, hoping the decoder would discard that second part.
…ig to fit into two bytes or one byte respectively
@floscher floscher changed the base branch from release/2.13.x to release/2.14.x November 15, 2021 12:32
@davidlindercwa
Copy link

Thanks a lot for submitting this, and apologies for the delayed response! We'll be looking at it as soon as we can.

@marcauberer marcauberer modified the milestones: 2.13.0, 2.14.0 Nov 19, 2021
@chiljamgossow
Copy link
Contributor

chiljamgossow commented Nov 24, 2021

@floscher Thank you very much for your contribution. We appreciate the time effort you have put into this.
We are required to follow the reference implementation provided by the EU and therefore cannot include your PR.
So I kindly ask you to close the PR.

@floscher floscher closed this Nov 25, 2021
@vaubaehn
Copy link
Contributor

vaubaehn commented Nov 25, 2021

That's sad, indeed. @chiljamgossow & @mtwalli But could you consider to replace the certificate for the unit test like suggested in #4341 (comment) , or is the cert/unit test also part of the EU reference implementation?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community Tag issues created by community members mirrored-to-jira This item is also tracked internally in JIRA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants