Mentions légales du service

Skip to content
Snippets Groups Projects
Commit eec16fbc authored by Deniro StopCovid's avatar Deniro StopCovid
Browse files

Merge branch '10-lossy-conversion' into 'develop'

Resolve "Lossy conversion"

Closes #10

See merge request !15
parents 67519ec9 850a0bce
No related branches found
No related tags found
1 merge request!15Resolve "Lossy conversion"
...@@ -138,10 +138,6 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> { ...@@ -138,10 +138,6 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> {
* Robert Spec Step #5: check that the delta between tA (16 bits) & timeA (32 bits) [truncated to 16bits] is below threshold. * Robert Spec Step #5: check that the delta between tA (16 bits) & timeA (32 bits) [truncated to 16bits] is below threshold.
*/ */
private boolean step5CheckDeltaTaAndTimeABelowThreshold(HelloMessageDetail helloMessageDetail) { private boolean step5CheckDeltaTaAndTimeABelowThreshold(HelloMessageDetail helloMessageDetail) {
// Cast values from int that is unsigned into a signed long
final long timeFromHelloNTPsec = Integer.toUnsignedLong(helloMessageDetail.getTimeFromHelloMessage());
final long timeFromDevice = helloMessageDetail.getTimeCollectedOnDevice();
// Process 16-bit values for sanity check // Process 16-bit values for sanity check
final long timeFromHelloNTPsecAs16bits = castIntegerToLong(helloMessageDetail.getTimeFromHelloMessage(), 2); final long timeFromHelloNTPsecAs16bits = castIntegerToLong(helloMessageDetail.getTimeFromHelloMessage(), 2);
final long timeFromDeviceAs16bits = castLong(helloMessageDetail.getTimeCollectedOnDevice(), 2); final long timeFromDeviceAs16bits = castLong(helloMessageDetail.getTimeCollectedOnDevice(), 2);
...@@ -160,10 +156,10 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> { ...@@ -160,10 +156,10 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> {
/** /**
* Robert Spec Step #6 * Robert Spec Step #6
*/ */
private boolean step6CheckTimeACorrespondsToEpochiA(byte[] epochId, int timeFromDevice) { private boolean step6CheckTimeACorrespondsToEpochiA(byte[] epochId, long timeFromDevice) {
final int epochIdFromEBID = ByteUtils.convertEpoch24bitsToInt(epochId); final int epochIdFromEBID = ByteUtils.convertEpoch24bitsToInt(epochId);
final long tpstStartNTPsec = this.serverConfigurationService.getServiceTimeStart(); final long tpstStartNTPsec = this.serverConfigurationService.getServiceTimeStart();
long epochIdFromMessage = TimeUtils.getNumberOfEpochsBetween(tpstStartNTPsec, Integer.toUnsignedLong(timeFromDevice)); long epochIdFromMessage = TimeUtils.getNumberOfEpochsBetween(tpstStartNTPsec, timeFromDevice);
// Check if epochs match with a limited tolerance // Check if epochs match with a limited tolerance
if (Math.abs(epochIdFromMessage - epochIdFromEBID) > 1) { if (Math.abs(epochIdFromMessage - epochIdFromEBID) > 1) {
...@@ -258,7 +254,7 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> { ...@@ -258,7 +254,7 @@ public class ContactProcessor implements ItemProcessor<Contact, Contact> {
byte[] epochId) { byte[] epochId) {
final long timeFromDevice = helloMessageDetail.getTimeCollectedOnDevice(); final long timeFromDevice = helloMessageDetail.getTimeCollectedOnDevice();
if (!step5CheckDeltaTaAndTimeABelowThreshold(helloMessageDetail) if (!step5CheckDeltaTaAndTimeABelowThreshold(helloMessageDetail)
|| !step6CheckTimeACorrespondsToEpochiA(epochId, (int) timeFromDevice) || !step6CheckTimeACorrespondsToEpochiA(epochId, timeFromDevice)
// Step #7: retrieve from IDTable, KA, the key associated with idA // Step #7: retrieve from IDTable, KA, the key associated with idA
|| !step8VerifyMACIsValid(ebid, encryptedCodeCountry, helloMessageDetail, registration)) { || !step8VerifyMACIsValid(ebid, encryptedCodeCountry, helloMessageDetail, registration)) {
return false; return false;
......
...@@ -214,7 +214,7 @@ public class ContactProcessorTest { ...@@ -214,7 +214,7 @@ public class ContactProcessorTest {
return HelloMessageDetail.builder() return HelloMessageDetail.builder()
.timeFromHelloMessage(timeHello) .timeFromHelloMessage(timeHello)
.timeCollectedOnDevice((long)timeReceived) .timeCollectedOnDevice(Integer.toUnsignedLong(timeReceived))
.rssiCalibrated(rssi) .rssiCalibrated(rssi)
.mac(mac) .mac(mac)
.build(); .build();
...@@ -253,7 +253,8 @@ public class ContactProcessorTest { ...@@ -253,7 +253,8 @@ public class ContactProcessorTest {
// Setup id with an existing score below threshold // Setup id with an existing score below threshold
Registration registrationWithEE = this.registration.get(); Registration registrationWithEE = this.registration.get();
registrationWithEE.setExposedEpochs(Arrays.asList(EpochExposition.builder() registrationWithEE.setExposedEpochs(Arrays.asList(
EpochExposition.builder()
.epochId(previousEpoch) .epochId(previousEpoch)
.expositionScores(Arrays.asList(3.0)) .expositionScores(Arrays.asList(3.0))
.build(), .build(),
......
...@@ -243,7 +243,7 @@ public class RSSICalibratedScoringStrategyTest { ...@@ -243,7 +243,7 @@ public class RSSICalibratedScoringStrategyTest {
.build()); .build());
messages.add(HelloMessageDetail.builder() messages.add(HelloMessageDetail.builder()
.timeCollectedOnDevice(this.randomReferenceEpochStartTime + (900 - 5)) .timeCollectedOnDevice(this.randomReferenceEpochStartTime + (900L - 5L))
.rssiCalibrated(-78) .rssiCalibrated(-78)
.build()); .build());
...@@ -289,7 +289,7 @@ public class RSSICalibratedScoringStrategyTest { ...@@ -289,7 +289,7 @@ public class RSSICalibratedScoringStrategyTest {
public void testScoreRiskOneMessageLateNotAtRisk() { public void testScoreRiskOneMessageLateNotAtRisk() {
List<HelloMessageDetail> messages = new ArrayList<>(); List<HelloMessageDetail> messages = new ArrayList<>();
messages.add(HelloMessageDetail.builder() messages.add(HelloMessageDetail.builder()
.timeCollectedOnDevice(this.randomReferenceEpochStartTime + (900 - 5)) .timeCollectedOnDevice(this.randomReferenceEpochStartTime + (900L - 5L))
.rssiCalibrated(-78) .rssiCalibrated(-78)
.build()); .build());
......
...@@ -14,10 +14,18 @@ import lombok.ToString; ...@@ -14,10 +14,18 @@ import lombok.ToString;
@Builder @Builder
public class HelloMessageDetail { public class HelloMessageDetail {
/**
* WARNING: Since Java does not support unsigned int, we are obligated to store the value coming from the JSON representation
* as a Long even though it should be used as an unsigned int.
*/
@NotNull @NotNull
@ToString.Exclude @ToString.Exclude
private Long timeCollectedOnDevice; private Long timeCollectedOnDevice;
/**
* WARNING: Since Java does not support unsigned short, we are obligated to store the value coming from the JSON
* representation as an Integer even though it should be used as an unsigned short.
*/
@NotNull @NotNull
@ToString.Exclude @ToString.Exclude
private Integer timeFromHelloMessage; private Integer timeFromHelloMessage;
......
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