mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(ses): add the S/MIME identity certificate operations (#5111)
* feat(ses): add the S/MIME identity certificate operations Implement AssociateEmailIdentityCertificate, DisassociateEmailIdentityCertificate and ListEmailIdentityCertificates as a control plane only: associations are stored per region and Floci never signs mail. Request validation, messages and precedence follow real SES: a domain identity needs a FromAddress in the domain or a subdomain, one certificate per address regardless of case, the request members are checked before the identity, and the certificate is not inspected on association. The reported status is Floci's own rule: ACTIVE while the ARN names an issued, unexpired ACM certificate (with its expiry as CertificateExpiryTime), FAILED otherwise. Disassociation is immediate and idempotent, and the list pages through SesListPaging. DeleteEmailIdentity now refuses an identity that still has a certificate associated, as SES does. The v1 DeleteIdentity and DeleteVerifiedEmailAddress share the identities and refuse it too. * fix(ses): apply the documented S/MIME certificate requirements ListEmailIdentityCertificates now reports ACTIVE only when the association meets the SES Developer Guide's S/MIME certificate considerations: the identity is verified, and the certificate is currently valid, has an allowed key (RSA 2048/3072/4096 or EC P-256, P-384, P-521, read from the certificate itself since ACM's stored key algorithm folds other sizes into those) and an RFC822Name SAN equal to the From address, case-sensitively. The docs link that section instead of calling the criteria undocumented. * fix(ses): require an email-signing end-entity S/MIME certificate A probe against SES found requirements beyond the Developer Guide's list: a CA certificate fails even with the right usages, and the certificate needs both a key usage including digitalSignature and an extended key usage including emailProtection, while other usages may sit alongside them. ListEmailIdentityCertificates now applies them, and the docs list them next to the guide's link. * refactor(ses): reuse SesIdentityService's verified-identity check
This commit is contained in:
1 parent
c81290823b
commit
3f6fb371d1
12 files changed
+1382
-4
No files matched your search
+369
@@ -0,0 +1,369 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.CertificateMaterialException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.acm.AcmService;
|
||||
import io.github.hectorvent.floci.services.acm.model.Certificate;
|
||||
import io.github.hectorvent.floci.services.acm.model.CertificateStatus;
|
||||
import io.github.hectorvent.floci.services.ses.model.IdentityCertificate;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.PublicKey;
|
||||
import java.security.cert.CertificateParsingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.interfaces.ECPublicKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.ECGenParameterSpec;
|
||||
import java.security.spec.ECParameterSpec;
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* S/MIME certificate associations of email identities (Associate/Disassociate/ListEmailIdentityCertificates).
|
||||
* Floci stores them and never signs mail. Messages and precedence follow real SES (probed 2026-10-04):
|
||||
* the request members are checked before the identity is looked up, and the certificate itself is
|
||||
* not checked when it is associated. The status applies the SES Developer Guide's certificate
|
||||
* requirements, plus the ones a probe found SES also enforces, when the list is read: an association
|
||||
* is ACTIVE while its identity is verified and its ARN names an issued, currently valid end-entity
|
||||
* certificate in Floci's ACM, with an allowed key, the email-signing key usages and an RFC822Name
|
||||
* SAN equal to the From address, and FAILED otherwise.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesIdentityCertificateService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesIdentityCertificateService.class);
|
||||
|
||||
static final String STATUS_ACTIVE = "ACTIVE";
|
||||
static final String STATUS_FAILED = "FAILED";
|
||||
|
||||
private static final int RFC822_NAME = 1;
|
||||
private static final int DIGITAL_SIGNATURE = 0;
|
||||
private static final String EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4";
|
||||
private static final Set<Integer> RSA_SIGNING_KEY_SIZES = Set.of(2048, 3072, 4096);
|
||||
private static final List<String> EC_SIGNING_CURVES = List.of("secp256r1", "secp384r1", "secp521r1");
|
||||
|
||||
private static final Pattern CERTIFICATE_ARN =
|
||||
Pattern.compile("arn:[\\w+=/,.@-]+:[\\w+=/,.@-]+:[\\w+=/,.@-]*:[0-9]+:certificate/[\\w+=,.@-]+");
|
||||
|
||||
private final StorageBackend<String, IdentityCertificate> store;
|
||||
private final SesIdentityService identityService;
|
||||
private final AcmService acmService;
|
||||
private final Clock clock;
|
||||
// Keeps an association and the identity delete-guard from interleaving, so a delete never
|
||||
// leaves an association behind on a gone identity.
|
||||
private final Object mutationLock = new Object();
|
||||
|
||||
@Inject
|
||||
public SesIdentityCertificateService(StorageFactory storageFactory, SesIdentityService identityService,
|
||||
AcmService acmService, Clock clock) {
|
||||
this(storageFactory.create("ses", "ses-identity-certificates.json",
|
||||
new TypeReference<Map<String, IdentityCertificate>>() {}), identityService, acmService, clock);
|
||||
}
|
||||
|
||||
SesIdentityCertificateService(StorageBackend<String, IdentityCertificate> store,
|
||||
SesIdentityService identityService, AcmService acmService, Clock clock) {
|
||||
this.store = store;
|
||||
this.identityService = identityService;
|
||||
this.acmService = acmService;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
/** A view of an association with its current status, for ListEmailIdentityCertificates. */
|
||||
public record Entry(String fromAddress, String status, String certificateArn, Instant expiryTime) {}
|
||||
|
||||
public void associate(String emailIdentity, String fromAddress, String certificateArn, String region) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
requireIdentityMember(emailIdentity, violations);
|
||||
if (certificateArn == null) {
|
||||
violations.add(violation("certificateArn", "Member must not be null"));
|
||||
} else {
|
||||
if (certificateArn.length() < 20) {
|
||||
violations.add(violation("certificateArn", "Member must have length greater than or equal to 20"));
|
||||
}
|
||||
if (certificateArn.length() > 2048) {
|
||||
violations.add(violation("certificateArn", "Member must have length less than or equal to 2048"));
|
||||
}
|
||||
if (!CERTIFICATE_ARN.matcher(certificateArn).matches()) {
|
||||
violations.add(violation("certificateArn",
|
||||
"Member must satisfy regular expression pattern: " + CERTIFICATE_ARN.pattern()));
|
||||
}
|
||||
}
|
||||
throwViolations(violations);
|
||||
String sender = resolveFromAddress(emailIdentity, fromAddress);
|
||||
synchronized (mutationLock) {
|
||||
requireIdentity(emailIdentity, region);
|
||||
String key = key(region, emailIdentity, sender);
|
||||
IdentityCertificate existing = store.get(key).orElse(null);
|
||||
if (existing != null) {
|
||||
throw new AwsException("AlreadyExistsException",
|
||||
"A certificate is already associated with sender <" + existing.fromAddress()
|
||||
+ "> on identity <" + emailIdentity + ">.", 400);
|
||||
}
|
||||
store.put(key, new IdentityCertificate(emailIdentity, sender, certificateArn, Instant.now(clock)));
|
||||
}
|
||||
LOG.infov("Associated certificate {0} with sender {1} on identity {2} in region {3}",
|
||||
certificateArn, sender, emailIdentity, region);
|
||||
}
|
||||
|
||||
/** Idempotent: an identity with no association for the address is a silent success, as on SES. */
|
||||
public void disassociate(String emailIdentity, String fromAddress, String region) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
requireIdentityMember(emailIdentity, violations);
|
||||
throwViolations(violations);
|
||||
String sender = resolveFromAddress(emailIdentity, fromAddress);
|
||||
synchronized (mutationLock) {
|
||||
requireIdentity(emailIdentity, region);
|
||||
store.delete(key(region, emailIdentity, sender));
|
||||
}
|
||||
LOG.infov("Disassociated certificate from sender {0} on identity {1} in region {2}",
|
||||
sender, emailIdentity, region);
|
||||
}
|
||||
|
||||
public PaginatedResult<Entry> list(String emailIdentity, Integer pageSize, String nextToken, String region) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
requireIdentityMember(emailIdentity, violations);
|
||||
throwViolations(violations);
|
||||
SesListPaging paging = SesListPaging.V2_LIST_EMAIL_IDENTITY_CERTIFICATES;
|
||||
paging.checkRequest(pageSize, nextToken);
|
||||
requireIdentity(emailIdentity, region);
|
||||
List<IdentityCertificate> associations = store.scan(k -> k.startsWith(identityPrefix(region, emailIdentity)));
|
||||
PaginatedResult<IdentityCertificate> page = paging.page(region, emailIdentity, associations,
|
||||
c -> c.fromAddress().toLowerCase(Locale.ROOT), pageSize, nextToken);
|
||||
boolean identityVerified = identityService.isIdentityVerified(emailIdentity, region);
|
||||
List<Entry> entries = page.items().stream().map(c -> entry(c, identityVerified, region)).toList();
|
||||
return new PaginatedResult<>(entries, page.nextToken());
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an identity deletion under the association lock. SES refuses to delete an identity that
|
||||
* still has a certificate associated, whatever its status, and does not cascade.
|
||||
*/
|
||||
public void deleteIdentityGuarded(String emailIdentity, String accountId, String region, Runnable deleteAction) {
|
||||
synchronized (mutationLock) {
|
||||
if (store.keys().stream().anyMatch(k -> k.startsWith(identityPrefix(region, emailIdentity)))) {
|
||||
String identityArn = AwsArnUtils.Arn.of("ses", region, accountId, "identity/" + emailIdentity)
|
||||
.toString();
|
||||
throw new AwsException("BadRequestException",
|
||||
"Cannot delete <" + identityArn + "> because it has certificates associated with it. "
|
||||
+ "Disassociate all certificates and try again.", 400);
|
||||
}
|
||||
deleteAction.run();
|
||||
}
|
||||
}
|
||||
|
||||
private Entry entry(IdentityCertificate association, boolean identityVerified, String region) {
|
||||
Certificate certificate = identityVerified
|
||||
? usableCertificate(association.certificateArn(), association.fromAddress(), region)
|
||||
: null;
|
||||
if (certificate == null) {
|
||||
return new Entry(association.fromAddress(), STATUS_FAILED, association.certificateArn(), null);
|
||||
}
|
||||
return new Entry(association.fromAddress(), STATUS_ACTIVE, association.certificateArn(),
|
||||
certificate.getNotAfter());
|
||||
}
|
||||
|
||||
private Certificate usableCertificate(String certificateArn, String fromAddress, String region) {
|
||||
Certificate certificate;
|
||||
try {
|
||||
certificate = acmService.getCertificate(certificateArn, region);
|
||||
} catch (AwsException e) {
|
||||
if (!"ResourceNotFoundException".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
LOG.debugv("Certificate {0} is not in ACM, so its association is FAILED", certificateArn);
|
||||
return null;
|
||||
}
|
||||
// ACM looks the certificate up by its id alone, so an ARN naming another region or account
|
||||
// could still find one here.
|
||||
if (!certificateArn.equals(certificate.getArn()) || certificate.getStatus() != CertificateStatus.ISSUED) {
|
||||
return null;
|
||||
}
|
||||
Instant now = Instant.now(clock);
|
||||
Instant notBefore = certificate.getNotBefore();
|
||||
Instant notAfter = certificate.getNotAfter();
|
||||
if ((notBefore != null && notBefore.isAfter(now)) || (notAfter != null && !notAfter.isAfter(now))) {
|
||||
return null;
|
||||
}
|
||||
X509Certificate x509 = parse(certificate);
|
||||
if (x509 == null || !isSigningKey(x509.getPublicKey()) || !isEmailSigningCertificate(x509)
|
||||
|| !emailSubjectAlternativeNames(x509).contains(fromAddress)) {
|
||||
return null;
|
||||
}
|
||||
return certificate;
|
||||
}
|
||||
|
||||
private static X509Certificate parse(Certificate certificate) {
|
||||
if (certificate.getCertificateBody() == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Pem.parseCertificate(certificate.getCertificateBody());
|
||||
} catch (CertificateMaterialException e) {
|
||||
LOG.debugv(e, "Certificate {0} could not be parsed, so its association is FAILED", certificate.getArn());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the key itself: ACM's stored KeyAlgorithm folds every RSA size and EC curve it does
|
||||
* not name into RSA_2048 or EC_prime256v1.
|
||||
*/
|
||||
private static boolean isSigningKey(PublicKey key) {
|
||||
if (key instanceof RSAPublicKey rsa) {
|
||||
return RSA_SIGNING_KEY_SIZES.contains(rsa.getModulus().bitLength());
|
||||
}
|
||||
if (key instanceof ECPublicKey ec) {
|
||||
ECParameterSpec params = ec.getParams();
|
||||
for (String curve : EC_SIGNING_CURVES) {
|
||||
ECParameterSpec named = namedCurve(curve);
|
||||
if (named != null && named.getCurve().equals(params.getCurve())
|
||||
&& named.getGenerator().equals(params.getGenerator())
|
||||
&& named.getOrder().equals(params.getOrder())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* What SES requires beyond the Developer Guide's list (probed 2026-10-06): an end-entity
|
||||
* certificate (a CA certificate fails even with both usages) whose key usage includes
|
||||
* digitalSignature and whose extended key usage includes emailProtection. Other usages may sit
|
||||
* alongside them.
|
||||
*/
|
||||
private static boolean isEmailSigningCertificate(X509Certificate x509) {
|
||||
if (x509.getBasicConstraints() != -1) {
|
||||
return false;
|
||||
}
|
||||
boolean[] keyUsage = x509.getKeyUsage();
|
||||
if (keyUsage == null || !keyUsage[DIGITAL_SIGNATURE]) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
List<String> extendedKeyUsage = x509.getExtendedKeyUsage();
|
||||
return extendedKeyUsage != null && extendedKeyUsage.contains(EMAIL_PROTECTION);
|
||||
} catch (CertificateParsingException e) {
|
||||
LOG.debugv(e, "The extended key usage of {0} could not be read",
|
||||
x509.getSubjectX500Principal().getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static ECParameterSpec namedCurve(String name) {
|
||||
try {
|
||||
AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
|
||||
parameters.init(new ECGenParameterSpec(name));
|
||||
return parameters.getParameterSpec(ECParameterSpec.class);
|
||||
} catch (GeneralSecurityException e) {
|
||||
LOG.warnv(e, "EC curve {0} is unavailable, so no key on it counts as a signing key", name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> emailSubjectAlternativeNames(X509Certificate x509) {
|
||||
try {
|
||||
Collection<List<?>> names = x509.getSubjectAlternativeNames();
|
||||
if (names == null) {
|
||||
return List.of();
|
||||
}
|
||||
return names.stream()
|
||||
.filter(name -> Integer.valueOf(RFC822_NAME).equals(name.get(0)))
|
||||
.map(name -> (String) name.get(1))
|
||||
.toList();
|
||||
} catch (CertificateParsingException e) {
|
||||
LOG.debugv(e, "The SAN of {0} could not be read, so it names no sender",
|
||||
x509.getSubjectX500Principal().getName());
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
private void requireIdentity(String emailIdentity, String region) {
|
||||
if (identityService.find(emailIdentity, region).isEmpty()) {
|
||||
throw new AwsException("NotFoundException", "Email identity <" + emailIdentity + "> does not exist.", 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The sender an association is keyed by. A domain identity needs an address in the domain or one
|
||||
* of its subdomains; an email identity defaults to itself. These checks come before the identity
|
||||
* is looked up, so whether the identity is a domain is read from its shape.
|
||||
*/
|
||||
private static String resolveFromAddress(String emailIdentity, String fromAddress) {
|
||||
boolean domain = !emailIdentity.contains("@");
|
||||
if (fromAddress == null) {
|
||||
if (domain) {
|
||||
throw badRequest("FromAddress is required when EmailIdentity is a domain.");
|
||||
}
|
||||
return emailIdentity;
|
||||
}
|
||||
int at = fromAddress.lastIndexOf('@');
|
||||
if (at <= 0 || at == fromAddress.length() - 1 || fromAddress.indexOf('@') != at
|
||||
|| fromAddress.chars().anyMatch(Character::isWhitespace)) {
|
||||
throw badRequest("FromAddress <" + fromAddress + "> is not a valid email address.");
|
||||
}
|
||||
if (domain) {
|
||||
String addressDomain = fromAddress.substring(at + 1).toLowerCase(Locale.ROOT);
|
||||
String identityDomain = emailIdentity.toLowerCase(Locale.ROOT);
|
||||
if (!addressDomain.equals(identityDomain) && !addressDomain.endsWith("." + identityDomain)) {
|
||||
throw badRequest("FromAddress <" + fromAddress + "> does not belong to the domain identity <"
|
||||
+ emailIdentity + ">.");
|
||||
}
|
||||
} else if (!fromAddress.equals(emailIdentity)) {
|
||||
// The model requires an exact match; SES's wording for a mismatch was not probed.
|
||||
throw badRequest("FromAddress <" + fromAddress + "> does not match the email identity <"
|
||||
+ emailIdentity + ">.");
|
||||
}
|
||||
return fromAddress;
|
||||
}
|
||||
|
||||
private static void requireIdentityMember(String emailIdentity, List<String> violations) {
|
||||
if (emailIdentity == null) {
|
||||
violations.add(violation("emailIdentity", "Member must not be null"));
|
||||
} else if (emailIdentity.isEmpty()) {
|
||||
violations.add(violation("emailIdentity", "Member must have length greater than or equal to 1"));
|
||||
}
|
||||
}
|
||||
|
||||
private static String violation(String member, String constraint) {
|
||||
return "Value at '" + member + "' failed to satisfy constraint: " + constraint;
|
||||
}
|
||||
|
||||
private static void throwViolations(List<String> violations) {
|
||||
if (violations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String count = violations.size() == 1 ? "1 validation error detected: "
|
||||
: violations.size() + " validation errors detected: ";
|
||||
throw badRequest(count + String.join("; ", violations));
|
||||
}
|
||||
|
||||
private static AwsException badRequest(String message) {
|
||||
return new AwsException("BadRequestException", message, 400);
|
||||
}
|
||||
|
||||
private static String identityPrefix(String region, String emailIdentity) {
|
||||
return "certificate::" + region + "::" + emailIdentity.length() + "::" + emailIdentity + "::";
|
||||
}
|
||||
|
||||
private static String key(String region, String emailIdentity, String fromAddress) {
|
||||
return identityPrefix(region, emailIdentity) + fromAddress.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,9 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAb
|
||||
* Reads and the single-domain attribute writes call
|
||||
* {@link SesIdentityService} directly; create, delete, the policy operations and the default
|
||||
* configuration set go through the {@link SesService} facade, which checks the configuration set
|
||||
* exists, guards the delete against tenant associations and cascades the identity's policies.
|
||||
* exists, guards the delete against tenant and certificate associations and cascades the
|
||||
* identity's policies. The S/MIME certificate associations ({@code /v2/email/identity/certificates})
|
||||
* call {@link SesIdentityCertificateService}.
|
||||
*/
|
||||
@Path("/v2/email")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@@ -62,14 +64,17 @@ public class SesIdentityController {
|
||||
|
||||
private final SesIdentityService identityService;
|
||||
private final SesService sesService;
|
||||
private final SesIdentityCertificateService certificateService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public SesIdentityController(SesIdentityService identityService, SesService sesService,
|
||||
SesIdentityCertificateService certificateService,
|
||||
RegionResolver regionResolver, ObjectMapper objectMapper) {
|
||||
this.identityService = identityService;
|
||||
this.sesService = sesService;
|
||||
this.certificateService = certificateService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
@@ -451,6 +456,60 @@ public class SesIdentityController {
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/identity/certificates")
|
||||
public Response associateEmailIdentityCertificate(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
try {
|
||||
certificateService.associate(stringMemberOrAbsent(request, "EmailIdentity"),
|
||||
stringMemberOrAbsent(request, "FromAddress"), stringMemberOrAbsent(request, "CertificateArn"),
|
||||
region);
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
}
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/identity/certificates/delete")
|
||||
public Response disassociateEmailIdentityCertificate(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
try {
|
||||
certificateService.disassociate(stringMemberOrAbsent(request, "EmailIdentity"),
|
||||
stringMemberOrAbsent(request, "FromAddress"), region);
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
}
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/identity/certificates/list")
|
||||
public Response listEmailIdentityCertificates(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
PaginatedResult<SesIdentityCertificateService.Entry> page;
|
||||
try {
|
||||
page = certificateService.list(stringMemberOrAbsent(request, "EmailIdentity"),
|
||||
intMemberOrAbsent(request, "PageSize"), stringMemberOrAbsent(request, "NextToken"), region);
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
}
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode certificates = result.putArray("Certificates");
|
||||
for (SesIdentityCertificateService.Entry entry : page.items()) {
|
||||
ObjectNode item = certificates.addObject();
|
||||
item.put("FromAddress", entry.fromAddress());
|
||||
item.put("Status", entry.status());
|
||||
item.put("CertificateArn", entry.certificateArn());
|
||||
putTimestamp(item, "CertificateExpiryTime", entry.expiryTime());
|
||||
}
|
||||
result.put("NextToken", page.nextToken());
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
private ObjectNode buildFullIdentityResponse(Identity identity, String region) {
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
result.put("IdentityType", toV2IdentityType(identity.getIdentityType()));
|
||||
|
||||
@@ -183,7 +183,7 @@ public class SesIdentityService {
|
||||
&& isIdentityVerified(fromEmail.substring(at + 1), region);
|
||||
}
|
||||
|
||||
private boolean isIdentityVerified(String identity, String region) {
|
||||
boolean isIdentityVerified(String identity, String region) {
|
||||
Identity id = getIdentityVerificationAttributes(identity, region);
|
||||
return id != null && "Success".equals(id.getVerificationStatus());
|
||||
}
|
||||
|
||||
@@ -107,6 +107,17 @@ public enum SesListPaging {
|
||||
token -> badRequest("Provided NextToken is invalid"),
|
||||
true),
|
||||
|
||||
/**
|
||||
* ListEmailIdentityCertificates (probed 2026-10-04) answers Smithy's page-size messages; its
|
||||
* default could not be measured and is taken to be the bound.
|
||||
*/
|
||||
V2_LIST_EMAIL_IDENTITY_CERTIFICATES(Namespace.IDENTITY_CERTIFICATE, 1000, 1000,
|
||||
size -> badRequest("1 validation error detected: Value '" + size + "' at 'pageSize' failed to "
|
||||
+ "satisfy constraint: Member must have value "
|
||||
+ (size < 1 ? "greater than or equal to 1" : "less than or equal to 1000")),
|
||||
token -> badRequest("Invalid NextToken."),
|
||||
false),
|
||||
|
||||
/** 12 pools came back whole without a PageSize, so the default is taken to be the bound. */
|
||||
V2_LIST_DEDICATED_IP_POOLS(Namespace.DEDICATED_IP_POOL, 1000, 1000,
|
||||
size -> badRequest("The page size must be in [1, 1000] range."),
|
||||
@@ -145,6 +156,7 @@ public enum SesListPaging {
|
||||
static final String IMPORT_JOB = "import-job";
|
||||
static final String CONTACT_LIST = "contact-list";
|
||||
static final String CONTACT = "contact";
|
||||
static final String IDENTITY_CERTIFICATE = "identity-certificate";
|
||||
static final String DEDICATED_IP_POOL = "dedicated-ip-pool";
|
||||
static final String DEDICATED_IP = "dedicated-ip";
|
||||
static final String SUPPRESSED_DESTINATION = "suppressed-destination";
|
||||
|
||||
@@ -120,6 +120,9 @@ public class SesService {
|
||||
// the tenant record; the facade keeps the associations, the delete cascade, the send-time tenant
|
||||
// gate and the tenant-scoped suppression routing.
|
||||
private final SesTenantService tenantService;
|
||||
// S/MIME certificate associations live in SesIdentityCertificateService, which the v2 controller
|
||||
// calls directly; the facade only reaches it for the identity delete-guard.
|
||||
private final SesIdentityCertificateService certificateService;
|
||||
private final SmtpRelay smtpRelay;
|
||||
private final SesEventPublisher eventPublisher;
|
||||
private final String defaultAccountId;
|
||||
@@ -136,7 +139,7 @@ public class SesService {
|
||||
SesSuppressionService suppressionService, SesDedicatedIpService dedicatedIpService,
|
||||
SesTemplateService templateService, SesSentEmailService sentEmailService,
|
||||
SesTenantService tenantService, SesConfigurationSetService configSetService,
|
||||
SmtpRelay smtpRelay,
|
||||
SesIdentityCertificateService certificateService, SmtpRelay smtpRelay,
|
||||
SesEventPublisher eventPublisher, EmulatorConfig config,
|
||||
RegionResolver regionResolver) {
|
||||
this.identityService = identityService;
|
||||
@@ -149,6 +152,7 @@ public class SesService {
|
||||
this.policyService = policyService;
|
||||
this.cvetService = cvetService;
|
||||
this.tenantService = tenantService;
|
||||
this.certificateService = certificateService;
|
||||
this.smtpRelay = smtpRelay;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.defaultAccountId = config.defaultAccountId();
|
||||
@@ -166,6 +170,7 @@ public class SesService {
|
||||
SesPolicyService policyService,
|
||||
SesCvetService cvetService,
|
||||
SesTenantService tenantService,
|
||||
SesIdentityCertificateService certificateService,
|
||||
SmtpRelay smtpRelay) {
|
||||
this.identityService = identityService;
|
||||
this.sentEmailService = sentEmailService;
|
||||
@@ -177,6 +182,7 @@ public class SesService {
|
||||
this.policyService = policyService;
|
||||
this.cvetService = cvetService;
|
||||
this.tenantService = tenantService;
|
||||
this.certificateService = certificateService;
|
||||
this.smtpRelay = smtpRelay;
|
||||
this.eventPublisher = null;
|
||||
this.defaultAccountId = "000000000000";
|
||||
@@ -201,8 +207,10 @@ public class SesService {
|
||||
if (identityValue == null || identityValue.isBlank()) {
|
||||
return;
|
||||
}
|
||||
String accountId = regionResolver != null ? regionResolver.getAccountId() : defaultAccountId;
|
||||
tenantService.deleteBackingResource(SesTenantService.RESOURCE_TYPE_IDENTITY, identityValue,
|
||||
region, () -> doDeleteIdentity(identityValue, region));
|
||||
region, () -> certificateService.deleteIdentityGuarded(identityValue, accountId, region,
|
||||
() -> doDeleteIdentity(identityValue, region)));
|
||||
}
|
||||
|
||||
private void doDeleteIdentity(String identityValue, String region) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.github.hectorvent.floci.services.ses.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* An S/MIME certificate association created by {@code AssociateEmailIdentityCertificate}.
|
||||
* {@code fromAddress} keeps the spelling the caller gave; SES matches it without regard to case.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public record IdentityCertificate(String emailIdentity,
|
||||
String fromAddress,
|
||||
String certificateArn,
|
||||
Instant associatedTimestamp) {
|
||||
}
|
||||
Reference in new issue
Block a user