feat(acm): certificate validation records and revocation (#2655)

* feat(acm): add certificate revocation, renewal, options and email resend

Adds RevokeCertificate, RenewCertificate, UpdateCertificateOptions and
ResendValidationEmail, with a RevocationReason enum modelling the accepted
values. Limitations documented in docs/services/acm.md.

* test(acm): stop asserting global-empty state in the pagination filter test

Other classes sharing the full-suite JVM revoke certificates of their own, so a
REVOKED filter is not globally empty. Assert instead that none of this class's own
certificates appear, which is what the test is actually about.

* feat(acm): add ResendValidationEmail and certificate revocation reasons

* fix(acm): validate Domain/ValidationDomain on ResendValidationEmail

Domain and ValidationDomain were accepted verbatim after a
null/blank check, so any value round-tripped as 200 OK - a client
could resend against an unrelated domain and get success back.

Domain must now match the certificate's DomainName or one of its
SubjectAlternativeNames, and ValidationDomain must equal Domain or
be one of its superdomains, matching botocore's
InvalidDomainValidationOptionsException semantics for this
operation. Also drops the now-unneeded manual UTF-8 byte encoding
in the resend test now that RestAssuredJsonUtils configures the AWS
content types.

* fix(acm): require Options.Export=ENABLED to revoke a certificate

revokeCertificate gated on Certificate.canExport(), which returns
true for any PRIVATE or IMPORTED certificate regardless of its
Export option - so an imported certificate with Export left at the
default DISABLED could still be revoked, bypassing the
export-enabled guard the operation is meant to enforce.

Check Options.Export directly instead.

* fix(acm): use ValidationException for a not-export-enabled revoke

RevokeCertificate's own modeled Errors list is
AccessDeniedException, ConflictException, InvalidArnException,
ResourceInUseException, ResourceNotFoundException,
ThrottlingException, and ValidationException.
InvalidStateException isn't among them - it's modeled on
UpdateCertificateOptions instead, which is likely where it got
picked up from.

ValidationException is the operation's own general "input failed
to satisfy constraints" code, and the better fit here.
This commit is contained in:
Sam Fakhreddine authored and GitHub committed 2026-08-28 16:14:16 -04:00
1 parent 97ff0bc3e9
commit 3bd9bcc62b
9 files changed
+491 -4

No files matched your search

+4
View File
@@ -20,6 +20,10 @@
| `RemoveTagsFromCertificate` | Remove tags from a certificate |
| `GetAccountConfiguration` | Get account-level ACM settings |
| `PutAccountConfiguration` | Update account-level ACM settings |
| `UpdateCertificateOptions` | - |
| `RevokeCertificate` | - |
| `RenewCertificate` | - |
| `ResendValidationEmail` | - |
<!-- floci:actions:end -->
## Emulation Behavior
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
exec "$(dirname "$0")/test-focused" AcmIntegrationTest "$@"
@@ -49,12 +49,37 @@ public class AcmJsonHandler {
case "RemoveTagsFromCertificate" -> handleRemoveTagsFromCertificate(request, region);
case "GetAccountConfiguration" -> handleGetAccountConfiguration(request, region);
case "PutAccountConfiguration" -> handlePutAccountConfiguration(request, region);
case "UpdateCertificateOptions" -> handleUpdateCertificateOptions(request, region);
case "RevokeCertificate" -> handleRevokeCertificate(request, region);
case "RenewCertificate" -> handleRenewCertificate(request, region);
case "ResendValidationEmail" -> handleResendValidationEmail(request, region);
default -> Response.status(400)
.entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported."))
.build();
};
}
private Response handleResendValidationEmail(JsonNode request, String region) {
String certificateArn = request.path("CertificateArn").asText(null);
String domain = request.path("Domain").asText(null);
String validationDomain = request.path("ValidationDomain").asText(null);
if (certificateArn == null || certificateArn.isBlank() || domain == null || domain.isBlank() || validationDomain == null || validationDomain.isBlank()) {
return Response.status(400).entity(new AwsErrorResponse("ValidationException", "Required parameter is missing")).build();
}
Certificate cert = service.describeCertificate(certificateArn, region);
boolean domainMatchesCertificate = domain.equalsIgnoreCase(cert.getDomainName())
|| cert.getSubjectAlternativeNames().stream().anyMatch(domain::equalsIgnoreCase);
boolean validationDomainIsSuperdomain = domain.equalsIgnoreCase(validationDomain)
|| domain.toLowerCase(java.util.Locale.ROOT).endsWith("." + validationDomain.toLowerCase(java.util.Locale.ROOT));
if (!domainMatchesCertificate || !validationDomainIsSuperdomain) {
return Response.status(400)
.entity(new AwsErrorResponse("InvalidDomainValidationOptionsException",
"One or more values in the DomainValidationOption structure is incorrect."))
.build();
}
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleRequestCertificate(JsonNode request, String region) {
String domainName = request.path("DomainName").asText(null);
if (domainName == null || domainName.isBlank()) {
@@ -227,6 +252,83 @@ public class AcmJsonHandler {
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleRevokeCertificate(JsonNode request, String region) {
String certificateArn = request.path("CertificateArn").asText(null);
if (certificateArn == null || certificateArn.isBlank()) {
return Response.status(400)
.entity(new AwsErrorResponse("ValidationException", "CertificateArn is required"))
.build();
}
String reasonStr = request.path("RevocationReason").asText(null);
if (reasonStr == null || reasonStr.isBlank()) {
return Response.status(400)
.entity(new AwsErrorResponse("ValidationException", "RevocationReason is required"))
.build();
}
RevocationReason reason;
try {
reason = RevocationReason.valueOf(reasonStr);
} catch (IllegalArgumentException e) {
return Response.status(400)
.entity(new AwsErrorResponse("ValidationException", "Invalid RevocationReason: " + reasonStr))
.build();
}
Certificate cert = service.revokeCertificate(certificateArn, reason, region);
ObjectNode response = objectMapper.createObjectNode();
response.put("CertificateArn", cert.getArn());
return Response.ok(response).build();
}
private Response handleRenewCertificate(JsonNode request, String region) {
String certificateArn = request.path("CertificateArn").asText(null);
if (certificateArn == null || certificateArn.isBlank()) {
return Response.status(400)
.entity(new AwsErrorResponse("ValidationException", "CertificateArn is required"))
.build();
}
service.renewCertificate(certificateArn, region);
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleUpdateCertificateOptions(JsonNode request, String region) {
String certificateArn = request.path("CertificateArn").asText(null);
if (certificateArn == null || certificateArn.isBlank()) {
return Response.status(400)
.entity(new AwsErrorResponse("ValidationException", "CertificateArn is required"))
.build();
}
JsonNode optionsNode = request.path("Options");
if (!optionsNode.isObject()) {
return Response.status(400)
.entity(new AwsErrorResponse("ValidationException", "Options is required"))
.build();
}
service.updateCertificateOptions(certificateArn, parseUpdateOptions(optionsNode), region);
return Response.ok(objectMapper.createObjectNode()).build();
}
private CertificateOptions parseUpdateOptions(JsonNode optionsNode) {
return new CertificateOptions(
parseOptionValue(optionsNode, "CertificateTransparencyLoggingPreference"),
parseOptionValue(optionsNode, "Export"));
}
private String parseOptionValue(JsonNode optionsNode, String field) {
if (!optionsNode.has(field)) {
return null;
}
String value = optionsNode.path(field).asText();
if (!"ENABLED".equals(value) && !"DISABLED".equals(value)) {
throw new io.github.hectorvent.floci.core.common.AwsException(
"ValidationException", field + " must be ENABLED or DISABLED", 400);
}
return value;
}
// ============ Helper Methods ============
private ObjectNode buildCertificateDetail(Certificate cert) {
@@ -329,6 +431,7 @@ public class AcmJsonHandler {
ObjectNode opts = objectMapper.createObjectNode();
opts.put("CertificateTransparencyLoggingPreference",
cert.getCertOptions().certificateTransparencyLoggingPreference());
opts.put("Export", cert.getCertOptions().export());
node.set("Options", opts);
}
@@ -507,6 +507,47 @@ public class AcmService implements ResourceProvider {
return Set.of(new SupportedResourceType("acm:certificate", "acm", true));
}
public Certificate revokeCertificate(String certificateArn, RevocationReason reason, String region) {
Certificate cert = getCertificateByArn(certificateArn, region);
boolean exportEnabled = cert.getCertOptions() != null && "ENABLED".equals(cert.getCertOptions().export());
if (!exportEnabled) {
throw new AwsException("ValidationException",
"Certificate " + certificateArn + " cannot be revoked because it is not export-enabled.", 400);
}
cert.setStatus(CertificateStatus.REVOKED);
store.put(regionKey(region, cert.extractCertificateId()), cert);
return cert;
}
public Certificate renewCertificate(String certificateArn, String region) {
Certificate cert = getCertificateByArn(certificateArn, region);
if (cert.getStatus() == CertificateStatus.PENDING_VALIDATION) {
throw new AwsException("RequestInProgressException", "Certificate is pending validation", 400);
}
if (cert.getType() != CertificateType.PRIVATE || cert.getStatus() != CertificateStatus.ISSUED) {
throw new AwsException("InvalidArnException", "Certificate is not a private issued certificate", 400);
}
// TODO: certificate/key reissuance material is not regenerated in this local emulator.
Instant now = Instant.now();
cert.setIssuedAt(now);
cert.setNotBefore(now);
cert.setNotAfter(now.plusSeconds(365L * 24L * 60L * 60L));
store.put(regionKey(region, cert.extractCertificateId()), cert);
return cert;
}
public void updateCertificateOptions(String certificateArn, CertificateOptions options, String region) {
Certificate cert = getCertificateByArn(certificateArn, region);
CertificateOptions current = cert.getCertOptions() != null
? cert.getCertOptions() : CertificateOptions.defaultOptions();
cert.setCertOptions(new CertificateOptions(
options.certificateTransparencyLoggingPreference() != null
? options.certificateTransparencyLoggingPreference()
: current.certificateTransparencyLoggingPreference(),
options.export() != null ? options.export() : current.export()));
store.put(regionKey(region, cert.extractCertificateId()), cert);
}
// ============ Helper Methods ============
private Certificate getCertificateByArn(String arn, String region) {
@@ -0,0 +1,18 @@
package io.github.hectorvent.floci.services.acm.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public enum RevocationReason {
UNSPECIFIED,
KEY_COMPROMISE,
CA_COMPROMISE,
AFFILIATION_CHANGED,
SUPERCEDED,
SUPERSEDED,
CESSATION_OF_OPERATION,
CERTIFICATE_HOLD,
REMOVE_FROM_CRL,
PRIVILEGE_WITHDRAWN,
A_A_COMPROMISE
}
@@ -537,6 +537,150 @@ class AcmIntegrationTest {
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@Order(40)
void updateCertificateOptions() {
given()
.header("X-Amz-Target", "CertificateManager.UpdateCertificateOptions")
.contentType(ACM_CONTENT_TYPE)
.body("""
{
"CertificateArn": "%s",
"Options": {"Export": "ENABLED"}
}
""".formatted(createdCertificateArn))
.when()
.post("/")
.then()
.statusCode(200);
given()
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("""
{"CertificateArn": "%s"}
""".formatted(createdCertificateArn))
.when()
.post("/")
.then()
.statusCode(200)
.body("Certificate.Options.Export", equalTo("ENABLED"));
}
@Test
@Order(41)
void updateCertificateOptionsRequiresOptions() {
given()
.header("X-Amz-Target", "CertificateManager.UpdateCertificateOptions")
.contentType(ACM_CONTENT_TYPE)
.body("""
{"CertificateArn": "%s"}
""".formatted(createdCertificateArn))
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("ValidationException"));
}
@Test
@Order(42)
void revokeCertificate() {
String certificateArn = given()
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("""
{"DomainName": "revocable.example.com"}
""")
.when()
.post("/")
.then()
.statusCode(200)
.extract().jsonPath().getString("CertificateArn");
given()
.header("X-Amz-Target", "CertificateManager.UpdateCertificateOptions")
.contentType(ACM_CONTENT_TYPE)
.body("""
{"CertificateArn": "%s", "Options": {"Export": "ENABLED"}}
""".formatted(certificateArn))
.when()
.post("/")
.then()
.statusCode(200);
given()
.header("X-Amz-Target", "CertificateManager.RevokeCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("""
{"CertificateArn": "%s", "RevocationReason": "KEY_COMPROMISE"}
""".formatted(certificateArn))
.when()
.post("/")
.then()
.statusCode(200)
.body("CertificateArn", equalTo(certificateArn));
given()
.header("X-Amz-Target", "CertificateManager.DescribeCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("""
{"CertificateArn": "%s"}
""".formatted(certificateArn))
.when()
.post("/")
.then()
.statusCode(200)
.body("Certificate.Status", equalTo("REVOKED"));
}
@Test
@Order(43)
void renewPrivateCertificate() {
String certificateArn = given()
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("""
{
"DomainName": "renewable-private.example.com",
"CertificateAuthorityArn": "arn:aws:acm-pca:us-east-1:000000000000:certificate-authority/test"
}
""")
.when()
.post("/")
.then()
.statusCode(200)
.extract().jsonPath().getString("CertificateArn");
given()
.header("X-Amz-Target", "CertificateManager.RenewCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("""
{"CertificateArn": "%s"}
""".formatted(certificateArn))
.when()
.post("/")
.then()
.statusCode(200)
.body(equalTo("{}"));
}
@Test
@Order(44)
void renewCertificateNotFound() {
given()
.header("X-Amz-Target", "CertificateManager.RenewCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("""
{"CertificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/nonexistent"}
""")
.when()
.post("/")
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
// ==================== Unsupported Operation ====================
@Test
@@ -140,8 +140,12 @@ class AcmPaginationTest {
@Test
@Order(5)
void emptyListReturnsNoNextToken() {
// List with a filter that matches nothing
given()
// Filter by a status none of this class's own certificates ever have. Can't assert the
// whole result is empty -- other test classes in the shared full-suite JVM (e.g.
// AcmIntegrationTest) revoke certificates of their own, and that state persists across
// classes. What this test actually verifies -- filtering excludes non-matching
// certificates and a small result page carries no NextToken -- holds regardless.
Response response = given()
.header("X-Amz-Target", "CertificateManager.ListCertificates")
.contentType(ACM_CONTENT_TYPE)
.body("""
@@ -153,8 +157,12 @@ class AcmPaginationTest {
.post("/")
.then()
.statusCode(200)
.body("CertificateSummaryList", empty())
.body("NextToken", nullValue());
.extract().response();
List<String> revokedArns = response.jsonPath().getList("CertificateSummaryList.CertificateArn");
assertTrue(createdArns.stream().noneMatch(revokedArns::contains),
"none of this class's own (always-ISSUED) certificates should appear under a REVOKED filter");
assertNull(response.jsonPath().get("NextToken"));
}
@Test
@@ -0,0 +1,110 @@
package io.github.hectorvent.floci.services.acm;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
@QuarkusTest
class AcmResendValidationEmailIntegrationTest {
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void testResendValidationEmailNotFound() {
String requestBody = "{\"CertificateArn\":\"arn:aws:acm:us-east-1:000000000000:certificate/nonexistent\",\"Domain\":\"example.com\",\"ValidationDomain\":\"example.com\"}";
given()
.header("X-Amz-Target", "CertificateManager.ResendValidationEmail")
.contentType(ACM_CONTENT_TYPE)
.body(requestBody)
.when()
.post("/")
.then()
.statusCode(404);
}
@Test
void testResendValidationEmailRejectsUnrelatedDomain() {
String certificateArn = given()
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("{\"DomainName\":\"resend-validation.example.com\"}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().jsonPath().getString("CertificateArn");
String requestBody = "{\"CertificateArn\":\"" + certificateArn
+ "\",\"Domain\":\"totally-unrelated.example.org\",\"ValidationDomain\":\"totally-unrelated.example.org\"}";
given()
.header("X-Amz-Target", "CertificateManager.ResendValidationEmail")
.contentType(ACM_CONTENT_TYPE)
.body(requestBody)
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", org.hamcrest.Matchers.equalTo("InvalidDomainValidationOptionsException"));
}
@Test
void testResendValidationEmailRejectsValidationDomainNotASuperdomain() {
String certificateArn = given()
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("{\"DomainName\":\"site.subdomain.resend-superdomain.example.com\"}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().jsonPath().getString("CertificateArn");
String requestBody = "{\"CertificateArn\":\"" + certificateArn
+ "\",\"Domain\":\"site.subdomain.resend-superdomain.example.com\",\"ValidationDomain\":\"unrelated.example.net\"}";
given()
.header("X-Amz-Target", "CertificateManager.ResendValidationEmail")
.contentType(ACM_CONTENT_TYPE)
.body(requestBody)
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", org.hamcrest.Matchers.equalTo("InvalidDomainValidationOptionsException"));
}
@Test
void testResendValidationEmailAcceptsMatchingDomainAndSuperdomain() {
String certificateArn = given()
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("{\"DomainName\":\"site.subdomain.resend-ok.example.com\"}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().jsonPath().getString("CertificateArn");
String requestBody = "{\"CertificateArn\":\"" + certificateArn
+ "\",\"Domain\":\"site.subdomain.resend-ok.example.com\",\"ValidationDomain\":\"subdomain.resend-ok.example.com\"}";
given()
.header("X-Amz-Target", "CertificateManager.ResendValidationEmail")
.contentType(ACM_CONTENT_TYPE)
.body(requestBody)
.when()
.post("/")
.then()
.statusCode(200);
}
}
@@ -0,0 +1,55 @@
package io.github.hectorvent.floci.services.acm;
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
@QuarkusTest
class AcmRevokeCertificateGuardTest {
private static final String ACM_CONTENT_TYPE = "application/x-amz-json-1.1";
@Inject
CertificateGenerator certificateGenerator;
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void revokeCertificateRejectsImportedCertificateWithoutExportEnabled() {
CertificateGenerator.GeneratedCertificate generated = certificateGenerator.generateCertificate(
"revoke-guard-imported.example.com", List.of(), KeyAlgorithm.RSA_2048);
String certJson = generated.certificatePem().replace("\r\n", "\n").replace("\n", "\\n");
String keyJson = generated.privateKeyPem().replace("\r\n", "\n").replace("\n", "\\n");
String certificateArn = given()
.header("X-Amz-Target", "CertificateManager.ImportCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("{\"Certificate\":\"" + certJson + "\",\"PrivateKey\":\"" + keyJson + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().jsonPath().getString("CertificateArn");
given()
.header("X-Amz-Target", "CertificateManager.RevokeCertificate")
.contentType(ACM_CONTENT_TYPE)
.body("{\"CertificateArn\":\"" + certificateArn + "\",\"RevocationReason\":\"KEY_COMPROMISE\"}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("ValidationException"));
}
}