Skip to content

Commit

Permalink
Merge pull request #12 from corona-warn-app/feat/valueset_signature
Browse files Browse the repository at this point in the history
Added signature for single value sets
  • Loading branch information
mschulte-tsi authored Aug 10, 2021
2 parents c5a61bf + 5794ba3 commit cd78ce1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ public class ValueSetEntity {
@Lob
@Column(name = "raw_data", nullable = false)
String rawData;

@Column(name = "signature", length = 256)
private String signature;
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,24 @@ public ResponseEntity<String> getValueSet(
@RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion,
@Valid @PathVariable("hash") String hash
) {
ResponseEntity<String> responseEntity;

ValueSetEntity vse = valueSetService.getValueSetByHash(hash);

if (vse == null) {
throw new DgcaBusinessRulesResponseException(HttpStatus.NOT_FOUND, "0x001", "Possible reasons: "
+ "The provided hash value is not correct", hash, "");
}

return ResponseEntity.ok(vse.getRawData());
if (vse.getSignature() != null) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set(BusinessRuleController.X_SIGNATURE_HEADER, vse.getSignature());
responseEntity = ResponseEntity.ok().headers(responseHeaders).body(vse.getRawData());
} else {
responseEntity = ResponseEntity.ok(vse.getRawData());
}

return responseEntity;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ValueSetService {
private final ValueSetRepository valueSetRepository;
private final ListSigningService listSigningService;
private final SignedListRepository signedListRepository;
private final Optional<SigningService> signingService;

/**
* Gets list of all value set ids and hashes.
Expand Down Expand Up @@ -119,6 +120,10 @@ public void saveValueSet(String hash, String valueSetName, String valueSetData)
vse.setId(valueSetName);
vse.setRawData(valueSetData);

if (signingService.isPresent()) {
vse.setSignature(signingService.get().computeSignature(vse.getHash()));
}

valueSetRepository.save(vse);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<include file="db/changelog/init_tables.xml"/>
<include file="db/changelog/add_list_table.xml"/>
<include file="db/changelog/add_rule_signature_column.xml"/>
<include file="db/changelog/add_valueset_signature_column.xml"/>
</databaseChangeLog>
15 changes: 15 additions & 0 deletions src/main/resources/db/changelog/add_valueset_signature_column.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<changeSet id="add_valueset_signature_column" author="slaurenz">
<addColumn tableName="valuesets">
<column name="signature" type="VARCHAR(256)">
<constraints nullable="true" />
</column>
</addColumn>
</changeSet>
</databaseChangeLog>

0 comments on commit cd78ce1

Please sign in to comment.