Skip to content

Commit

Permalink
DT-908: Add all requested signed error scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Niels Thykier <[email protected]>
  • Loading branch information
nt-gt committed Mar 12, 2024
1 parent 1f83f15 commit b8da196
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.check.JsonSchemaValidator;
import org.dcsa.conformance.core.scenario.ConformanceAction;
Expand Down Expand Up @@ -42,10 +41,20 @@ public static LinkedHashMap<String, PintScenarioListBuilder> createModuleScenari
.thenEither(
initiateAndCloseTransferAction(PintResponseCode.RECE).thenEither(
noAction(),
initiateAndCloseTransferAction(PintResponseCode.DUPE)),
retryTransfer(PintResponseCode.DUPE),
manipulateLatestTransactionParameters().then(
retryTransfer(PintResponseCode.DISE)
)),
initiateAndCloseTransferAction(PintResponseCode.RECE, SenderTransmissionClass.VALID_TRANSFER).thenEither(
noAction(),
manipulateLatestTransactionParameters().then(
retryTransfer(PintResponseCode.DISE)
)
),
initiateAndCloseTransferAction(PintResponseCode.BSIG, SenderTransmissionClass.SIGNATURE_ISSUE).then(
initiateAndCloseTransferAction(PintResponseCode.RECE)
)
),
initiateAndCloseTransferAction(PintResponseCode.BENV, SenderTransmissionClass.WRONG_RECIPIENT_PLATFORM)
),
receiverStateSetup(ScenarioClass.INVALID_RECIPIENT).then(
initiateAndCloseTransferAction(PintResponseCode.BENV)
Expand Down Expand Up @@ -99,6 +108,19 @@ private static PintScenarioListBuilder supplyScenarioParameters(int documentCoun
));
}

private static PintScenarioListBuilder manipulateLatestTransactionParameters() {
String sendingPlatform = SENDING_PLATFORM_PARTY_NAME.get();
String receivingPlatform = RECEIVING_PLATFORM_PARTY_NAME.get();
return new PintScenarioListBuilder(
previousAction ->
new ManipulateTransactionsAction(
receivingPlatform,
sendingPlatform,
(PintAction) previousAction
));
}


