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

DOB hash calculation & wiring (EXPOSUREAPP-7488, EXPOSUREAPP-7509) #3317

Merged
merged 15 commits into from Jun 1, 2021

Conversation

d4rken
Copy link
Member

@d4rken d4rken commented May 28, 2021

  • Adds date of birth hash calculation for PCR test registration
  • Wires up date of birth hash to be passed from to verification server (UI test registration request -> corona test repo -> test processor -> playbook -> server -> api)
  • Extends verification server API with new attribute and adjusts request padding calculation

@d4rken d4rken added the maintainers Tag pull requests created by maintainers label May 28, 2021
@d4rken d4rken added this to the 2.4.0 milestone May 28, 2021
@d4rken d4rken changed the base branch from release/2.4.x to feature/7487-dgc-properties-for-tests May 28, 2021 11:10
mtwalli
mtwalli previously approved these changes May 28, 2021
@mtwalli mtwalli self-assigned this May 28, 2021
Base automatically changed from feature/7487-dgc-properties-for-tests to release/2.4.x May 28, 2021 13:21
Some refactoring to make it less complicated to adjust for future changes.
# Conflicts:
#	Corona-Warn-App/src/main/java/de/rki/coronawarnapp/coronatest/type/pcr/PCRProcessor.kt
@d4rken d4rken changed the title DOB hash calculation & wiring (EXPOSUREAPP-7488) DOB hash calculation & wiring (EXPOSUREAPP-7488, EXPOSUREAPP-7509) May 31, 2021
@SerializedName("requestPadding") val requestPadding: String? = null
@SerializedName("keyType") val keyType: VerificationKeyType,
@SerializedName("key") val key: String,
@SerializedName("keyDob") val dateOfBirthKey: String? = null,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new optional attribute

Comment on lines +6 to +10
@SerializedName("GUID")
GUID,

@SerializedName("TELETAN")
TELETAN;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We previously just relied on the enums never being renamed or obfuscated, this was a bit too fragile for my taste.

Comment on lines +187 to +212
/**
* The specific sizes are not important, but all requests should be padded up to the same size.
* Pick a total size that is guaranteed to be above or equal to the maximum size a request can be.
*/
// `"requestPadding":""`
private const val BODY_SIZE_PADDING_OVERHEAD = 19 //

// `{}` json brackets
private const val BODY_SIZE_OVERHEAD = BODY_SIZE_PADDING_OVERHEAD + 2
private const val BODY_SIZE_EXPECTED = 250

/**
* The header itself is larger.
* We care about the header fields we set that are request specific.
* We don't need to pad for device specific fields set by OK http.
*/
// `POST /version/v1/registrationToken` -> 34 (longest method + url atm) use 64 to have a buffer
private const val HEADER_SIZE_LONGEST_METHOD = 34

const val PADDING_LENGTH_HEADER_REGISTRATION_TOKEN = 0
const val PADDING_LENGTH_BODY_REGISTRATION_TOKEN_TELETAN = 51 + VERIFICATION_BODY_FILL
const val PADDING_LENGTH_BODY_REGISTRATION_TOKEN_GUID = 0 + VERIFICATION_BODY_FILL
// `cwa-fake 0\n` -> 12
private const val HEADER_SIZE_VAL_FAKE = 12

// padding test result
const val PADDING_LENGTH_HEADER_TEST_RESULT = 7
const val PADDING_LENGTH_BODY_TEST_RESULT = 31 + VERIFICATION_BODY_FILL
// `cwa-header-padding\n` -> 22
private const val HEADER_SIZE_VAL_PADDING = 22
private const val HEADER_SIZE_OVERHEAD = HEADER_SIZE_VAL_FAKE + HEADER_SIZE_VAL_PADDING
private const val HEADER_SIZE_OUR_DATA = HEADER_SIZE_LONGEST_METHOD + HEADER_SIZE_OVERHEAD
Copy link
Member Author

@d4rken d4rken May 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pad the request for plausible deniability, so they all have the same size.
Previously the padding was difficult to understand why a certain value was picked, as we summed up the differences to other API requests, this was a bit too 🧙.
This PR changes the padding calculation to start of with an expected size, and then each API call subtracts its own size, and what we are left with is the required padding.

Comment on lines +16 to +20
val key by lazy {
val dobFormatted = dateOfBirth.toString(DOB_FORMATTER)
val keyHash = "${testGuid}$dobFormatted".toSHA256()
"x${keyHash.substring(1)}"
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date of Birth hash calculation

@d4rken d4rken marked this pull request as ready for review May 31, 2021 11:46
@d4rken d4rken requested a review from a team May 31, 2021 11:46
@chiljamgossow chiljamgossow self-assigned this May 31, 2021
Copy link
Contributor

@kolyaopahle kolyaopahle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the new padding calculations ❤️ tests seem good to me aswell

@sonarcloud
Copy link

sonarcloud bot commented May 31, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

92.9% 92.9% Coverage
0.0% 0.0% Duplication

@d4rken d4rken merged commit d59e678 into release/2.4.x Jun 1, 2021
@d4rken d4rken deleted the feature/7488-dob-hash-calculation branch June 1, 2021 07:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
maintainers Tag pull requests created by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants