diff --git a/src/test/java/io/floci/aws/services/paymentcryptography/PaymentCryptographyKeyExchangeTest.java b/src/test/java/io/floci/aws/services/paymentcryptography/PaymentCryptographyKeyExchangeTest.java index c606f87bcd..8f13d67437 100644 --- a/src/test/java/io/floci/aws/services/paymentcryptography/PaymentCryptographyKeyExchangeTest.java +++ b/src/test/java/io/floci/aws/services/paymentcryptography/PaymentCryptographyKeyExchangeTest.java @@ -1,6 +1,5 @@ package io.floci.aws.services.paymentcryptography; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import io.floci.aws.core.common.AwsException; @@ -267,7 +266,7 @@ class PaymentCryptographyKeyExchangeTest { PaymentCryptographyKey outgoing = createKey("AES_128", "TR31_K0_KEY_ENCRYPTION_KEY"); Map translated = (Map) service.translateKeyMaterial("us-east-1", - translateRequest(exchange.material(), (String) wrapped.get("KeyMaterial"), outgoing)) + translateRequest(exchange.material(), (String) wrapped.get("KeyMaterial"), outgoing.getKeyId())) .get("WrappedKey"); assertEquals("TR31_KEY_BLOCK", translated.get("WrappedKeyMaterialFormat")); @@ -296,7 +295,7 @@ class PaymentCryptographyKeyExchangeTest { PaymentCryptographyKey outgoing = createKey("AES_128", "TR31_K0_KEY_ENCRYPTION_KEY"); Map translated = (Map) service.translateKeyMaterial("us-east-1", - translateRequest(exchange.material(), (String) wrapped.get("KeyMaterial"), outgoing)) + translateRequest(exchange.material(), (String) wrapped.get("KeyMaterial"), outgoing.getKeyId())) .get("WrappedKey"); String block = (String) translated.get("WrappedKeyMaterial"); @@ -319,7 +318,7 @@ class PaymentCryptographyKeyExchangeTest { AwsException refused = assertThrows(AwsException.class, () -> service.translateKeyMaterial("us-east-1", translateRequest( - exchange.material(), (String) wrapped.get("KeyMaterial"), outgoing))); + exchange.material(), (String) wrapped.get("KeyMaterial"), outgoing.getKeyId()))); assertEquals("ValidationException", refused.getErrorCode()); assertTrue(refused.getMessage().contains("may not leave the service"), refused.getMessage()); @@ -339,7 +338,7 @@ class PaymentCryptographyKeyExchangeTest { AwsException refused = assertThrows(AwsException.class, () -> service.translateKeyMaterial("us-east-1", translateRequest( - material, (String) wrapped.get("KeyMaterial"), outgoing))); + material, (String) wrapped.get("KeyMaterial"), outgoing.getKeyId()))); assertEquals("ValidationException", refused.getErrorCode()); assertTrue(refused.getMessage().contains("at least as strong"), refused.getMessage()); @@ -362,7 +361,7 @@ class PaymentCryptographyKeyExchangeTest { AwsException refused = assertThrows(AwsException.class, () -> service.translateKeyMaterial("us-east-1", - translateRequest(material, incoming, outgoing))); + translateRequest(material, incoming, outgoing.getKeyId()))); assertEquals("ValidationException", refused.getErrorCode()); assertTrue(refused.getMessage().contains("at least as strong"), refused.getMessage()); @@ -384,7 +383,7 @@ class PaymentCryptographyKeyExchangeTest { AwsException refused = assertThrows(AwsException.class, () -> service.translateKeyMaterial("us-east-1", - translateRequest(material, incoming, outgoing))); + translateRequest(material, incoming, outgoing.getKeyId()))); assertEquals("ValidationException", refused.getErrorCode()); assertTrue(refused.getMessage().contains("may not be made of"), refused.getMessage()); @@ -399,7 +398,7 @@ class PaymentCryptographyKeyExchangeTest { "DiffieHellmanTr31KeyBlock", exchange.material(), "", "").get("WrappedKey"); PaymentCryptographyKey outgoing = createKey("AES_128", "TR31_K0_KEY_ENCRYPTION_KEY"); Map request = translateRequest(exchange.material(), - (String) wrapped.get("KeyMaterial"), outgoing); + (String) wrapped.get("KeyMaterial"), outgoing.getKeyId()); request.put("KeyCheckValueAlgorithm", "CMAC"); Map translated = (Map) service.translateKeyMaterial("us-east-1", request) @@ -418,7 +417,7 @@ class PaymentCryptographyKeyExchangeTest { "DiffieHellmanTr31KeyBlock", exchange.material(), "", "").get("WrappedKey"); PaymentCryptographyKey outgoing = createKey("AES_128", "TR31_K0_KEY_ENCRYPTION_KEY"); Map request = translateRequest(exchange.material(), - (String) wrapped.get("KeyMaterial"), outgoing); + (String) wrapped.get("KeyMaterial"), outgoing.getKeyId()); request.put("KeyCheckValueAlgorithm", "ANSI_X9_24"); AwsException refused = assertThrows(AwsException.class, @@ -438,7 +437,7 @@ class PaymentCryptographyKeyExchangeTest { Map wrapped = (Map) service.exportKey("us-east-1", exchange.key().getKeyId(), "DiffieHellmanTr31KeyBlock", exchange.material(), "", "").get("WrappedKey"); PaymentCryptographyKey outgoing = createKey("AES_128", "TR31_K0_KEY_ENCRYPTION_KEY"); - ObjectNode request = (ObjectNode) translateBody(exchange, + ObjectNode request = translateBody(exchange, (String) wrapped.get("KeyMaterial"), outgoing); request.putNull("KeyCheckValueAlgorithm"); @@ -473,7 +472,7 @@ class PaymentCryptographyKeyExchangeTest { PaymentCryptographyKey outgoing = createKey("AES_256", "TR31_K0_KEY_ENCRYPTION_KEY"); Map translated = (Map) service.translateKeyMaterial("us-east-1", - translateRequest(material, incoming, outgoing)).get("WrappedKey"); + translateRequest(material, incoming, outgoing.getKeyId())).get("WrappedKey"); // The block that goes out holds the key that came in, and the check value is the // one the sample computes locally. @@ -491,44 +490,39 @@ class PaymentCryptographyKeyExchangeTest { * * @param material the material of the agreement * @param block the block that comes in - * @param wrappingKey the key the block goes out under + * @param wrappingKeyIdentifier the identifier of the key the block goes out under * @return the request */ private static Map translateRequest(Map material, String block, - PaymentCryptographyKey wrappingKey) { + String wrappingKeyIdentifier) { Map incoming = new LinkedHashMap<>(material); incoming.put("WrappedKeyBlock", block); Map request = new LinkedHashMap<>(); request.put("IncomingKeyMaterial", Map.of("DiffieHellmanTr31KeyBlock", incoming)); request.put("OutgoingKeyMaterial", Map.of( - "Tr31KeyBlock", Map.of("WrappingKeyIdentifier", wrappingKey.getKeyId()))); + "Tr31KeyBlock", Map.of("WrappingKeyIdentifier", wrappingKeyIdentifier))); return request; } /** * The body of a request that translates a block that came in under the agreed key. * - *

The identifiers are the ARNs the model asks for, and the request names no check - * value algorithm. + *

The body is the request of {@link #translateRequest}, and the identifiers in it are + * the ARNs the model asks for, so the request is the one the data plane would read. + * The request names no check value algorithm. * * @param exchange the exchange the two parties made * @param block the block that comes in * @param wrappingKey the key the block goes out under * @return the body of the request */ - private static JsonNode translateBody(Exchange exchange, String block, - PaymentCryptographyKey wrappingKey) { + private static ObjectNode translateBody(Exchange exchange, String block, + PaymentCryptographyKey wrappingKey) { Map material = new LinkedHashMap<>(exchange.material()); material.put("PrivateKeyIdentifier", exchange.agreement().getArn()); material.put("CertificateAuthorityPublicKeyIdentifier", exchange.authority().getArn()); - material.put("WrappedKeyBlock", block); ObjectMapper mapper = new ObjectMapper(); - ObjectNode body = mapper.createObjectNode(); - body.set("IncomingKeyMaterial", mapper.valueToTree(Map.of( - "DiffieHellmanTr31KeyBlock", material))); - body.set("OutgoingKeyMaterial", mapper.valueToTree(Map.of( - "Tr31KeyBlock", Map.of("WrappingKeyIdentifier", wrappingKey.getArn())))); - return body; + return mapper.valueToTree(translateRequest(material, block, wrappingKey.getArn())); } /**