private static PintScenarioListBuilder receiverStateSetup(ScenarioClass scenarioClass) {
String sendingPlatform = SENDING_PLATFORM_PARTY_NAME.get();
String receivingPlatform = RECEIVING_PLATFORM_PARTY_NAME.get();
Expand Down Expand Up @@ -204,7 +226,7 @@ private static PintScenarioListBuilder retryTransfer(PintResponseCode pintRespon


private static PintScenarioListBuilder initiateAndCloseTransferAction(PintResponseCode signedResponseCode) {
return initiateAndCloseTransferAction(signedResponseCode, SenderTransmissionClass.VALID);
return initiateAndCloseTransferAction(signedResponseCode, SenderTransmissionClass.VALID_ISSUANCE);
}

private static PintScenarioListBuilder initiateAndCloseTransferAction(PintResponseCode signedResponseCode, SenderTransmissionClass senderTransmissionClass) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.dcsa.conformance.standards.eblinterop.action;

import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Getter
@Slf4j
public class ManipulateTransactionsAction extends PintAction {

public ManipulateTransactionsAction(
String platformPartyName,
String carrierPartyName,
PintAction previousAction) {
super(
carrierPartyName,
platformPartyName,
previousAction,
"ManipulateTransaction",
-1);
}

@Override
public ObjectNode asJsonNode() {
var node = super.asJsonNode();
node.set("rsp", getRsp().toJson());
node.set("ssp", getSsp().toJson());
node.set("dsp", getDsp().toJson());
return node;
}

@Override
public boolean isInputRequired() {
return true;
}


@Override
public String getHumanReadablePrompt() {
return ("Manipulate the latest transaction");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public PintAction(
this.dspReference =
new OverwritingReference<>(null, new DynamicScenarioParameters(null, -1, Set.of(), null));
this.rspReference = new OverwritingReference<>(null, new ReceiverScenarioParameters("", "", "", "", ""));
this.sspReference = new OverwritingReference<>(null, new SenderScenarioParameters(null, ""));
this.sspReference = new OverwritingReference<>(null, new SenderScenarioParameters(null, "", ""));
} else {
this.dspReference = new OverwritingReference<>(previousAction.dspReference, null);
this.rspReference = new OverwritingReference<>(previousAction.rspReference, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String getHumanReadablePrompt() {
@Override
public ObjectNode asJsonNode() {
var node = super.asJsonNode()
.put("senderTransmissionClass", SenderTransmissionClass.VALID.name());
.put("senderTransmissionClass", SenderTransmissionClass.VALID_ISSUANCE.name());
node.set("rsp", getRsp().toJson());
node.set("ssp", getSsp().toJson());
node.set("dsp", getDsp().toJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public String getHumanReadablePrompt() {
@Override
public ObjectNode asJsonNode() {
var node = super.asJsonNode()
.put("senderTransmissionClass", SenderTransmissionClass.VALID.name());
.put("senderTransmissionClass", SenderTransmissionClass.VALID_ISSUANCE.name());
node.set("rsp", getRsp().toJson());
node.set("ssp", getSsp().toJson());
node.set("dsp", getDsp().toJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.dcsa.conformance.core.traffic.ConformanceExchange;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.eblinterop.checks.PintChecks;
import org.dcsa.conformance.standards.eblinterop.crypto.PayloadSignerFactory;
import org.dcsa.conformance.standards.eblinterop.crypto.SignatureVerifier;
import org.dcsa.conformance.standards.eblinterop.party.PintRole;

Expand Down Expand Up @@ -62,7 +61,7 @@ public String getHumanReadablePrompt() {
@Override
public ObjectNode asJsonNode() {
var node = super.asJsonNode()
.put("senderTransmissionClass", SenderTransmissionClass.VALID.name());
.put("senderTransmissionClass", SenderTransmissionClass.VALID_ISSUANCE.name());
node.set("rsp", getRsp().toJson());
node.set("ssp", getSsp().toJson());
node.set("dsp", getDsp().toJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public PintRetryTransferAndCloseAction(
receivingPlatform,
previousAction,
"RetryTransfer(%s)".formatted(responseCode.name()),
200
responseCode.getHttpResponseCode()
);
this.responseCode = responseCode;
this.requestSchemaValidator = requestSchemaValidator;
Expand All @@ -60,7 +60,7 @@ public String getHumanReadablePrompt() {
@Override
public ObjectNode asJsonNode() {
var node = super.asJsonNode()
.put("senderTransmissionClass", SenderTransmissionClass.VALID.name());
.put("senderTransmissionClass", SenderTransmissionClass.VALID_ISSUANCE.name());
node.set("rsp", getRsp().toJson());
node.set("ssp", getSsp().toJson());
node.set("dsp", getDsp().toJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.standards.eblinterop.models.ReceiverScenarioParameters;
import org.dcsa.conformance.standards.eblinterop.models.SenderScenarioParameters;

@Getter
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void handlePartyInput(JsonNode partyInput) {
public JsonNode getJsonForHumanReadablePrompt() {
return new SenderScenarioParameters(
"TD reference",
"WAVE",
"-----BEGIN RSA PUBLIC KEY-----\n<YOUR PUBLIC SIGNING KEY HERE>\n-----END RSA PUBLIC KEY-----\n"
).toJson();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.dcsa.conformance.standards.eblinterop.action;

public enum SenderTransmissionClass {
VALID,
VALID_ISSUANCE,
VALID_TRANSFER,
SIGNATURE_ISSUE,
WRONG_RECIPIENT_PLATFORM,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER;
import static org.dcsa.conformance.standards.ebl.checks.EBLChecks.genericTDContentChecks;
import static org.dcsa.conformance.standards.eblinterop.crypto.SignedNodeSupport.parseSignedNode;

import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.nimbusds.jose.Algorithm;
import com.nimbusds.jose.JWSObject;
Expand All @@ -14,6 +16,7 @@
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.ebl.party.TransportDocumentStatus;
import org.dcsa.conformance.standards.eblinterop.action.PintResponseCode;
import org.dcsa.conformance.standards.eblinterop.crypto.Checksums;
import org.dcsa.conformance.standards.eblinterop.crypto.SignatureVerifier;
import org.dcsa.conformance.standards.eblinterop.models.DynamicScenarioParameters;
import org.dcsa.conformance.standards.eblinterop.models.ReceiverScenarioParameters;
Expand Down Expand Up @@ -370,6 +373,40 @@ public static ActionCheck validateInitiateTransferRequest(
)
)
);
jsonContentChecks.add(
JsonAttribute.customValidator(
"Validate transfer chain checksums",
JsonAttribute.path("envelopeTransferChain", (etc, contextPath) -> {
String expectedChecksum = null;
if (!etc.isArray()) {
// Leave that to schema validation
return Set.of();
}
var issues = new LinkedHashSet<String>();
for (int i = 0 ; i < etc.size() ; i++) {
JsonNode entry = etc.path(i);
JsonNode parsed;
try {
parsed = parseSignedNode(entry);
} catch (ParseException | JsonProcessingException e) {
// Signed content + schema validation already takes care of that issue.
continue;
}
var actualChecksum = parsed.path("previousEnvelopeTransferChainEntrySignedContentChecksum").asText(null);
if (!Objects.equals(expectedChecksum, actualChecksum)) {
var path = contextPath + "[" + i + "].previousEnvelopeTransferChainEntrySignedContentChecksum";
issues.add("The checksum in '%s' was '%s' but it should have been '%s' (which is the checksum of the preceding item)".formatted(
path,
actualChecksum,
expectedChecksum
));
}
expectedChecksum = Checksums.sha256(entry.asText());
}
return issues;
})
)
);
return JsonAttribute.contentChecks(
PintRole::isSendingPlatform,
matched,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER;

@With
public record SenderScenarioParameters(String transportDocumentReference, String senderPublicKeyPEM) {
public record SenderScenarioParameters(String transportDocumentReference, String eblPlatform, String senderPublicKeyPEM) {
public ObjectNode toJson() {
return OBJECT_MAPPER
.createObjectNode()
.put("transportDocumentReference", transportDocumentReference)
.put("eblPlatform", eblPlatform)
.put("senderPublicKeyPEM", senderPublicKeyPEM);
}

public static SenderScenarioParameters fromJson(JsonNode jsonNode) {
return new SenderScenarioParameters(
jsonNode.required("transportDocumentReference").asText(),
jsonNode.required("eblPlatform").asText(),
jsonNode.required("senderPublicKeyPEM").asText()
);
}
Expand Down
Loading

0 comments on commit b8da196

Please sign in to comment.